Skip to content

Commit

Permalink
new DiffuseReflectivityModel in simpack
Browse files Browse the repository at this point in the history
new code for the simulation of diffuse x-ray reflectivity of multilayers
  • Loading branch information
dkriegner committed Jul 2, 2018
1 parent bb80230 commit 7aa0399
Show file tree
Hide file tree
Showing 6 changed files with 654 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* simulation code for diffuse X-ray reflectivity
* more flexibility in defining materials Wyckoff positions
* convenience function to calculate diffracted intensities of thin films to
compare various Bragg peaks (coplanar diffraction geoemetry)
Expand Down
55 changes: 55 additions & 0 deletions examples/simpack_xrr_diffuse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This file is part of xrayutilities.
#
# xrayutilities is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2018 Dominik Kriegner <dominik.kriegner@gmail.com>

import time

import xrayutilities as xu
from matplotlib.pylab import *

sub = xu.simpack.Layer(xu.materials.Si, inf, roughness=1, lat_correl=100)
lay1 = xu.simpack.Layer(xu.materials.Si, 200, roughness=1, lat_correl=200)
lay2 = xu.simpack.Layer(xu.materials.Ge, 70, roughness=3, lat_correl=50)

ls = xu.simpack.LayerStack('SL 5', sub+5*(lay2+lay1))

alphai = arange(0.17, 2, 0.001)

print("calculate method=1, H=1, vert=0")
start = time.time()
m = xu.simpack.DiffuseReflectivityModel(ls, sample_width=10, beam_width=1,
energy='CuKa1', vert_correl=1000,
vert_nu=0, H=1, method=1, vert_int=0)
d1 = m.simulate(alphai)
print("elapsed time: %.4f" % (time.time() - start))


print("calculate method=2, H=1, vert=0")
start = time.time()
m = xu.simpack.DiffuseReflectivityModel(ls, sample_width=10, beam_width=1,
energy='CuKa1', vert_correl=1000,
vert_nu=0, H=1, method=2, vert_int=0)
d2 = m.simulate(alphai)
print("elapsed time: %.4f" % (time.time() - start))

figure()
semilogy(alphai, d1, label='method=1')
semilogy(alphai, d2, label='method=2')

legend()
xlabel('incidence angle (deg)')
ylabel('intensity (arb. u.)')
tight_layout()
65 changes: 65 additions & 0 deletions tests/test_xrrdiffuse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This file is part of xrayutilities.
#
# xrayutilities is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2018 Dominik Kriegner <dominik.kriegner@gmail.com>

import os
import unittest

import numpy
import xrayutilities as xu


class Test_DiffuseReflectivityModel(unittest.TestCase):
diffmax = 2e-6
# define used layer stack
sub = xu.simpack.Layer(xu.materials.Si, numpy.inf, roughness=1,
lat_correl=100)
lay1 = xu.simpack.Layer(xu.materials.Si, 200, roughness=1, lat_correl=200)
lay2 = xu.simpack.Layer(xu.materials.Ge, 70, roughness=3, lat_correl=50)

ls = xu.simpack.LayerStack('SL 5', sub+5*(lay2+lay1))

# simulation parameters
kwargs = dict(sample_width=10, beam_width=1, energy='CuKa1',
vert_correl=1000, vert_nu=0, H=1, method=1, vert_int=0)

@classmethod
def setUpClass(cls):
cls.m1 = xu.simpack.DiffuseReflectivityModel(cls.ls, **cls.kwargs)
cls.kwargs['H'] = cls.kwargs['H'] - xu.config.EPSILON
cls.m2 = xu.simpack.DiffuseReflectivityModel(cls.ls, **cls.kwargs)
cls.kwargs['H'] = 1
cls.kwargs['method'] = 2
cls.m3 = xu.simpack.DiffuseReflectivityModel(cls.ls, **cls.kwargs)
cls.ai = numpy.arange(0.3, 2, 0.005)

def test_Calculation(self):
sim = self.m1.simulate(self.ai)
self.assertEqual(len(sim), len(self.ai))
self.assertTrue(numpy.all(sim >= 0))

def test_Consistency(self):
# calc models
sim1 = self.m1.simulate(self.ai)
sim2 = self.m2.simulate(self.ai)
sim3 = self.m3.simulate(self.ai)

self.assertTrue((numpy.mean(sim1) - numpy.mean(sim2)) < self.diffmax)
self.assertTrue((numpy.mean(sim1) - numpy.mean(sim3)) < self.diffmax)


if __name__ == '__main__':
unittest.main()
3 changes: 2 additions & 1 deletion xrayutilities/simpack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2016 Dominik Kriegner <dominik.kriegner@gmail.com>
# Copyright (C) 2016-2018 Dominik Kriegner <dominik.kriegner@gmail.com>
"""
simulation subpackage of xrayutilities.
Expand All @@ -36,6 +36,7 @@
from .models import KinematicalModel
from .models import KinematicalMultiBeamModel
from .models import SpecularReflectivityModel
from .models import DiffuseReflectivityModel
from .models import SimpleDynamicalCoplanarModel
from .models import DynamicalModel

Expand Down

0 comments on commit 7aa0399

Please sign in to comment.