LCOV - code coverage report
Current view: top level - test - testFunctionalGroups.cpp (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 20 23 87.0 %
Date: 2024-04-29 14:43:01 Functions: 1 2 50.0 %

          Line data    Source code
       1             : #include "CRPropa.h"
       2             : #include "gtest/gtest.h"
       3             : 
       4             : namespace crpropa {
       5             : 
       6             : /*
       7             :  * Functional test which calculates the particle's gyroradius in a uniform field
       8             :  * r_g = R / (B*c) = 1 EV / (1 nG * c) \approx 1.08*Mpc
       9             :  */
      10           2 : TEST(testFunctionalGroups, gyroradius) {
      11             :         double energy = 1*EeV;
      12             :         double field = 1*nG;
      13             : 
      14           1 :         ParticleState p;
      15           1 :         p.setId(nucleusId(1, 1));
      16           1 :         p.setEnergy(energy);
      17           1 :         p.setPosition(Vector3d(0, 0, 0));
      18           1 :         p.setDirection(Vector3d(0, 0, 1));
      19             : 
      20           1 :         ref_ptr<Candidate> c = new Candidate(p);
      21           1 :         ref_ptr<PropagationCK> propa = new PropagationCK(new UniformMagneticField(Vector3d(field, 0, 0)));
      22           1 :         ref_ptr<ParticleCollector> collector = new ParticleCollector();
      23           1 :         collector->setClone(true);
      24           1 :         ref_ptr<ModuleList> sim = new ModuleList();
      25             : 
      26             :         Vector3d pos;
      27             :         double max_y = 0;
      28             : 
      29           1 :         sim->add(propa);
      30           1 :         sim->add(new MaximumTrajectoryLength(10*Mpc));
      31           1 :         sim->add(collector);
      32             : 
      33           1 :         sim->run(c);
      34             : 
      35          16 :         for (ParticleCollector::iterator itr = collector->begin(); itr != collector->end(); ++itr){
      36          15 :                 pos = (*(itr->get())).current.getPosition();
      37          15 :                 if (max_y < pos.getY())
      38             :                         max_y = pos.getY();
      39             :         }
      40             : 
      41           1 :         EXPECT_NEAR(max_y/2.0, energy/(field * c_light * eplus), 0.01*Mpc);
      42             : 
      43           1 : }
      44             : 
      45           0 : int main(int argc, char **argv) {
      46           0 :         ::testing::InitGoogleTest(&argc, argv);
      47           0 :         return RUN_ALL_TESTS();
      48             : }
      49             : 
      50             : } // namespace crpropa

Generated by: LCOV version 1.14