diff --git a/cmake/CorsikaUtilities.cmake b/cmake/CorsikaUtilities.cmake index 919aa819f3b69de30d5f42ac522b0482169a13ec..85e232bdc85762470eb1ceb73b87c00e8e31b21e 100644 --- a/cmake/CorsikaUtilities.cmake +++ b/cmake/CorsikaUtilities.cmake @@ -57,7 +57,7 @@ function (CORSIKA_ADD_TEST) endif () add_executable (${name} ${sources}) - target_link_libraries (${name} CORSIKA8 CONAN_PKG::catch2) + target_link_libraries (${name} CORSIKA8 CONAN_PKG::catch2 CorsikaTestingCommon) target_compile_options (${name} PRIVATE -g) # do not skip asserts target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test_outputs/) diff --git a/corsika/detail/media/NuclearComposition.inl b/corsika/detail/media/NuclearComposition.inl index 4e4985bfa8cf3ec9a72f5d3b2eddbd8bdc076208..4c2d9982f334ace2950814942ac3032b34062edf 100644 --- a/corsika/detail/media/NuclearComposition.inl +++ b/corsika/detail/media/NuclearComposition.inl @@ -22,7 +22,7 @@ namespace corsika { - NuclearComposition::NuclearComposition(std::vector<corsika::Code> const& pComponents, + NuclearComposition::NuclearComposition(std::vector<Code> const& pComponents, std::vector<float> const& pFractions) : numberFractions_(pFractions) , components_(pComponents) @@ -46,7 +46,7 @@ namespace corsika { } template <typename TFunction> - double NuclearComposition::getWeightedSum(TFunction const& func) const { + inline double NuclearComposition::getWeightedSum(TFunction const& func) const { using ResultQuantity = decltype(func(*components_.cbegin())); auto const prod = [&](auto const compID, auto const fraction) { @@ -66,22 +66,23 @@ namespace corsika { } } - size_t NuclearComposition::getSize() const { return numberFractions_.size(); } + inline size_t NuclearComposition::getSize() const { return numberFractions_.size(); } - std::vector<float> const& NuclearComposition::getFractions() const { + inline std::vector<float> const& NuclearComposition::getFractions() const { return numberFractions_; } - std::vector<corsika::Code> const& NuclearComposition::getComponents() const { + inline std::vector<Code> const& NuclearComposition::getComponents() const { return components_; } - double const NuclearComposition::getAverageMassNumber() const { return avgMassNumber_; } + inline double const NuclearComposition::getAverageMassNumber() const { + return avgMassNumber_; + } template <class TRNG> - corsika::Code NuclearComposition::sampleTarget( - std::vector<CrossSectionType> const& sigma, TRNG& randomStream) const { - using namespace units::si; + inline Code NuclearComposition::sampleTarget(std::vector<CrossSectionType> const& sigma, + TRNG& randomStream) const { assert(sigma.size() == numberFractions_.size()); @@ -98,12 +99,12 @@ namespace corsika { // Note: when this class ever modifies its internal data, the hash // must be updated, too! - size_t NuclearComposition::getHash() const { return hash_; } + inline size_t NuclearComposition::getHash() const { return hash_; } - void NuclearComposition::updateHash() { + inline void NuclearComposition::updateHash() { std::vector<std::size_t> hashes; for (float ifrac : this->getFractions()) hashes.push_back(std::hash<float>{}(ifrac)); - for (corsika::Code icode : this->getComponents()) + for (Code icode : this->getComponents()) hashes.push_back(std::hash<int>{}(static_cast<int>(icode))); std::size_t h = std::hash<double>{}(this->getAverageMassNumber()); for (std::size_t ih : hashes) h = h ^ (ih << 1); diff --git a/corsika/detail/media/ShowerAxis.inl b/corsika/detail/media/ShowerAxis.inl index 195d05f9595d08fc63cf7503b3d9785a20e062c2..efb7dc58d304ddeec3656c4d9529831739aec3fe 100644 --- a/corsika/detail/media/ShowerAxis.inl +++ b/corsika/detail/media/ShowerAxis.inl @@ -14,11 +14,11 @@ namespace corsika { template <typename TEnvModel> - ShowerAxis::ShowerAxis(Point const& pStart, corsika::Vector<length_d> const& length, + ShowerAxis::ShowerAxis(Point const& pStart, Vector<length_d> const& length, Environment<TEnvModel> const& env, int steps) : pointStart_(pStart) , length_(length) - , max_length_(length_.norm()) + , max_length_(length_.getNorm()) , steplength_(max_length_ / steps) , axis_normalized_(length / max_length_) , X_(steps + 1) { diff --git a/corsika/detail/media/WeightProvider.inl b/corsika/detail/media/WeightProvider.inl new file mode 100644 index 0000000000000000000000000000000000000000..af9849aa3ca75b9bdaeefc661d56232f1ab895f4 --- /dev/null +++ b/corsika/detail/media/WeightProvider.inl @@ -0,0 +1,48 @@ +/* + * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <vector> + +namespace corsika { + + template <class AConstIterator, class BConstIterator> + WeightProviderIterator<AConstIterator, BConstIterator>::WeightProviderIterator( + AConstIterator a, BConstIterator b) + : aIter_(a) + , bIter_(b) {} + + template <class AConstIterator, class BConstIterator> + typename WeightProviderIterator<AConstIterator, BConstIterator>::value_type + WeightProviderIterator<AConstIterator, BConstIterator>::operator*() const { + return ((*aIter_) * (*bIter_)).magnitude(); + } + + template <class AConstIterator, class BConstIterator> + WeightProviderIterator<AConstIterator, BConstIterator>& + WeightProviderIterator<AConstIterator, + BConstIterator>::operator++() { // prefix ++ + ++aIter_; + ++bIter_; + return *this; + } + + template <class AConstIterator, class BConstIterator> + bool WeightProviderIterator<AConstIterator, BConstIterator>::operator==( + WeightProviderIterator other) { + return aIter_ == other.aIter_; + } + + template <class AConstIterator, class BConstIterator> + bool WeightProviderIterator<AConstIterator, BConstIterator>::operator!=( + WeightProviderIterator other) { + return !(*this == other); + } + +} // namespace corsika \ No newline at end of file diff --git a/corsika/media/NuclearComposition.hpp b/corsika/media/NuclearComposition.hpp index c3d2585f6c9d41f785ee3fa11d665afec2c031aa..b394b463a7552c076720073b2ff8d9cf0f0d95af 100644 --- a/corsika/media/NuclearComposition.hpp +++ b/corsika/media/NuclearComposition.hpp @@ -31,47 +31,47 @@ namespace corsika { * should be 1. Otherwise an exception is thrown * @param pComponents List of particle types * @param pFractions List of fractions how much each particle contributes. The sum - *needs to add up to 1 + * needs to add up to 1 **/ - NuclearComposition(std::vector<corsika::Code> const& pComponents, - std::vector<float> const& pFractions); + inline NuclearComposition(std::vector<Code> const& pComponents, + std::vector<float> const& pFractions); /** Sum all all relative composition weighted by func(element) * This function sums all relative compositions given during this classes *construction. Each entry is weighted by the user defined function func given to this *function. * @tparam TFunction Type of functions for the weights. The type should be - *corsika::Code -> float + * Code -> float * @param func Functions for reweighting specific elements * @retval returns the weighted sum with the type defined by the return type of func **/ template <typename TFunction> - double getWeightedSum(TFunction const& func) const; + inline double getWeightedSum(TFunction const& func) const; /** Number of elements in the composition array * @retval returns the number of elements in the composition array **/ - size_t getSize() const; + inline size_t getSize() const; /// Returns a const reference to the fraction - std::vector<float> const& getFractions() const; + inline std::vector<float> const& getFractions() const; /// Returns a const reference to the fraction - std::vector<corsika::Code> const& getComponents() const; - double const getAverageMassNumber() const; + inline std::vector<Code> const& getComponents() const; + inline double const getAverageMassNumber() const; template <class TRNG> - Code sampleTarget(std::vector<units::si::CrossSectionType> const& sigma, - TRNG& randomStream) const; + inline Code sampleTarget(std::vector<CrossSectionType> const& sigma, + TRNG& randomStream) const; // Note: when this class ever modifies its internal data, the hash // must be updated, too! - size_t getHash() const; + inline size_t getHash() const; private: - void updateHash(); + inline void updateHash(); std::vector<float> const numberFractions_; //!< relative fractions of number density - std::vector<corsika::Code> const components_; //!< particle codes of consitutents + std::vector<Code> const components_; //!< particle codes of consitutents double const avgMassNumber_; diff --git a/corsika/media/ShowerAxis.hpp b/corsika/media/ShowerAxis.hpp index a2fea4cd83cd97eb2a4b67e8fcb90c9a818c09de..a9cc58b086bbaec36743590b9063a5927f8622f5 100644 --- a/corsika/media/ShowerAxis.hpp +++ b/corsika/media/ShowerAxis.hpp @@ -44,7 +44,7 @@ namespace corsika { class ShowerAxis { public: template <typename TEnvModel> - ShowerAxis(Point const& pStart, Vector<length_d> length, + ShowerAxis(Point const& pStart, Vector<length_d> const& length, Environment<TEnvModel> const& env, int steps = 10'000); LengthType getSteplength() const; diff --git a/corsika/media/WeightProvider.hpp b/corsika/media/WeightProvider.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0093e9c5ad908ebdbb6a0055f457a9d425c11adb --- /dev/null +++ b/corsika/media/WeightProvider.hpp @@ -0,0 +1,49 @@ +/* + * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu + * + * This software is distributed under the terms of the GNU General Public + * Licence version 3 (GPL Version 3). See file LICENSE for a full version of + * the license. + */ + +#pragma once + +#include <vector> + +namespace corsika { + + + /** Double Iterator + * Iterator that allowes the iteration of two individual lists at the same time. The + *user needs to take care that booth lists have the same length. + * @tparam AConstIterator Iterator Type of the first list + * @tparam BConstIterator Iterator Type of the second list + + \todo TODO: replace with https://www.boost.org/doc/libs/1_74_0/libs/iterator/doc/zip_iterator.html or ranges zip + \todo check resource allocation + **/ + template <class AConstIterator, class BConstIterator> + class WeightProviderIterator { + AConstIterator aIter_; + BConstIterator bIter_; + + public: + using value_type = double; + using iterator_category = std::input_iterator_tag; + using pointer = value_type*; + using reference = value_type&; + using difference_type = ptrdiff_t; + + WeightProviderIterator(AConstIterator a, BConstIterator b); + + value_type operator*() const; + + WeightProviderIterator& operator++(); + + bool operator==(WeightProviderIterator other); + + bool operator!=(WeightProviderIterator other); + }; +} // namespace corsika + +#include <corsika/detail/media/WeightProvider.inl> diff --git a/corsika/modules/sibyll/Interaction.hpp b/corsika/modules/sibyll/Interaction.hpp index 8f0869e51e47849a644af56248bb734a2243951d..8ce7686a719eb208e3f37eca7563081c46a76543 100644 --- a/corsika/modules/sibyll/Interaction.hpp +++ b/corsika/modules/sibyll/Interaction.hpp @@ -46,7 +46,7 @@ namespace corsika::sibyll { HEPEnergyType GetMinEnergyCoM() const { return minEnergyCoM_; } HEPEnergyType GetMaxEnergyCoM() const { return maxEnergyCoM_; } bool IsValidTarget(corsika::Code TargetId) const { - return corsika::is_nucleus(TargetId) && (corsika::nucleus_A(TargetId) < maxTargetMassNumber_); + return corsika::is_nucleus(TargetId) && (corsika::get_nucleus_A(TargetId) < maxTargetMassNumber_); } std::tuple<CrossSectionType, CrossSectionType> GetCrossSection( diff --git a/corsika/modules/sibyll/SibStack.hpp b/corsika/modules/sibyll/SibStack.hpp index 3c2b1c0d12ddb95b1a4da541e34b1adf53d40588..4cb10cb08d685351c3dfb94160d1e16752710b63 100644 --- a/corsika/modules/sibyll/SibStack.hpp +++ b/corsika/modules/sibyll/SibStack.hpp @@ -23,30 +23,29 @@ namespace corsika::sibyll { class SibStackData { public: - void Dump() const {} + void dump() const {} - void Clear() { s_plist_.np = 0; } - unsigned int GetSize() const { return s_plist_.np; } - unsigned int GetCapacity() const { return 8000; } + void clear() { s_plist_.np = 0; } + unsigned int getSize() const { return s_plist_.np; } + unsigned int getCapacity() const { return 8000; } - void SetId(const unsigned int i, const int v) { s_plist_.llist[i] = v; } - void SetEnergy(const unsigned int i, const HEPEnergyType v) { + void setId(const unsigned int i, const int v) { s_plist_.llist[i] = v; } + void setEnergy(const unsigned int i, const HEPEnergyType v) { s_plist_.p[3][i] = v / 1_GeV; } - void SetMass(const unsigned int i, const HEPMassType v) { + void setMass(const unsigned int i, const HEPMassType v) { s_plist_.p[4][i] = v / 1_GeV; } - void SetMomentum(const unsigned int i, const MomentumVector& v) { - auto tmp = v.GetComponents(); + void setMomentum(const unsigned int i, const MomentumVector& v) { + auto tmp = v.getComponents(); for (int idx = 0; idx < 3; ++idx) s_plist_.p[idx][i] = tmp[idx] / 1_GeV; } - int GetId(const unsigned int i) const { return s_plist_.llist[i]; } - HEPEnergyType GetEnergy(const int i) const { return s_plist_.p[3][i] * 1_GeV; } - HEPEnergyType GetMass(const unsigned int i) const { return s_plist_.p[4][i] * 1_GeV; } - MomentumVector GetMomentum(const unsigned int i) const { - CoordinateSystem& rootCS = - RootCoordinateSystem::getInstance().GetRootCoordinateSystem(); + int getId(const unsigned int i) const { return s_plist_.llist[i]; } + HEPEnergyType getEnergy(const int i) const { return s_plist_.p[3][i] * 1_GeV; } + HEPEnergyType getMass(const unsigned int i) const { return s_plist_.p[4][i] * 1_GeV; } + MomentumVector getMomentum(const unsigned int i) const { + CoordinateSystemPtr& rootCS = get_root_CoordinateSystem(); QuantityVector<hepmomentum_d> components = { s_plist_.p[0][i] * 1_GeV, s_plist_.p[1][i] * 1_GeV, s_plist_.p[2][i] * 1_GeV}; return MomentumVector(rootCS, components); @@ -57,14 +56,14 @@ namespace corsika::sibyll { for (unsigned int i = 0; i < 5; ++i) s_plist_.p[i][i2] = s_plist_.p[i][i1]; } - void Swap(const unsigned int i1, const unsigned int i2) { + void swap(const unsigned int i1, const unsigned int i2) { std::swap(s_plist_.llist[i1], s_plist_.llist[i2]); for (unsigned int i = 0; i < 5; ++i) std::swap(s_plist_.p[i][i1], s_plist_.p[i][i2]); } - void IncrementSize() { s_plist_.np++; } - void DecrementSize() { + void incrementSize() { s_plist_.np++; } + void decrementSize() { if (s_plist_.np > 0) { s_plist_.np--; } } }; @@ -72,49 +71,49 @@ namespace corsika::sibyll { template <typename StackIteratorInterface> class ParticleInterface : public corsika::ParticleBase<StackIteratorInterface> { - using corsika::ParticleBase<StackIteratorInterface>::GetStackData; - using corsika::ParticleBase<StackIteratorInterface>::GetIndex; + using corsika::ParticleBase<StackIteratorInterface>::getStackData; + using corsika::ParticleBase<StackIteratorInterface>::getIndex; public: - void SetParticleData(const int vID, // corsika::sibyll::SibyllCode vID, + void setParticleData(const int vID, // corsika::sibyll::SibyllCode vID, const HEPEnergyType vE, const MomentumVector& vP, const HEPMassType vM) { - SetPID(vID); - SetEnergy(vE); - SetMomentum(vP); - SetMass(vM); + setPID(vID); + setEnergy(vE); + setMomentum(vP); + setMass(vM); } - void SetParticleData(ParticleInterface<StackIteratorInterface>& /*parent*/, + void setParticleData(ParticleInterface<StackIteratorInterface>& /*parent*/, const int vID, // corsika::sibyll::SibyllCode vID, const HEPEnergyType vE, const MomentumVector& vP, const HEPMassType vM) { - SetPID(vID); - SetEnergy(vE); - SetMomentum(vP); - SetMass(vM); + setPID(vID); + setEnergy(vE); + setMomentum(vP); + setMass(vM); } - void SetEnergy(const HEPEnergyType v) { GetStackData().SetEnergy(GetIndex(), v); } + void setEnergy(const HEPEnergyType v) { getStackData().setEnergy(getIndex(), v); } - HEPEnergyType GetEnergy() const { return GetStackData().GetEnergy(GetIndex()); } + HEPEnergyType getEnergy() const { return getStackData().getEnergy(getIndex()); } - bool HasDecayed() const { return abs(GetStackData().GetId(GetIndex())) > 100; } + bool hasDecayed() const { return abs(getStackData().getId(getIndex())) > 100; } - void SetMass(const HEPMassType v) { GetStackData().SetMass(GetIndex(), v); } + void setMass(const HEPMassType v) { getStackData().setMass(getIndex(), v); } - HEPEnergyType GetMass() const { return GetStackData().GetMass(GetIndex()); } + HEPEnergyType getMass() const { return getStackData().getMass(getIndex()); } - void SetPID(const int v) { GetStackData().SetId(GetIndex(), v); } + void setPID(const int v) { getStackData().setId(getIndex(), v); } - corsika::sibyll::SibyllCode GetPID() const { - return static_cast<corsika::sibyll::SibyllCode>(GetStackData().GetId(GetIndex())); + corsika::sibyll::SibyllCode getPID() const { + return static_cast<corsika::sibyll::SibyllCode>(getStackData().getId(getIndex())); } - MomentumVector GetMomentum() const { return GetStackData().GetMomentum(GetIndex()); } + MomentumVector getMomentum() const { return getStackData().getMomentum(getIndex()); } - void SetMomentum(const MomentumVector& v) { - GetStackData().SetMomentum(GetIndex(), v); + void setMomentum(const MomentumVector& v) { + getStackData().setMomentum(getIndex(), v); } }; diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index b8b5bfa2e02bb367910e2e54eff3e734d2c3ea0b..eb3d1be55ccc2031dc28bdfbe76038d992360538 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -1,2 +1,2 @@ -add_library (CorsikaTesting INTERFACE) -target_include_directories (CorsikaTesting INTERFACE ${CMAKE_SOURCE_DIR}/tests/common/) +add_library (CorsikaTestingCommon INTERFACE) +target_include_directories (CorsikaTestingCommon INTERFACE ${CMAKE_SOURCE_DIR}/tests/common/) diff --git a/tests/framework/testClassTimer.cpp b/tests/framework/testClassTimer.cpp index ffbd79429448046f36fecdf1acd3172309a843cf..e82c373d2fe4615c5dc4867158caadad2ffd3e2f 100644 --- a/tests/framework/testClassTimer.cpp +++ b/tests/framework/testClassTimer.cpp @@ -74,7 +74,7 @@ public: class fooT1 { public: template <typename T1, typename T2> - int inside_t(T1 a, T2 b, T2 c) { + int inside_t(T1, T2, T2) { return 123; } }; diff --git a/tests/media/CMakeLists.txt b/tests/media/CMakeLists.txt index ead30414ca61b6912d185c9bc5854a53113c3aa3..e366e73faacfb68c6f4b6c20db0fcb36fcf91ea8 100644 --- a/tests/media/CMakeLists.txt +++ b/tests/media/CMakeLists.txt @@ -7,3 +7,5 @@ set (test_media_sources ) CORSIKA_ADD_TEST (testMedia SOURCES ${test_media_sources}) + +target_link_libraries (testMedia CONAN_PKG::boost) # for math/quadrature/gauss_kronrod.hpp diff --git a/tests/media/testShowerAxis.cpp b/tests/media/testShowerAxis.cpp index cba73d6cc393071659d3458adc1b3f55ea27babe..7e20974b42f360c71541c2ccc26c972c27a3674f 100644 --- a/tests/media/testShowerAxis.cpp +++ b/tests/media/testShowerAxis.cpp @@ -29,18 +29,18 @@ auto setupEnvironment(Code vTargetCode) { // setup environment, geometry auto env = std::make_unique<Environment<IMediumModel>>(); auto& universe = *(env->getUniverse()); - const CoordinateSystem& cs = env->getCoordinateSystem(); + const CoordinateSystemPtr& cs = env->getCoordinateSystem(); auto theMedium = Environment<IMediumModel>::createNode<Sphere>( Point{cs, 0_m, 0_m, 0_m}, 1_km * std::numeric_limits<double>::infinity()); using MyHomogeneousModel = HomogeneousMedium<IMediumModel>; - theMedium->SetModelProperties<MyHomogeneousModel>( + theMedium->setModelProperties<MyHomogeneousModel>( density, NuclearComposition(std::vector<Code>{vTargetCode}, std::vector<float>{1.})); auto const* nodePtr = theMedium.get(); - universe.AddChild(std::move(theMedium)); + universe.addChild(std::move(theMedium)); return std::make_tuple(std::move(env), &cs, nodePtr); }