Skip to content

Commit

Permalink
Merge pull request #927 from festim-dev/fix-no-borders
Browse files Browse the repository at this point in the history
Fix for no borders in multi-materials sims
  • Loading branch information
RemDelaporteMathurin authored Dec 12, 2024
2 parents d5bb806 + 61ad5aa commit 42810ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions festim/meshing/mesh_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions test/system/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 42810ca

Please sign in to comment.