| 1 |
""" |
| 2 |
Check automatic slicing by comparing scattering from particle in decorated_layer |
| 3 |
- (A) without slicing |
| 4 |
- (B) with slicing provoked by dividing decorated_layer into sublayers |
| 5 |
""" |
| 6 |
|
| 7 |
import unittest |
| 8 |
import PyFuTestInfrastructure as infrastruct |
| 9 |
import bornagain as ba |
| 10 |
|
| 11 |
matVacuum = ba.Vacuum() |
| 12 |
matSubstrate_color = (0.55, 0.55, 0.55) |
| 13 |
matSubstrate = ba.RefractiveMaterial("Substrate", matSubstrate_color, 3.2e-6, 3.2e-8) |
| 14 |
matParticle_color = (0.86, 0.24, 0.18) |
| 15 |
matParticle = ba.RefractiveMaterial("Ag", matParticle_color, 1.2e-5, 5.4e-7) |
| 16 |
|
| 17 |
R = 10.0 |
| 18 |
dz = 4.0 |
| 19 |
|
| 20 |
|
| 21 |
def get_sample(particle, sliced): |
| 22 |
""" |
| 23 |
Returns a sample, with given particles attached to substrate or vacuum layer. |
| 24 |
""" |
| 25 |
sample = ba.Sample() |
| 26 |
sample.addLayer(ba.Layer(matVacuum)) |
| 27 |
if sliced: |
| 28 |
sample.addLayer(ba.Layer(matSubstrate, 5)) |
| 29 |
sample.addLayer(ba.Layer(matSubstrate, 3)) |
| 30 |
sample.addLayer(ba.Layer(matSubstrate, 2)) |
| 31 |
else: |
| 32 |
sample.addLayer(ba.Layer(matSubstrate, 10)) |
| 33 |
substrate = ba.Layer(matSubstrate) |
| 34 |
substrate.suspend2D(ba.Dilute2D(0.001, particle)) |
| 35 |
sample.addLayer(substrate) |
| 36 |
|
| 37 |
return sample |
| 38 |
|
| 39 |
|
| 40 |
class SlicedSpheresTest(unittest.TestCase): |
| 41 |
|
| 42 |
def runPlainFF(self, ff, eps = 1e-14): |
| 43 |
particle = ba.Particle(matParticle, ff) |
| 44 |
d1 = infrastruct.run_simulation_MiniGISAS(get_sample(particle, False)) |
| 45 |
d2 = infrastruct.run_simulation_MiniGISAS(get_sample(particle, False)) |
| 46 |
self.assertTrue(ba.checkRelativeDifference(d1, d2, eps)) |
| 47 |
|
| 48 |
def testSlicingPlainFF(self): |
| 49 |
self.runPlainFF(ba.Cone(8., 9., 80*ba.deg)) |
| 50 |
self.runPlainFF(ba.Cylinder(3., 9.)) |
| 51 |
self.runPlainFF(ba.EllipsoidalCylinder(3., 4., 9.)) |
| 52 |
self.runPlainFF(ba.Ellipsoid(7., 8., 9.)) |
| 53 |
self.runPlainFF(ba.HorizontalCylinder(5., 19.), 5e-12) |
| 54 |
self.runPlainFF(ba.HorizontalCylinder(5., 19., 1., 1.), 5e-12) |
| 55 |
self.runPlainFF(ba.HorizontalCylinder(6., 19., 3., 3.), 5e-12) |
| 56 |
self.runPlainFF(ba.Sphere(5.)) |
| 57 |
self.runPlainFF(ba.Spheroid(4., 4.)) |
| 58 |
self.runPlainFF(ba.SphericalSegment(7., 9., 1.)) |
| 59 |
self.runPlainFF(ba.SpheroidalSegment(7., 9., .9, 1.)) |
| 60 |
self.runPlainFF(ba.EllipsoidalSegment(5., 7., 9., .9, 1.)) |
| 61 |
|
| 62 |
self.runPlainFF(ba.PlatonicTetrahedron(12.)) |
| 63 |
self.runPlainFF(ba.Prism3(8., 10.)) |
| 64 |
self.runPlainFF(ba.Prism6(4., 9.)) |
| 65 |
self.runPlainFF(ba.Pyramid3(8., 10., 80*ba.deg)) |
| 66 |
self.runPlainFF(ba.Pyramid4(8., 9., 80*ba.deg)) |
| 67 |
self.runPlainFF(ba.Pyramid6(18., 8., 40*ba.deg)) |
| 68 |
|
| 69 |
|
| 70 |
if __name__ == '__main__': |
| 71 |
unittest.main() |