Integration with HTM#
Objectives
Use the hydrogen transport materials database HTM
Directly integrate it with FESTIM
H-transport-materials (HTM) is a python library for accessing hydrogen transport properties such as diffusivities, solubilities, recombination coefficients, etc.
It is an open-source project and contributions to the database are more than welcome! Many materials are already available: Tungsten, copper, CuCrZr, Flinak, Flibe…
To install HTM simply run:
pip install h-transport-materials
Now the interesting thing with HTM is that it can be used in FESTIM.
Let’s first have a look at the HTM api.
The HTM library#
The diffusivities in the HTM database are stored in htm.diffusivities.
They can be filtered by material, isotope, author, year with the .filter() method.
import h_transport_materials as htm
# filter only tungsten and H
diffusivities = htm.diffusivities.filter(material="tungsten").filter(isotope="h")
# plot the properties
htm.plotting.plot(diffusivities)
import matplotlib.pyplot as plt
plt.yscale("log")
plt.ylabel("Diffusivity (m$^2$/s)")
plt.legend()
plt.show()
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import h_transport_materials as htm
2
3 # filter only tungsten and H
4 diffusivities = htm.diffusivities.filter(material="tungsten").filter(isotope="h")
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'
plt.figure()
# filter only tungsten and H
solubilities = htm.solubilities.filter(material="tungsten")
htm.plotting.plot(solubilities)
plt.yscale("log")
plt.ylabel("Solubility")
plt.legend()
plt.show()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[2], line 1
----> 1 plt.figure()
2 # filter only tungsten and H
3 solubilities = htm.solubilities.filter(material="tungsten")
4
NameError: name 'plt' is not defined
FESTIM integration#
We want to use the properties of Frauenfelder for tungsten.
Let’s therefore filter the properties with .filter(author="frauenfelder").
We can obtain a single htm.ArrheniusProperty object:
diffusivities = htm.diffusivities.filter(material="tungsten").filter(isotope="h").filter(author="frauenfelder")
D = diffusivities[0]
print(type(diffusivities))
print(type(D))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[3], line 1
----> 1 diffusivities = htm.diffusivities.filter(material="tungsten").filter(isotope="h").filter(author="frauenfelder")
2 D = diffusivities[0]
3
4 print(type(diffusivities))
NameError: name 'htm' is not defined
A htm.ArrheniusProperty object has several useful attributes like .pre_exp which holds the pre-exponential factor, .act_energy for the activation energy but also .author and .year.
print(D)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[4], line 1
----> 1 print(D)
NameError: name 'D' is not defined
Let’s pick a solubility too:
S = htm.solubilities.filter(material="tungsten").filter(author="frauenfelder")[0]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[5], line 1
----> 1 S = htm.solubilities.filter(material="tungsten").filter(author="frauenfelder")[0]
NameError: name 'htm' is not defined
These properties can then be used inside a FESTIM.Material object.
This is extremely useful to avoid silly copy-pasting mistakes and typos in simulations.
import festim as F
tungsten = F.Material(
id=1,
D_0=D.pre_exp.magnitude, E_D=D.act_energy.magnitude,
S_0=S.pre_exp.magnitude, E_S=S.act_energy.magnitude
)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[6], line 6
2
3
4 tungsten = F.Material(
5 id=1,
----> 6 D_0=D.pre_exp.magnitude, E_D=D.act_energy.magnitude,
7 S_0=S.pre_exp.magnitude, E_S=S.act_energy.magnitude
8 )
NameError: name 'D' is not defined