IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 60ef8ce5 authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch 'refactory-2020' into 'master'

Refactory 2020

See merge request AirShowerPhysics/corsika!280
parents a6fa68d4 ea2e5ce1
No related branches found
No related tags found
No related merge requests found
Showing
with 227 additions and 1554 deletions
......@@ -11,7 +11,7 @@ variables:
LSAN_OPTIONS: "log_threads=1"
ASAN_OPTIONS: "detect_leaks=0:detect_stack_use_after_return=1"
# location of AirShowerPhysics/corsika-data
CORSIKA_DATA: "${CI_PROJECT_DIR}/Data" # the git submodule
CORSIKA_DATA: "${CI_PROJECT_DIR}/modules/data" # the git submodule
# _alternatively_ corsika-data can be downloaded as submodule:
GIT_SUBMODULE_STRATEGY: normal # none: we get the submodules in before_script,
# normal: get submodules automatically
......@@ -29,7 +29,6 @@ stages:
- build
- test
- build_test
- python
- example
- build_test_example
- install
......@@ -68,8 +67,18 @@ check-clang-format:
- if: $CI_COMMIT_BRANCH
allow_failure: true
### CodeQuality tool ####
#include:
# - template: Code-Quality.gitlab-ci.yml
#
#code_quality:
# stage: quality
# rules:
# - if: '$CODE_QUALITY_DISABLED'
# when: never
# - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' # Run code quality job in merge request pipelines
# - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' # Run code quality job in pipelines on the master branch (but not in other branch pipelines)
# - if: '$CI_COMMIT_TAG' # Run code quality job in pipelines for tags
####### CONFIG ##############
......@@ -80,19 +89,24 @@ check-clang-format:
stage: config
tags:
- corsika
script:
script:
- mkdir -p build
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_PYTHIA=ON
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DUSE_PYTHIA8_C8=SYSTEM
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH
artifacts:
when: on_failure
expire_in: 3 days
paths:
- ${CI_PROJECT_DIR}/build/CMakeFiles/CMakeOutput.log
cache:
paths:
- ${CI_PROJECT_DIR}/build/
untracked: true
policy: pull-push
policy: pull-push
# config for gcc
config-u-18_04:
......@@ -272,8 +286,6 @@ build_test-clang-8:
# normal pipeline for each commit
.example:
stage: example
before_script:
- apt-get -qq update && apt-get -qq install -y gdb
tags:
- corsika
script:
......@@ -328,8 +340,6 @@ example-clang-8:
stage: build_test_example
tags:
- corsika
before_script:
- apt-get -qq update && apt-get -qq install -y gdb
script:
- cd build
- cmake --build . -- -j4
......@@ -438,11 +448,9 @@ install-clang-8:
stage: optional
tags:
- corsika
before_script:
- apt-get -qq update && apt-get -qq install -y gdb
script:
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=Release
- cmake .. -DCMAKE_BUILD_TYPE=Release -DUSE_PYTHIA8_C8=SYSTEM
- cmake --build . -- -j4
- set -o pipefail
- ctest -j4
......@@ -505,7 +513,7 @@ coverage:
- corsika
script:
- cd build
- cmake .. -DCMAKE_BUILD_TYPE=Coverage
- cmake .. -DCMAKE_BUILD_TYPE=Coverage -DUSE_PYTHIA8_C8=SYSTEM
- cmake --build . -- -j4
- ctest -j4
- cmake --build . --target coverage
......@@ -535,41 +543,6 @@ coverage:
##########################################################
documentation:
image: corsika/devel:u-18.04
dependencies:
- config-u-18_04
stage: optional
tags:
- corsika
script:
- cd build
- cmake --build . --target doxygen -- -j4
- mkdir -p .public
- cp -r Documentation/Doxygen/html .public/
- mv .public ../public
rules:
- if: '$CI_MERGE_REQUEST_LABELS =~ /Ready for code review/' # run on merge requests, if label 'Ready for code review' is set
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
allow_failure: true
- if: $CI_MERGE_REQUEST_ID
when: manual
allow_failure: true
- if: $CI_COMMIT_TAG
when: manual
allow_failure: true
artifacts:
expire_in: 3 weeks
paths:
- ${CI_PROJECT_DIR}/public
cache:
paths:
- ${CI_PROJECT_DIR}/build/
untracked: true
policy: pull
key: "${CI_COMMIT_REF_SLUG}-gcc"
......@@ -604,36 +577,3 @@ sanity:
key: "${CI_COMMIT_REF_SLUG}-gcc"
##########################################################
# template for all Python jobs
.python:
stage: python
tags:
- corsika
script:
- cd ${CI_PROJECT_DIR}/Python # change into the Python directory
- pip install --user -e '.[test]' # install the package + test deps
- make all 2&>1 | tee python-test.log # this runs all of the Python tests
- echo "finished" >> python-test.log # create even an empty file...
- cd ${CI_PROJECT_DIR} # reset the directory
artifacts:
when: always
expire_in: 1 year
paths:
- ${CI_PROJECT_DIR}/Python/python-test.log
allow_failure: true
# we now configure the jobs for the three
# supported Python versions
python-3.6:
extends: .python
image: python:3.6
python-3.7:
extends: .python
image: python:3.7
python-3.8:
extends: .python
image: python:3.8
[submodule "Data"]
path = Data
[submodule "modules/data"]
path = modules/data
url = ../../AirShowerPhysics/corsika-data
branch = master
[submodule "ThirdParty/spdlog"]
path = ThirdParty/spdlog
url = https://github.com/gabime/spdlog.git
shallow = true
[submodule "Processes/Proposal/PROPOSAL"]
path = Processes/Proposal/PROPOSAL
shallow = true
[submodule "modules/proposal"]
path = modules/proposal
url = https://github.com/tudo-astroparticlephysics/PROPOSAL.git
shallow = true
branch = restructure_parametrization
shallow = true
[submodule "modules/conex"]
path = modules/conex
url = ../../AirShowerPhysics/cxroot
branch = master
shallow = true
cmake_minimum_required (VERSION 3.9)
# we would need 3.16 to have CMP0097 for external subproject submodule (non) support
#+++++++++++++++++++++++++++++
# prevent in-source builds and give warning message
#
if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
message (FATAL_ERROR "In-source builds are disabled.
Please create a build-dir and use `cmake <source-dir>` inside it.
......@@ -9,57 +10,94 @@ if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
You must delete them, or cmake will refuse to work.")
endif ()
#+++++++++++++++++++++++++++++
# project name
#
project (
corsika
VERSION 8.0.0
DESCRIPTION "CORSIKA C++ project"
DESCRIPTION "CORSIKA C++ project (alpha status)"
LANGUAGES CXX
)
include (FeatureSummary)
#+++++++++++++++++++++++++++++
# as long as there still are modules using it:
#
enable_language (Fortran)
set (CMAKE_Fortran_FLAGS "-std=legacy -Wfunction-elimination")
# TEMPORARY: this should be removed, the sanitizers should be always enabled
option (WITH_CORSIKA_SANITIZERS_ENABLED "temporary way to globally disable sanitizers until the currently failing tests are fixed" OFF)
add_feature_info (CORSIKA_SANITIZERS_ENABLED WITH_CORSIKA_SANITIZERS_ENABLED "Switch to run c++ sanitzers on CORSIKA objects and code.")
option (WITH_COAST "Flag to switch on/off COAST (reverse) interface" OFF)
add_feature_info (COAST WITH_COAST "The COAST interface, so that you can write C8 processes to run inside C7.")
# HISTORY option selection
option (WITH_HISTORY "Flag to switch on/off HISTORY" ON)
add_feature_info (HISTORY WITH_HISTORY "The Foo feature provides very cool stuffdddd.")
# check for python
set (Python_ADDITIONAL_VERSIONS 3)
find_package (PythonInterp 3 REQUIRED)
#+++++++++++++++++++++++++++++
# warn user if system is not UNIX
#
if (NOT UNIX)
message (FATAL_ERROR "| CORSIKA8 > This is an unsupported system.")
endif ()
#+++++++++++++++++++++++++++++
# cmake path dir, and cmake config
#
set (CORSIKA8_CMAKE_DIR "${PROJECT_SOURCE_DIR}/cmake")
set (CMAKE_MODULE_PATH "${CORSIKA8_CMAKE_DIR}" ${CMAKE_MODULE_PATH})
include (CorsikaUtilities) # extra cmake function
set (CMAKE_VERBOSE_MAKEFILE OFF) # this can be done with `make VERBOSE=1`
# ignore many irrelevant Up-to-date messages during install
set (CMAKE_INSTALL_MESSAGE LAZY)
# directory for local cmake modules
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
include (CorsikaUtilities) # a few cmake function
#+++++++++++++++++++++++++++++
# Setup hardware and infrastructure dependent defines
#
include(CorsikaDefines)
#+++++++++++++++++++++++++++++
# check if compiler is C++17 compliant
#
include (CheckCXXCompilerFlag)
check_CXX_compiler_flag ("--std=c++17" COMPILER_SUPPORTS_CXX17)
if (NOT COMPILER_SUPPORTS_CXX17)
message (FATAL "| CORSIKA8 > The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.")
endif ()
# set CXX compile flags and options and warning settings
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_EXTENSIONS OFF)
enable_testing ()
set (CTEST_OUTPUT_ON_FAILURE 1)
list (APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
#+++++++++++++++++++++++++++++
# Compiler and linker flags, settings
#
# enable warnings and disallow non-standard language
# configure the various build types here, too
# FYI: optimizer flags: -O2 would not trade speed for size, neither O2/3 use fast-math
# debug: O0, relwithdebinfo: 02, release: O3, minsizerel: Os (all defaults)
set (CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra -Wno-ignored-qualifiers")
set (CMAKE_Fortran_FLAGS "-std=legacy -Wfunction-elimination")
set (DEFAULT_BUILD_TYPE "Release")
# clang produces a lot of unecessary warnings without this:
add_compile_options (
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-nonportable-include-path>
)
#+++++++++++++++++++++++++++++
# Build types settings
#
# setup coverage build type
set (CMAKE_CXX_FLAGS_COVERAGE "-g --coverage")
set (CMAKE_EXE_LINKER_FLAGS_COVERAGE "--coverage")
set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE "--coverage")
# set a flag to inform code that we are in debug mode
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
#+++++++++++++++++++++++++++++
# Build type selection
#
# Set the possible values of build type for cmake-gui and command line check
set (ALLOWED_BUILD_TYPES Debug Release MinSizeRel RelWithDebInfo Coverage)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${ALLOWED_BUILD_TYPES})
# Set a default build type if none was specified
# by default: "Debug", if local ".git" directory is found, otherwise "Release"
set (DEFAULT_BUILD_TYPE "Release")
if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
set (DEFAULT_BUILD_TYPE "Debug")
endif ()
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message (STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as no other was specified.")
set (CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
......@@ -74,42 +112,33 @@ else (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message (STATUS "Build type is: ${CMAKE_BUILD_TYPE}")
endif (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# enable warnings and disallow non-standard language
# configure the various build types here, too
# FYI: optimizer flags: -O2 would not trade speed for size, neither O2/3 use fast-math
# debug: O0, relwithdebinfo: 02, release: O3, minsizerel: Os (all defaults), coverage -> O0
set (CMAKE_CXX_FLAGS "-Wall -pedantic -Wextra -Wno-ignored-qualifiers")
set (CMAKE_Fortran_FLAGS "-std=legacy -Wfunction-elimination")
# setup coverage build type
set (CMAKE_CXX_FLAGS_COVERAGE "-g --coverage")
set (CMAKE_EXE_LINKER_FLAGS_COVERAGE "--coverage")
set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE "--coverage")
# clang produces a lot of unecessary warnings without this:
add_compile_options ("$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-nonportable-include-path>")
# set a flag to inform code that we are in debug mode
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
# COAST - interface, this requires CORSIKA7 to be installed first
# COAST will allow you to program code in CORSIKA8 and execute it inside CORSIKA7
if (WITH_COAST)
message (STATUS "Compiling CORSIKA8 for the use with COAST/corsika7.")
add_compile_options ("-fPIC")
endif ()
#+++++++++++++++++++++++++++++
# Setup external dependencies.
#
include (conan) # self-provided in 'cmake' directory
#
# download and build all dependencies
conan_cmake_run (CONANFILE conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing
BUILD_TYPE "Release")
#
# add cnpy temporarily. As long as SaveBoostHistogram does not save to parquet directly
#
add_subdirectory (externals/cnpy)
#+++++++++++++++++++++++++++++
# Coverage
#
# targets and settings needed to generate coverage reports
if (CMAKE_BUILD_TYPE STREQUAL Coverage)
find_package (Perl REQUIRED)
# compile coverage under -O2 to remove unused functions
# add_compile_options ("-O2")
# compile coverage under -O0 to avoid any optimization, function elimation etc.
add_compile_options ("-O0")
set (GCOV gcov CACHE STRING "gcov executable" FORCE)
set (LCOV_BIN_DIR "${PROJECT_SOURCE_DIR}/ThirdParty/lcov/bin")
set (LCOV_BIN_DIR "${PROJECT_SOURCE_DIR}/externals/lcov/bin")
# collect coverage data
add_custom_command (
OUTPUT raw-coverage.info
......@@ -119,8 +148,8 @@ if (CMAKE_BUILD_TYPE STREQUAL Coverage)
# remove uninteresting entries
add_custom_command (
OUTPUT coverage.info
COMMAND ${LCOV_BIN_DIR}/lcov -q --remove raw-coverage.info "*/usr/*" --output-file coverage2.info
COMMAND ${LCOV_BIN_DIR}/lcov --remove coverage2.info "*/ThirdParty/*" --output-file coverage.info
COMMAND ${LCOV_BIN_DIR}/lcov -q --remove raw-coverage.info "*/usr/*" "/usr/*" --output-file coverage2.info
COMMAND ${LCOV_BIN_DIR}/lcov --remove coverage2.info "*/externals/*" "*/tests/*" "*/sibyll2.3d.cpp" "*/.conan/*" "*/include/Pythia8/*" "${CMAKE_CURRENT_SOURCE_DIR}/modules/*" "${CMAKE_CURRENT_BINARY_DIR}/modules/*" --output-file coverage.info
COMMAND ${CMAKE_COMMAND} -E remove coverage2.info
DEPENDS raw-coverage.info
)
......@@ -133,39 +162,97 @@ if (CMAKE_BUILD_TYPE STREQUAL Coverage)
add_custom_target (coverage DEPENDS coverage-report)
endif ()
# include this test only if NOT run on gitlab-ci, since there we have a dedicated job for it:
#+++++++++++++++++++++++++++++
# CTest config
#
enable_testing ()
if (${CMAKE_VERSION} VERSION_LESS "3.12.0")
list (APPEND CMAKE_CTEST_ARGUMENTS "--output-on-failure")
else (${CMAKE_VERSION} VERSION_LESS "3.12.0")
set (CTEST_OUTPUT_ON_FAILURE 1) # this is for new versions of cmake
endif (${CMAKE_VERSION} VERSION_LESS "3.12.0")
set (CTEST_CUSTOM_COVERAGE_EXCLUDE "./tests/" "./examples/" "./modules/" "test*.(hpp/cpp)$")
# include this test only if NOT run on gitlab-ci; On CI this is a dedicated job:
if (NOT DEFINED ENV{CI})
# add call to ./do-copyright.py to run as unit-test-case
add_test (NAME copyright_notices COMMAND ./do-copyright.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif (NOT DEFINED ENV{CI})
if (DEFINED ENV{CORSIKA_DATA})
message ("Found corsika-data in $ENV{CORSIKA_DATA}")
set (CORSIKA_DATA $ENV{CORSIKA_DATA})
add_subdirectory ($ENV{CORSIKA_DATA} corsika_data)
else ()
message ("CORSIKA_DATA not defined: NEED to download AirShowerPhysics/corsika-data via git submodule")
message ("cmake will fail if you did not do this already.")
set (CORSIKA_DATA ${PROJECT_SOURCE_DIR}/Data)
add_subdirectory (Data)
endif ()
# include potential ThirdParty code provided with CORSIKA
add_subdirectory (ThirdParty)
# order of subdirectories
add_subdirectory (Framework)
add_subdirectory (Environment)
add_subdirectory (Stack)
add_subdirectory (Setup)
add_subdirectory (Processes)
add_subdirectory (Documentation)
add_subdirectory (Main)
add_subdirectory (Tools)
if (WITH_COAST)
add_subdirectory (COAST)
endif ()
#+++++++++++++++++++++++++++++
# Options
#
# HISTORY option selection
option (WITH_HISTORY "Flag to switch on/off HISTORY" ON)
#+++++++++++++++++++++++++++++
# Externals
#
set (Python_ADDITIONAL_VERSIONS 3)
find_package (PythonInterp 3 REQUIRED)
#+++++++++++++++++++++++++++++
# CORSIKA8
#
add_library (CORSIKA8 INTERFACE)
target_include_directories (
CORSIKA8
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}>
)
# since CORSIKA8 is a header only library we must specify all link dependencies here:
target_link_libraries (
CORSIKA8
INTERFACE
CONAN_PKG::eigen
CONAN_PKG::spdlog
CONAN_PKG::boost
cnpy # for SaveBoostHistogram
stdc++fs # experimental::filesystem
)
# "src" is needed, since some headers (namely GeneratedParticleProperties.inc ec.) are produced by python script from e.g. ParticleData.xml
add_subdirectory (src)
add_subdirectory (documentation)
#+++++++++++++++++++++++++++++
# =~~~~~~~~~~~~~~~~~~~~~~~~~=
# = Add of subdirectories =
# =~~~~~~~~~~~~~~~~~~~~~~~~~=
#+++++++++++++++++++++++++++++
# modules
#
set (CORSIKA_DATA_WITH_TEST ON) # we want to run the corsika-data unit test
add_subdirectory (modules/data)
add_subdirectory (modules/pythia)
add_subdirectory (modules/sibyll)
add_subdirectory (modules/qgsjetII)
add_subdirectory (modules/urqmd)
add_subdirectory (modules/conex)
#
# we really need a better proposal CMakeList.txt files:
set (ADD_PYTHON OFF)
file(READ modules/CMakeLists_PROPOSAL.txt overwrite_CMakeLists_PROPOSAL_txt)
file(WRITE modules/proposal/CMakeLists.txt ${overwrite_CMakeLists_PROPOSAL_txt})
add_subdirectory (modules/proposal)
target_link_libraries (CORSIKA8 INTERFACE PROPOSAL)
#+++++++++++++++++++++++++++++++
# unit testing
#
add_subdirectory (tests)
#+++++++++++++++++++++++++++++++
# examples
#
add_subdirectory (examples)
#+++++++++++++++++++++++++++++++
#
# final summary output
#
include (FeatureSummary)
add_feature_info (HISTORY WITH_HISTORY "Full information on cascade history for particles.")
feature_summary (WHAT ALL)
set (
COAST_HEADERS
COASTProcess.h
COASTStack.h
ParticleConversion.h
)
set (
COAST_SOURCES
COASTUserLib.cc
COASTProcess.cc
ParticleConversion.cc
)
set (
COAST_NAMESPACE
corsika/coast
)
add_library (COAST SHARED ${COAST_SOURCES})
CORSIKA_COPY_HEADERS_TO_NAMESPACE (COAST ${COAST_NAMESPACE} ${COAST_HEADERS})
set_target_properties (
COAST
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
# PUBLIC_HEADER "${MODEL_HEADERS}"
)
target_link_libraries (
COAST
PUBLIC
CORSIKAgeometry
CORSIKAunits
CORSIKAparticles
CORSIKAgeometry
CORSIKAsetup
# SuperStupidStack
)
target_include_directories (
COAST
PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include/include>
)
target_include_directories (
COAST
SYSTEM
PUBLIC
$ENV{COAST_DIR}/include
)
install (
TARGETS COAST
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/${COAST_NAMESPACE}
)
#install (
# FILES ${COAST_HEADERS}
# DESTINATION include/${COAST_NAMESPACE}
# )
/*
* (c) Copyright 2018 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/coast/COASTProcess.h>
#include <corsika/coast/COASTStack.h>
#include <iostream>
using namespace std;
namespace corsika::coast {
/**
the init function is called during the start of corsika.
*/
void COASTProcess::Init() {
cout << "************* Greetings from CORSIKA8 *****************" << endl;
}
/**
the docontinous function is called for each tracking step in
corsika. Take care: you cannot modify the particle, the track or
the stack from here (docontinuous) inside corisika7. In corsika8
you will be able to do that.
*/
corsika::process::EProcessReturn COASTProcess::DoContinuous(const Particle& p,
const Track& t,
const Stack&) {
using namespace corsika::units::si;
auto const start = t.GetPosition(0).GetCoordinates();
auto const delta = t.GetPosition(1).GetCoordinates() - start;
auto const name = corsika::particles::GetName(p.GetPID());
cout << "CORSIKA8: particle=" << name << ", pos=" << start
<< " track-l=" << delta.norm() << ", track-t=" << t.GetDuration() << endl;
return corsika::process::EProcessReturn::eOk;
}
} // namespace corsika::coast
/*
* (c) Copyright 2018 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.
*/
#pragma once
#include <corsika/particles/ParticleProperties.h>
#include <corsika/process/ContinuousProcess.h>
#include <corsika/setup/SetupTrajectory.h>
#include <corsika/units/PhysicalUnits.h>
#include <corsika/coast/COASTStack.h>
#include <limits>
typedef corsika::coast::COASTStack Stack;
typedef corsika::coast::COASTStack::ParticleType Particle;
typedef corsika::geometry::Trajectory<corsika::geometry::Line> Track;
namespace corsika::coast {
class COASTProcess : public corsika::process::ContinuousProcess<COASTProcess> {
public:
void Init();
corsika::process::EProcessReturn DoContinuous(const Particle&, const Track&,
const Stack&);
corsika::units::si::LengthType MaxStepLength(Particle&, Track&) {
return corsika::units::si::meter * std::numeric_limits<double>::infinity();
}
private:
};
} // namespace corsika::coast
/*
* (c) Copyright 2018 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.
*/
#pragma once
#include <corsika/coast/ParticleConversion.h>
#include <corsika/particles/ParticleProperties.h>
#include <corsika/stack/ParticleBase.h>
#include <corsika/stack/Stack.h>
#include <corsika/units/PhysicalUnits.h>
#include <corsika/geometry/Point.h>
#include <corsika/geometry/RootCoordinateSystem.h> // remove
#include <corsika/geometry/Vector.h>
#include <crs/CParticle.h>
#include <crs/CorsikaTypes.h>
#include <algorithm>
#include <vector>
namespace corsika::coast {
typedef corsika::geometry::Vector<corsika::units::si::hepmomentum_d> MomentumVector;
/**
* Example of a particle object on the stack.
*/
template <typename StackIteratorInterface>
class ParticleInterface : public corsika::stack::ParticleBase<StackIteratorInterface> {
using corsika::stack::ParticleBase<StackIteratorInterface>::GetStackData;
using corsika::stack::ParticleBase<StackIteratorInterface>::GetIndex;
public:
corsika::particles::Code GetPID() const { return GetStackData().GetPID(GetIndex()); }
corsika::units::si::HEPEnergyType GetEnergy() const {
return GetStackData().GetEnergy(GetIndex());
}
MomentumVector GetMomentum(const corsika::geometry::CoordinateSystem& cs) const {
using namespace corsika::units::si;
const HEPEnergyType mass = corsika::particles::GetMass(GetPID());
const auto P = sqrt((GetEnergy() - mass) * (GetEnergy() + mass));
const auto p = GetStackData().GetDirection(cs);
return p * P;
}
corsika::geometry::Point GetPosition(
const corsika::geometry::CoordinateSystem& cs) const {
return GetStackData().GetPosition(cs, GetIndex());
}
corsika::geometry::Vector<corsika::units::si::speed_d> GetVelocity(
const corsika::geometry::CoordinateSystem& cs) const {
return GetStackData().GetVelocity(cs, GetIndex());
}
corsika::units::si::TimeType GetTime() const {
return GetStackData().GetTime(GetIndex());
}
corsika::geometry::Vector<corsika::units::si::dimensionless_d> GetDirection(
const corsika::geometry::CoordinateSystem& cs) const {
return GetStackData().GetDirection(cs);
}
corsika::units::si::TimeType GetTimeInterval() const {
return GetStackData().GetTimeInterval();
}
};
/**
*
* Memory implementation of the most simple (stupid) particle stack object.
*/
class COASTStackImpl {
const crs::CParticle* fParticle1 = 0;
const crs::CParticle* fParticle2 = 0;
public:
COASTStackImpl(const crs::CParticle* v1, const crs::CParticle* v2) {
fParticle1 = v1;
fParticle2 = v2;
}
void Init() {}
void Clear() {}
// there is one particle only
int GetSize() const { return 1; }
int GetCapacity() const { return 1; }
// you cannot modify the particle:
// there are no Set... function defined
// readout particle data, there is just one particle!
/*
double x;
double y;
double z;
double depth;
double time;
double energy;
double weight;
int particleId;
int hadronicGeneration;
*/
corsika::particles::Code GetPID(const int) const {
return ConvertFromCoast(static_cast<CoastCode>(fParticle1->particleId));
}
corsika::units::si::HEPEnergyType GetEnergy(const int) const {
using namespace corsika::units::si;
return fParticle1->energy * 1_GeV;
}
corsika::geometry::Vector<corsika::units::si::dimensionless_d> GetDirection(
const corsika::geometry::CoordinateSystem& cs) const {
using namespace corsika::units::si;
corsika::geometry::Point p1(
cs, {fParticle1->x * 1_cm, fParticle1->y * 1_cm, fParticle1->z * 1_cm});
corsika::geometry::Point p2(
cs, {fParticle2->x * 1_cm, fParticle2->y * 1_cm, fParticle2->z * 1_cm});
const corsika::geometry::Vector D = p2 - p1;
const auto magD = D.norm();
const corsika::geometry::Vector dir = D / magD;
return dir;
}
corsika::geometry::Vector<corsika::units::si::speed_d> GetVelocity(
const corsika::geometry::CoordinateSystem& cs, const int) const {
using namespace corsika::units::si;
corsika::geometry::Vector<corsika::units::si::dimensionless_d> dir =
GetDirection(cs);
corsika::geometry::Point p1(
cs, {fParticle1->x * 1_cm, fParticle1->y * 1_cm, fParticle1->z * 1_cm});
corsika::geometry::Point p2(
cs, {fParticle2->x * 1_cm, fParticle2->y * 1_cm, fParticle2->z * 1_cm});
const corsika::geometry::Vector D = p2 - p1;
const LengthType magD = D.norm();
const TimeType deltaT = GetTimeInterval();
return dir * magD / deltaT;
}
corsika::geometry::Point GetPosition(const corsika::geometry::CoordinateSystem& cs,
const int) const {
using namespace corsika::units::si;
return corsika::geometry::Point(
cs, {fParticle1->x * 1_cm, fParticle1->y * 1_cm, fParticle1->z * 1_cm});
}
corsika::units::si::TimeType GetTime(const int) const {
using namespace corsika::units::si;
return fParticle1->time * 1_s;
}
corsika::units::si::TimeType GetTimeInterval() const {
using namespace corsika::units::si;
return (fParticle2->time - fParticle1->time) * 1_s;
}
/**
* We do not allow copying!
*/
void Copy(const int, const int) {}
/**
* We do not allow swapping particles, there is just one...
*/
void Swap(const int, const int) {}
// size cannot be increased, do nothing
void IncrementSize() {}
// size cannot be decremented, do nothing
void DecrementSize() {}
}; // end class COASTStackImpl
typedef corsika::stack::Stack<COASTStackImpl, ParticleInterface> COASTStack;
} // namespace corsika::coast
/*
* (c) Copyright 2018 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 <interface/CorsikaInterface.h>
#include <corsika/coast/COASTProcess.h>
#include <corsika/coast/COASTStack.h>
#include <corsika/geometry/CoordinateSystem.h>
#include <corsika/geometry/Line.h>
#include <corsika/geometry/Point.h>
#include <corsika/geometry/Trajectory.h>
#include <corsika/geometry/Vector.h>
#include <corsika/units/PhysicalUnits.h>
#include <crs/CInteraction.h>
#include <crs/CParticle.h>
#include <crs/CorsikaTypes.h>
#include <crs/TSubBlock.h>
#include <iostream>
#include <sstream>
using namespace std;
using namespace corsika;
using namespace corsika::units::si;
corsika::coast::COASTProcess gCorsikaProcess;
/*
Data is one CORSIKA data-block constining of 21 SubBlocks.
A SubBlock can be:
- thinned mode: 39 (Particles) * 8 (ENTRIES) * 4 (BYTES)
- not-thinned mode: 39 (Particles) * 7 (ENTRIES) * 4 (BYTES)
*/
extern "C" void wrida_([[maybe_unused]] const CREAL* Data) {
// crs::CParticleFortranPtr p;
// const bool isF = prminfo_(p);
}
extern "C" void inida_([[maybe_unused]] const char* filename,
[[maybe_unused]] const int& thinning,
[[maybe_unused]] const int& /*curved*/,
[[maybe_unused]] const int& /*slant*/,
[[maybe_unused]] const int& /*stackinput*/,
[[maybe_unused]] const int& /*preshower*/,
[[maybe_unused]] int str_length) {
gCorsikaProcess.Init();
}
extern "C" void cloda_() {
// crs::CParticleFortranPtr pptr;
// const bool isF = prminfo_(pptr);
// gCorsikaProcess.Close();
}
void interaction_([[maybe_unused]] const crs::CInteraction& interaction) {
/*
all interactions in the shower are available in this function !
the information availabel in the CInteraction class are:
double x;
double y;
double z;
double etot; // lab energy
double sigma; // cross-section of process
double kela; // elasticity
int projId; // projectile
int targetId; // target
double time;
*/
}
extern "C" void track_([[maybe_unused]] const crs::CParticle& pre,
[[maybe_unused]] const crs::CParticle& post) {
/*
all particles in the shower are available in this function !
The pre and post objecte are the two endpoints for one single track
in the shower, where the information available in CParticle is:
double x;
double y;
double z;
double depth;
double time;
double energy;
double weight;
int particleId;
int hadronicGeneration;
*/
coast::COASTStack stack(&pre, &post);
const auto particle = stack.GetNextParticle();
const geometry::CoordinateSystem& rootCS =
geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem();
geometry::Line const line(particle.GetPosition(rootCS), particle.GetVelocity(rootCS));
const TimeType time = particle.GetTimeInterval();
const geometry::Trajectory<geometry::Line> track(line, time);
gCorsikaProcess.DoContinuous(particle, track, stack);
}
extern "C" void tabularizedatmosphere_([[maybe_unused]] const int& nPoints,
[[maybe_unused]] const double* height,
[[maybe_unused]] const double* refractiveIndex) {
// for special use only but should be defined because it is delcared in CORSIKA.F
}
/*
* (c) Copyright 2018 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/coast/ParticleConversion.h>
#include <corsika/particles/ParticleProperties.h>
#include <exception>
#include <iostream>
#include <sstream>
using namespace std;
namespace corsika::coast {
/**
Convert particle code, and check if it does exists. Throw exeption, if not!
*/
corsika::particles::Code ConvertFromCoast(CoastCode pCode) {
if (coast2corsika.count(pCode) == 0) {
ostringstream err;
err << "corsika::coast::ConvertFromCoast CoastCode does not exists="
<< static_cast<CoastCodeIntType>(pCode) << endl;
cout << err.str() << endl;
throw std::runtime_error(err.str());
}
return coast2corsika.find(pCode)->second;
}
} // namespace corsika::coast
/*
* (c) Copyright 2018 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.
*/
#pragma once
#include <corsika/particles/ParticleProperties.h>
#include <map>
namespace corsika::coast {
/**
Here we define the original CORSIKA particle codes, see corsika manual
*/
enum class CoastCode : int16_t {
Gamma = 1,
Positron = 2,
Electron = 3,
MuonBar = 5,
Muon = 6,
Pi0 = 7,
PiP = 8,
PiM = 9,
Klong = 10,
KP = 11,
KM = 12,
Neutron = 13,
Proton = 14,
ProtonBar = 15,
Kshort = 16,
Eta = 17,
Lambda = 18,
SigmaPlus = 19,
Sigma0 = 20,
SigmaMinus = 21,
Xi0 = 22,
XiMinus = 23,
OmegaMinus = 24,
NeutronBar = 25,
LambdaBar = 26,
SigmaMinusBar = 27,
Sigma0Bar = 28,
SigmaPlusBar = 29,
Xi0Bar = 30,
XiPlusBar = 31,
OmegaPlusBar = 32,
EtaPrime = 48,
Phi = 49,
omega = 50,
Rho0 = 51,
RhoPlus = 52,
RhoMinus = 53,
DeltaPlusPlus = 54,
DeltaPlus = 55,
Delta0 = 56,
DeltaMinus = 57,
DeltaMinusMinusBar = 58,
DeltaMinusBar = 59,
Delta0Bar = 60,
DeltaPlusBar = 61,
KStar0 = 62,
KStarPlus = 63,
KStarMinus = 64,
KStar0Bar = 65,
NeutrinoE = 66,
NeutrinoEBar = 67,
NeutrinoMu = 68,
NeutrinoMuBar = 69,
Code71 = 71,
Code72 = 72,
Code73 = 73,
Code74 = 74,
Code75 = 75,
Code76 = 76,
Code85 = 85,
Code86 = 86,
Code95 = 95,
Code96 = 96,
ProtonNucleus = 101,
Deuterium = 201,
Tritium = 301,
He3 = 302,
Helium = 402,
Lithium = 603,
Beryllium = 904,
Boron = 1005,
Carbon = 1206,
Carbon13 = 1306,
Nitrogen = 1407,
Oxygen = 1608,
Fluor = 1809,
Neon21 = 2110,
Neon = 2210,
Argon = 1838,
Iron = 5628,
Xenon = 12854,
Radon = 13888,
};
using CoastCodeIntType = std::underlying_type<CoastCode>::type;
/**
Here we convert CORSIKA7 to CORSIKA8 codes
*/
const std::map<corsika::coast::CoastCode, corsika::particles::Code> coast2corsika = {
{CoastCode::Gamma, corsika::particles::Code::Gamma},
{CoastCode::Positron, corsika::particles::Code::Positron},
{CoastCode::Electron, corsika::particles::Code::Electron},
//{CoastCode:: ,corsika::particles::Code::Unknown}, // 4
{CoastCode::MuonBar, corsika::particles::Code::MuPlus},
{CoastCode::Muon, corsika::particles::Code::MuMinus},
{CoastCode::Pi0, corsika::particles::Code::Pi0},
{CoastCode::PiP, corsika::particles::Code::PiPlus},
{CoastCode::PiM, corsika::particles::Code::PiMinus},
{CoastCode::Klong, corsika::particles::Code::K0Long}, // 10
{CoastCode::KP, corsika::particles::Code::KPlus},
{CoastCode::KM, corsika::particles::Code::KMinus},
{CoastCode::Neutron, corsika::particles::Code::Neutron},
{CoastCode::Proton, corsika::particles::Code::Proton}, // 14
{CoastCode::ProtonBar, corsika::particles::Code::AntiProton},
{CoastCode::Kshort, corsika::particles::Code::K0Short},
{CoastCode::Eta, corsika::particles::Code::Eta}, // 17
{CoastCode::Lambda, corsika::particles::Code::Lambda0},
{CoastCode::SigmaPlus, corsika::particles::Code::SigmaPlus},
{CoastCode::Sigma0, corsika::particles::Code::Sigma0}, // 20
{CoastCode::SigmaMinus, corsika::particles::Code::SigmaMinus},
{CoastCode::Xi0, corsika::particles::Code::Xi0},
{CoastCode::XiMinus, corsika::particles::Code::XiMinus},
{CoastCode::OmegaMinus, corsika::particles::Code::OmegaMinus},
{CoastCode::NeutronBar, corsika::particles::Code::AntiNeutron}, // 25
{CoastCode::LambdaBar, corsika::particles::Code::Lambda0Bar},
{CoastCode::SigmaMinusBar, corsika::particles::Code::SigmaMinusBar},
{CoastCode::Sigma0Bar, corsika::particles::Code::Sigma0Bar},
{CoastCode::SigmaPlusBar, corsika::particles::Code::SigmaPlusBar},
{CoastCode::Xi0Bar, corsika::particles::Code::Xi0Bar},
{CoastCode::XiPlusBar, corsika::particles::Code::XiPlusBar},
{CoastCode::OmegaPlusBar, corsika::particles::Code::OmegaPlusBar}, // 32
//{CoastCode:: ,corsika::particles::Code::Unknown}, // eta-prime
//{CoastCode:: ,corsika::particles::Code::Unknown}, // PHI
//{CoastCode:: ,corsika::particles::Code::Unknown}, // omega
{CoastCode::Rho0, corsika::particles::Code::Rho0}, // 51
{CoastCode::RhoPlus, corsika::particles::Code::RhoPlus},
{CoastCode::RhoMinus, corsika::particles::Code::RhoMinus},
{CoastCode::DeltaPlusPlus, corsika::particles::Code::DeltaPlusPlus},
{CoastCode::DeltaPlus, corsika::particles::Code::DeltaPlus},
{CoastCode::Delta0, corsika::particles::Code::Delta0}, // 56
//{CoastCode:: ,corsika::particles::Code::Unknown}, // DeltaMinus},
{CoastCode::DeltaMinusMinusBar, corsika::particles::Code::DeltaMinusMinusBar},
{CoastCode::DeltaMinusBar, corsika::particles::Code::DeltaMinusBar},
{CoastCode::Delta0Bar, corsika::particles::Code::Delta0Bar},
//{CoastCode:: ,corsika::particles::Code::Unknown}, // DeltaPlusBar
{CoastCode::KStar0, corsika::particles::Code::KStar0}, // 62
{CoastCode::KStarPlus, corsika::particles::Code::KStarPlus},
{CoastCode::KStarMinus, corsika::particles::Code::KStarMinus},
{CoastCode::KStar0Bar, corsika::particles::Code::KStar0Bar},
{CoastCode::NeutrinoE, corsika::particles::Code::NuE},
{CoastCode::NeutrinoEBar, corsika::particles::Code::NuEBar},
{CoastCode::NeutrinoMu, corsika::particles::Code::NuMu},
{CoastCode::NeutrinoMuBar, corsika::particles::Code::NuMuBar}, // 69
{CoastCode::Code71, corsika::particles::Code::Unknown},
{CoastCode::Code72, corsika::particles::Code::Unknown},
{CoastCode::Code73, corsika::particles::Code::Unknown},
{CoastCode::Code74, corsika::particles::Code::Unknown},
{CoastCode::Code75, corsika::particles::Code::Unknown},
{CoastCode::Code76, corsika::particles::Code::Unknown},
{CoastCode::Code85, corsika::particles::Code::Unknown},
{CoastCode::Code86, corsika::particles::Code::Unknown},
{CoastCode::Code95, corsika::particles::Code::Unknown},
{CoastCode::Code96, corsika::particles::Code::Unknown},
{CoastCode::ProtonNucleus, corsika::particles::Code::Proton}, // 101
{CoastCode::Deuterium, corsika::particles::Code::Deuterium},
{CoastCode::Tritium, corsika::particles::Code::Tritium},
{CoastCode::He3, corsika::particles::Code::Helium3},
{CoastCode::Helium, corsika::particles::Code::Helium}, // 402
//{CoastCode::Lithium, corsika::particles::Code::Lithium},
//{CoastCode::Beryllium, corsika::particles::Code::Beryllium},
//{CoastCode::Boron, corsika::particles::Code::Boron},
//{CoastCode::Carbon, corsika::particles::Code::Carbon},
//{CoastCode::Carbon13, corsika::particles::Code::Carbon13},
//{CoastCode::Nitrogen, corsika::particles::Code::Nitrogen},
//{CoastCode::Fluor, corsika::particles::Code::Fluor},
//{CoastCode::Oxygen, corsika::particles::Code::Oxygen},
//{CoastCode::Neon21, corsika::particles::Code::Neon21},
//{CoastCode::Neon, corsika::particles::Code::Neon},
//{CoastCode::Argon, corsika::particles::Code::Argon},
//{CoastCode::Xenon, corsika::particles::Code::Xenon},
//{CoastCode::Radon, corsika::particles::Code::Radon},
{CoastCode::Iron, corsika::particles::Code::Iron}, // 5628
//{CoastCode::, corsika::particles::Code::},
};
corsika::particles::Code ConvertFromCoast(CoastCode pCode);
} // namespace corsika::coast
# COAST interface {#COAST}
With the COAST interface of CORSIKA 8 you can write a CORSIKA 8
"process" class and link it to CORSIKA 7. This can be very powerful to
benchmark new CORSIKA 8 physics code in the context of "old" CORSIKA 7
simulations.
This is based on corsika7/trunk/coast/CoastOptions/example with an
additional interface to CORSIKA 8. See code in namespace corsika::coast for all details.
We provide a step-by-step example for a "COAST user library" using CORSIKA 8
technology. It explains the steps, how to use the COAST_USER_LIB
option of CORSIKA together with CORSIKA8/COAST
Step 1:
-------
Configure CORSIKA8 with 'cmake -DWITH_COAST=1' and other options you
prefer. You have to define COAST_DIR environment variable to the
location of your existing CORSIKA7 installation. Check that 'ls
$COAST_DIR/include/interface' contains the file
'CorsikaInterface.h'. If this is not the case, this is not a valid or
proper installation of CORSIKA. First compile CORSIKA, e.g. with
ROOTOUT option, or CoReas to get COAST installed!
Step 2:
-------
Compile CORSIKA8, edit COAST/COASTProcess.cc to modify/add your
physics module.
There should be a libCOAST.so as a result! This is what you need.
Step 3:
-------
Create COAST_USER_LIB environment variable to point at your current
directory, where now the 'libCOAST.so' library is located.
Add the path in $COAST_USER_LIB to your LD_LIBRARY_PATH environment
variable.
Step 4:
-------
Go back to your CORSIKA directory and re-start 'coconut'. The option
COAST_USER_LIB will now be visible. Please select it, copile CORSIKA
and start the executable. In the generated console output you will the
statements from your COAST library during Init and Close of the
simulation.
Add any kind of code now working on the CParticle or
CInteraction class to start using the full power of COAST.
Note: the default COASTProcess just prints out tons of ASCII. This is
not very useful, don't run a full MC with this...
Step 5:
-------
enjoy...
......@@ -23,12 +23,13 @@ liability and licensing question are only handled by the adopted
software license.
## The software license of the CORSIKA project
The license adopted for the CORSIKA project is the explicit copyleft
license GPLv3, as copied in full in the file
[LICENSE](LICENSE). Each source file of the CORSIKA project contains a
short statement of the copyright and this license. Each binary or
source code release of CORSIKA contains the file LICENSE. The
code, documentation and content in the folder [ThirdParty](ThirdParty)
code, documentation and content in the folder [externals](externals)
is not integral part of the CORSIKA project and can be based on, or
include, other licenses, which must be compatible with GPLv3. Check the
content of this folder for details and additional license information. It depends on the configuration of
......
......@@ -8,7 +8,7 @@ change/improve them.
# How to contribute
- We organize all development via `Issues` that may be feature requests,
- We organize all development via gitlab `Issues` that may be feature requests,
ideas, discussions, or bugs fix requests.
- New issues can be created, or existing issues
picked up or contributed to.
......@@ -19,7 +19,7 @@ change/improve them.
created directly via the gitlab web interface.
- Proposed code to close one issue (located in a specific git
branch) is reviewed, discussed, and eventually merged
into the master branch to close the issue.
into the master branch via a merge-request (MR) to close the issue.
- all merge request will undergo a code review, and must be approved before merge, in order to ensure high code qualtiy: [Code Approval Procedure](https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika/-/wikis/Code-Approval-Procedure)
......@@ -32,9 +32,9 @@ formatting. We provide a script `do-clang-format.sh`, which can be
very useful. But we urge everybody to integrate `clang-format` already
on the level of your source code editor. See [the official
page](https://clang.llvm.org/docs/ClangFormat.html) for information
about `clang-format` and its editor integration. At least: run
`do-clang-format.sh` prior to any `git add` command. Code with
improper formatting will not be accepted for merging.
about `clang-format` and its editor integrations. At least: run
`do-clang-format.sh` prior to any `git add/commit` command. Code with
improper formatting will not be accepted for merging. It will trigger automatic warnings by the continuous integration (CI) system.
The definition of source code format is written down in the file
[.clang-format](.clang-format) and can be changed, if the CORSIKA
......@@ -43,134 +43,36 @@ e.g. [link1](https://clangformat.com/) or
[link2](https://zed0.co.uk/clang-format-configurator/).
## Naming conventions
While `clang-format` does the structural formatting, we still need to agree on naming conventions:
- Classes and structs start with capital letters ```LikeThis```
- Class member variables start non-captial and have a trailing "_" ```likeThis_```
- Class member functions start with small letters ```LikeThis::doSomething(...)``` or ```LikeThis::do_something(...)```
- Any class setter begins with "set_" ```LikeThis::set_something(...)```
- Any class getter is named accoring to its property: ```LikeThis::something()```
- Logical getters may start with ```is_``` or ```has_```
- enums should be ```enum class```
- Named variables start with small letter ```likeThis```
- types in template definitions start with "T" ```TLikeThis```
- use names that explain and document the code, thus for example
```
TimeType TimeOfIntersection(Line const& line, Plane const& plane) {
auto const line_direction = line.GetDirection();
auto const plane_normal = plane.GetNormal();
return plane_normal.dot(plane.GetCenter()-line.GetPosition()) / plane_normal.dot(line_direction);
}
```
and not
```
TimeType TimeOfIntersection(Line const& l, Plane const& p) {
auto const d = p.GetCenter() - l.GetR0();
auto const v = l.GetV0();
auto const n = p.GetNormal();
auto const c = n.dot(v);
return n.dot(d) / c;
}
```
This actually is suffient to document the code, no further comments should be added in such cases. Only if further clarification is needed.
- We use namespaces to avoid clashes and to structure code
- *Everything* is part of one of those namespaces:
- ```corsika::framework```, ```corsika::physics```, or ```corsika::process```
- All classes and objects are encapsulated into suited sub-namespaces,
thus ```corsika::framework::geometry```, ```corsika::physics::process```, ```corsika::physics::units```, etc.
- Namespace names do not use capital letters.
- Every header file is located in the source tree in ```include/corsika/[namespace]```, which also means that in almost all cases each header file
can only provide definitions for a _single_ namespace. It is one
main purpose of namespaces to structure the location of header
files.
- Each header file uses an include protection ```#pragma once```
immediately below the copyright statement.
- Header files should always be included with `<..>`, thus,
`#include <corsika/geometry/Point.h>` since the build system
will always provide the correct include directives (and files
anyway cannot be found in file-system paths, which generally do
not follow the namespace naming conventions outlined
here).
- Header files are named after the main class (or object) they
define. This also means each header file name starts with a
capital letter.
## Coding rules
- Warnings should be fixed, when they appear on the system(s) currently used by the CI, by altering the code unless the warning originates from third-party code and cannot be fixed. In that case, the warning should be locally silenced with appropriate pragmas or by locally turning off warnings for that translation unit.
- All unit tests must succeed on the specified systems/configurations on gitlab-ci. If tests fail, code is not merged.
- The unit test code coverage should not decrease due to a new merge request.
- We use C++17 features wherever useful and helpful.
- On any major error or malfunction we throw an exception. This is needed and required for complex physics and shower debugging.
- We never catch exceptions for error handling, there might be very few special exceptions from this. We need to discuss such cases.
- Everything that should not change should be ```const```
- Everything that does not need to be visible to the outside of a class/struct should be `private` or `protected`
- We prefer the use of references, wherever useful
- There cannot be any raw pointer in the interface of any class or object
exposed to outside users, there might be (technical) raw pointers for very special cases
inside of classes.
- (member)functions that do something (are not just getters/setters), model actions or transformations, and should therefore be verbs. Classes are nouns.
- When you contribute new code, or extend existing code, at the same time provide unit-tests for all functionality.
- When you contribute new physics algorithms, in addition you also need to provide a validation module (this is still TBD what exactly this means)
- Code must be documented with `doxygen` commands extensively -> MAKE THIS INVESTMENT OF YOUR TIME EARLY, IT REALLY HELPS
- There should not be any useless comments in code, in particular absolutely avoid to commit commented-out debug remnants
- Add sufficient and meaningful comments to the code (only in English)
## CMAKE formatting
- command are lower cases, e.g. ```set (...)```
- variables upper case, e.g. ```set (VAR1 Text)```
Since cmake itself lacks structure almost entirely:
- put a space between command and start of parenthesis, e.g. ```command (...)```
- add two spaces for logical indent
```
if (condition)
do something
endif (condition)
```
- break long lines to start with new keyword in new line (indented)
```
install (
FILES ${CORSIKAstackinterface_HEADERS}
DESTINATION include/${CORSIKAstackinterface_NAMESPACE}
)
```
- add plenty of comments to all cmake code
- use expressive variables and functions
## Coding rules, conventions and guidelines
Please read the [Coding wiki page](https://gitlab.ikp.kit.edu/AirShowerPhysics/corsika/-/wikis/Coding-Conventions-and-Guidelines).
## Release versioning scheme
Releases of CORSIKA are thought to be the baseline for larger scale
testing, and full production. The releases are numbered as x.y.z,
starting with x=8 form the gitlab c++ version. X will only be
incremented for major design or physics changes. The y index is
updated for new official releases that normally contain improved or
enhanced physics performance, and may also contain normal interface
Releases of CORSIKA 8 are thought to be the baseline for larger scale
validation, and full production. The releases are numbered as x.y.z,
starting with x=8, which will not be changed for CORSIKA 8. The y index is
updated for new releases that normally contain improved or
enhanced physics performance, and also interface
changes to accomodate improvements. The z index can be updated more
frequently for bug fixes or new features. Changes in z will not
contain (major) interface changes, thus, production code will remain
fully compatible within changes of z. Special releases of CORSIKA can
also have a tag name from git, e.g. as in the "milestone1" release.
contain interface changes, thus, production code will remain
fully compatible within changes of z. Special releases of CORSIKA will
also have a release names.
# How to become scientific author of the CORSIKA Project
The CORSIKA Project decides on who becomes scientific author. The
following conditions are clearly sufficient, but not all of them are
following conditions are sufficient, but not all of them are
required all the time:
- responsibility for a particular functionality or software/management part
- have read and follow these [GUIDELINES](CONTRIBUTING.md)
- active in the CORSIKA Project, that means responsive to
discussions and problems in corsika-devel@list.kit.edu or on https//gitlab.ikp.kit.edu,
of relevant *Issues*,
or in (phone) meetings
- agreement to the [COLLABORATION_AGREEMENT](COLLABORATION_AGREEMENT.md) is strictly required
- the members of the CORSIKA Project panel agree
of relevant *Issues*, or in (phone) meetings
- agreement to the [COLLABORATION_AGREEMENT](COLLABORATION_AGREEMENT.md)
- the members of the CORSIKA Project must agree
Subproject commit 4d1785e74a7bf6769ee016509b357e63d7117438
add_subdirectory (Doxygen)
add_subdirectory (Examples)
CORSIKA_ADD_EXAMPLE (helix_example)
target_link_libraries (helix_example CORSIKAgeometry CORSIKAunits)
CORSIKA_ADD_EXAMPLE (particle_list_example)
target_link_libraries (particle_list_example CORSIKAparticles CORSIKAunits CORSIKAprocesses ProcessSibyll ProcessQGSJetII)
CORSIKA_ADD_EXAMPLE (geometry_example)
target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits)
CORSIKA_ADD_EXAMPLE (stack_example)
target_link_libraries (stack_example CORSIKAsetup CORSIKAunits)
# address sanitizer is making this example too slow, so we only do "undefined"
CORSIKA_ADD_EXAMPLE (boundary_example)
target_link_libraries (boundary_example
CORSIKAsetup
CORSIKAunits
CORSIKAlogging
CORSIKArandom
ProcessSibyll
CORSIKAcascade
ProcessTrackWriter
ProcessParticleCut
ProcessTrackingLine
ProcessPythia8
CORSIKAprocesses
CORSIKAparticles
CORSIKAgeometry
CORSIKAenvironment
CORSIKAprocesssequence
C8::ext::boost # boost::histogram
)
CORSIKA_ADD_EXAMPLE (cascade_example)
target_link_libraries (cascade_example
CORSIKAsetup
CORSIKAunits
CORSIKAlogging
CORSIKArandom
ProcessSibyll
ProcessProposal
CORSIKAcascade
ProcessEnergyLoss
ProcessTrackWriter
ProcessStackInspector
ProcessTrackingLine
ProcessParticleCut
ProcessHadronicElasticModel
ProcessStackInspector
CORSIKAprocesses
CORSIKAcascade
CORSIKAparticles
CORSIKAgeometry
CORSIKAenvironment
CORSIKAprocesssequence
)
if (Pythia8_FOUND)
CORSIKA_ADD_EXAMPLE (cascade_proton_example)
target_link_libraries (cascade_proton_example
CORSIKAsetup
CORSIKAunits
CORSIKAlogging
CORSIKArandom
ProcessSibyll
ProcessPythia8
ProcessUrQMD
CORSIKAcascade
ProcessEnergyLoss
ProcessTrackWriter
ProcessStackInspector
ProcessTrackingLine
ProcessParticleCut
ProcessOnShellCheck
ProcessHadronicElasticModel
ProcessStackInspector
CORSIKAprocesses
CORSIKAcascade
CORSIKAparticles
CORSIKAgeometry
CORSIKAenvironment
CORSIKAprocesssequence
)
CORSIKA_ADD_EXAMPLE (vertical_EAS RUN_OPTIONS 4 2 10000.)
target_link_libraries (vertical_EAS
CORSIKAsetup
CORSIKAunits
CORSIKAlogging
CORSIKArandom
CORSIKAhistory
ProcessSibyll
ProcessPythia8
ProcessUrQMD
CORSIKAcascade
ProcessProposal
ProcessPythia8
ProcessObservationPlane
ProcessInteractionCounter
ProcessTrackWriter
ProcessEnergyLoss
ProcessTrackingLine
ProcessParticleCut
ProcessOnShellCheck
ProcessStackInspector
ProcessLongitudinalProfile
CORSIKAprocesses
CORSIKAcascade
CORSIKAparticles
CORSIKAgeometry
CORSIKAenvironment
CORSIKAprocesssequence
CORSIKAhistory # for HistoryObservationPlane
)
CORSIKA_ADD_EXAMPLE (hybrid_MC RUN_OPTIONS 4 2 10000.)
target_link_libraries (hybrid_MC
CORSIKAsetup
CORSIKAunits
CORSIKAlogging
CORSIKArandom
CORSIKAhistory
ProcessCONEXSourceCut
ProcessInteractionCounter
ProcessSibyll
ProcessPythia8
ProcessUrQMD
CORSIKAcascade
ProcessPythia8
ProcessObservationPlane
ProcessInteractionCounter
ProcessTrackWriter
ProcessEnergyLoss
ProcessTrackingLine
ProcessParticleCut
ProcessOnShellCheck
ProcessStackInspector
ProcessLongitudinalProfile
CORSIKAprocesses
CORSIKAcascade
CORSIKAparticles
CORSIKAgeometry
CORSIKAenvironment
CORSIKAprocesssequence
CORSIKAhistory # for HistoryObservationPlane
)
endif()
CORSIKA_ADD_EXAMPLE (stopping_power stopping_power)
target_link_libraries (stopping_power
CORSIKAsetup
CORSIKAunits
CORSIKAlogging
ProcessEnergyLoss
CORSIKAparticles
CORSIKAgeometry
CORSIKAenvironment
)
CORSIKA_ADD_EXAMPLE (staticsequence_example)
target_link_libraries (staticsequence_example
CORSIKAprocesssequence
CORSIKAunits
CORSIKAgeometry
CORSIKAlogging)
CORSIKA_ADD_EXAMPLE (em_shower RUN_OPTIONS "100.")
target_link_libraries (em_shower
SuperStupidStack
CORSIKAunits
CORSIKAlogging
CORSIKArandom
ProcessSibyll
ProcessPythia8
ProcessUrQMD
CORSIKAcascade
ProcessEnergyLoss
ProcessObservationPlane
ProcessInteractionCounter
ProcessTrackWriter
ProcessProposal
ProcessTrackingLine
ProcessParticleCut
ProcessOnShellCheck
ProcessStackInspector
ProcessLongitudinalProfile
CORSIKAprocesses
CORSIKAcascade
CORSIKAparticles
CORSIKAgeometry
CORSIKAenvironment
CORSIKAprocesssequence
)
/*
* (c) Copyright 2018 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/particles/ParticleProperties.h>
#include <corsika/process/ProcessSequence.h>
#include <corsika/process/qgsjetII/ParticleConversion.h>
#include <corsika/process/sibyll/ParticleConversion.h>
#include <corsika/setup/SetupEnvironment.h>
#include <corsika/units/PhysicalUnits.h>
#include <iomanip>
#include <iostream>
#include <string>
using namespace corsika::units;
using namespace corsika::units::si;
using namespace corsika::particles;
using namespace std;
//
// The example main program for a particle list
//
int main() {
std::cout << "particle_list_example" << std::endl;
cout << "------------------------------------------"
<< "particles in CORSIKA"
<< "------------------------------------------" << endl;
cout << std::setw(20) << "Name"
<< " | " << std::setw(10) << "PDG-id"
<< " | " << std::setw(10) << "SIBYLL-id"
<< " | " << std::setw(10) << "QGSJETII-id"
<< " | " << std::setw(18) << "PDG-mass (GeV)"
<< " | " << std::setw(18) << "SIBYLL-mass (GeV)"
<< " | " << endl;
cout << std::setw(104) << std::setfill('-') << "-" << endl;
for (auto p : getAllParticles()) {
if (!IsNucleus(p)) {
corsika::process::sibyll::SibyllCode sib_id =
corsika::process::sibyll::ConvertToSibyll(p);
auto const sib_mass =
(sib_id != corsika::process::sibyll::SibyllCode::Unknown
? to_string(corsika::process::sibyll::GetSibyllMass(p) / 1_GeV)
: "--");
auto const qgs_id = corsika::process::qgsjetII::ConvertToQgsjetII(p);
cout << std::setw(20) << std::setfill(' ') << p << " | " << std::setw(10)
<< static_cast<int>(GetPDG(p)) << " | " << std::setw(10)
<< (sib_id != corsika::process::sibyll::SibyllCode::Unknown
? to_string(static_cast<int>(sib_id))
: "--")
<< " | " << std::setw(10)
<< (qgs_id != corsika::process::qgsjetII::QgsjetIICode::Unknown
? to_string(static_cast<int>(qgs_id))
: "--")
<< " | " << std::setw(18) << std::setprecision(5) << GetMass(p) / 1_GeV
<< " | " << std::setw(18) << std::setprecision(5) << sib_mass << " | " << endl;
}
}
cout << std::setw(104) << std::setfill('-') << "-" << endl;
}
add_custom_command (
OUTPUT ${PROJECT_BINARY_DIR}/Environment/GeneratedMediaProperties.inc
COMMAND ${PROJECT_SOURCE_DIR}/Environment/readProperties.py
${PROJECT_SOURCE_DIR}/Environment/properties8.dat
DEPENDS readProperties.py
properties8.dat
WORKING_DIRECTORY
${PROJECT_BINARY_DIR}/Environment
COMMENT "Read NIST properties8 data file and produce C++ source code GeneratedMediaProperties.inc"
VERBATIM
)
set (
ENVIRONMENT_SOURCES
ShowerAxis.cc
)
set (
ENVIRONMENT_HEADERS
VolumeTreeNode.h
IEmpty.hpp
IMediumModel.h
NuclearComposition.h
HomogeneousMedium.h
InhomogeneousMedium.h
HomogeneousMedium.h
LinearApproximationIntegrator.h
DensityFunction.h
Environment.h
NameModel.h
BaseExponential.h
FlatExponential.h
SlidingPlanarExponential.h
LayeredSphericalAtmosphereBuilder.h
ShowerAxis.h
IMagneticFieldModel.h
UniformMagneticField.h
NoMagneticField.h
IRefractiveIndexModel.h
UniformRefractiveIndex.h
IMediumPropertyModel.h
MediumProperties.h
MediumPropertyModel.h
${PROJECT_BINARY_DIR}/Environment/GeneratedMediaProperties.inc # this one is auto-generated
)
set (
ENVIRONMENT_NAMESPACE
corsika/environment
)
add_library (CORSIKAenvironment STATIC ${ENVIRONMENT_SOURCES})
CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAenvironment ${ENVIRONMENT_NAMESPACE} ${ENVIRONMENT_HEADERS})
set_target_properties (
CORSIKAenvironment
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION 1
PUBLIC_HEADER "${ENVIRONMENT_HEADERS}"
)
# ....................................................
# since GeneratedMediaProperties.inc is an automatically produced file in the build directory,
# create a symbolic link into the source tree, so that it can be found and edited more easily
# this is not needed for the build to succeed! .......
add_custom_command (
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedParticleProperties.inc
COMMAND ${CMAKE_COMMAND} -E create_symlink ${PROJECT_BINARY_DIR}/include/corsika/environment/GeneratedMediaProperties.inc ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedMediaProperties.inc
COMMENT "Generate link in source-dir: ${CMAKE_CURRENT_SOURCE_DIR}/GeneratedMediaProperties.inc"
)
add_custom_target (SourceDirLinkMedia DEPENDS ${PROJECT_BINARY_DIR}/Environment/GeneratedMediaProperties.inc)
add_dependencies (CORSIKAenvironment SourceDirLinkMedia)
# .....................................................
# target dependencies on other libraries (also the header onlys)
target_link_libraries (
CORSIKAenvironment
CORSIKAgeometry
CORSIKAparticles
CORSIKAunits
CORSIKAlogging
)
target_include_directories (
CORSIKAenvironment
PUBLIC
$<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
CORSIKA_ADD_TEST(testEnvironment)
target_link_libraries (
testEnvironment
CORSIKAsetup
CORSIKAenvironment
CORSIKAtesting
)
CORSIKA_ADD_TEST(testShowerAxis)
target_link_libraries (
testShowerAxis
CORSIKAsetup
CORSIKAenvironment
CORSIKAtesting
)
/*
* (c) Copyright 2018 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.
*/
#pragma once
#include <corsika/environment/VolumeTreeNode.h>
#include <corsika/geometry/Point.h>
#include <corsika/geometry/RootCoordinateSystem.h>
#include <corsika/geometry/Sphere.h>
#include <limits>
namespace corsika::environment {
struct Universe : public corsika::geometry::Sphere {
Universe(corsika::geometry::CoordinateSystem const& pCS)
: corsika::geometry::Sphere(
corsika::geometry::Point{pCS, 0 * corsika::units::si::meter,
0 * corsika::units::si::meter,
0 * corsika::units::si::meter},
corsika::units::si::meter * std::numeric_limits<double>::infinity()) {}
bool Contains(corsika::geometry::Point const&) const override { return true; }
};
template <typename IEnvironmentModel>
class Environment {
public:
using BaseNodeType = VolumeTreeNode<IEnvironmentModel>;
Environment()
: fCoordinateSystem{corsika::geometry::RootCoordinateSystem::GetInstance()
.GetRootCoordinateSystem()}
, fUniverse(std::make_unique<BaseNodeType>(
std::make_unique<Universe>(fCoordinateSystem))) {}
auto& GetUniverse() { return fUniverse; }
auto const& GetUniverse() const { return fUniverse; }
auto const& GetCoordinateSystem() const { return fCoordinateSystem; }
// factory method for creation of VolumeTreeNodes
template <class TVolumeType, typename... TVolumeArgs>
static auto CreateNode(TVolumeArgs&&... args) {
static_assert(std::is_base_of_v<corsika::geometry::Volume, TVolumeType>,
"unusable type provided, needs to be derived from "
"\"corsika::geometry::Volume\"");
return std::make_unique<BaseNodeType>(
std::make_unique<TVolumeType>(std::forward<TVolumeArgs>(args)...));
}
private:
corsika::geometry::CoordinateSystem const& fCoordinateSystem;
typename BaseNodeType::VTNUPtr fUniverse;
};
} // namespace corsika::environment
/*
* (c) Copyright 2018 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.
*/
#pragma once
#include <corsika/environment/BaseExponential.h>
#include <corsika/environment/NuclearComposition.h>
#include <corsika/geometry/Line.h>
#include <corsika/geometry/Point.h>
#include <corsika/particles/ParticleProperties.h>
#include <corsika/units/PhysicalUnits.h>
#include <corsika/setup/SetupTrajectory.h>
namespace corsika::environment {
//clang-format off
/**
* flat exponential density distribution with
* \f[
* \varrho(r) = \varrho_0 \exp\left( \frac{1}{\lambda} (r - p) \cdot
* \vec{a} \right).
* \f]
* \f$ \vec{a} \f$ denotes the axis and should be normalized to avoid degeneracy
* with the scale parameter \f$ \lambda \f$.
*/
//clang-format on
template <class T>
class FlatExponential : public BaseExponential<FlatExponential<T>>, public T {
geometry::Vector<units::si::dimensionless_d> const fAxis;
NuclearComposition const fNuclComp;
using Base = BaseExponential<FlatExponential<T>>;
public:
FlatExponential(geometry::Point const& vP0,
geometry::Vector<units::si::dimensionless_d> const& vAxis,
units::si::MassDensityType vRho, units::si::LengthType vLambda,
NuclearComposition vNuclComp)
: Base(vP0, vRho, vLambda)
, fAxis(vAxis)
, fNuclComp(vNuclComp) {}
units::si::MassDensityType GetMassDensity(geometry::Point const& vP) const override {
return Base::fRho0 * exp(Base::fInvLambda * (vP - Base::fP0).dot(fAxis));
}
NuclearComposition const& GetNuclearComposition() const override { return fNuclComp; }
units::si::GrammageType IntegratedGrammage(setup::Trajectory const& vLine,
units::si::LengthType vTo) const override {
return Base::IntegratedGrammage(vLine, vTo, fAxis);
}
units::si::LengthType ArclengthFromGrammage(
setup::Trajectory const& vLine,
units::si::GrammageType vGrammage) const override {
return Base::ArclengthFromGrammage(vLine, vGrammage, fAxis);
}
};
} // namespace corsika::environment
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