#!/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 

[((21, 8, 21, 56), 'journal.debug', 'journal.debug', ({(21, 23, 21, 54): '"""Broadened_E_Q_Kernel_TestCase"""'}, {}), "('Broadened_E_Q_Kernel_TestCase')", False, 'import journal\n'), ((22, 10, 22, 60), 'journal.warning', 'journal.warning', ({(22, 27, 22, 58): '"""Broadened_E_Q_Kernel_TestCase"""'}, {}), "('Broadened_E_Q_Kernel_TestCase')", False, 'import journal\n'), ((72, 4, 72, 19), 'unittestX.main', 'unittest.main', ({}, {}), '()', True, 'import unittestX as unittest\n'), ((37, 17, 42, 13), 'mccomponents.mccomponentsbp.create_Broadened_E_Q_Kernel', 'mccomponentsbp.create_Broadened_E_Q_Kernel', ({(38, 12, 38, 15): 'E_Q', (38, 17, 38, 20): 'S_Q', (38, 22, 38, 29): 'sigma_Q', (39, 12, 39, 16): 'Qmin', (39, 18, 39, 22): 'Qmax', (40, 12, 40, 34): 'absorption_coefficient', (41, 12, 41, 34): 'scattering_coefficient'}, {}), '(E_Q, S_Q, sigma_Q, Qmin, Qmax,\n    absorption_coefficient, scattering_coefficient)', False, 'from mccomponents import mccomponentsbp\n'), ((46, 14, 46, 32), 'mcni.utils.conversion.e2v', 'conversion.e2v', ({(46, 29, 46, 31): 'ei'}, {}), '(ei)', False, 'from mcni.utils import conversion\n'), ((52, 20, 54, 36), 'mcni.neutron', 'mcni.neutron', (), '', False, 'import mcni\n'), ((56, 17, 56, 47), 'numpy.array', 'np.array', ({(56, 26, 56, 46): 'event.state.velocity'}, {}), '(event.state.velocity)', True, 'import numpy as np\n'), ((58, 31, 58, 45), 'numpy.linalg.norm', 'nl.norm', ({(58, 39, 58, 44): 'diffv'}, {}), '(diffv)', True, 'import numpy.linalg as nl\n'), ((59, 32, 59, 43), 'numpy.linalg.norm', 'nl.norm', ({(59, 40, 59, 42): 'vf'}, {}), '(vf)', True, 'import numpy.linalg as nl\n')]