| 1 |
|
| 2 |
""" |
| 3 |
Reflectivity with and without polarization analyzer. |
| 4 |
""" |
| 5 |
import unittest |
| 6 |
import bornagain as ba |
| 7 |
from bornagain import deg, nm, R3 |
| 8 |
|
| 9 |
from math import sin, cos |
| 10 |
|
| 11 |
|
| 12 |
def get_sample(): |
| 13 |
|
| 14 |
Bmag = 1e8 |
| 15 |
Bangle = 60*deg |
| 16 |
B = R3(Bmag*cos(Bangle), Bmag*sin(Bangle), 0) |
| 17 |
layer_color = (0.05, 0.62, 0.55) |
| 18 |
layer_mat = ba.SLDMaterial("Layer", layer_color, 0.0001, 1e-08, B) |
| 19 |
substrate_color = (0.55, 0.55, 0.55) |
| 20 |
substrate_mat = ba.SLDMaterial("Substrate", substrate_color, 7e-05, 2e-06) |
| 21 |
vacuum = ba.Vacuum() |
| 22 |
|
| 23 |
|
| 24 |
layer_1 = ba.Layer(vacuum) |
| 25 |
layer_2 = ba.Layer(layer_mat, 10*nm) |
| 26 |
layer_3 = ba.Layer(substrate_mat) |
| 27 |
|
| 28 |
|
| 29 |
sample = ba.Sample() |
| 30 |
sample.addLayer(layer_1) |
| 31 |
sample.addLayer(layer_2) |
| 32 |
sample.addLayer(layer_3) |
| 33 |
|
| 34 |
return sample |
| 35 |
|
| 36 |
|
| 37 |
def run_simulation(polarizer_vec, analyzer_vec=None): |
| 38 |
sample = get_sample() |
| 39 |
|
| 40 |
n = 50 |
| 41 |
scan = ba.AlphaScan(n, 5*deg/n, 5*deg) |
| 42 |
scan.setWavelength(0.15*nm) |
| 43 |
|
| 44 |
|
| 45 |
scan.setPolarization(polarizer_vec) |
| 46 |
if analyzer_vec: |
| 47 |
scan.setAnalyzer(analyzer_vec) |
| 48 |
|
| 49 |
simulation = ba.SpecularSimulation(scan, sample) |
| 50 |
|
| 51 |
result = simulation.simulate() |
| 52 |
|
| 53 |
return result.xCenters(), result.intensities() |
| 54 |
|
| 55 |
|
| 56 |
class PolarizedNoAnalyzerTest(unittest.TestCase): |
| 57 |
|
| 58 |
def testPolarizedNoAnalyzer(self): |
| 59 |
q, results_pp = run_simulation(R3(0, +1, 0), R3(0, +1, 0)) |
| 60 |
q, results_mm = run_simulation(R3(0, -1, 0), R3(0, -1, 0)) |
| 61 |
|
| 62 |
q, results_pm = run_simulation(R3(0, +1, 0), R3(0, -1, 0)) |
| 63 |
q, results_mp = run_simulation(R3(0, -1, 0), R3(0, +1, 0)) |
| 64 |
|
| 65 |
r_plus = results_pp + results_pm |
| 66 |
r_minus = results_mm + results_mp |
| 67 |
|
| 68 |
|
| 69 |
q, results_p = run_simulation(R3(0, +1, 0)) |
| 70 |
q, results_m = run_simulation(R3(0, -1, 0)) |
| 71 |
|
| 72 |
self.assertTrue(ba.checkRelVecDifference(results_pp + results_pm, results_p, 1e-14)) |
| 73 |
self.assertTrue(ba.checkRelVecDifference(results_mp + results_mm, results_m, 1e-14)) |
| 74 |
|
| 75 |
|
| 76 |
if __name__ == '__main__': |
| 77 |
unittest.main() |