Skip to content

Commit 42810ca

Browse files
Merge pull request #927 from festim-dev/fix-no-borders
Fix for no borders in multi-materials sims
2 parents d5bb806 + 61ad5aa commit 42810ca

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

festim/meshing/mesh_1d.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def define_volume_markers(self, materials):
7373

7474
def define_measures(self, materials):
7575
"""Creates the fenics.Measure objects for self.dx and self.ds"""
76+
if len(materials) > 1 and any(m.borders is None for m in materials):
77+
raise ValueError(
78+
"borders attributes need to be set for multiple 1D domains"
79+
)
7680
if materials[0].borders is not None:
7781
materials.check_borders(self.size)
7882
self.define_markers(materials)

test/system/test_misc.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,3 +877,31 @@ def test_error_raised_when_diverge_with_no_dt_min():
877877

878878
with pytest.raises(ValueError, match="Solver diverged but dt_min is not set."):
879879
my_model.run()
880+
881+
882+
def test_error_with_multiple_1d_domains_no_borders():
883+
"""Test to catch #926"""
884+
my_model = F.Simulation()
885+
my_model.mesh = F.MeshFromVertices(vertices=[0, 1, 2, 3, 4, 5])
886+
887+
# define two mats with no borders
888+
mat1 = F.Material(id=1, D_0=1, E_D=0)
889+
mat2 = F.Material(id=2, D_0=3, E_D=0)
890+
my_model.materials = [mat1, mat2]
891+
892+
my_model.T = 800
893+
894+
my_model.boundary_conditions = [
895+
F.DirichletBC(value=F.x, field=0, surfaces=[1, 2]),
896+
]
897+
898+
my_model.settings = F.Settings(
899+
absolute_tolerance=1e-10,
900+
relative_tolerance=1e-10,
901+
transient=False,
902+
)
903+
with pytest.raises(
904+
ValueError,
905+
match="borders attributes need to be set for multiple 1D domains",
906+
):
907+
my_model.initialise()

0 commit comments

Comments
 (0)