From f0a83115097613f331b1c9b858115a4aa1605d56 Mon Sep 17 00:00:00 2001 From: Mathieu Doucet Date: Tue, 10 Sep 2024 17:01:51 -0400 Subject: [PATCH] Add hydration model --- docs/index.rst | 8 ---- src/refl1d_models/hydration_model.py | 56 ++++++++++++++++++++++++++++ tests/test_hydration_model.py | 9 +++++ 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/refl1d_models/hydration_model.py create mode 100644 tests/test_hydration_model.py diff --git a/docs/index.rst b/docs/index.rst index 1b5768e..5388370 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,11 +7,3 @@ Refl1d example models :caption: Contents: README - -========================================= -Indices and tables -========================================= - -* :ref:`genindex` -* :ref:`modindex` -* :ref:`search` diff --git a/src/refl1d_models/hydration_model.py b/src/refl1d_models/hydration_model.py new file mode 100644 index 0000000..129e4b8 --- /dev/null +++ b/src/refl1d_models/hydration_model.py @@ -0,0 +1,56 @@ +""" +Hydration model example +""" + +import numpy as np +from refl1d.names import SLD, Experiment, FitProblem, Parameter, QProbe + +# PRobe ######################################################################## +q = np.logspace(np.log10(0.009), np.log10(0.18), num=150) +dq = 0.025 * q / 2.35 + +probe = QProbe(q, dq) + +# Materials #################################################################### +silicon = SLD(name="Si", rho=2.07, irho=0.0) +d2o = SLD(name="D2O", rho=6.13, irho=0.0) +titanium = SLD(name="Ti", rho=-1.238, irho=0.0) +copper = SLD(name="Cu", rho=6.446, irho=0.0) +material = SLD(name="material", rho=-1.648, irho=0.1) +sei = SLD(name="SEI", rho=4.581, irho=0.1) + +# Film definition ############################################################## +sample = ( + d2o(0, 43.77) | sei(177.7, 23.04) | material(21.73, 18.22) | copper(566.1, 9.736) | titanium(52.91, 12.7) | silicon +) + +# Parameter ranges ############################################################# +sample["Ti"].thickness.range(20.0, 60.0) +sample["Ti"].material.rho.range(-2.0, 0.0) +sample["Ti"].interface.range(1.0, 20.0) +sample["Cu"].thickness.range(10.0, 800.0) +sample["Cu"].interface.range(8.0, 15.0) +sample["material"].thickness.range(15.0, 100.0) +sample["material"].material.rho.range(-3.0, 8.0) +sample["material"].interface.range(1.0, 35.0) +sample["SEI"].thickness.range(100.0, 300.0) +sample["SEI"].interface.range(5.0, 25.0) + +# Define a base SLD value for the SEI layer +base_sld = Parameter(value=3, name="base_sld").range(-3.0, 8.0) + +# Define a solvent penetration parameter for the SEI layer +solvent_penetration = Parameter(value=0.0, name="penetration").range(0, 1) + +# The SLD of the SEI layer is a linear combination of the base SLD and the solvent SLD, +# according to the solvent penetration parameter +sample["SEI"].material.rho = base_sld * (1 - solvent_penetration) + sample["D2O"].material.rho * solvent_penetration + +# The probe has a normalization parameter and a background parameter +probe.intensity = Parameter(value=1.0, name="normalization") +probe.background.range(0.0, 1e-05) +sample["D2O"].interface.range(25.0, 150.0) + +# Create the experiment and the problem objects +experiment = Experiment(probe=probe, sample=sample) +problem = FitProblem(experiment) diff --git a/tests/test_hydration_model.py b/tests/test_hydration_model.py new file mode 100644 index 0000000..e35ed6d --- /dev/null +++ b/tests/test_hydration_model.py @@ -0,0 +1,9 @@ +from refl1d_models.hydration_model import experiment + + +def test_hydration_model(): + """ + Example use and test of the hydration model + """ + r, dr = experiment.reflectivity() + assert len(r) == 150