| 1 |
""" |
| 2 |
BornAgain functional test. |
| 3 |
Transform invariance of a box in the middle layer of a 3-layer system: |
| 4 |
Box(50,20,10) rotated around Z then Y reaches the orientation of Box(10,50,20), |
| 5 |
so the two must scatter identically. |
| 6 |
""" |
| 7 |
|
| 8 |
import unittest |
| 9 |
import PyFuTestInfrastructure as infrastruct |
| 10 |
from bornagain import * |
| 11 |
|
| 12 |
layer_thickness = 100.0 |
| 13 |
|
| 14 |
|
| 15 |
class BoxTransformationsTest(unittest.TestCase): |
| 16 |
|
| 17 |
def get_sample(self, particle): |
| 18 |
mAmbience = Vacuum() |
| 19 |
mMiddle = RefractiveMaterial("Teflon", (0.70, 0.73, 0.78), 2.900e-6, |
| 20 |
6.019e-9) |
| 21 |
mSubstrate = RefractiveMaterial("Substrate", (0.55, 0.55, 0.55), |
| 22 |
3.212e-6, 3.244e-8) |
| 23 |
|
| 24 |
vacuum_layer = Layer(mAmbience) |
| 25 |
middle_layer = Layer(mMiddle, layer_thickness) |
| 26 |
middle_layer.deposit2D(Dilute2D(0.001, particle)) |
| 27 |
substrate = Layer(mSubstrate) |
| 28 |
|
| 29 |
sample = Sample() |
| 30 |
sample.addLayer(vacuum_layer) |
| 31 |
sample.addLayer(middle_layer) |
| 32 |
sample.addLayer(substrate) |
| 33 |
return sample |
| 34 |
|
| 35 |
def get_result(self, particle): |
| 36 |
sample = self.get_sample(particle) |
| 37 |
simulation = infrastruct.get_simulation_MiniGISAS(sample) |
| 38 |
simulation.options().setUseAvgMaterials(False) |
| 39 |
return simulation.simulate() |
| 40 |
|
| 41 |
def testBoxTransform(self): |
| 42 |
""" |
| 43 |
Reference box (10,50,20) is compared against box (50,20,10) rotated |
| 44 |
Z then Y into the same orientation, both at the layer midplane. |
| 45 |
""" |
| 46 |
mParticle = RefractiveMaterial("Ag", (0.86, 0.24, 0.18), 1.245e-5, |
| 47 |
5.419e-7) |
| 48 |
|
| 49 |
|
| 50 |
height = 20 |
| 51 |
box = Particle(mParticle, Box(10, 50, height)) |
| 52 |
box.translate(R3(0, 0, -layer_thickness / 2 - height / 2)) |
| 53 |
reference = self.get_result(box) |
| 54 |
|
| 55 |
|
| 56 |
box = Particle(mParticle, Box(50, 20, 10)) |
| 57 |
box.rotate(RotationZ(90 * deg)) |
| 58 |
box.rotate(RotationY(90 * deg)) |
| 59 |
box.translate(R3(0, 0, -layer_thickness / 2)) |
| 60 |
|
| 61 |
data = self.get_result(box) |
| 62 |
|
| 63 |
self.assertTrue(checkRelativeDifference(data, reference, 1e-10)) |
| 64 |
|
| 65 |
|
| 66 |
if __name__ == '__main__': |
| 67 |
unittest.main() |