Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Nov 1, 2024
1 parent 0ee90b1 commit 7b5899c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/festim/boundary_conditions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from .dirichlet_bc import FixedConcentrationBC, FixedTemperatureBC
from .flux_bc import HeatFluxBC, ParticleFluxBC
from .surface_reaction import SurfaceReactionBC

__all__ = ["FixedConcentrationBC", "FixedTemperatureBC", "ParticleFluxBC", "HeatFluxBC"]
__all__ = [
"FixedConcentrationBC",
"FixedTemperatureBC",
"ParticleFluxBC",
"SurfaceReactionBC",
"HeatFluxBC",
]
43 changes: 35 additions & 8 deletions src/festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,26 @@ def assign_functions_to_species(self):
spe.test_function = sub_test_functions[idx]

def define_boundary_conditions(self):
# @jhdark this all_bcs could be a property
# I just don't want to modify self.boundary_conditions

# create all_bcs which includes all flux bcs from SurfaceReactionBC
all_bcs = self.boundary_conditions.copy()
for bc in self.boundary_conditions:
if isinstance(bc, boundary_conditions.FixedConcentrationBC):
if isinstance(bc.species, str):
# if name of species is given then replace with species object
bc.species = _species.find_species_from_name(
bc.species, self.species
)
if isinstance(bc, boundary_conditions.SurfaceReactionBC):
all_bcs += bc.flux_bcs
all_bcs.remove(bc)

for bc in all_bcs:
if isinstance(bc.species, str):
# if name of species is given then replace with species object
bc.species = _species.find_species_from_name(bc.species, self.species)
if isinstance(bc, boundary_conditions.ParticleFluxBC):
bc.create_value_fenics(
mesh=self.mesh.mesh,
temperature=self.temperature_fenics,
t=self.t,
)

super().define_boundary_conditions()

Expand Down Expand Up @@ -684,6 +697,13 @@ def create_formulation(self):
* bc.species.test_function
* self.ds(bc.subdomain.id)
)
if isinstance(bc, boundary_conditions.SurfaceReactionBC):
for flux_bc in bc.flux_bcs:
self.formulation -= (
flux_bc.value_fenics
* flux_bc.species.test_function
* self.ds(flux_bc.subdomain.id)
)

# check if each species is defined in all volumes
if not self.settings.transient:
Expand Down Expand Up @@ -717,8 +737,15 @@ def update_time_dependent_values(self):
self.temperature_fenics.interpolate(self.temperature_expr)

for bc in self.boundary_conditions:
if bc.temperature_dependent:
bc.update(t=t)
if isinstance(
bc,
(
boundary_conditions.FixedConcentrationBC,
boundary_conditions.ParticleFluxBC,
),
):
if bc.temperature_dependent:
bc.update(t=t)

for source in self.sources:
if source.temperature_dependent:
Expand Down
2 changes: 2 additions & 0 deletions test/system_tests/test_surface_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ def test_pressure_varies_in_time():

expected_flux_after_pressure = -2 * k_d * pressure
computed_flux_after_pressure = flux_as_array[time_as_array > t_pressure]
print(computed_flux_after_pressure)
print(expected_flux_after_pressure)
assert np.allclose(
computed_flux_after_pressure, expected_flux_after_pressure, rtol=1e-2
)
2 changes: 1 addition & 1 deletion test/test_h_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ def test_create_flux_values_fenics_multispecies():
my_model.define_temperature()

# RUN
my_model.define_boundary_conditions()
my_model.create_flux_values_fenics()

# TEST
assert np.isclose(my_model.boundary_conditions[0].value_fenics.value, 5)
Expand Down

0 comments on commit 7b5899c

Please sign in to comment.