def test(self): 'mcni.pyre_components.NeutronsOnCone_FixedQE' from mcni.pyre_components.NeutronsOnCone_FixedQE import NeutronsOnCone_FixedQE as factory component = factory('source') component.inventory.Q = Q component.inventory.E = E component.inventory.Ei = Ei component.inventory.L1 = L1 component._configure() component._init() import mcni neutrons = mcni.neutron_buffer(10) component.process(neutrons) from numpy.linalg import norm from mcni.utils import v2e, e2v, v2k vi = e2v(Ei) t = L1 / vi for n in neutrons: vv = n.state.velocity vQv = -vv[0], -vv[1], vi - vv[2] vQ = norm(vQv) Q1 = v2k(vQ) v = norm(vv) self.assertAlmostEqual(v2e(v), Ei - E, 4) self.assertAlmostEqual(n.time, t, 4) self.assertAlmostEqual(Q, Q1, 4) continue component._fini() return
def test(self): 'mcni.pyre_components.NeutronsOnCone_FixedQE' from mcni.pyre_components.NeutronsOnCone_FixedQE import NeutronsOnCone_FixedQE as factory component = factory( 'source' ) component.inventory.Q = Q component.inventory.E = E component.inventory.Ei = Ei component.inventory.L1 = L1 component._configure() component._init() import mcni neutrons = mcni.neutron_buffer( 10 ) component.process( neutrons ) from numpy.linalg import norm from mcni.utils import v2e, e2v, v2k vi = e2v( Ei ) t = L1/vi for n in neutrons: vv = n.state.velocity vQv = -vv[0], -vv[1], vi-vv[2] vQ = norm(vQv) Q1 = v2k(vQ) v = norm( vv ) self.assertAlmostEqual( v2e(v), Ei-E, 4) self.assertAlmostEqual( n.time, t, 4 ) self.assertAlmostEqual( Q, Q1, 4 ) continue component._fini() return
def test2(self): "instrument: monochromatic source, sample, ??? detector" mod2sample = 10.0 # meter Ei = 70 from mcni.utils import e2v vi = e2v(Ei) # m/s Qmin = 0 Qmax = 10 nQ = 100 from SSD import Instrument as base class Instrument(base): class Inventory(base.Inventory): from mcni.pyre_support import facility, componentfactory as component detector = facility( "detector", default=component("monitors", "NeutronPrinter", supplier="mcni")("detector") ) pass # end of Inventory def __init__(self, name="test"): base.__init__(self, name) return def _defaults(self): base._defaults(self) geometer = self.inventory.geometer geometer.inventory.source = (0, 0, 0), (0, 0, 0) geometer.inventory.sample = (0, 0, mod2sample), (0, 0, 0) geometer.inventory.detector = (0, 0, mod2sample), (0, 0, 0) source = self.inventory.source source.inventory.position = 0, 0, 0 source.inventory.velocity = 0, 0, vi source.inventory.probability = 1 source.inventory.time = 0.0 sample = self.inventory.sample sample.inventory.xml = sampleassembly_xml detector = self.inventory.detector return pass # end of Instrument app = Instrument() app.run() return
def test2(self): 'instrument: monochromatic source, sample, ??? detector' mod2sample = 10. # meter Ei = 70 from mcni.utils import e2v vi = e2v( Ei ) #m/s Qmin = 0; Qmax = 10; nQ = 100 from SSD import Instrument as base class Instrument(base): class Inventory(base.Inventory): from mcni.pyre_support import facility, componentfactory as component detector = facility( 'detector', default = component( 'monitors', 'NeutronPrinter', supplier = 'mcni')\ ('detector') ) pass # end of Inventory def __init__(self, name = "test"): base.__init__(self, name) return def _defaults(self): base._defaults(self) geometer = self.inventory.geometer geometer.inventory.source = (0,0,0), (0,0,0) geometer.inventory.sample = (0,0,mod2sample), (0,0,0) geometer.inventory.detector = (0,0,mod2sample), (0,0,0) source = self.inventory.source source.inventory.position = 0,0,0 source.inventory.velocity = 0,0,vi source.inventory.probability = 1 source.inventory.time = 0.0 sample = self.inventory.sample sample.inventory.xml = sampleassembly_xml detector = self.inventory.detector return pass # end of Instrument app = Instrument() app.run() return
def onMonochromaticSource(self, source): kwds = { 'name': source.label, 'category': 'sources', 'type': 'MonochromaticSource', 'supplier': 'mcni', } self.onNeutronComponent(**kwds) from mcni.utils import e2v v = e2v(source.energy) self.Ei = source.energy self.cmdline_opts['%s.velocity' % source.label] = (0, 0, v) return
def onMonochromaticSource(self, source): kwds = { 'name': source.label, 'category': 'sources', 'type': 'MonochromaticSource', 'supplier': 'mcni', } self.onNeutronComponent( **kwds ) from mcni.utils import e2v v = e2v( source.energy ) self.Ei = source.energy self.cmdline_opts[ '%s.velocity' % source.label ] = (0,0,v) return
def __init__(self, name, Q, E, Ei, L1): AbstractComponent.__init__(self, name) Ef = Ei - E from mcni.utils import e2k, e2v ki = e2k( Ei ) kf = e2k( Ef ) assert Q > abs(kf-ki) and Q < ki+kf, \ 'invalid: ki=%s, kf=%s, Q=%s' % ( ki, kf, Q ) cost = (ki*ki+kf*kf-Q*Q)/2/ki/kf from math import acos, cos, sin theta = acos( cost ) vf = e2v( Ef ) self.vz = vf * cos( theta ) self.vp = vf * sin( theta ) vi = e2v( Ei ) self.t0 = L1/vi return
def __init__(self, name, Q, E, Ei, L1): AbstractComponent.__init__(self, name) Ef = Ei - E from mcni.utils import e2k, e2v ki = e2k(Ei) kf = e2k(Ef) assert Q > abs(kf-ki) and Q < ki+kf, \ 'invalid: ki=%s, kf=%s, Q=%s' % ( ki, kf, Q ) cost = (ki * ki + kf * kf - Q * Q) / 2 / ki / kf from math import acos, cos, sin theta = acos(cost) vf = e2v(Ef) self.vz = vf * cos(theta) self.vp = vf * sin(theta) vi = e2v(Ei) self.t0 = L1 / vi return
# Jiao Lin # California Institute of Technology # (C) 2007 All Rights Reserved # # {LicenseText} # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # eventsdat = 'events.dat' instrumentxml = 'Pharos.xml' Ei = 70 from mcni.utils import e2v vi = e2v( Ei ) #m/s from instrument.nixml import parse_file instrument = parse_file( instrumentxml ) geometer = instrument.geometer import mcni.units as units meter = units.length.meter mod2sample = geometer.distanceToSample( instrument.getModerator() ) / meter tmin = mod2sample/vi sample2det = instrument.getDetectorSystem().shape().in_radius tmax = tmin + sample2det/e2v( 5 ) tofparams = tmin, tmax, (tmax-tmin)/1000 print tofparams Idpt_filename = 'Idpt.h5'
eventsdat = 'events.dat' instrumentxml = 'Pharos.xml' Ei = 70 #incident energy Q = 5 #momentum transfer E = 30 #energy transfer from mcni.utils import e2v vi = e2v(Ei) #m/s from instrument.nixml import parse_file instrument = parse_file(instrumentxml) geometer = instrument.geometer import mcni.units as units meter = units.length.meter mod2sample = geometer.distanceToSample(instrument.getModerator()) / meter tmin = mod2sample / vi sample2det = instrument.getDetectorSystem().shape().in_radius tmax = tmin + sample2det / e2v(5) tofparams = tmin, tmax, (tmax - tmin) / 1000 Idpt_filename = 'Idpt.h5'