Skip to content

Commit

Permalink
additional tests for avg volume
Browse files Browse the repository at this point in the history
  • Loading branch information
jhdark committed Jan 14, 2025
1 parent 47f853e commit 301cba0
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions test/simulation/test_initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,15 @@ def test_cartesian_and_surface_flux_warning(quantity, sys):
my_model.initialise()


@pytest.mark.parametrize(
"quantity",
[
F.AverageSurfaceCylindrical(field="solute", surface=1),
F.AverageVolumeCylindrical(field="solute", volume=1),
],
)
@pytest.mark.parametrize("sys", ["cartesian", "spherical"])
def test_cylindrical_quantities_warning(sys):
def test_cylindrical_quantities_warning(quantity, sys):
"""
Creates a Simulation object and checks that, if either a cartesian
or spherical meshes are given with a AverageSurfaceCylindrical, a warning is raised.
Expand All @@ -169,17 +176,15 @@ def test_cylindrical_quantities_warning(sys):
absolute_tolerance=1e-10, relative_tolerance=1e-10, final_time=4
)

derived_quantities = F.DerivedQuantities(
[F.AverageSurfaceCylindrical(field="solute", surface=1)]
)
derived_quantities = F.DerivedQuantities([quantity])
my_model.exports = [derived_quantities]

# test
with pytest.warns(UserWarning, match=f"may not work as intended for {sys} meshes"):
my_model.initialise()


def test_spherical_quantities_warning():
def test_avg_surf_spherical_quantities_warning():
"""
Creates a Simulation object and checks that, if a cylindrical
mesh is given with a AverageSurfaceSpherical, a warning is raised.
Expand All @@ -206,6 +211,35 @@ def test_spherical_quantities_warning():
my_model.initialise()


@pytest.mark.parametrize("sys", ["cartesian", "cylindrical"])
def test_avg_volume_spherical_quantities_warning(sys):
"""
Creates a Simulation object and checks that, if either a cylindrical or
cartesian meshes are given with a AverageVolumeSpherical, a warning is raised.
Args:
sys (str): type of the coordinate system
"""
# build
my_model = F.Simulation()
my_model.mesh = F.MeshFromVertices([1, 2, 3], type=sys)
my_model.materials = F.Material(id=1, D_0=1, E_D=0)
my_model.T = F.Temperature(100)
my_model.dt = F.Stepsize(initial_value=3)
my_model.settings = F.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, final_time=4
)

derived_quantities = F.DerivedQuantities(
[F.AverageVolumeSpherical(field="solute", volume=1)]
)
my_model.exports = [derived_quantities]

# test
with pytest.warns(UserWarning, match=f"may not work as intended for {sys} meshes"):
my_model.initialise()


@pytest.mark.parametrize(
"value",
[
Expand Down

0 comments on commit 301cba0

Please sign in to comment.