Skip to content

Commit

Permalink
Merge pull request #617 from jhdark/multispecies_support
Browse files Browse the repository at this point in the history
Multispecies support
  • Loading branch information
RemDelaporteMathurin authored Oct 26, 2023
2 parents 6f627cd + 3376833 commit b975a64
Show file tree
Hide file tree
Showing 16 changed files with 721 additions and 195 deletions.
2 changes: 1 addition & 1 deletion festim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from .settings import Settings

from .species import Species, Trap, ImplicitSpecies
from .species import Species, Trap, ImplicitSpecies, find_species_from_name

from .subdomain.surface_subdomain import SurfaceSubdomain1D
from .subdomain.volume_subdomain import VolumeSubdomain1D
Expand Down
22 changes: 2 additions & 20 deletions festim/boundary_conditions/dirichlet_bc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def define_surface_subdomain_dofs(self, facet_meshtags, mesh, function_space):
"""
bc_facets = facet_meshtags.find(self.subdomain.id)
bc_dofs = fem.locate_dofs_topological(function_space, mesh.fdim, bc_facets)

return bc_dofs

def create_value(
Expand Down Expand Up @@ -98,7 +99,7 @@ def create_value(
if "t" in arguments and "x" not in arguments and "T" not in arguments:
# only t is an argument
self.value_fenics = F.as_fenics_constant(
mesh=mesh, value=self.value(t=t.value)
mesh=mesh, value=self.value(t=float(t))
)
else:
self.value_fenics = fem.Function(function_space)
Expand All @@ -118,25 +119,6 @@ def create_value(
)
self.value_fenics.interpolate(self.bc_expr)

def create_formulation(self, dofs, function_space):
"""Applies the boundary condition
Args:
dofs (numpy.ndarray): the degrees of freedom of surface facets
function_space (dolfinx.fem.FunctionSpace): the function space
"""
if isinstance(self.value_fenics, fem.Function):
form = fem.dirichletbc(
value=self.value_fenics,
dofs=dofs,
)
else:
form = fem.dirichletbc(
value=self.value_fenics,
dofs=dofs,
V=function_space,
)
return form

def update(self, t):
"""Updates the boundary condition value
Expand Down
13 changes: 8 additions & 5 deletions festim/exports/vtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ def field(self):
@field.setter
def field(self, value):
# check that field is festim.Species or list of festim.Species
if not isinstance(value, F.Species) and not isinstance(value, list):
if not isinstance(value, (F.Species, str)) and not isinstance(value, list):
raise TypeError(
"field must be of type festim.Species or list of festim.Species"
"field must be of type festim.Species or str or a list of festim.Species or str"
)
# check that all elements of list are festim.Species
if isinstance(value, list):
for element in value:
if not isinstance(element, F.Species):
if not isinstance(element, (F.Species, str)):
raise TypeError(
"field must be of type festim.Species or list of festim.Species"
"field must be of type festim.Species or str or a list of festim.Species or str"
)
# if field is festim.Species, convert to list
if not isinstance(value, list):
Expand All @@ -72,7 +72,10 @@ def define_writer(self, comm: mpi4py.MPI.Intracomm) -> None:
comm (mpi4py.MPI.Intracomm): the MPI communicator
"""
self.writer = VTXWriter(
comm, self.filename, [field.solution for field in self.field], "BP4"
comm,
self.filename,
[field.post_processing_solution for field in self.field],
"BP4",
)

def write(self, t: float):
Expand Down
10 changes: 5 additions & 5 deletions festim/exports/xdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def field(self):
@field.setter
def field(self, value):
# check that field is festim.Species or list of festim.Species
if not isinstance(value, F.Species) and not isinstance(value, list):
if not isinstance(value, (F.Species, str)) and not isinstance(value, list):
raise TypeError(
"field must be of type festim.Species or list of festim.Species"
"field must be of type festim.Species or str or a list of festim.Species or str"
)
# check that all elements of list are festim.Species
if isinstance(value, list):
for element in value:
if not isinstance(element, F.Species):
if not isinstance(element, (F.Species, str)):
raise TypeError(
"field must be of type festim.Species or list of festim.Species"
"field must be of type festim.Species or str or a list of festim.Species or str"
)
# if field is festim.Species, convert to list
if not isinstance(value, list):
Expand All @@ -71,4 +71,4 @@ def write(self, t: float):
t (float): the time of export
"""
for field in self.field:
self.writer.write_function(field.solution, t)
self.writer.write_function(field.post_processing_solution, t)
Loading

0 comments on commit b975a64

Please sign in to comment.