def mcvine2mcstas(inpath, outpath): arr = ns.readneutrons_asnpyarr(inpath) N = len(arr) newarr = np.zeros((N, 11), dtype=float) newarr[:, list(range(10))] = arr[:, [9, 0, 1, 2, 3, 4, 5, 8, 6, 7]] np.savetxt(outpath, newarr) return
def test1(): # create mcvine input neutrons cmd = 'cd mcvine-create-neutrons; ./dump.py' if os.system(cmd): raise RuntimeError("%s failed" % cmd) # convert from mcvine to mcstas from mcstas2mcvine.beam import mcvine2mcstas, mcstas2mcvine mcvine2mcstas('input-neutrons.mcvine', 'output-neutrons.mcstas') # run through virtual_input and virtual_output inside mcstas cmd = 'cd ./test-mcvine2mcstas-output/; ./build.sh; ./run-test.sh' if os.system(cmd): raise RuntimeError("%s failed" % cmd) # convert from mcstas to mcvine mcstas2mcvine('test-mcvine2mcstas-output/beam-copy.dat', 'output-neutrons.mcvine') # load and verify from mcni.neutron_storage import readneutrons_asnpyarr ns1 = readneutrons_asnpyarr('input-neutrons.mcvine') ns2 = readneutrons_asnpyarr('output-neutrons.mcvine') assert np.allclose(ns1, ns2) return
def test2(self): cmd = './neutron_storage_normalization_TestCase-app2' outdir = 'out-neutron_storage_normalization_TestCase-app2' outfile = os.path.join(outdir, 'neutrons') if os.system(cmd): raise RuntimeError, "%r failed" % cmd # make sure the final result is normalized from mcni.neutron_storage import readneutrons_asnpyarr neutrons = readneutrons_asnpyarr(outfile) self.assertEqual(len(neutrons), ncount / 10) expected = [0., 0., -1., 0., 0., 3000., 0., 1., 0., 1. / 10] for n in neutrons: self.assert_((n == expected).all()) continue return
def test2(self): cmd = './neutron_storage_normalization_TestCase-app2' outdir = 'out-neutron_storage_normalization_TestCase-app2' outfile = os.path.join(outdir, 'neutrons') if os.system(cmd): raise RuntimeError, "%r failed" % cmd # make sure the final result is normalized from mcni.neutron_storage import readneutrons_asnpyarr neutrons = readneutrons_asnpyarr(outfile) self.assertEqual(len(neutrons), ncount/10) expected = [0., 0., -1., 0., 0., 3000., 0., 1., 0., 1./10] for n in neutrons: self.assert_((n==expected).all()) continue return
def test2(self): 'mpi run of neutron_storage component: overwrite_datafiles is off' import shutil shutil.rmtree(outdir) cmd = './neutron_storage_normalization_TestCase-app --mpirun.nodes=2 --overwrite-datafiles=off --output-dir=%s' % outdir import os if os.system(cmd): raise RuntimeError, "%r failed" % cmd # make sure the final result is normalized from mcni.neutron_storage import readneutrons_asnpyarr neutrons = readneutrons_asnpyarr(outfile) self.assertEqual(len(neutrons), ncount) expected = [0., 0., -1., 0., 0., 3000., 0., 1., 0., 1] for n in neutrons: self.assert_((n==expected).all()) continue return
def test1(self): 'mpi run of neutron_storage component: overwrite_datafiles is on' cmd = './neutron_storage_normalization_TestCase-app --mpirun.nodes=2 --overwrite-datafiles --output-dir=%s' % outdir import os if os.system(cmd): raise RuntimeError, "%r failed" % cmd # make sure the final result is normalized # the probability should be 1 since it is first normalized by mc count # and then scaled by # of neutrons in the storage, which # equals to mc count in this case from mcni.neutron_storage import readneutrons_asnpyarr neutrons = readneutrons_asnpyarr(outfile) self.assertEqual(len(neutrons), ncount) expected = [0., 0., -1., 0., 0., 3000., 0., 1., 0., 1] for n in neutrons: self.assert_((n==expected).all()) continue return