Skip to content

Commit

Permalink
show_units now defaults to True
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Oct 8, 2024
1 parent abe3942 commit c04eccc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
9 changes: 2 additions & 7 deletions festim/exports/derived_quantities/derived_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DerivedQuantities(list):
iterations between each export. If None, the file will be
exported at the last timestep. Defaults to None.
show_units (bool, optional): will show the units of each
derived quantity in the title in export
derived quantity in the title in export. Defaults to True.
Attributes:
filename (str): the filename.
Expand All @@ -45,7 +45,7 @@ def __init__(
filename: str = None,
nb_iterations_between_compute: int = 1,
nb_iterations_between_exports: int = None,
show_units=False,
show_units=True,
) -> None:
# checks that input is list
if len(args) == 0:
Expand Down Expand Up @@ -125,11 +125,6 @@ def make_header(self):
header = ["t(s)"]
for quantity in self:
quantity.show_units = self.show_units
if self.show_units is False:
warnings.warn(
"The current derived_quantities title style will be deprecated in a future release, please use show_units=True instead",
DeprecationWarning,
)
header.append(quantity.title)
return header

Expand Down
2 changes: 1 addition & 1 deletion festim/exports/derived_quantities/derived_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, field) -> None:
self.T = None
self.data = []
self.t = []
self.show_units = False
self.show_units = True

@property
def allowed_meshes(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ class TestMakeHeader:
sph_surface_flux_2 = SurfaceFluxSpherical("T", 6)
ads_h = AdsorbedHydrogen(1)

mesh = f.UnitIntervalMesh(10)
V = f.FunctionSpace(mesh, "P", 1)

def test_simple(self):
"""
Tests that a proper header is made for the output .csv file
when there is only one festim.DerivedQuantity object
"""
my_derv_quant = DerivedQuantities([self.surface_flux_1])

for quantity in my_derv_quant:
quantity.function = f.Function(self.V)

header = my_derv_quant.make_header()

expected_header = ["t(s)", self.surface_flux_1.title]
assert header == expected_header

Expand All @@ -68,6 +76,9 @@ def test_two_quantities(self):
self.tot_surf_1,
]
)
for quantity in my_derv_quant:
quantity.function = f.Function(self.V)

header = my_derv_quant.make_header()
expected_header = ["t(s)", self.surface_flux_1.title, self.tot_surf_1.title]
assert header == expected_header
Expand All @@ -89,6 +100,11 @@ def test_all_quantities(self):
self.ads_h,
]
)

# to compute the units of the quantities they need a function
for quantity in my_derv_quant:
quantity.function = f.Function(self.V)

header = my_derv_quant.make_header()
expected_header = ["t(s)"] + [
self.surface_flux_1.title,
Expand Down

0 comments on commit c04eccc

Please sign in to comment.