From 6f96d72da28111643a7d2f4a9927219f195d0027 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 12 Dec 2024 12:10:45 -0500 Subject: [PATCH 1/2] added test to catch the bug --- test/system/test_misc.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/system/test_misc.py b/test/system/test_misc.py index 5879903e8..ad9ac589f 100644 --- a/test/system/test_misc.py +++ b/test/system/test_misc.py @@ -877,3 +877,31 @@ def test_error_raised_when_diverge_with_no_dt_min(): with pytest.raises(ValueError, match="Solver diverged but dt_min is not set."): my_model.run() + + +def test_error_with_multiple_1d_domains_no_borders(): + """Test to catch #926""" + my_model = F.Simulation() + my_model.mesh = F.MeshFromVertices(vertices=[0, 1, 2, 3, 4, 5]) + + # define two mats with no borders + mat1 = F.Material(id=1, D_0=1, E_D=0) + mat2 = F.Material(id=2, D_0=3, E_D=0) + my_model.materials = [mat1, mat2] + + my_model.T = 800 + + my_model.boundary_conditions = [ + F.DirichletBC(value=F.x, field=0, surfaces=[1, 2]), + ] + + my_model.settings = F.Settings( + absolute_tolerance=1e-10, + relative_tolerance=1e-10, + transient=False, + ) + with pytest.raises( + ValueError, + match="borders attributes need to be set for multiple 1D domains", + ): + my_model.initialise() From 61ad5aa06ce3b95f715600e5a1534a5ee87a0c68 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Thu, 12 Dec 2024 12:14:22 -0500 Subject: [PATCH 2/2] fixed bug --- festim/meshing/mesh_1d.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/festim/meshing/mesh_1d.py b/festim/meshing/mesh_1d.py index f845b8972..0fc95f533 100644 --- a/festim/meshing/mesh_1d.py +++ b/festim/meshing/mesh_1d.py @@ -73,6 +73,10 @@ def define_volume_markers(self, materials): def define_measures(self, materials): """Creates the fenics.Measure objects for self.dx and self.ds""" + if len(materials) > 1 and any(m.borders is None for m in materials): + raise ValueError( + "borders attributes need to be set for multiple 1D domains" + ) if materials[0].borders is not None: materials.check_borders(self.size) self.define_markers(materials)