IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 03d6cedf authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

"mechanical" interface seems to work

parent b7bd7801
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,7 @@ find_package (Eigen3 REQUIRED)
# order of subdirectories
add_subdirectory (ThirdParty)
add_subdirectory (Framework)
add_subdirectory (Environment)
add_subdirectory (Stack)
add_subdirectory (Processes)
add_subdirectory (Documentation)
......
set (
ENVIRONMENT_HEADERS
VolumeTreeNode.h
IMediumModel.h
NuclearComposition.h
HomogeneousMedium.h
)
set (
ENVIRONMENT_NAMESPACE
corsika/environment
)
add_library (CORSIKAenvironment INTERFACE)
CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAenvironment ${ENVIRONMENT_NAMESPACE} ${ENVIRONMENT_HEADERS})
# target dependencies on other libraries (also the header onlys)
target_link_libraries (
CORSIKAenvironment
INTERFACE
CORSIKAgeometry
CORSIKAparticles
CORSIKAunits
)
target_include_directories (
CORSIKAenvironment
INTERFACE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
install (
TARGETS CORSIKAenvironment
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/${ENVIRONMENT_NAMESPACE}
)
# --------------------
# code unit testing
add_executable (testEnvironment testEnvironment.cc)
target_link_libraries (
testEnvironment
CORSIKAenvironment
CORSIKAthirdparty # for catch2
)
add_test (NAME testGeometry COMMAND testGeometry)
......@@ -2,6 +2,8 @@
#define _include_HomogeneousMedium_h_
#include <corsika/environment/NuclearComposition.h>
#include <corsika/geometry/BaseTrajectory.h>
#include <corsika/geometry/Point.h>
#include <corsika/particles/ParticleProperties.h>
#include <corsika/units/PhysicalUnits.h>
......@@ -13,16 +15,33 @@ namespace corsika::environment {
template <class T>
class HomogeneousMedium : T {
MassDensityType const fDensity;
corsika::units::si::MassDensityType const fDensity;
NuclearComposition const fNuclComp;
public:
HomogeneousMedium(MassDensityType pDensity, NuclearComposition pNuclComp)
HomogeneousMedium(corsika::units::si::MassDensityType pDensity,
NuclearComposition pNuclComp)
: fDensity(pDensity)
, fNuclComp(pNuclComp){};
MassDensityType GetMassDensity(Point const& p) const override { return fDensity; }
corsika::units::si::MassDensityType GetMassDensity([
[maybe_unused]] corsika::geometry::Point const& p) const override {
return fDensity;
}
NuclearComposition const& GetNuclearComposition() const override { return fNuclComp; }
corsika::units::si::GrammageType IntegratedGrammage(
corsika::geometry::BaseTrajectory const& pTraj,
corsika::units::si::TimeType pTo) const override {
using namespace corsika::units::si;
return pTraj.DistanceBetween(0_s, pTo) * fDensity;
}
corsika::units::si::TimeType FromGrammage(
corsika::geometry::BaseTrajectory const& pTraj,
corsika::units::si::GrammageType pGrammage) const override {
return pTraj.TimeFromArclength(pGrammage / fDensity);
}
};
} // namespace corsika::environment
......
......@@ -3,6 +3,7 @@
#include <corsika/environment/NuclearComposition.h>
#include <corsika/geometry/BaseTrajectory.h>
#include <corsika/geometry/Point.h>
#include <corsika/units/PhysicalUnits.h>
#include <tuple>
#include <vector>
......@@ -15,8 +16,11 @@ namespace corsika::environment {
virtual corsika::units::si::MassDensityType GetMassDensity(
corsika::geometry::Point const&) const = 0;
virtual corsika::units::si::GrammageType IntegratedGrammage(BaseTrajectory const&,
double, double) const = 0;
virtual corsika::units::si::GrammageType IntegratedGrammage(
corsika::geometry::BaseTrajectory const&, corsika::units::si::TimeType) const = 0;
virtual corsika::units::si::TimeType FromGrammage(
corsika::geometry::BaseTrajectory const&,
corsika::units::si::GrammageType) const = 0;
virtual NuclearComposition const& GetNuclearComposition() const = 0;
};
......
#ifndef _include_NuclearComposition_h
#define _include_NuclearComposition_h
#include <algorithm>
#include <corsika/particles/ParticleProperties.h>
#include <numeric>
#include <vector>
namespace corsika::environment {
class NuclearComposition {
std::vector<float> const fNumberFractions; //<! relative fractions of number density
std::vector<float> const fNumberFractions; //!< relative fractions of number density
std::vector<corsika::particles::Code> const
fComponents; //!< particle codes of consitutents
......@@ -18,7 +19,7 @@ namespace corsika::environment {
auto const sumFractions =
std::accumulate(pFractions.cbegin(), pFractions.cend(), 0.f);
if (!(0.999f < sum && sum < 1.001f)) {
if (!(0.999f < sumFractions && sumFractions < 1.001f)) {
throw std::string("element fractions do not add up to 1");
}
}
......
......@@ -81,7 +81,7 @@ namespace corsika::environment {
fModelProperties = std::make_unique<ModelProperties>(std::forward<Args>(args)...);
}
auto SetModelProperties(IMPSharedPtr ptr) { fModelProperties = IMPSharedPtr; }
void SetModelProperties(IMPSharedPtr ptr) { fModelProperties = ptr; }
template <class MediumType, typename... Args>
static auto CreateMedium(Args&&... args) {
......@@ -94,8 +94,9 @@ namespace corsika::environment {
// factory methods for creation of nodes
template <class VolumeType, typename... Args>
static auto CreateNode(Args&&... args) {
static_assert(std::is_base_of_v<Volume, VolumeType>,
"unusable type provided, needs to be derived from \"Volume\"");
static_assert(std::is_base_of_v<corsika::geometry::Volume, VolumeType>,
"unusable type provided, needs to be derived from "
"\"corsika::geometry::Volume\"");
return std::make_unique<VolumeTreeNode<IModelProperties>>(
std::make_unique<VolumeType>(std::forward<Args>(args)...));
......
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one
// cpp file
#include <corsika/environment/HomogeneousMedium.h>
#include <corsika/environment/IMediumModel.h>
#include <corsika/environment/NuclearComposition.h>
#include <corsika/environment/VolumeTreeNode.h>
#include <corsika/particles/ParticleProperties.h>
#include <catch2/catch.hpp>
using namespace corsika::geometry;
using namespace corsika::environment;
using namespace corsika::units::si;
TEST_CASE("HomogeneousMedium") {
NuclearComposition const protonComposition(
std::vector<corsika::particles::Code>{corsika::particles::Code::Proton},
std::vector<float>{1.f});
HomogeneousMedium<IMediumModel> const medium(19.2_g / cube(1_cm), protonComposition);
}
......@@ -24,6 +24,9 @@ namespace corsika::geometry {
virtual LengthType DistanceBetween(corsika::units::si::TimeType t1,
corsika::units::si::TimeType t2) const = 0;
virtual corsika::units::si::TimeType TimeFromArclength(
corsika::units::si::LengthType) const = 0;
};
} // namespace corsika::geometry
......
......@@ -47,10 +47,15 @@ namespace corsika::geometry {
auto GetRadius() const { return radius; }
LengthType DistanceBetween(corsika::units::si::TimeType t1,
corsika::units::si::TimeType t2) const override {
corsika::units::si::LengthType DistanceBetween(
corsika::units::si::TimeType t1, corsika::units::si::TimeType t2) const override {
return (vPar + vPerp).norm() * (t2 - t1);
}
corsika::units::si::TimeType TimeFromArclength(
corsika::units::si::LengthType t) const override {
return t / (vPar + vPerp).norm();
}
};
} // namespace corsika::geometry
......
......@@ -28,6 +28,11 @@ namespace corsika::geometry {
assert(t2 >= t1);
return v0.norm() * (t2 - t1);
}
corsika::units::si::TimeType TimeFromArclength(
corsika::units::si::LengthType t) const override {
return t / v0.norm();
}
};
} // namespace corsika::geometry
......
#ifndef _include_SPHERE_H_
#define _include_SPHERE_H_
#include <corsika/geometry/Volume.h>
#include <corsika/geometry/Point.h>
#include <corsika/geometry/Volume.h>
#include <corsika/units/PhysicalUnits.h>
namespace corsika::geometry {
......
......@@ -6,11 +6,11 @@
namespace corsika::geometry {
class Volume {
public:
//! returns true if the Point p is within the volume
virtual bool Contains(Point const& p) const = 0;
virtual ~Volume() = default;
};
......
......@@ -38,7 +38,7 @@ namespace corsika::units::si {
using EnergyType = phys::units::quantity<phys::units::energy_d, double>;
using MassType = phys::units::quantity<phys::units::mass_d, double>;
using MassDensityType = phys::units::quantity<phys::units::mass_density_d, double>;
using GrammageType = phys::units::quantity<phys::units::dimensions<-2,1>, double>;
using GrammageType = phys::units::quantity<phys::units::dimensions<-2, 1, 0>, double>;
} // end namespace corsika::units::si
......
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