#!/usr/bin/env python
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#                                   Jiao Lin
#                      California Institute of Technology
#                      (C) 2006-2010 All Rights Reserved  
#
# {LicenseText}
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#


standalone = True


import unittestX as unittest
import journal

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


import mcni
from mccomposite import mccompositebp 
from mccomponents import mccomponentsbp

class TestCase(unittest.TestCase):

    def test(self):
        E_Q = "Q*Q/3."
        S_Q = "1"
        sigma_Q = "Q/2."
        Qmin = 0; Qmax = 10
        absorption_coefficient = scattering_coefficient = 1.
        kernel = mccomponentsbp.create_Broadened_E_Q_Kernel(
            E_Q, S_Q, sigma_Q,
            Qmin, Qmax,
            absorption_coefficient,
            scattering_coefficient,
            )

        ei = 500 # meV
        from mcni.utils import conversion
        vil = conversion.e2v(ei)
        vi = (0,0,vil)

        import numpy.linalg as nl
        import numpy as np
        for i in range(10):
            event = mcni.neutron( 
                r = (0,0,0), v = vi, 
                prob = 1, time = 0 )
            kernel.scatter( event );
            vf = np.array(event.state.velocity)
            diffv = vi - vf
            Q = conversion.v2k(nl.norm(diffv))
            ef = conversion.v2e(nl.norm(vf))
            E = ei - ef
            # print E, Q, event
            E1 = eval(E_Q)
            continue

        return
    
    
    pass  # end of TestCase

    
def main():
    unittest.main()
    return
    
    
if __name__ == "__main__":
    main()
    
# version
__id__ = "$Id: TestCase.py 696 2010-11-09 06:23:06Z linjiao $"

# End of file 

[((447, 493), 'journal.debug', 'journal.debug', (['"""Broadened_E_Q_Kernel_TestCase"""'], {}), "('Broadened_E_Q_Kernel_TestCase')\n", (460, 493), False, 'import journal\n'), ((506, 554), 'journal.warning', 'journal.warning', (['"""Broadened_E_Q_Kernel_TestCase"""'], {}), "('Broadened_E_Q_Kernel_TestCase')\n", (521, 554), False, 'import journal\n'), ((1771, 1786), 'unittestX.main', 'unittest.main', ([], {}), '()\n', (1784, 1786), True, 'import unittestX as unittest\n'), ((879, 1004), 'mccomponents.mccomponentsbp.create_Broadened_E_Q_Kernel', 'mccomponentsbp.create_Broadened_E_Q_Kernel', (['E_Q', 'S_Q', 'sigma_Q', 'Qmin', 'Qmax', 'absorption_coefficient', 'scattering_coefficient'], {}), '(E_Q, S_Q, sigma_Q, Qmin, Qmax,\n    absorption_coefficient, scattering_coefficient)\n', (921, 1004), False, 'from mccomponents import mccomponentsbp\n'), ((1144, 1162), 'mcni.utils.conversion.e2v', 'conversion.e2v', (['ei'], {}), '(ei)\n', (1158, 1162), False, 'from mcni.utils import conversion\n'), ((1296, 1343), 'mcni.neutron', 'mcni.neutron', ([], {'r': '(0, 0, 0)', 'v': 'vi', 'prob': '(1)', 'time': '(0)'}), '(r=(0, 0, 0), v=vi, prob=1, time=0)\n', (1308, 1343), False, 'import mcni\n'), ((1440, 1470), 'numpy.array', 'np.array', (['event.state.velocity'], {}), '(event.state.velocity)\n', (1448, 1470), True, 'import numpy as np\n'), ((1530, 1544), 'numpy.linalg.norm', 'nl.norm', (['diffv'], {}), '(diffv)\n', (1537, 1544), True, 'import numpy.linalg as nl\n'), ((1578, 1589), 'numpy.linalg.norm', 'nl.norm', (['vf'], {}), '(vf)\n', (1585, 1589), True, 'import numpy.linalg as nl\n')]