IAP GITLAB

testMedium.cpp 3.2 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 24 25 26 27 28

#include <catch2/catch.hpp>

using namespace corsika;
using namespace corsika::units::si;

TEST_CASE("MediumPropertyModel w/ Homogeneous") {

  CoordinateSystem const& gCS =
29
      RootCoordinateSystem::getInstance().GetRootCoordinateSystem();
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

  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
45
  const Medium type = corsika::Medium::AirDry1Atm;
46 47 48 49 50

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

  // and require that it is constant
51 52 53 54
  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)));
55 56

  // a new refractive index
57
  const Medium type2 = corsika::Medium::StandardRock;
58 59

  // update the refractive index of this atmospheric model
60
  medium.setMedium(type2);
61 62

  // check that the returned refractive index is correct
63 64 65 66
  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)));
67 68 69 70 71

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

  // check the density and nuclear composition
72 73
  CHECK(density == medium.getMassDensity(Point(gCS, 0_m, 0_m, 0_m)));
  medium.getNuclearComposition();
74 75 76 77 78 79 80 81 82 83 84 85

  // 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
86 87
  CHECK((medium.integratedGrammage(trajectory, 3_m) / (density * 3_m)) == Approx(1));
  CHECK((medium.arclengthFromGrammage(trajectory, density * 5_m) / 5_m) == Approx(1));
88
}