Skip to content

Commit 32d138d

Browse files
authored
Merge pull request #1037 from jhdark/diffusion_fix
Only get diffusion coeff if mobile
2 parents 0783ddc + 21cdcfb commit 32d138d

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

src/festim/hydrogen_transport_problem.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,10 +814,10 @@ def create_formulation(self):
814814
v = spe.test_function
815815

816816
for vol in self.volume_subdomains:
817-
D = vol.material.get_diffusion_coefficient(
818-
self.mesh.mesh, self.temperature_fenics, spe
819-
)
820817
if spe.mobile:
818+
D = vol.material.get_diffusion_coefficient(
819+
self.mesh.mesh, self.temperature_fenics, spe
820+
)
821821
match self.mesh.coordinate_system:
822822
case CoordinateSystem.CARTESIAN:
823823
self.formulation += ufl.dot(
@@ -1379,13 +1379,13 @@ def create_subdomain_formulation(self, subdomain: _subdomain.VolumeSubdomain):
13791379
u_n = spe.subdomain_to_prev_solution[subdomain]
13801380
v = spe.subdomain_to_test_function[subdomain]
13811381

1382-
D = subdomain.material.get_diffusion_coefficient(
1383-
self.mesh.mesh, self.temperature_fenics, spe
1384-
)
13851382
if self.settings.transient:
13861383
form += ((u - u_n) / self.dt) * v * self.dx(subdomain.id)
13871384

13881385
if spe.mobile:
1386+
D = subdomain.material.get_diffusion_coefficient(
1387+
self.mesh.mesh, self.temperature_fenics, spe
1388+
)
13891389
match self.mesh.coordinate_system:
13901390
case CoordinateSystem.CARTESIAN:
13911391
form += ufl.dot(D * ufl.grad(u), ufl.grad(v)) * self.dx(

test/system_tests/test_misc.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,42 @@ def test_del():
245245
my_model.exports = [F.VTXSpeciesExport(filename="h.bp", field=H)]
246246

247247
my_model.__del__()
248+
249+
250+
def test_multispecies_with_immobile():
251+
"""test to catch bug 1036, that the diffusion coefficent for a non-mobile species
252+
is not requested in the dict given to material"""
253+
254+
my_model = F.HydrogenTransportProblem()
255+
my_model.mesh = F.Mesh1D(vertices=np.linspace(0, 1, num=50))
256+
257+
H = F.Species("H")
258+
D = F.Species("D")
259+
trap = F.Species("trap", mobile=False)
260+
trapping_site = F.ImplicitSpecies(n=100, others=[H])
261+
my_model.species = [H, trap]
262+
263+
my_mat = F.Material(
264+
D_0={H: 1, D: 1},
265+
E_D={H: 0, D: 0},
266+
)
267+
vol = F.VolumeSubdomain1D(id=1, borders=[0, 1], material=my_mat)
268+
my_model.subdomains = [vol]
269+
270+
my_model.reactions = [
271+
F.Reaction(
272+
reactant=[H, trapping_site],
273+
k_0=1,
274+
E_k=0,
275+
p_0=1,
276+
E_p=0,
277+
product=[trap],
278+
volume=vol,
279+
)
280+
]
281+
282+
my_model.temperature = 500
283+
284+
my_model.settings = F.Settings(transient=False, atol=1e-10, rtol=1e-10)
285+
286+
my_model.initialise()

0 commit comments

Comments
 (0)