Пример #1
0
 def testParticleCollectorAsModuleListOutput(self):
     sim = crp.ModuleList()
     sim.add(crp.MaximumTrajectoryLength(3.14))
     sim.add(crp.SimplePropagation(0.001, 0.001))
     collector = crp.ParticleCollector()
     sim.add(collector)
     c = crp.Candidate()
     sim.run(c)
     self.assertAlmostEqual(collector[0].getTrajectoryLength(),
                            3.14,
                            places=2)
Пример #2
0
 def testParticleCollectorAsModuleListInput(self):
     sim = crp.ModuleList()
     sim.add(crp.MaximumTrajectoryLength(3.14))
     sim.add(crp.SimplePropagation(0.001, 0.001))
     collector = crp.ParticleCollector()
     c1 = crp.Candidate()
     c2 = crp.Candidate()
     collector.process(c1)
     collector.process(c2)
     sim.run(collector.getContainer())
     for c in collector:
         self.assertAlmostEqual(c.getTrajectoryLength(), 3.14, places=2)
    def runTest(self):

        outputFile = tempfile.NamedTemporaryFile()

        sim = crp.ModuleList()

        # photon fields
        CMB = crp.CMB()
        IRB = crp.IRB_Kneiske04()

        sim.add(crp.SimplePropagation(1 * crp.kpc, 1 * crp.Mpc))
        sim.add(crp.Redshift())
        sim.add(crp.PhotoPionProduction(CMB))
        sim.add(crp.PhotoPionProduction(IRB))
        sim.add(crp.PhotoDisintegration(CMB))
        sim.add(crp.PhotoDisintegration(IRB))
        sim.add(crp.NuclearDecay())
        sim.add(crp.ElectronPairProduction(CMB))
        sim.add(crp.ElectronPairProduction(IRB))
        sim.add(crp.MinimumEnergy(1 * crp.EeV))
        sim.add(crp.EMCascade())

        # observer
        obs = crp.Observer()
        obs.add(crp.ObserverPoint())
        sim.add(obs)

        # output
        output = crp.TextOutput(outputFile.name)
        output.set1D(True)
        obs.onDetection(output)

        # source
        source = crp.Source()
        source.add(crp.SourceUniform1D(1 * crp.Mpc, 1000 * crp.Mpc))
        source.add(crp.SourceRedshift1D())

        # power law spectrum with charge dependent maximum energy Z*100 EeV
        # elements: H, He, N, Fe with equal abundances at constant energy per
        # nucleon
        composition = crp.SourceComposition(1 * crp.EeV, 100 * crp.EeV, -1)
        composition.add(1,  1,  1)  # H
        composition.add(4,  2,  1)  # He-4
        composition.add(14, 7,  1)  # N-14
        composition.add(56, 26, 1)  # Fe-56
        source.add(composition)

        # run simulation
        sim.run(source, 1)

        outputFile.close()
Пример #4
0
import crpropa
import CRPropaROOTOutput

print("My Simulation\n")

ml = crpropa.ModuleList()

ml.add(crpropa.SimplePropagation(1 * crpropa.parsec, 100 * crpropa.parsec))
ml.add(crpropa.MaximumTrajectoryLength(1000 * crpropa.parsec))

print("+++ List of modules")
print(ml.getDescription())

print("+++ Preparing source")
source = crpropa.Source()
print(source.getDescription())

print("+++ Starting Simulation")
ml.run(source, 1)

print("+++ Done")
# of influence of the Galactic magnetic field follows an isotropic arrival
# distribution at any point within our Galaxy.
# First, we are setting up the oberver which we will place further outside of
# the Galactic center than Earth to exaggerate the observed effects:

# In[1]:

import crpropa
import numpy as np

n = 10000000

# simulation setup
sim = crpropa.ModuleList()
# we just need propagation in straight lines here to demonstrate the effect
sim.add(crpropa.SimplePropagation())

# collect arriving cosmic rays at observer 19 kpc outside of the Galactic center
# to exaggerate effects
obs = crpropa.Observer()
pos_earth = crpropa.Vector3d(-19, 0, 0) * crpropa.kpc
# observer with radius 500 pc to collect fast reasonable statistics
obs.add(crpropa.ObserverSurface(crpropa.Sphere(pos_earth, 0.5 * crpropa.kpc)))
# Use crpropa's particle collector to only collect the cosmic rays at Earth
output = crpropa.ParticleCollector()
obs.onDetection(output)
sim.add(obs)

# discard outwards going cosmic rays, that missed Earth and leave the Galaxy
obs_trash = crpropa.Observer()
obs_trash.add(