Skip to content
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
13 changes: 13 additions & 0 deletions festim/generic_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ def check_boundary_conditions(self):
msg += f"on surfaces {intersection} for field {dc_sk_bc.field}"
raise ValueError(msg)

def check_mesh_dim_coords(self):
"""Checks if the used coordinates can be applied for geometry with the specified dimensions"""

if self.mesh.type == "spherical" and self.mesh.mesh.topology().dim() != 1:
raise AttributeError(
"spherical coordinates can be used for one-dimensional domains only"
)
if self.mesh.type == "cylindrical" and self.mesh.mesh.topology().dim() > 2:
raise AttributeError(
"cylindrical coordinates cannot be used for 3D domains"
)

def attribute_boundary_conditions(self):
"""Assigns boundary_conditions to mobile and T"""
self.T.boundary_conditions = []
Expand Down Expand Up @@ -324,6 +336,7 @@ def initialise(self):
self.attribute_source_terms()
self.attribute_boundary_conditions()

self.check_mesh_dim_coords()
if isinstance(self.mesh, festim.Mesh1D):
self.mesh.define_measures(self.materials)
else:
Expand Down
55 changes: 55 additions & 0 deletions test/simulation/test_initialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
import pytest
import sympy as sp
import fenics as f


def test_initialise_changes_nb_of_sources():
Expand Down Expand Up @@ -283,3 +284,57 @@ def test_initial_concentration_traps():
)

model.initialise()


@pytest.mark.parametrize("mesh", [f.UnitSquareMesh(10, 10), f.UnitCubeMesh(10, 10, 10)])
def test_error_raised_when_spherical_non1D(mesh):
"""
Creates a Simulation object and checks that AttributeError is raised
when spherical coordinates are used for non-1D geometries
"""

my_model = F.Simulation()

my_model.mesh = F.Mesh(
mesh,
type="spherical",
)

my_model.materials = F.Material(id=1, D_0=1, E_D=0)
my_model.T = 100
my_model.settings = F.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, transient=False
)

# test
with pytest.raises(
AttributeError,
match=f"spherical coordinates can be used for one-dimensional domains only",
):
my_model.initialise()


def test_error_raised_when_cylindrical_3D():
"""
Creates a Simulation object and checks that AttributeError is raised
when cylindrical coordinates are used for a 3D geometry
"""

my_model = F.Simulation()

my_model.mesh = F.Mesh(
f.UnitCubeMesh(5, 5, 5),
type="cylindrical",
)

my_model.materials = F.Material(id=1, D_0=1, E_D=0)
my_model.T = 100
my_model.settings = F.Settings(
absolute_tolerance=1e-10, relative_tolerance=1e-10, transient=False
)

# test
with pytest.raises(
AttributeError, match=f"cylindrical coordinates cannot be used for 3D domains"
):
my_model.initialise()
Loading