File: transform_box.py

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (72 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Test of rotation/position of box in the middle layer of 3 layers system.
Box(50, 20, 10), is rotated around Z, then around Y, then shifted up and then
compared with Box(10, 50, 20)
"""

import unittest
import bornagain as ba
from bornagain import deg, R3
import PyFuTestInfrastructure as infrastruct

layer_thickness = 100


class BoxTransformationsTest(unittest.TestCase):

    def get_sample(self, particle):
        mAmbience = ba.RefractiveMaterial("Vacuum", 0, 0)
        mMiddle = ba.RefractiveMaterial("Teflon", 2.900e-6, 6.019e-9)
        mSubstrate = ba.RefractiveMaterial("Substrate", 3.212e-6, 3.244e-8)

        layout = ba.ParticleLayout()
        layout.addParticle(particle)

        vacuum_layer = ba.Layer(mAmbience)
        middle_layer = ba.Layer(mMiddle, layer_thickness)
        middle_layer.addLayout(layout)
        substrate = ba.Layer(mSubstrate)

        sample = ba.Sample()
        sample.addLayer(vacuum_layer)
        sample.addLayer(middle_layer)
        sample.addLayer(substrate)
        return sample

    def get_result(self, particle):
        sample = self.get_sample(particle)
        simulation = infrastruct.get_simulation_MiniGISAS(sample)
        return simulation.simulate()

    def testBoxTransform(self):
        """
        Reference box of (10,50,20) size is compared against the box (50,20,10)
        with two rotations applied to get reference one
        """
        mParticle = ba.RefractiveMaterial("Ag", 1.245e-5, 5.419e-7)

        # reference box
        length = 10
        width = 50
        height = 20

        box = ba.Particle(mParticle, ba.Box(length, width, height))
        box.translate(R3(0, 0, -layer_thickness / 2 - height / 2))
        reference = self.get_result(box)

        # second box
        length = 50
        width = 20
        height = 10
        box = ba.Particle(mParticle, ba.Box(length, width, height))
        box.rotate(ba.RotationZ(90 * deg))
        box.rotate(ba.RotationY(90 * deg))
        box.translate(R3(0, 0, -layer_thickness / 2))

        data = self.get_result(box)

        self.assertTrue(ba.checkRelativeDifference(data, reference, 4e-13))


if __name__ == '__main__':
    unittest.main()