From 301cba09ac941256ce952e8150150a7810458e77 Mon Sep 17 00:00:00 2001 From: jhdark Date: Tue, 14 Jan 2025 11:07:34 -0500 Subject: [PATCH] additional tests for avg volume --- test/simulation/test_initialise.py | 44 ++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/test/simulation/test_initialise.py b/test/simulation/test_initialise.py index 3418a14d9..afa6ac1e3 100644 --- a/test/simulation/test_initialise.py +++ b/test/simulation/test_initialise.py @@ -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. @@ -169,9 +176,7 @@ 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 @@ -179,7 +184,7 @@ def test_cylindrical_quantities_warning(sys): 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. @@ -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", [