Skip to content

Commit

Permalink
Refactor derived quantity titles to include export units
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Oct 8, 2024
1 parent c04eccc commit d31bcb8
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 47 deletions.
12 changes: 8 additions & 4 deletions festim/exports/derived_quantities/average_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ def __init__(self, field, surface) -> None:
def allowed_meshes(self):
return ["cartesian"]

@property
def export_unit(self):
if self.field == "T":
return "K"
else:
return "H m-3"

@property
def title(self):
quantity_title = f"Average {self.field} surface {self.surface}"
if self.show_units:
if self.field == "T":
return quantity_title + " (K)"
else:
return quantity_title + " (H m-3)"
return quantity_title + f" ({self.export_unit})"
else:
return quantity_title

Expand Down
12 changes: 8 additions & 4 deletions festim/exports/derived_quantities/average_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ def __init__(self, field, volume: int) -> None:
def allowed_meshes(self):
return ["cartesian"]

@property
def export_unit(self):
if self.field == "T":
return "K"
else:
return "H m-3"

@property
def title(self):
quantity_title = f"Average {self.field} volume {self.volume}"
if self.show_units:
if self.field == "T":
return quantity_title + " (K)"
else:
return quantity_title + " (H m-3)"
return quantity_title + f" ({self.export_unit})"
else:
return quantity_title

Expand Down
12 changes: 8 additions & 4 deletions festim/exports/derived_quantities/maximum_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class MaximumSurface(SurfaceQuantity):
def __init__(self, field, surface) -> None:
super().__init__(field=field, surface=surface)

@property
def export_unit(self):
if self.field == "T":
return "K"
else:
return "H m-3"

@property
def title(self):
quantity_title = f"Maximum {self.field} surface {self.surface}"
if self.show_units:
if self.field == "T":
return quantity_title + " (K)"
else:
return quantity_title + " (H m-3)"
return quantity_title + f" ({self.export_unit})"
else:
return quantity_title

Expand Down
12 changes: 8 additions & 4 deletions festim/exports/derived_quantities/maximum_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class MaximumVolume(VolumeQuantity):
def __init__(self, field, volume) -> None:
super().__init__(field=field, volume=volume)

@property
def export_unit(self):
if self.field == "T":
return "K"
else:
return "H m-3"

@property
def title(self):
quantity_title = f"Maximum {self.field} volume {self.volume}"
if self.show_units:
if self.field == "T":
return quantity_title + " (K)"
else:
return quantity_title + " (H m-3)"
return quantity_title + f" ({self.export_unit})"
else:
return quantity_title

Expand Down
12 changes: 8 additions & 4 deletions festim/exports/derived_quantities/minimum_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class MinimumSurface(SurfaceQuantity):
def __init__(self, field, surface) -> None:
super().__init__(field=field, surface=surface)

@property
def export_unit(self):
if self.field == "T":
return "K"
else:
return "H m-3"

@property
def title(self):
quantity_title = f"Minimum {self.field} surface {self.surface}"
if self.show_units:
if self.field == "T":
return quantity_title + " (K)"
else:
return quantity_title + " (H m-3)"
return quantity_title + f" ({self.export_unit})"
else:
return quantity_title

Expand Down
12 changes: 8 additions & 4 deletions festim/exports/derived_quantities/minimum_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ class MinimumVolume(VolumeQuantity):
def __init__(self, field, volume) -> None:
super().__init__(field=field, volume=volume)

@property
def export_unit(self):
if self.field == "T":
return "K"
else:
return "H m-3"

@property
def title(self):
quantity_title = f"Minimum {self.field} volume {self.volume}"
if self.show_units:
if self.field == "T":
return quantity_title + " (K)"
else:
return quantity_title + " (H m-3)"
return quantity_title + f" ({self.export_unit})"
else:
return quantity_title

Expand Down
12 changes: 8 additions & 4 deletions festim/exports/derived_quantities/point_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ def __init__(self, field: str or int, x: int or float or tuple or list) -> None:
x = [x]
self.x = x

@property
def export_unit(self):
if self.field == "T":
return "K"
else:
return "H m-3"

@property
def title(self):
quantity_title = f"{self.field} value at {self.x}"
if self.show_units:
if self.field == "T":
return quantity_title + " (K)"
else:
return quantity_title + " (H m-3)"
return quantity_title + f" ({self.export_unit})"
else:
return quantity_title

Expand Down
12 changes: 5 additions & 7 deletions festim/exports/derived_quantities/surface_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ def export_unit(self):

@property
def title(self):
quantity_title = f"Flux surface {self.surface}: {self.field}"
if self.show_units:
if self.field == "T":
quantity_title = f"Heat flux surface {self.surface}"
else:
quantity_title = f"{self.field} flux surface {self.surface}"
if self.field == "T":
quantity_title = f"Heat flux surface {self.surface}"
else:
quantity_title = f"{self.field} flux surface {self.surface}"

if self.show_units:
return quantity_title + f" ({self.export_unit})"

else:
return quantity_title

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def test_title_with_units():

def test_title_without_units():
my_quantity = AdsorbedHydrogen(1)
my_quantity.show_units = False
assert my_quantity.title == "Adsorbed H on surface 1"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def test_title(field, surface):
"""

my_average = AverageSurface(field, surface)
assert my_average.title == "Average {} surface {}".format(field, surface)
assert (
my_average.title
== f"Average {field} surface {surface} ({my_average.export_unit})"
)


class TestCompute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def test_title(field, volume):
"""

my_average = AverageVolume(field, volume)
assert my_average.title == "Average {} volume {}".format(field, volume)
assert (
my_average.title
== f"Average {field} volume {volume} ({my_average.export_unit})"
)


class TestCompute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ def test_title_with_units(function, expected_title):

def test_title_without_units():
my_flux = HydrogenFlux(4)
assert my_flux.title == "Flux surface 4: solute"
my_flux.show_units = False
assert my_flux.title == "solute flux surface 4"
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_title(field, surface):
"""

my_max = MaximumSurface(field, surface)
assert my_max.title == "Maximum {} surface {}".format(field, surface)
assert my_max.title == f"Maximum {field} surface {surface} ({my_max.export_unit})"


class TestCompute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_title(field, volume):
"""

my_max = MaximumVolume(field, volume)
assert my_max.title == "Maximum {} volume {}".format(field, volume)
assert my_max.title == f"Maximum {field} volume {volume} ({my_max.export_unit})"


class TestCompute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_title(field, surface):
"""

my_min = MinimumSurface(field, surface)
assert my_min.title == "Minimum {} surface {}".format(field, surface)
assert my_min.title == f"Minimum {field} surface {surface} ({my_min.export_unit})"


class TestCompute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_title(field, volume):
"""

my_min = MinimumVolume(field, volume)
assert my_min.title == "Minimum {} volume {}".format(field, volume)
assert my_min.title == f"Minimum {field} volume {volume} ({my_min.export_unit})"


class TestCompute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_title(field):
"""
x = 1
my_value = PointValue(field, x)
assert my_value.title == "{} value at [{}]".format(field, x)
assert my_value.title == f"{field} value at [{x}] ({my_value.export_unit})"


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def test_title(field, surface):
"""

my_h_flux = SurfaceFlux(field, surface)
assert my_h_flux.title == "Flux surface {}: {}".format(surface, field)
my_h_flux.function = c_1D
if field == "T":
expected_title = f"Heat flux surface {surface} ({my_h_flux.export_unit})"
else:
expected_title = f"{field} flux surface {surface} ({my_h_flux.export_unit})"
assert my_h_flux.title == expected_title


class TestCompute:
Expand Down Expand Up @@ -324,6 +329,7 @@ def test_cylindrical_flux_title_no_units_solute():
festim.CylindricalSurfaceFlux with a solute field without units"""

my_h_flux = SurfaceFluxCylindrical("solute", 2)
my_h_flux.show_units = False
assert my_h_flux.title == "solute flux surface 2"


Expand All @@ -332,6 +338,7 @@ def test_cylindrical_flux_title_no_units_temperature():
festim.CylindricalSurfaceFlux with a T field without units"""

my_heat_flux = SurfaceFluxCylindrical("T", 4)
my_heat_flux.show_units = False
assert my_heat_flux.title == "Heat flux surface 4"


Expand All @@ -357,6 +364,7 @@ def test_spherical_flux_title_no_units_solute():
festim.SphericalSurfaceFlux with a solute field without units"""

my_h_flux = SurfaceFluxSpherical("solute", 3)
my_h_flux.show_units = False
assert my_h_flux.title == "solute flux surface 3"


Expand All @@ -365,6 +373,7 @@ def test_spherical_flux_title_no_units_temperature():
festim.CSphericalSurfaceFlux with a T field without units"""

my_heat_flux = SurfaceFluxSpherical("T", 5)
my_heat_flux.show_units = False
assert my_heat_flux.title == "Heat flux surface 5"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ def test_title_with_units(function, expected_title):

def test_title_without_units():
my_flux = ThermalFlux(5)
my_flux.show_units = False

assert my_flux.title == "Flux surface 5: T"
assert my_flux.title == "Heat flux surface 5"
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_title(field, surface):
"""

my_total = TotalSurface(field, surface)
assert my_total.title == "Total {} surface {}".format(field, surface)
my_total.function = c_2D
assert my_total.title == f"Total {field} surface {surface} ({my_total.export_unit})"


class TestCompute:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_title(field, volume):
"""

my_total = TotalVolume(field, volume)
assert my_total.title == "Total {} volume {}".format(field, volume)
my_total.function = c_2D
assert my_total.title == f"Total {field} volume {volume} ({my_total.export_unit})"


class TestCompute:
Expand Down

0 comments on commit d31bcb8

Please sign in to comment.