Skip to content

Commit

Permalink
refactored logic + splitted methos
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Oct 25, 2023
1 parent 39d5001 commit b848278
Showing 1 changed file with 49 additions and 38 deletions.
87 changes: 49 additions & 38 deletions festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,49 +242,60 @@ def define_markers_and_measures(self):
def define_boundary_conditions(self):
"""Defines the dirichlet boundary conditions of the model"""
for bc in self.boundary_conditions:
# if name of species is given then replace with species object
if isinstance(bc.species, str):
# if name of species is given then replace with species object
bc.species = F.find_species_from_name(bc.species, self.species)

if isinstance(bc, F.DirichletBC):
if (len(self.species) > 1) and (
not isinstance(bc.value, (int, float, fem.Constant))
):
bc_dofs = bc.define_surface_subdomain_dofs(
facet_meshtags=self.facet_meshtags,
mesh=self.mesh,
function_space=(
bc.species.sub_function_space,
bc.species.collapsed_function_space,
),
)
bc.create_value(
mesh=self.mesh.mesh,
temperature=self.temperature,
function_space=bc.species.collapsed_function_space,
t=self.t,
)
else:
bc_dofs = bc.define_surface_subdomain_dofs(
facet_meshtags=self.facet_meshtags,
mesh=self.mesh,
function_space=bc.species.sub_function_space,
)
bc.create_value(
mesh=self.mesh.mesh,
temperature=self.temperature,
function_space=bc.species.sub_function_space,
t=self.t,
)
if (len(self.species) == 1) and (
isinstance(bc.value_fenics, (fem.Function))
):
form = bc.create_formulation(dofs=bc_dofs, function_space=None)
else:
form = bc.create_formulation(
dofs=bc_dofs, function_space=bc.species.sub_function_space
)
form = self.create_dirichletbc_form(bc)
self.bc_forms.append(form)

def create_dirichletbc_form(self, bc):
"""Creates the dirichlet boundary condition form
Args:
bc (festim.DirichletBC): Boundary condition object
Returns:
dolfinx.fem.bcs.DirichletBC: Representation of the
Dirichlet boundary condition which is imposed on
a linear system.
"""
if len(self.species) == 1 or isinstance(bc.value, (int, float, fem.Constant)):
function_space_dofs = bc.species.sub_function_space
function_space_species = bc.species.sub_function_space
else:
function_space_dofs = (
bc.species.sub_function_space,
bc.species.collapsed_function_space,
)
function_space_species = bc.species.collapsed_function_space

bc_dofs = bc.define_surface_subdomain_dofs(
facet_meshtags=self.facet_meshtags,
mesh=self.mesh,
function_space=function_space_dofs,
)
bc.create_value(
mesh=self.mesh.mesh,
temperature=self.temperature,
function_space=function_space_species,
t=self.t,
)

if (len(self.species) == 1) and (isinstance(bc.value_fenics, (fem.Function))):
# todo remove DirichletBC.create_form
return fem.dirichletbc(
value=bc.value_fenics,
dofs=bc_dofs,
)
else:
return fem.dirichletbc(
value=bc.value_fenics,
dofs=bc_dofs,
V=bc.species.sub_function_space,
)

def create_formulation(self):
"""Creates the formulation of the model"""
if len(self.sources) > 1:
Expand Down

0 comments on commit b848278

Please sign in to comment.