Skip to content
Snippets Groups Projects
Commit 86d126a0 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

cleanup

parent bd6b3725
No related branches found
No related tags found
1 merge request!1726pol doc ctd
#!/usr/bin/env python3
"""
Splin-flip reflectivity from a magnetized sample.
"""
from math import sqrt
import matplotlib.pyplot as plt
import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, nm, R3
def get_sample():
# Materials
vacuum = ba.MaterialBySLD("Vacuum", 0, 0)
h = 1e8
B = R3(1/2*h, sqrt(3)/2*h, 0)
material_layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, B)
material_substrate = ba.MaterialBySLD("Substrate", 7e-05, 2e-06)
# Layers
layer_1 = ba.Layer(vacuum)
layer_2 = ba.Layer(material_layer, 10*nm)
layer_3 = ba.Layer(material_substrate)
# Sample
sample = ba.MultiLayer()
sample.addLayer(layer_1)
sample.addLayer(layer_2)
sample.addLayer(layer_3)
return sample
def run_simulation(polarizer_dir, analyzer_dir=None):
sample = get_sample()
n = 500
scan = ba.AlphaScan(n, 5*deg/n, 5*deg)
scan.setWavelength(1.54*angstrom)
# adding polarizer and analyzer operator
scan.setPolarization(polarizer_dir)
if analyzer_dir:
scan.setAnalyzer(analyzer_dir, 1, 0.5)
simulation = ba.SpecularSimulation(scan, sample)
result = simulation.simulate()
return result.convertedBinCenters(), result.array()
def plot(axis, data, labels):
plt.figure()
plt.yscale('log')
for d, l in zip(data, labels):
plt.plot(axis, d, label=l, linewidth=1)
plt.legend(loc='upper right')
bp.inside_ticks()
plt.xlabel(r"$\alpha_{\rm i} \;(^\circ)$")
plt.ylabel("Reflectivity")
plt.tight_layout()
if __name__ == '__main__':
q, results_pp = run_simulation(R3(0, +1, 0), R3(0, +1, 0))
q, results_mm = run_simulation(R3(0, -1, 0), R3(0, -1, 0))
q, results_pm = run_simulation(R3(0, +1, 0), R3(0, -1, 0))
q, results_mp = run_simulation(R3(0, -1, 0), R3(0, +1, 0))
r_plus = results_pp + results_pm
r_minus = results_mm + results_mp
plot(q, [r_plus, r_minus], ["$+$", "$-$"])
# same result, but need half the computational time
q, results_p = run_simulation(R3(0, +1, 0))
q, results_m = run_simulation(R3(0, -1, 0))
plot(q, [results_p, results_m], ["$+$", "$-$"])
bp.show_or_export()
#!/usr/bin/env python3
"""
Splin-flip reflectivity from a magnetized sample.
"""
from math import sqrt
import matplotlib.pyplot as plt
import bornagain as ba
from bornagain import angstrom, ba_plot as bp, deg, nm, R3
def get_sample():
# Materials
vacuum = ba.MaterialBySLD("Vacuum", 0, 0)
h = 1e8
B = R3(1/2*h, sqrt(3)/2*h, 0)
material_layer = ba.MaterialBySLD("Layer", 0.0001, 1e-08, B)
material_substrate = ba.MaterialBySLD("Substrate", 7e-05, 2e-06)
# Layers
layer_1 = ba.Layer(vacuum)
layer_2 = ba.Layer(material_layer, 10*nm)
layer_3 = ba.Layer(material_substrate)
# Sample
sample = ba.MultiLayer()
sample.addLayer(layer_1)
sample.addLayer(layer_2)
sample.addLayer(layer_3)
return sample
def run_simulation(polarizer_dir, analyzer_dir=None):
sample = get_sample()
n = 50
scan = ba.AlphaScan(n, 5*deg/n, 5*deg)
scan.setWavelength(1.54*angstrom)
# adding polarizer and analyzer operator
scan.setPolarization(polarizer_dir)
if analyzer_dir:
scan.setAnalyzer(analyzer_dir, 1, 0.5)
simulation = ba.SpecularSimulation(scan, sample)
result = simulation.simulate()
return result.convertedBinCenters(), result.array()
def plot(axis, data, labels):
plt.figure()
plt.yscale('log')
for d, l in zip(data, labels):
plt.plot(axis, d, label=l, linewidth=1)
plt.legend(loc='upper right')
bp.inside_ticks()
plt.xlabel(r"$\alpha_{\rm i} \;(^\circ)$")
plt.ylabel("Reflectivity")
plt.tight_layout()
if __name__ == '__main__':
q, results_pp = run_simulation(R3(0, +1, 0), R3(0, +1, 0))
q, results_mm = run_simulation(R3(0, -1, 0), R3(0, -1, 0))
q, results_pm = run_simulation(R3(0, +1, 0), R3(0, -1, 0))
q, results_mp = run_simulation(R3(0, -1, 0), R3(0, +1, 0))
r_plus = results_pp + results_pm
r_minus = results_mm + results_mp
plot(q, [r_plus, r_minus], ["$+$", "$-$"])
# same result, but need half the computational time
q, results_p = run_simulation(R3(0, +1, 0))
q, results_m = run_simulation(R3(0, -1, 0))
plot(q, [results_p, results_m], ["$+$", "$-$"])
bp.show_or_export()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment