IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 9cf2ab6b authored by ralfulrich's avatar ralfulrich Committed by Ralf Ulrich
Browse files

coverage

parent d7917b08
No related branches found
No related tags found
No related merge requests found
......@@ -140,7 +140,6 @@ namespace corsika {
CORSIKA_LOG_ERROR("cannot integrate negative grammage");
throw std::runtime_error("negative grammage error");
}
LengthType const height = (traj.getPosition(0) - point_).getNorm() - referenceHeight_;
double const fbin = height / deltaHeight_;
......
......@@ -88,7 +88,8 @@ namespace corsika::urqmd {
break;
default: { // LCOV_EXCL_START since this can never happen due to canInteract
CORSIKA_LOG_WARN("UrQMD cross-section not tabulated for {}", projectileCode);
return CrossSectionType::zero(); // LCOV_EXCL_STOP
return CrossSectionType::zero();
// LCOV_EXCL_STOP
}
}
......@@ -395,9 +396,9 @@ namespace corsika::urqmd {
boost::filesystem::ifstream file(filename, std::ios::in);
if (!file.is_open()) {
throw std::runtime_error(
filename.native() +
" could not be opened."); // LCOV_EXCL_LINE since this is pointless to test
// LCOV_EXCL_START since this is pointless to test
throw std::runtime_error(filename.native() + " could not be opened.");
// LCOV_EXCL_STOP
}
std::string line;
......
......@@ -21,7 +21,7 @@ namespace corsika {
/**
* This class provides the grammage/length conversion functionality for
* (locally) flat exponential atmospheres.
* (locally) flat tabulated atmospheres.
*/
template <typename TDerived>
class BaseTabular {
......@@ -38,40 +38,8 @@ namespace corsika {
MassDensityType getMassDensity(LengthType const height) const;
// clang-format off
/**
* For a (normalized) axis \f$ \vec{a} \f$, the grammage along a non-orthogonal line with (normalized)
* direction \f$ \vec{u} \f$ is given by
* \f[
* X = \frac{\varrho_0 \lambda}{\vec{u} \cdot \vec{a}} \left( \exp\left( \vec{u} \cdot \vec{a} \frac{l}{\lambda} \right) - 1 \right)
* \f], where \f$ \varrho_0 \f$ is the density at the starting point.
*
* If \f$ \vec{u} \cdot \vec{a} = 0 \f$, the calculation is just like with a homogeneous density:
* \f[
* X = \varrho_0 l;
* \f]
*/
// clang-format on
GrammageType getIntegratedGrammage(BaseTrajectory const& line) const;
// clang-format off
/**
* For a (normalized) axis \f$ \vec{a} \f$, the length of a non-orthogonal line with (normalized)
* direction \f$ \vec{u} \f$ corresponding to grammage \f$ X \f$ is given by
* \f[
* l = \begin{cases}
* \frac{\lambda}{\vec{u} \cdot \vec{a}} \log\left(Y \right), & \text{if} Y := 0 > 1 +
* \vec{u} \cdot \vec{a} \frac{X}{\rho_0 \lambda}
* \infty & \text{else,}
* \end{cases}
* \f] where \f$ \varrho_0 \f$ is the density at the starting point.
*
* If \f$ \vec{u} \cdot \vec{a} = 0 \f$, the calculation is just like with a homogeneous density:
* \f[
* l = \frac{X}{\varrho_0}
* \f]
*/
// clang-format on
LengthType getArclengthFromGrammage(BaseTrajectory const& line,
GrammageType const grammage) const;
......
......@@ -12,7 +12,6 @@
#include <corsika/framework/core/PhysicalUnits.hpp>
#include <corsika/framework/geometry/Line.hpp>
#include <corsika/framework/geometry/Point.hpp>
#include <corsika/framework/random/RNGManager.hpp>
#include <corsika/framework/geometry/BaseTrajectory.hpp>
#include <corsika/media/NuclearComposition.hpp>
#include <corsika/media/BaseTabular.hpp>
......@@ -23,11 +22,11 @@ namespace corsika {
/**
* The SlidingPlanarTabular models mass density as
* \f[
* \varrho(r) = \varrho_0 \exp\left( \frac{|p_0 - r|}{\lambda} \right).
* \varrho(r) = \varrho_0 \rho\left( |p_0 - r| \right).
* \f]
* For grammage/length conversion, the density distribution is approximated as
* locally flat at the starting point \f$ r_0 \f$ of the trajectory with the axis pointing
* from \f$ p_0 \f$ to \f$ r_0 \f$.
* locally flat at the starting point \f$ r_0 \f$ of the trajectory with the
* axis pointing rom \f$ p_0 \f$ to \f$ r_0 \f$ defining the local height.
*/
// clang-format on
......
......@@ -71,6 +71,8 @@ namespace corsika::dummy_stack {
*/
void copy(const int /*i1*/, const int /*i2*/) {}
void swap(const int, const int) {}
void incrementSize() { entries_++; }
void decrementSize() { entries_--; }
......
......@@ -83,6 +83,9 @@ TEST_CASE("HomogeneousMedium") {
std::vector<float>{1.f});
HomogeneousMedium<IMediumModel> const medium(19.2_g / cube(1_cm), protonComposition);
CHECK(protonComposition.getFractions() == std::vector<float>{1.});
CHECK(protonComposition.getComponents() == std::vector<Code>{Code::Proton});
CHECK_THROWS(NuclearComposition({Code::Proton}, {1.1}));
CHECK_THROWS(NuclearComposition({Code::Proton}, {0.99}));
}
......@@ -103,6 +106,10 @@ TEST_CASE("FlatExponential") {
LengthType const length = 2_m;
TimeType const tEnd = length / speed;
CHECK(medium.getNuclearComposition().getFractions() == std::vector<float>{1.});
CHECK(medium.getNuclearComposition().getComponents() ==
std::vector<Code>{Code::Proton});
SECTION("horizontal") {
Line const line(gOrigin, Vector<SpeedType::dimension_type>(
gCS, {speed, 0_m / second, 0_m / second}));
......@@ -245,6 +252,26 @@ TEST_CASE("SlidingPlanarTabular") {
SlidingPlanarTabular<IMediumModel> const medium(gOrigin, rhoFunc, 1000, 10_m,
protonComposition);
SECTION("not possible") {
CHECK_THROWS(medium.getMassDensity({gCS, {0_m, 1e10_m, 0_m}}));
SpeedType const speed = 5_m / second;
TimeType const tEnd = 1e10_s;
Line const line(
{gCS, {0_m, 0_m, 1_m}},
Vector<SpeedType::dimension_type>(gCS, {0_m / second, 0_m / second, speed}));
setup::Trajectory const trajectory =
setup::testing::make_track<setup::Trajectory>(line, tEnd);
CHECK_THROWS(medium.getIntegratedGrammage(trajectory));
Line const line2(
{gCS, {0_m, 0_m, 1e9_m}},
Vector<SpeedType::dimension_type>(gCS, {0_m / second, 0_m / second, speed}));
setup::Trajectory const trajectory2 =
setup::testing::make_track<setup::Trajectory>(line2, tEnd);
CHECK_THROWS(medium.getArclengthFromGrammage(trajectory2, 1e3_g / square(1_cm)));
}
SECTION("density") {
CHECK(medium.getMassDensity({gCS, {0_m, 0_m, 3_m}}) /
medium.getMassDensity({gCS, {0_m, 3_m, 0_m}}) ==
......
......@@ -38,6 +38,7 @@ TEST_CASE("epos", "modules") {
corsika::epos::convertFromEpos(corsika::epos::EposCode::Electron));
CHECK(Code::Proton ==
corsika::epos::convertFromEpos(corsika::epos::EposCode::Proton));
CHECK_THROWS(corsika::epos::convertFromEpos(corsika::epos::EposCode::Unknown));
}
SECTION("corsika -> epos") {
......
......@@ -86,4 +86,30 @@ TEST_CASE("GeometryNodeStackExtension", "stack") {
CHECK(v == 99 * data);
CHECK(s.getEntries() == 0);
}
SECTION("copy and swap") {
const int data1 = 16;
const int data2 = 17;
TestStack s;
// add 99 particles, each 10th particle is a nucleus with A=i and Z=A/2!
for (int i = 0; i < 4; ++i) {
auto p = s.addParticle(std::tuple<dummy_stack::NoData>{noData});
p.setNode(i % 2 == 0 ? &data1 : &data2);
}
CHECK(*((s.first() + 0)).getNode() == 16);
CHECK(*((s.first() + 1)).getNode() == 17);
CHECK(*((s.first() + 2)).getNode() == 16);
CHECK(*((s.first() + 3)).getNode() == 17);
s.copy(s.first() + 0, s.first() + 1);
CHECK(*((s.first() + 0)).getNode() == 16);
CHECK(*((s.first() + 1)).getNode() == 16);
s.swap(s.first() + 3, s.first() + 1);
CHECK(*((s.first() + 1)).getNode() == 17);
CHECK(*((s.first() + 3)).getNode() == 16);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment