Skip to content

Commit

Permalink
Add hydration model
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Sep 10, 2024
1 parent 906fe83 commit f0a8311
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
8 changes: 0 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,3 @@ Refl1d example models
:caption: Contents:

README

=========================================
Indices and tables
=========================================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
56 changes: 56 additions & 0 deletions src/refl1d_models/hydration_model.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions tests/test_hydration_model.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f0a8311

Please sign in to comment.