IAP GITLAB

testMedium.cpp 3.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
/*
 * (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>

#include <catch2/catch.hpp>

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

TEST_CASE("MediumPropertyModel w/ Homogeneous") {

  CoordinateSystem const& gCS =
      RootCoordinateSystem::GetInstance().GetRootCoordinateSystem();

  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
  const Medium type = Medium::AirDry1Atm;

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

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

  // a new refractive index
  const Medium type2 = Medium::StandardRock;

  // update the refractive index of this atmospheric model
  medium.set_medium(type2);

  // check that the returned refractive index is correct
  CHECK(type2 == medium.medium(Point(gCS, -10_m, 4_m, 35_km)));
  CHECK(type2 == medium.medium(Point(gCS, +210_m, 0_m, 7_km)));
  CHECK(type2 == medium.medium(Point(gCS, 0_m, 0_m, 0_km)));
  CHECK(type2 == medium.medium(Point(gCS, 100_km, 400_km, 350_km)));

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

  // check the density and nuclear composition
  CHECK(density == medium.GetMassDensity(Point(gCS, 0_m, 0_m, 0_m)));
  medium.GetNuclearComposition();

  // 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
  CHECK((medium.IntegratedGrammage(trajectory, 3_m) / (density * 3_m)) == Approx(1));
  CHECK((medium.ArclengthFromGrammage(trajectory, density * 5_m) / 5_m) == Approx(1));
}