Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowed_meshes property for derived quantities #832

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions festim/exports/derived_quantities/average_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class AverageSurface(SurfaceQuantity):
def __init__(self, field, surface) -> None:
super().__init__(field=field, surface=surface)

@property
def allowed_meshes(self):
return ["cartesian"]

@property
def title(self):
quantity_title = f"Average {self.field} surface {self.surface}"
Expand Down
4 changes: 4 additions & 0 deletions festim/exports/derived_quantities/average_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class AverageVolume(VolumeQuantity):
def __init__(self, field, volume: int) -> None:
super().__init__(field=field, volume=volume)

@property
def allowed_meshes(self):
return ["cartesian"]

@property
def title(self):
quantity_title = f"Average {self.field} volume {self.volume}"
Expand Down
25 changes: 25 additions & 0 deletions festim/exports/derived_quantities/derived_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ class DerivedQuantity(Export):

Args:
field (str, int): the field ("solute", 0, 1, "T", "retention")

Attributes:
field (str, int): the field ("solute", 0, 1, "T", "retention")
title (str): the title of the derived quantity
show_units (bool): show the units in the title in the derived quantities
file
function (fenics.Function): the solution function of
the field
dx (fenics.Measure): the measure of the volume
ds (fenics.Measure): the measure of the surface
n (fenics.Function): the normal vector
D (fenics.Function): the diffusion coefficient
S (fenics.Function): the source term
thermal_cond (fenics.Function): the thermal conductivity
Q (fenics.Function): the heat source term
data (list): the data of the derived quantity
t (list): the time values of the data
allowed_meshes (list): the allowed meshes for the derived quantity
"""

def __init__(self, field) -> None:
Expand All @@ -18,10 +36,17 @@ def __init__(self, field) -> None:
self.S = None
self.thermal_cond = None
self.Q = None
self.T = None
self.data = []
self.t = []
self.show_units = False

@property
def allowed_meshes(self):
# by default, all meshes are allowed
# override this method if that's not the case
return ["cartesian", "cylindrical", "spherical"]


class VolumeQuantity(DerivedQuantity):
"""DerivedQuantity relative to a volume
Expand Down
12 changes: 12 additions & 0 deletions festim/exports/derived_quantities/surface_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class SurfaceFlux(SurfaceQuantity):
def __init__(self, field, surface) -> None:
super().__init__(field=field, surface=surface)

@property
def allowed_meshes(self):
return ["cartesian"]

@property
def export_unit(self):
# obtain domain dimension
Expand Down Expand Up @@ -111,6 +115,10 @@ def __init__(self, field, surface, azimuth_range=(0, 2 * np.pi)) -> None:
self.r = None
self.azimuth_range = azimuth_range

@property
def allowed_meshes(self):
return ["cylindrical"]

@property
def title(self):
if self.field == "T":
Expand Down Expand Up @@ -199,6 +207,10 @@ def __init__(
self.polar_range = polar_range
self.azimuth_range = azimuth_range

@property
def allowed_meshes(self):
return ["spherical"]

@property
def title(self):
if self.field == "T":
Expand Down
4 changes: 4 additions & 0 deletions festim/exports/derived_quantities/total_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class TotalSurface(SurfaceQuantity):
def __init__(self, field, surface) -> None:
super().__init__(field=field, surface=surface)

@property
def allowed_meshes(self):
return ["cartesian"]

@property
def export_unit(self):
# obtain domain dimension
Expand Down
4 changes: 4 additions & 0 deletions festim/exports/derived_quantities/total_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class TotalVolume(VolumeQuantity):
def __init__(self, field, volume) -> None:
super().__init__(field=field, volume=volume)

@property
def allowed_meshes(self):
return ["cartesian"]

@property
def export_unit(self):
# obtain domain dimension
Expand Down
21 changes: 1 addition & 20 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,29 +359,10 @@ def initialise(self):

# raise warning if the derived quantities don't match the type of mesh
# eg. SurfaceFlux is used with cylindrical mesh
all_types_quantities = [
festim.MaximumSurface,
festim.MinimumSurface,
festim.MaximumVolume,
festim.MinimumVolume,
festim.PointValue,
] # these quantities can be used with any mesh
allowed_quantities = {
"cartesian": [
festim.SurfaceFlux,
festim.AverageSurface,
festim.AverageVolume,
festim.TotalVolume,
]
+ all_types_quantities,
"cylindrical": [festim.SurfaceFluxCylindrical] + all_types_quantities,
"spherical": [festim.SurfaceFluxSpherical] + all_types_quantities,
}

for export in self.exports:
if isinstance(export, festim.DerivedQuantities):
for q in export:
if not isinstance(q, tuple(allowed_quantities[self.mesh.type])):
if self.mesh.type not in q.allowed_meshes:
warnings.warn(
f"{type(q)} may not work as intended for {self.mesh.type} meshes"
)
Expand Down
5 changes: 5 additions & 0 deletions test/system/test_cylindrical_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ def test_run_MMS():
transient=False,
)

exports = [
festim.DerivedQuantities([festim.SurfaceFluxCylindrical(field=0, surface=2)])
]

my_sim = festim.Simulation(
mesh=my_mesh,
materials=my_materials,
boundary_conditions=my_bcs,
temperature=my_temp,
sources=my_sources,
settings=my_settings,
exports=exports,
)

my_sim.initialise()
Expand Down
5 changes: 5 additions & 0 deletions test/system/test_spherical_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ def test_run_MMS():
transient=False,
)

exports = [
festim.DerivedQuantities([festim.SurfaceFluxSpherical(field=0, surface=2)])
]

my_sim = festim.Simulation(
mesh=my_mesh,
materials=my_materials,
boundary_conditions=my_bcs,
temperature=my_temp,
sources=my_sources,
settings=my_settings,
exports=exports,
)

my_sim.initialise()
Expand Down
Loading