Solution#
Here you will find the solution for the challenge A.
Two simulations are needed, one with the barrier and one without.
import festim as F
import h_transport_materials as htm
import numpy as np
upstream_pressure = 1e6 # Pa (=10 bar)
barrier_thick = 2.5e-6
substrate_thick = 0.02
# eurofer properties
diffusivity_eurofer = htm.diffusivities.filter(material="eurofer_97").filter(
author="chen"
)
D_eurofer = diffusivity_eurofer[0]
solubility_eurofer = htm.solubilities.filter(material="eurofer_97").filter(
author="chen"
)
S_eurofer = solubility_eurofer[0]
# Al2O3 properties
diffusivity_al2o3 = (
htm.diffusivities.filter(material="alumina")
.filter(isotope="h")
.filter(author="serra")
)
D_al2o3 = diffusivity_al2o3[0]
solubility_al2o3 = (
htm.solubilities.filter(material="alumina")
.filter(isotope="h")
.filter(author="serra")
)
S_al2o3 = solubility_al2o3[0]
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 2
1 import festim as F
----> 2 import h_transport_materials as htm
3 import numpy as np
4
5 upstream_pressure = 1e6 # Pa (=10 bar)
File ~/checkouts/readthedocs.org/user_builds/festim-workshop/conda/festim1/lib/python3.11/site-packages/h_transport_materials/__init__.py:25
22 Rg = 8.314 * ureg.Pa * ureg.m**3 * ureg.mol**-1 * ureg.K**-1
23 avogadro_nb = 6.022e23 * ureg.particle * ureg.mol**-1
---> 25 from pybtex.database import parse_file
26 from pathlib import Path
28 bib_database = parse_file(str(Path(__file__).parent) + "/references.bib")
File ~/checkouts/readthedocs.org/user_builds/festim-workshop/conda/festim1/lib/python3.11/site-packages/pybtex/database/__init__.py:44
42 from pybtex.errors import report_error
43 from pybtex.py3compat import fix_unicode_literals_in_doctest, python_2_unicode_compatible
---> 44 from pybtex.plugin import find_plugin
47 # for python2 compatibility
48 def indent(text, prefix):
File ~/checkouts/readthedocs.org/user_builds/festim-workshop/conda/festim1/lib/python3.11/site-packages/pybtex/plugin/__init__.py:26
2 # Copyright (c) 2006-2021 Andrey Golovizin
3 # Copyright (c) 2014 Matthias C. M. Troffaes
4 #
(...) 21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 import os.path # splitext
---> 26 import pkg_resources
28 from pybtex.exceptions import PybtexError
31 class Plugin(object):
ModuleNotFoundError: No module named 'pkg_resources'
Model with barrier#
model_with_barrier = F.Simulation(log_level=40)
# define mesh
vertices_left = np.linspace(0, substrate_thick, num=500)
vertices_right = np.linspace(substrate_thick, substrate_thick + barrier_thick, num=500)
vertices = np.concatenate([vertices_left, vertices_right])
model_with_barrier.mesh = F.MeshFromVertices(vertices)
# define materials
eurofer = F.Material(
id=2,
borders=[0, substrate_thick],
D_0=D_eurofer.pre_exp.magnitude,
E_D=D_eurofer.act_energy.magnitude,
S_0=S_eurofer.pre_exp.magnitude,
E_S=S_eurofer.act_energy.magnitude,
)
al2o3 = F.Material(
id=1,
borders=[substrate_thick, substrate_thick + barrier_thick],
D_0=D_al2o3.pre_exp.magnitude,
E_D=D_al2o3.act_energy.magnitude,
S_0=S_al2o3.pre_exp.magnitude,
E_S=S_al2o3.act_energy.magnitude,
)
model_with_barrier.materials = [eurofer, al2o3]
# define temperature
model_with_barrier.T = 600
# define boundary conditions
model_with_barrier.boundary_conditions = [
F.SievertsBC(
surfaces=1, S_0=eurofer.S_0, E_S=eurofer.E_S, pressure=upstream_pressure
),
F.DirichletBC(surfaces=2, value=0, field="solute"),
]
# define settings
model_with_barrier.settings = F.Settings(
absolute_tolerance=1e10,
relative_tolerance=1e-10,
transient=True,
chemical_pot=True,
final_time=1e5,
)
# define exports
# define exports
permeation_flux_with_barrier = F.SurfaceFlux("solute", surface=2)
model_with_barrier.exports = [
F.DerivedQuantities([permeation_flux_with_barrier], show_units=True)
]
model_with_barrier.dt = F.Stepsize(initial_value=0.5, stepsize_change_ratio=1.1)
# run simulation
model_with_barrier.initialise()
model_with_barrier.run()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[2], line 4
1 model_with_barrier = F.Simulation(log_level=40)
2
3 # define mesh
----> 4 vertices_left = np.linspace(0, substrate_thick, num=500)
5
6 vertices_right = np.linspace(substrate_thick, substrate_thick + barrier_thick, num=500)
7
NameError: name 'np' is not defined
Model without barrier#
model_without_barrier = F.Simulation(log_level=40)
# define mesh
vertices = np.linspace(0, substrate_thick, num=500)
model_without_barrier.mesh = F.MeshFromVertices(vertices)
# define materials
eurofer = F.Material(
id=2,
borders=[0, substrate_thick],
D_0=D_eurofer.pre_exp.magnitude,
E_D=D_eurofer.act_energy.magnitude,
S_0=S_eurofer.pre_exp.magnitude,
E_S=S_eurofer.act_energy.magnitude,
)
model_without_barrier.materials = eurofer
# define temperature
model_without_barrier.T = F.Temperature(value=600)
# define boundary conditions
model_without_barrier.boundary_conditions = [
F.SievertsBC(
surfaces=1, S_0=eurofer.S_0, E_S=eurofer.E_S, pressure=upstream_pressure
),
F.DirichletBC(surfaces=2, value=0, field="solute"),
]
# define settings
model_without_barrier.settings = F.Settings(
absolute_tolerance=1e10,
relative_tolerance=1e-10,
transient=True,
chemical_pot=False,
final_time=1e5,
)
model_without_barrier.dt = F.Stepsize(initial_value=0.5, stepsize_change_ratio=1.1)
# define exports
permeation_flux_without_barrier = F.SurfaceFlux("solute", surface=2)
model_without_barrier.exports = [
F.DerivedQuantities([permeation_flux_without_barrier], show_units=True)
]
# run simulation
model_without_barrier.initialise()
model_without_barrier.run()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[3], line 4
1 model_without_barrier = F.Simulation(log_level=40)
2
3 # define mesh
----> 4 vertices = np.linspace(0, substrate_thick, num=500)
5
6 model_without_barrier.mesh = F.MeshFromVertices(vertices)
7
NameError: name 'np' is not defined
Results#
t_without_barrier = permeation_flux_without_barrier.t
t_with_barrier = permeation_flux_with_barrier.t
permeation_flux_with_barrier_vals = -np.array(permeation_flux_with_barrier.data)
permeation_flux_without_barrier_vals = -np.array(permeation_flux_without_barrier.data)
import matplotlib.pyplot as plt
plt.figure()
plt.plot(t_without_barrier, permeation_flux_without_barrier_vals, label="without barrier")
plt.plot(t_with_barrier, permeation_flux_with_barrier_vals, label="with barrier")
plt.xscale("log")
plt.yscale("log")
plt.ylim(bottom=1e5)
plt.legend()
plt.xlabel("Time (s)")
plt.ylabel("Permeation flux (H/m2/s)")
plt.show()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[4], line 1
----> 1 t_without_barrier = permeation_flux_without_barrier.t
2 t_with_barrier = permeation_flux_with_barrier.t
3
4 permeation_flux_with_barrier_vals = -np.array(permeation_flux_with_barrier.data)
NameError: name 'permeation_flux_without_barrier' is not defined
PRF = permeation_flux_without_barrier_vals[-1] / permeation_flux_with_barrier_vals[-1]
print(f"PRF: {PRF:.2e}")
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[5], line 1
----> 1 PRF = permeation_flux_without_barrier_vals[-1] / permeation_flux_with_barrier_vals[-1]
2
3 print(f"PRF: {PRF:.2e}")
NameError: name 'permeation_flux_without_barrier_vals' is not defined