Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for no borders in multi-materials sims #927

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading