Esempio n. 1
0
    def test3(self):
        'LinearlyInterpolatedDispersion_3D'
        import mccomponents.sample.phonon.bindings as bindings
        b = bindings.get('BoostPython')

        nAtoms = 2
        nBranches = 3 * nAtoms
        nQx = 10
        nQy = 12
        nQz = 14
        Qaxes = [
            ([1, 1, 0], nQx),
            ([1, 0, 1], nQy),
            ([0, 1, 1], nQz),
        ]

        import histogram as H
        qx = H.axis('qx', H.arange(0, 1 + 1e-10, 1. / (nQx - 1)))
        qy = H.axis('qy', H.arange(0, 1 + 1e-10, 1. / (nQy - 1)))
        qz = H.axis('qz', H.arange(0, 1 + 1e-10, 1. / (nQz - 1)))
        br = H.axis('branchId', range(nBranches))
        atoms = H.axis('atomId', range(nAtoms))
        pols = H.axis('polId', range(3))
        realimags = H.axis('realimagId', range(2))

        eps = H.histogram('eps', [qx, qy, qz, br, atoms, pols, realimags],
                          fromfunction=lambda qx, qy, qz, br, atom, pol,
                          realimag: qx + qy + qz + br + atom + pol + realimag)
        e = H.histogram('e', [qx, qy, qz, br],
                        fromfunction=lambda qx, qy, qz, br: qx + qy + qz + br)

        disp = b.linearlyinterpolateddispersion_3d(nAtoms, Qaxes, eps.I, e.I)

        Q = b.vector3
        # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        # these tests failed because we are not doing interpolation
        # right now since we don't have a good way to do
        # it for the polarization vectors.
        # right now we just take the value of the closest vertex.
        checkDiff = self.assertAlmostEqual

        def checkDiff(a, b):
            print a, b

        checkDiff(disp.energy(0, Q(0, 0, 0)), 0)
        checkDiff(disp.energy(0, Q(1 - 1e-5, 1 - 1e-5, 0)), 1 - 1e-5)
        checkDiff(disp.energy(0, Q(0.5, 0.5, 0)), 0.5)
        checkDiff(disp.energy(0, Q(0.5, 0, 0.5)), 0.5)
        checkDiff(disp.energy(0, Q(0, 0.5, 0.5)), 0.5)
        checkDiff(disp.energy(0, Q(0.5, 0.5, 1 - 1e-10)), 1)
        return
    def test3(self):
        'LinearlyInterpolatedDispersion_3D'
        import mccomponents.sample.phonon.bindings as bindings
        b = bindings.get('BoostPython')
        
        nAtoms = 2
        nBranches = 3 * nAtoms
        nQx = 10; nQy = 12; nQz = 14
        Qaxes = [ ([1,1,0], nQx),
                  ([1,0,1], nQy),
                  ([0,1,1], nQz),
                  ]

        import histogram as H
        qx = H.axis('qx', H.arange(0, 1+1e-10, 1./(nQx-1)))
        qy = H.axis('qy', H.arange(0, 1+1e-10, 1./(nQy-1)))
        qz = H.axis('qz', H.arange(0, 1+1e-10, 1./(nQz-1)))
        br = H.axis('branchId', range(nBranches))
        atoms = H.axis('atomId', range(nAtoms))
        pols = H.axis('polId', range(3))
        realimags = H.axis('realimagId', range(2))
        
        eps = H.histogram(
            'eps', [qx,qy,qz,br,atoms,pols,realimags],
            fromfunction = lambda qx,qy,qz,br,atom,pol,realimag: qx+qy+qz+br+atom+pol+realimag)
        e = H.histogram(
            'e', [qx,qy,qz,br],
            fromfunction = lambda qx,qy,qz,br: qx+qy+qz+br)

        disp = b.linearlyinterpolateddispersion_3d(nAtoms, Qaxes, eps.I, e.I)

        Q = b.vector3
        # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        # these tests failed because we are not doing interpolation
        # right now since we don't have a good way to do 
        # it for the polarization vectors.
        # right now we just take the value of the closest vertex.
        checkDiff = self.assertAlmostEqual
        def checkDiff(a, b):
            print a,b
        checkDiff(disp.energy(0, Q(0,0,0)), 0)
        checkDiff(disp.energy(0, Q(1-1e-5,1-1e-5,0)), 1-1e-5)
        checkDiff(disp.energy(0, Q(0.5,0.5,0)), 0.5)
        checkDiff(disp.energy(0, Q(0.5,0,0.5)), 0.5)
        checkDiff(disp.energy(0, Q(0,0.5,0.5)), 0.5)
        checkDiff(disp.energy(0, Q(0.5,0.5,1-1e-10)), 1)
        return
    def test(self):
        nQs = 20
        Qx_axis = mccomponentsbp.LinearlyInterpolatableAxis_dbl(-10, 1., nQs)
        Qy_axis = mccomponentsbp.LinearlyInterpolatableAxis_dbl(-10, 1., nQs)
        Qz_axis = mccomponentsbp.LinearlyInterpolatableAxis_dbl(-10, 1., nQs)
        nAtoms = 5
        nDims = 3
        nBranches = nAtoms * nDims
        import numpy
        eps_data = numpy.zeros(
            (nQs + 1, nQs + 1, nQs + 1, nBranches, nAtoms, nDims, 2),
            dtype=numpy.double)
        E_data = numpy.zeros((nQs + 1, nQs + 1, nQs + 1, nBranches),
                             dtype=numpy.double)

        from mccomponents.sample.phonon.bindings import get
        binding = get('BoostPython')
        eps_arr = binding.ndarray(eps_data)
        E_arr = binding.ndarray(E_data)

        disp = mccomponentsbp.LinearlyInterpolatedDispersionOnGrid_3D_dblarrays(
            nAtoms, Qx_axis, Qy_axis, Qz_axis, eps_arr, E_arr)
        return
def example():
    nQs = 25
    Qx_axis = mccomponentsbp.LinearlyInterpolatableAxis_dbl( -12, 1., nQs )
    Qy_axis = mccomponentsbp.LinearlyInterpolatableAxis_dbl( -12, 1., nQs )
    Qz_axis = mccomponentsbp.LinearlyInterpolatableAxis_dbl( -12, 1., nQs )
    nAtoms = 5
    nDims = 3
    nBranches = nAtoms*nDims
    import numpy
    eps_data = numpy.zeros(
        ( nQs+1, nQs+1, nQs+1, nBranches, nAtoms, nDims, 2 ),
        dtype = numpy.double)
    E_data = numpy.zeros(
        ( nQs+1, nQs+1, nQs+1, nBranches ),
        dtype = numpy.double)
    
    from mccomponents.sample.phonon.bindings import get
    binding = get('BoostPython')
    eps_arr = binding.ndarray( eps_data )
    E_arr = binding.ndarray( E_data )
    
    disp = mccomponentsbp.LinearlyInterpolatedDispersionOnGrid_3D_dblarrays(
        nAtoms, Qx_axis, Qy_axis, Qz_axis, eps_arr, E_arr )
    return disp
Esempio n. 5
0
    eps = H.histogram('eps', [qx, qy, qz, br, atoms, pols, realimags])
    eps.I[:] = 1
    e = H.histogram(
        'e',
        [qx, qy, qz, br],
        fromfunction=lambda qx, qy, qz, br:
        (qx * qx + qy * qy + qz * qz) / 3. * 50,
    )

    disp = b.linearlyinterpolateddispersion_3d(nAtoms, Qaxes, eps.I, e.I)
    disp = b.periodicdispersion(disp, ((1, 0, 0), (0, 1, 0), (0, 0, 1)))
    return disp


import mccomponents.sample.phonon.bindings as bindings
b = bindings.get('BoostPython')

import numpy as N


def pysuite():
    suite1 = unittest.makeSuite(TestCase)
    return unittest.TestSuite((suite1, ))


def main():
    #debug.activate()
    #journal.debug("CompositeNeutronScatterer_Impl").activate()
    #journal.debug('phonon_coherent_inelastic_polyxtal_kernel').activate()
    pytests = pysuite()
    alltests = unittest.TestSuite((pytests, ))
def makeDW():
    nsampling = 100
    return b.dwfromDOS(mkDOS(), mass, temperature, nsampling)
    

def makeDispersion():
    from mccomponents.sample.phonon import periodicdispersion_fromidf
    disp = periodicdispersion_fromidf(dispersion_dir)
    from mccomponents.homogeneous_scatterer import kernelEngine, scattererEngine
    disp = scattererEngine(disp)
    return disp


import mccomponents.sample.phonon.bindings as bindings
b = bindings.get('BoostPython')

from mcstas2.pyre_support._component_interfaces.monitors.IQE_monitor import get_histogram
import numpy as N


def pysuite():
    TestCase.interactive = True
    suite1 = unittest.makeSuite(TestCase)
    return unittest.TestSuite( (suite1,) )


def main():
    #debug.activate()
    #journal.debug("CompositeNeutronScatterer_Impl").activate()
    #journal.debug('phonon_coherent_inelastic_polyxtal_kernel').activate()
# {LicenseText}
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#



import unittestX as unittest
import journal

debug = journal.debug( "BoostPython_TestCase" )
warning = journal.warning( "BoostPython_TestCase" )


from mccomponents.sample.phonon.bindings import get
bp = get('BoostPython')


class TestCase(unittest.TestCase):


    def test1(self):
        'linearlyinterpolateddos'
        import numpy as N
        Z = N.zeros( 50 )
        area = 0
        for i in range(50):
            Z[i] = i*i
            area += Z[i]
            continue
        dos = bp.linearlyinterpolateddos(0, 1., 50, Z )
Esempio n. 8
0
#                        (C) 2007 All Rights Reserved
#
# {LicenseText}
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#

import unittestX as unittest
import journal

debug = journal.debug("BoostPython_TestCase")
warning = journal.warning("BoostPython_TestCase")

from mccomponents.sample.phonon.bindings import get

bp = get('BoostPython')


class TestCase(unittest.TestCase):
    def test1(self):
        'linearlyinterpolateddos'
        import numpy as N
        Z = N.zeros(50)
        area = 0
        for i in range(50):
            Z[i] = i * i
            area += Z[i]
            continue
        dos = bp.linearlyinterpolateddos(0, 1., 50, Z)
        self.assertAlmostEqual(dos(3), 3.**2 / area)
        return

def makeDispersion():
    from mccomponents.sample.phonon import periodicdispersion_fromidf

    disp = periodicdispersion_fromidf("phonon-dispersion-fccNi-primitive-reciprocal-unitcell")
    from mccomponents.homogeneous_scatterer import kernelEngine, scattererEngine

    disp = scattererEngine(disp)
    return disp


import numpy as N
import mccomponents.sample.phonon.bindings as bindings

bp = bindings.get("BoostPython")


def pysuite():
    suite1 = unittest.makeSuite(TestCase)
    return unittest.TestSuite((suite1,))


def main():
    # debug.activate()
    journal.debug("periodicdispersion_3d").activate()
    pytests = pysuite()
    alltests = unittest.TestSuite((pytests,))
    res = unittest.TextTestRunner(verbosity=2).run(alltests)
    import sys