From dec38b4f95d3a55601b328c02dcc3b6d4f16b0e2 Mon Sep 17 00:00:00 2001 From: Tobias Winchen Date: Mon, 29 Jan 2018 11:14:06 +0100 Subject: [PATCH] Added test for #165: Segfault extending SourceFeature in python https://github.com/CRPropa/CRPropa3/issues/165 --- test/testPythonExtension.py.in | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/testPythonExtension.py.in b/test/testPythonExtension.py.in index 9d885b92d0..e7cf2442ad 100644 --- a/test/testPythonExtension.py.in +++ b/test/testPythonExtension.py.in @@ -73,6 +73,36 @@ class testCrossLanguagePolymorphism(unittest.TestCase): obs.process(candidate) self.assertEqual(i + 1, counter.value) + def test_SourceFeature(self): + Mpc = crp.Mpc + EeV = crp.EeV + nG = crp.nG + + class MySourceFeature(crp.SourceFeature): + def __init__(self): + crp.SourceFeature.__init__(self) + + def prepareParticle(self, particleState): + particleState.setEnergy(10 * EeV) + + vgrid = crp.VectorGrid(crp.Vector3d(0), 128, 1 * Mpc) + crp.initTurbulence(vgrid, 1 * nG, 2 * Mpc, 5 * Mpc, -11. / 3.) + BField = crp.MagneticFieldGrid(vgrid) + + m = crp.ModuleList() + m.add(crp.PropagationCK(BField, 1e-4, 0.1 * Mpc, 5 * Mpc)) + m.add(crp.MaximumTrajectoryLength(25 * Mpc)) + + # source setup + source = crp.Source() + source.add(crp.SourcePosition(crp.Vector3d(0, 0, 0) * Mpc)) + source.add(crp.SourceIsotropicEmission()) + source.add(crp.SourceParticleType(crp.nucleusId(1, 1))) + source.add(MySourceFeature()) + m.run(source, 1000) + + + class testCandidatePropertymap(unittest.TestCase): def setUp(self):