Skip to content

Commit 3e87bf1

Browse files
committed
refactors makeLayer in example
1 parent ffc53ca commit 3e87bf1

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

ratapi/examples/domains/domains_XY_model.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Custom model file for the domains custom XY example."""
22

3-
import math
3+
from math import sqrt
44

55
import numpy as np
6+
from scipy.special import erf
67

78

89
def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
@@ -19,13 +20,13 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
1920
z = np.arange(0, 141)
2021

2122
# Make the volume fraction distribution for our Silicon substrate
22-
[vfSilicon, siSurf] = makeLayer(z, -25, 50, 1, subRough, subRough)
23+
[vfSilicon, siSurf] = make_layer(z, -25, 50, 1, subRough, subRough)
2324

2425
# ... and the Oxide ...
25-
[vfOxide, oxSurface] = makeLayer(z, siSurf, oxideThick, 1, subRough, subRough)
26+
[vfOxide, oxSurface] = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)
2627

2728
# ... and also our layer.
28-
[vfLayer, laySurface] = makeLayer(z, oxSurface, layerThick, 1, subRough, layerRough)
29+
[vfLayer, laySurface] = make_layer(z, oxSurface, layerThick, 1, subRough, layerRough)
2930

3031
# Everything that is not already occupied will be filled will water
3132
totalVF = vfSilicon + vfOxide + vfLayer
@@ -53,7 +54,7 @@ def domains_XY_model(params, bulk_in, bulk_out, contrast, domain):
5354
return SLD, subRough
5455

5556

56-
def makeLayer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
57+
def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
5758
"""Produce a layer, with a defined thickness, height and roughness.
5859
5960
Each side of the layer has its own roughness value.
@@ -63,12 +64,9 @@ def makeLayer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
6364
right = prevLaySurf + thickness
6465

6566
# Make our heaviside
66-
a = (z - left) / ((2**0.5) * Sigma_L)
67-
b = (z - right) / ((2**0.5) * Sigma_R)
67+
erf_left = erf((z - left) / (sqrt(2) * Sigma_L))
68+
erf_right = erf((z - right) / (sqrt(2) * Sigma_R))
6869

69-
erf_a = np.array([math.erf(value) for value in a])
70-
erf_b = np.array([math.erf(value) for value in b])
71-
72-
VF = np.array((height / 2) * (erf_a - erf_b))
70+
VF = np.array((0.5 * height) * (erf_left - erf_right))
7371

7472
return VF, right

ratapi/examples/normal_reflectivity/custom_XY_DSPC.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
5252
z = np.arange(0, 141)
5353

5454
# Make our Silicon substrate
55-
vfSilicon, siSurf = layer(z, -25, 50, 1, subRough, subRough)
55+
vfSilicon, siSurf = make_layer(z, -25, 50, 1, subRough, subRough)
5656

5757
# Add the Oxide
58-
vfOxide, oxSurface = layer(z, siSurf, oxideThick, 1, subRough, subRough)
58+
vfOxide, oxSurface = make_layer(z, siSurf, oxideThick, 1, subRough, subRough)
5959

6060
# We fill in the water at the end, but there may be a hydration layer between the bilayer and the oxide,
6161
# so we start the bilayer stack an appropriate distance away
@@ -66,15 +66,15 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
6666
headThick = vHead / lipidAPM
6767

6868
# ... and make a box for the volume fraction (1 for now, we correct for coverage later)
69-
vfHeadL, headLSurface = layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
69+
vfHeadL, headLSurface = make_layer(z, watSurface, headThick, 1, bilayerRough, bilayerRough)
7070

7171
# ... also do the same for the tails
7272
# We'll make both together, so the thickness will be twice the volume
7373
tailsThick = (2 * vTail) / lipidAPM
74-
vfTails, tailsSurf = layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
74+
vfTails, tailsSurf = make_layer(z, headLSurface, tailsThick, 1, bilayerRough, bilayerRough)
7575

7676
# Finally the upper head ...
77-
vfHeadR, headSurface = layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
77+
vfHeadR, headSurface = make_layer(z, tailsSurf, headThick, 1, bilayerRough, bilayerRough)
7878

7979
# Making the model
8080
# We've created the volume fraction profiles corresponding to each of the groups.
@@ -120,7 +120,7 @@ def custom_XY_DSPC(params, bulk_in, bulk_out, contrast):
120120
return SLD, subRough
121121

122122

123-
def layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
123+
def make_layer(z, prevLaySurf, thickness, height, Sigma_L, Sigma_R):
124124
"""Produce a layer, with a defined thickness, height and roughness.
125125
126126
Each side of the layer has its own roughness value.

0 commit comments

Comments
 (0)