IAP GITLAB

Commit 95fcf10d authored by Ralf Ulrich's avatar Ralf Ulrich

cleanup of Cascade class. fixed some problems. improved factorization. added Setup headers.

parent e4c039cf
......@@ -17,7 +17,6 @@ include (CorsikaUtilities) # a few cmake function
# enable warnings and disallow non-standard language
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
# --std=c++17
set (CMAKE_CXX_STANDARD 17)
enable_testing ()
set (CTEST_OUTPUT_ON_FAILURE 1)
......@@ -37,15 +36,16 @@ set (CTEST_OUTPUT_ON_FAILURE 1)
#add_custom_command (TARGET corsika_pre_build PRE_BUILD COMMAND "${PROJECT_SOURCE_DIR}/pre_compile.py")
# dependencies
find_package (Boost 1.40 COMPONENTS program_options REQUIRED)
#find_package (Boost 1.40 COMPONENTS program_options REQUIRED)
find_package (Eigen3 REQUIRED)
#find_package (HDF5) # not yet needed
# order of subdirectories
add_subdirectory (ThirdParty)
#add_subdirectory (Utilities)
add_subdirectory (Framework)
add_subdirectory (Stack)
add_subdirectory (Setup)
add_subdirectory (Processes)
add_subdirectory (Documentation)
add_subdirectory (Main)
......@@ -55,3 +55,26 @@ function (CORSIKA_COPY_HEADERS_TO_NAMESPACE for_library in_namespace)
endfunction (CORSIKA_COPY_HEADERS_TO_NAMESPACE)
#
# use: CORSIKA_ADD_FILES_ABSOLUTE varname
#
# add list of filenames with absolute paths (pointing to CMAKE_SOURCE_DIR) to ${varname} in PARAENT_SCOPE
#
macro (CORSIKA_ADD_FILES_ABSOLUTE varname)
file (RELATIVE_PATH _relPath "${PROJECT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}")
foreach (_src ${ARGN})
if (_relPath)
list (APPEND "${varname}" "${CMAKE_SOURCE_DIR}/${_relPath}/${_src}")
else()
list (APPEND "${varname}" "${CMAKE_SOURCE_DIR}/${_src}")
endif()
endforeach()
if (_relPath)
# propagate SRCS to parent directory
set ("${varname}" "${${varname}}" PARENT_SCOPE)
endif()
endmacro(CORSIKA_ADD_FILES_ABSOLUTE)
......@@ -51,11 +51,13 @@ add_executable (
target_link_libraries (
testCascade
# CORSIKAutls
CORSIKAcascade
ProcessStackInspector
CORSIKAprocesses
CORSIKAparticles
CORSIKAgeometry
CORSIKAprocesssequence
SuperStupidStack
CORSIKAunits
CORSIKAthirdparty # for catch2
)
......
......@@ -2,19 +2,13 @@
using namespace corsika::cascade;
template <typename ProcessList, typename Particle, typename Trajectory, typename Stack>
Cascade<ProcessList, Particle, Trajectory, Stack>::Cascade() {
// kkk;
// kk;
}
template <typename ProcessList, typename Particle, typename Trajectory, typename Stack>
template <typename ProcessList, typename Stack> //, typename Trajectory>
void Cascade::Init() {
fStack.Init();
fProcesseList.Init();
}
template <typename ProcessList, typename Particle, typename Trajectory, typename Stack>
template <typename ProcessList, typename Stack> //, typename Trajectory>
void Cascade::Run() {
if (!fStack.IsEmpty()) {
if (!fStack.IsEmpty()) {
......@@ -27,10 +21,11 @@ void Cascade::Run() {
}
}
template <typename Sequence, typename Trajectory>
template <typename ProcessList, typename Stack> //, typename Trajectory>
void Cascade::Step(Particle& particle) {
double nextStep = fProcesseList.MinStepLength(particle);
Trajectory trajectory = fProcesseList.Transport(particle, nextStep);
corsika::geometry::LineTrajectory trajectory =
fProcesseList.Transport(particle, nextStep);
sequence.DoContinuous(particle, trajectory);
sequence.DoDiscrete(particle);
}
#ifndef _include_Cascade_h_
#define _include_Cascade_h_
#include <corsika/geometry/LineTrajectory.h> // to be removed
#include <corsika/geometry/Point.h> // to be removed
#include <corsika/geometry/LineTrajectory.h> // to be removed. for dummy trajectory only
#include <corsika/geometry/Point.h> // to be removed. for dummy trajectory only
#include <corsika/process/ProcessReturn.h>
#include <corsika/units/PhysicalUnits.h>
......@@ -10,11 +10,13 @@ using namespace corsika::units::si;
namespace corsika::cascade {
template <typename Trajectory, typename ProcessList, typename Stack>
template <typename ProcessList, typename Stack> //, typename Trajectory>
class Cascade {
typedef typename Stack::ParticleType Particle;
Cascade() = delete;
public:
Cascade(ProcessList& pl, Stack& stack)
: fProcesseList(pl)
......@@ -28,34 +30,37 @@ namespace corsika::cascade {
void Run() {
while (!fStack.IsEmpty()) {
while (!fStack.IsEmpty()) {
// Particle& p = *fStack.GetNextParticle();
EnergyType Emin;
typename Stack::StackIterator pMin(fStack, 0);
bool first = true;
for (typename Stack::StackIterator ip = fStack.begin(); ip != fStack.end();
++ip) {
Particle& pNext = *fStack.GetNextParticle();
/*
EnergyType Emin;
typename Stack::StackIterator pNext(fStack, 0);
bool first = true;
for (typename Stack::StackIterator ip = fStack.begin(); ip != fStack.end();
++ip) {
if (first || ip.GetEnergy() < Emin) {
first = false;
pMin = ip;
Emin = pMin.GetEnergy();
first = false;
pNext = ip;
Emin = pMin.GetEnergy();
}
}
Step(pMin);
}
*/
Step(pNext);
}
// do cascade equations, which can put new particles on Stack,
// thus, the double loop
// DoCascadeEquations(); //
}
}
void Step(Particle& particle) {
double nextStep = fProcesseList.MinStepLength(particle);
[[maybe_unused]] double nextStep = fProcesseList.MinStepLength(particle);
// corsika::utls::ignore(nextStep);
corsika::geometry::CoordinateSystem root;
Trajectory trajectory(
corsika::geometry::Point(root, {0_m, 0_m, 0_m}),
corsika::geometry::Vector<corsika::units::si::SpeedType::dimension_type>(
root, 0 * 1_m / second, 0 * 1_m / second, 1 * 1_m / second));
corsika::geometry::LineTrajectory
trajectory( // trajectory is not yet used. this is a dummy.
corsika::geometry::Point(root, {0_m, 0_m, 0_m}),
corsika::geometry::Vector<corsika::units::si::SpeedType::dimension_type>(
root, 0 * 1_m / second, 0 * 1_m / second, 1 * 1_m / second));
corsika::process::EProcessReturn status =
fProcesseList.DoContinuous(particle, trajectory, fStack);
if (status == corsika::process::EProcessReturn::eParticleAbsorbed) {
......@@ -64,10 +69,10 @@ namespace corsika::cascade {
fProcesseList.DoDiscrete(particle, fStack);
}
}
private:
Stack& fStack;
ProcessList& fProcesseList;
Stack& fStack;
};
} // namespace corsika::cascade
......
......@@ -2,12 +2,15 @@
#include <corsika/geometry/LineTrajectory.h>
#include <corsika/process/ProcessSequence.h>
#include <corsika/process/stack_inspector/StackInspector.h>
#include <corsika/stack/super_stupid/SuperStupidStack.h>
#include <corsika/setup/SetupStack.h>
#include <corsika/setup/SetupTrajectory.h>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one
// cpp file
#include <catch2/catch.hpp>
using namespace corsika;
using namespace corsika::process;
using namespace corsika::units;
......@@ -26,7 +29,8 @@ public:
}
template <typename Particle, typename Trajectory, typename Stack>
EProcessReturn DoContinuous(Particle& p, Trajectory& t, Stack& s) const {
EProcessReturn DoContinuous(Particle&, Trajectory&, Stack&) const {
// corsika::utls::ignore(p);
return EProcessReturn::eOk;
}
......@@ -49,55 +53,14 @@ public:
private:
};
class ProcessReport : public corsika::process::BaseProcess<ProcessReport> {
bool fReport = false;
public:
ProcessReport(bool v)
: fReport(v) {}
template <typename Particle>
double MinStepLength(Particle&) const {
return 0;
}
template <typename Particle, typename Trajectory, typename Stack>
EProcessReturn DoContinuous(Particle& p, Trajectory& t, Stack& s) const {
static int countStep = 0;
if (!fReport) return EProcessReturn::eOk;
// std::cout << "generation " << countStep << std::endl;
int i = 0;
EnergyType Etot = 0_GeV;
for (auto& iterP : s) {
EnergyType E = iterP.GetEnergy();
Etot += E;
/* std::cout << " particle data: " << i++ << ", id=" << iterP.GetPID()
<< ", E=" << double(E / 1_GeV) << " GeV "
<< " | " << std::endl;
*/
}
countStep++;
// cout << "#=" << countStep << " " << s.GetSize() << " " << Etot/1_GeV << endl;
cout << countStep << " " << s.GetSize() << " " << Etot / 1_GeV << " " << fCount
<< endl;
return EProcessReturn::eOk;
}
template <typename Particle, typename Stack>
void DoDiscrete(Particle& p, Stack& s) const {}
void Init() {}
};
TEST_CASE("Cascade", "[Cascade]") {
ProcessReport p0(true);
stack_inspector::StackInspector<setup::Stack, setup::Trajectory> p0(true);
ProcessSplit p1;
const auto sequence = p0 + p1;
corsika::stack::super_stupid::SuperStupidStack stack;
setup::Stack stack;
corsika::cascade::Cascade<corsika::geometry::LineTrajectory, decltype(sequence),
decltype(stack)>
EAS(sequence, stack);
corsika::cascade::Cascade EAS(sequence, stack);
stack.Clear();
auto particle = stack.NewParticle();
......
......@@ -42,7 +42,7 @@ target_link_libraries (
target_include_directories (
CORSIKAgeometry
PRIVATE ${EIGEN3_INCLUDE_DIR}
PUBLIC ${EIGEN3_INCLUDE_DIR}
INTERFACE ${EIGEN3_INCLUDE_DIR}
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/include>
......
......@@ -95,8 +95,9 @@ TEST_CASE("transformations between CoordinateSystems") {
QuantityVector<length_d> const zAxis{0_m, 0_m, 1_km};
QuantityVector<length_d> const yAxis{0_m, 7_nm, 0_m};
QuantityVector<length_d> const xAxis{2_m, 0_nm, 0_m};
QuantityVector<magnetic_flux_density_d> components{1. * tesla, 2. * tesla, 3. * tesla};
QuantityVector<magnetic_flux_density_d> components{1. * tesla, 2. * tesla,
3. * tesla};
Vector<magnetic_flux_density_d> v1(rootCS, components);
double const angle = 90. / 180. * M_PI;
......
......@@ -14,6 +14,11 @@ add_custom_command (
VERBATIM
)
set (
PARTICLE_SOURCES
ParticleProperties.cc
)
# all public header files of library, includes automatic generated file(s)
set (
PARTICLE_HEADERS
......@@ -26,7 +31,7 @@ set (
corsika/particles
)
add_library (CORSIKAparticles INTERFACE)
add_library (CORSIKAparticles STATIC ${PARTICLE_SOURCES})
CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAparticles ${PARTICLE_NAMESPACE} ${PARTICLE_HEADERS})
......@@ -39,14 +44,27 @@ add_custom_command (
COMMAND ${CMAKE_COMMAND} -E create_symlink ${PROJECT_BINARY_DIR}/include/corsika/particles/GeneratedParticleProperties.inc ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedParticleProperties.inc
COMMENT "Generate link in source-dir: ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedParticleProperties.inc"
)
add_custom_target (SourceDirLink DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedParticleProperties.inc)
add_custom_target (SourceDirLink DEPENDS ${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc)
add_dependencies (CORSIKAparticles SourceDirLink)
# .....................................................
target_link_libraries (
CORSIKAparticles
PUBLIC
CORSIKAunits
)
set_target_properties (
CORSIKAparticles
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER "${PARTICLE_HEADERS}"
)
target_include_directories (
CORSIKAparticles
INTERFACE
PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
......
#include <corsika/particles/ParticleProperties.h>
namespace corsika::particles::io {
std::ostream& operator<<(std::ostream& stream, Code const p) {
return stream << GetName(p);
}
} // namespace corsika::particles::io
......@@ -4,8 +4,8 @@
Interface to particle properties
*/
#ifndef _include_ParticleProperties_h_
#define _include_ParticleProperties_h_
#ifndef _include_corsika_particles_ParticleProperties_h_
#define _include_corsika_particles_ParticleProperties_h_
#include <array>
#include <cstdint>
......@@ -24,6 +24,7 @@
*/
namespace corsika::particles {
enum class Code : int16_t;
using PDGCodeType = int16_t;
......@@ -34,7 +35,7 @@ namespace corsika::particles {
corsika::units::si::ElectricChargeType constexpr GetElectricCharge(Code const);
corsika::units::si::MassType constexpr GetMass(Code const);
PDGCodeType constexpr GetPDG(Code const);
std::string const& GetName(Code const);
constexpr std::string const& GetName(Code const);
#include <corsika/particles/GeneratedParticleProperties.inc>
......@@ -60,15 +61,13 @@ namespace corsika::particles {
return GetElectricChargeNumber(p) * (corsika::units::si::constants::e / 3.);
}
std::string const& GetName(Code const p) {
constexpr std::string const& GetName(Code const p) {
return names[static_cast<CodeIntType const>(p)];
}
namespace io {
std::ostream& operator<<(std::ostream& stream, Code const p) {
return stream << GetName(p);
}
std::ostream& operator<<(std::ostream& stream, Code const p);
} // namespace io
......
add_library (CORSIKAstack INTERFACE)
target_include_directories (CORSIKAstack INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (FILES Stack.h StackIterator.h
DESTINATION include/Stack)
......@@ -31,9 +31,7 @@ install (
include/${CORSIKAstackinterface_NAMESPACE}
)
# code testing
#code testing
add_executable (testStackInterface testStackInterface.cc)
target_link_libraries (testStackInterface CORSIKAstackinterface CORSIKAthirdparty) # for catch2
add_test(NAME testStackInterface COMMAND testStackInterface)
target_link_libraries (testStackInterface CORSIKAstackinterface CORSIKAthirdparty) # for catch2
......@@ -16,7 +16,7 @@ TEST_CASE("PhysicalUnits", "[Units]") {
}
SECTION("Constructors") {
auto E1 = 10_GeV;
[[maybe_unused]] auto E1 = 10_GeV;
REQUIRE(E1 == 10_GeV);
LengthType l1 = 10_nm;
......@@ -25,11 +25,11 @@ TEST_CASE("PhysicalUnits", "[Units]") {
LengthType arr0[5];
arr0[0] = 5_m;
LengthType arr1[2] = {{1_mm}, {2_cm}};
[[maybe_unused]] LengthType arr1[2] = {{1_mm}, {2_cm}};
std::array<EnergyType, 4> arr2; // empty array
std::array<EnergyType, 4> arr3 = {1_GeV, 1_eV, 5_MeV};
[[maybe_unused]] std::array<EnergyType, 4> arr3 = {1_GeV, 1_eV, 5_MeV};
}
SECTION("Powers in literal units") {
......
add_subdirectory (NullModel)
add_subdirectory (Sibyll)
add_subdirectory (StackInspector)
#add_custom_target(CORSIKAprocesses)
add_library (CORSIKAprocesses INTERFACE)
add_dependencies(CORSIKAprocesses ProcessNullModel)
add_dependencies(CORSIKAprocesses ProcessSibyll)
add_dependencies(CORSIKAprocesses ProcessStackInspector)
......@@ -29,6 +29,7 @@ set_target_properties (
target_link_libraries (
ProcessStackInspector
CORSIKAunits
CORSIKAsetup
)
target_include_directories (
......@@ -52,7 +53,6 @@ add_executable (testStackInspector testStackInspector.cc)
target_link_libraries (
testStackInspector
CORSIKAgeometry
CORSIKAunits
CORSIKAthirdparty # for catch2
)
......
#include <corsika/process/stack_inspector/StackInspector.h>
#include <corsika/units/PhysicalUnits.h>
#include <iostream>
using namespace std;
using namespace corsika;
using namespace corsika::units::si;
using namespace corsika::process::stack_inspector;
StackInspector::StackInspector() {}
template <typename Stack, typename Trajectory>
StackInspector<Stack, Trajectory>::StackInspector(const bool aReport)
: fReport(aReport) {}
template <typename Stack, typename Trajectory>
StackInspector<Stack, Trajectory>::~StackInspector() {}
template <typename Stack, typename Trajectory>
process::EProcessReturn StackInspector<Stack, Trajectory>::DoContinuous(Particle&,
Trajectory&,
Stack& s) const {
// using namespace corsika::particles::io;
static int countStep = 0;
if (!fReport) return EProcessReturn::eOk;
// std::cout << "generation " << countStep << std::endl;
[[maybe_unused]] int i = 0;
EnergyType Etot = 0_GeV;
for (auto& iterP : s) {
EnergyType E = iterP.GetEnergy();
Etot += E;
// std::cout << " particle data: " << i++ << ", id=" << iterP << " | " << std::endl;
}
countStep++;
// cout << "#=" << countStep << " " << s.GetSize() << " " << Etot/1_GeV << endl;
cout << countStep << " " << s.GetSize() << " " << Etot / 1_GeV << " " << endl;
return EProcessReturn::eOk;
}
template <typename Stack, typename Trajectory>
double StackInspector<Stack, Trajectory>::MinStepLength(Particle&) const {
return 0;
}
StackInspector::~StackInspector() {}
template <typename Stack, typename Trajectory>
void StackInspector<Stack, Trajectory>::DoDiscrete(Particle&, Stack&) const {}
void StackInspector::init() {}
template <typename Stack, typename Trajectory>
void StackInspector<Stack, Trajectory>::Init() {}
void StackInspector::run() {}
#include <corsika/setup/SetupStack.h>
#include <corsika/setup/SetupTrajectory.h>
double StackInspector::GetStepLength() { return 0; }
template class corsika::process::stack_inspector::StackInspector<setup::Stack,
setup::Trajectory>;
#ifndef _Physics_StackInspector_StackInspector_h_
#define _Physics_StackInspector_StackInspector_h_
#include <corsika/process/ProcessSequence.h>
namespace corsika::process {
namespace stack_inspector {
class StackInspector {
template <typename Stack, typename Trajectory>
class StackInspector
: public corsika::process::BaseProcess<StackInspector<Stack, Trajectory>> {
typedef typename Stack::ParticleType Particle;
public:
StackInspector();
StackInspector(const bool aReport);
~StackInspector();
void init();
void run();
double GetStepLength();
void Init();
// template <typename Particle, typename Trajectory, typename Stack>
EProcessReturn DoContinuous(Particle&, Trajectory&, Stack& s) const;
// template <typename Particle>
double MinStepLength(Particle&) const;
// template <typename Particle, typename Stack>
void DoDiscrete(Particle&, Stack&) const;
private:
bool fReport;
};
} // namespace stack_inspector
......
set (
SETUP_HEADERS
SetupStack.h
SetupLogger.h
SetupEnvironment.h
SetupTrajectory.h
)
set (
SETUP_NAMESPACE
corsika/setup
)
add_library (CORSIKAsetup INTERFACE)
CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAsetup ${SETUP_NAMESPACE} ${SETUP_HEADERS})
target_link_libraries (
CORSIKAsetup
INTERFACE
CORSIKAgeometry
SuperStupidStack
)
target_include_directories (
CORSIKAsetup
INTERFACE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/include>
)
install (
FILES ${SETUP_HEADERS}
DESTINATION include/${SETUP_NAMESPACE}
)
#ifndef _include_corsika_setup_environment_h_
#define _include_corsika_setup_environment_h_
namespace corsika {}
#endif
#ifndef _include_corsika_setup_logger_h_
#define _include_corsika_setup_logger_h_
namespace corsika {}
#endif