IAP GITLAB

testMedium.cpp 3.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
 *
 * This software is distributed under the terms of the GNU General Public
 * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
 * the license.
 */

#include <corsika/framework/core/PhysicalUnits.hpp>
#include <corsika/framework/geometry/Line.hpp>
#include <corsika/framework/geometry/RootCoordinateSystem.hpp>
#include <corsika/framework/geometry/Vector.hpp>
#include <corsika/media/FlatExponential.hpp>
#include <corsika/media/HomogeneousMedium.hpp>
#include <corsika/media/IMediumModel.hpp>
#include <corsika/media/InhomogeneousMedium.hpp>
#include <corsika/media/NuclearComposition.hpp>
#include <corsika/media/MediumPropertyModel.hpp>
19
#include <corsika/media/MediumProperties.hpp>
20 21 22 23

#include <catch2/catch.hpp>

using namespace corsika;
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

TEST_CASE("MediumProperties") {

  // test access of medium properties via enum and class types

  const Medium type = Medium::AirDry1Atm;
  const MediumData& air = mediumData(type);
  CHECK(air.getIeff() == 85.7);
  CHECK(air.getCbar() == 10.5961);
  CHECK(air.getX0() == 1.7418);
  CHECK(air.getX1() == 4.2759);
  CHECK(air.getAA() == 0.10914);
  CHECK(air.getSK() == 3.3994);
  CHECK(air.getDlt0() == 0.0);
}

40 41
TEST_CASE("MediumPropertyModel w/ Homogeneous") {

Ralf Ulrich's avatar
Ralf Ulrich committed
42
  CoordinateSystemPtr gCS = get_root_CoordinateSystem();
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

  Point const gOrigin(gCS, {0_m, 0_m, 0_m});

  // setup our interface types
  using IModelInterface = IMediumPropertyModel<IMediumModel>;
  using AtmModel = MediumPropertyModel<HomogeneousMedium<IModelInterface>>;

  // the constant density
  const auto density{19.2_g / cube(1_cm)};

  // the composition we use for the homogenous medium
  NuclearComposition const protonComposition(std::vector<Code>{Code::Proton},
                                             std::vector<float>{1.f});

  // the refrative index that we use
58
  const Medium type = corsika::Medium::AirDry1Atm;
59 60 61 62 63

  // create the atmospheric model
  AtmModel medium(type, density, protonComposition);

  // and require that it is constant
64 65 66 67
  CHECK(type == medium.getMedium(Point(gCS, -10_m, 4_m, 35_km)));
  CHECK(type == medium.getMedium(Point(gCS, +210_m, 0_m, 7_km)));
  CHECK(type == medium.getMedium(Point(gCS, 0_m, 0_m, 0_km)));
  CHECK(type == medium.getMedium(Point(gCS, 100_km, 400_km, 350_km)));
68 69

  // a new refractive index
70
  const Medium type2 = corsika::Medium::StandardRock;
71 72

  // update the refractive index of this atmospheric model
73
  medium.setMedium(type2);
74 75

  // check that the returned refractive index is correct
76 77 78 79
  CHECK(type2 == medium.getMedium(Point(gCS, -10_m, 4_m, 35_km)));
  CHECK(type2 == medium.getMedium(Point(gCS, +210_m, 0_m, 7_km)));
  CHECK(type2 == medium.getMedium(Point(gCS, 0_m, 0_m, 0_km)));
  CHECK(type2 == medium.getMedium(Point(gCS, 100_km, 400_km, 350_km)));
80 81 82 83 84

  // define our axis vector
  Vector const axis(gCS, QuantityVector<dimensionless_d>(0, 0, 1));

  // check the density and nuclear composition
85 86
  CHECK(density == medium.getMassDensity(Point(gCS, 0_m, 0_m, 0_m)));
  medium.getNuclearComposition();
87 88 89 90 91 92 93 94 95 96 97 98

  // create a line of length 1 m
  Line const line(gOrigin, Vector<SpeedType::dimension_type>(
                               gCS, {1_m / second, 0_m / second, 0_m / second}));

  // the end time of our line
  auto const tEnd = 1_s;

  // and the associated trajectory
  Trajectory<Line> const trajectory(line, tEnd);

  // and check the integrated grammage
Ralf Ulrich's avatar
Ralf Ulrich committed
99 100
  CHECK((medium.getIntegratedGrammage(trajectory, 3_m) / (density * 3_m)) == Approx(1));
  CHECK((medium.getArclengthFromGrammage(trajectory, density * 5_m) / 5_m) == Approx(1));
101
}