IAP GITLAB

Skip to content
Snippets Groups Projects
Commit ae630696 authored by ralfulrich's avatar ralfulrich
Browse files

clang does not like mixture of class/struct

parent 07010aff
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ endif () ...@@ -39,7 +39,7 @@ endif ()
set (CORSIKA8_CMAKE_DIR "${PROJECT_SOURCE_DIR}/cmake") set (CORSIKA8_CMAKE_DIR "${PROJECT_SOURCE_DIR}/cmake")
set (CMAKE_MODULE_PATH "${CORSIKA8_CMAKE_DIR}" ${CMAKE_MODULE_PATH}) set (CMAKE_MODULE_PATH "${CORSIKA8_CMAKE_DIR}" ${CMAKE_MODULE_PATH})
include (CorsikaUtilities) # extra cmake function include (CorsikaUtilities) # extra cmake function
set (CMAKE_VERBOSE_MAKEFILE OFF) # this can be done with `make VERBOSE=1` set (CMAKE_VERBOSE_MAKEFILE ON) # this can be done with `make VERBOSE=1`
# ignore many irrelevant Up-to-date messages during install # ignore many irrelevant Up-to-date messages during install
set (CMAKE_INSTALL_MESSAGE LAZY) set (CMAKE_INSTALL_MESSAGE LAZY)
......
...@@ -13,8 +13,6 @@ ...@@ -13,8 +13,6 @@
namespace corsika { namespace corsika {
/** /**
@class ParticleBase
The base class to define the readout of particle properties from a The base class to define the readout of particle properties from a
particle stack. Every stack must implement this readout via the particle stack. Every stack must implement this readout via the
ParticleBase class. ParticleBase class.
...@@ -41,7 +39,7 @@ namespace corsika { ...@@ -41,7 +39,7 @@ namespace corsika {
*/ */
template <typename StackIterator> template <typename StackIterator>
struct ParticleBase { class ParticleBase {
public: public:
typedef StackIterator stack_iterator_type; typedef StackIterator stack_iterator_type;
......
...@@ -27,7 +27,7 @@ namespace corsika { ...@@ -27,7 +27,7 @@ namespace corsika {
*/ */
template <typename StackIteratorInterface> template <typename StackIteratorInterface>
struct ParticleInterface : public ParticleBase<StackIteratorInterface> { class ParticleInterface : public ParticleBase<StackIteratorInterface> {
private: private:
typedef ParticleBase<StackIteratorInterface> super_type; typedef ParticleBase<StackIteratorInterface> super_type;
......
...@@ -3,14 +3,13 @@ set (test_framework_sources ...@@ -3,14 +3,13 @@ set (test_framework_sources
TestMain.cpp TestMain.cpp
testFourVector.cpp testFourVector.cpp
testSaveBoostHistogram.cpp testSaveBoostHistogram.cpp
# testSwitchProcessSequence.cpp this does only test the SwitchProcess -> removed
testClassTimer.cpp testClassTimer.cpp
testLogging.cpp testLogging.cpp
testParticles.cpp testParticles.cpp
testStackInterface.cpp testStackInterface.cpp
testProcessSequence.cpp testProcessSequence.cpp
testCOMBoost.cpp testCOMBoost.cpp
#testCorsikaFenv.cpp # does not work because of use of exceptions in catch2 # testCorsikaFenv.cpp # does not work because of use of exceptions in catch2
testFunctionTimer.cpp testFunctionTimer.cpp
testSecondaryView.cpp testSecondaryView.cpp
testGeometry.cpp testGeometry.cpp
......
...@@ -37,8 +37,9 @@ using TestCascadeStack = corsika::CombinedStack< ...@@ -37,8 +37,9 @@ using TestCascadeStack = corsika::CombinedStack<
See also Issue 161 See also Issue 161
*/ */
#if defined(__clang__) #if defined(__clang__)
using TestCascadeStackView = corsika::SecondaryView<typename TestCascadeStack::StackImpl, using TestCascadeStackView =
StackWithGeometryInterface>; corsika::SecondaryView<typename TestCascadeStack::stack_implementation_type,
StackWithGeometryInterface>;
#elif defined(__GNUC__) || defined(__GNUG__) #elif defined(__GNUC__) || defined(__GNUG__)
using TestCascadeStackView = corsika::MakeView<TestCascadeStack>::type; using TestCascadeStackView = corsika::MakeView<TestCascadeStack>::type;
#endif #endif
/*
* (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/process/switch_process/SwitchProcess.h>
#include <corsika/stack/SecondaryView.h>
#include <corsika/stack/Stack.h>
#include <corsika/units/PhysicalUnits.h>
#include <catch2/catch.hpp>
#include <algorithm>
#include <random>
using namespace corsika;
using namespace corsika::process;
using namespace corsika::units::si;
class TestStackData {
public:
// these functions are needed for the Stack interface
void Clear() { fData.clear(); }
unsigned int GetSize() const { return fData.size(); }
unsigned int GetCapacity() const { return fData.size(); }
void Copy(int i1, int i2) { fData[i2] = fData[i1]; }
void Swap(int i1, int i2) { std::swap(fData[i1], fData[i2]); }
// custom data access function
void SetData(unsigned int i, HEPEnergyType v) { fData[i] = v; }
HEPEnergyType GetData(const unsigned int i) const { return fData[i]; }
// these functions are also needed by the Stack interface
void IncrementSize() { fData.resize(fData.size() + 1); }
void DecrementSize() {
if (fData.size() > 0) { fData.pop_back(); }
}
// custom private data section
private:
std::vector<HEPEnergyType> fData;
};
/**
* From static_cast of a StackIterator over entries in the
* TestStackData class you get and object of type
* TestParticleInterface defined here
*
* It provides Get/Set methods to read and write data to the "Data"
* storage of TestStackData obtained via
* "StackIteratorInterface::GetStackData()", given the index of the
* iterator "StackIteratorInterface::GetIndex()"
*
*/
template <typename StackIteratorInterface>
class TestParticleInterface
: public corsika::stack::ParticleBase<StackIteratorInterface> {
public:
using corsika::stack::ParticleBase<StackIteratorInterface>::GetStackData;
using corsika::stack::ParticleBase<StackIteratorInterface>::GetIndex;
/*
The SetParticleData methods are called for creating new entries
on the stack. You can specifiy various parametric versions to
perform this task:
*/
// default version for particle-creation from input data
void SetParticleData(const std::tuple<HEPEnergyType> v) { SetEnergy(std::get<0>(v)); }
void SetParticleData(TestParticleInterface<StackIteratorInterface>& /*parent*/,
std::tuple<HEPEnergyType> v) {
SetEnergy(std::get<0>(v));
}
// here are the fundamental methods for access to TestStackData data
void SetEnergy(HEPEnergyType v) { GetStackData().SetData(GetIndex(), v); }
HEPEnergyType GetEnergy() const { return GetStackData().GetData(GetIndex()); }
};
using SimpleStack = corsika::stack::Stack<TestStackData, TestParticleInterface>;
// see issue 161
#if defined(__clang__)
using StackTestView = corsika::stack::SecondaryView<TestStackData, TestParticleInterface>;
#elif defined(__GNUC__) || defined(__GNUG__)
using StackTestView = corsika::stack::MakeView<SimpleStack>::type;
#endif
auto constexpr kgMSq = 1_kg / (1_m * 1_m);
template <int N>
struct DummyProcess : InteractionProcess<DummyProcess<N>> {
template <typename TParticle>
corsika::units::si::GrammageType GetInteractionLength(TParticle const&) const {
return N * kgMSq;
}
template <typename TSecondaries>
corsika::process::EProcessReturn DoInteraction(TSecondaries& vSec) {
// to figure out which process was selected in the end, we produce N
// secondaries for DummyProcess<N>
for (int i = 0; i < N; ++i) {
vSec.AddSecondary(std::tuple<HEPEnergyType>{vSec.GetEnergy() / N});
}
return EProcessReturn::eOk;
}
};
using DummyLowEnergyProcess = DummyProcess<1>;
using DummyHighEnergyProcess = DummyProcess<2>;
using DummyAdditionalProcess = DummyProcess<3>;
TEST_CASE("SwitchProcess from InteractionProcess") {
DummyLowEnergyProcess low;
DummyHighEnergyProcess high;
DummyAdditionalProcess proc;
switch_process::SwitchProcess switchProcess(low, high, 1_TeV);
auto seq = switchProcess << proc;
SimpleStack stack;
SECTION("low energy") {
stack.AddParticle(std::tuple<HEPEnergyType>{0.5_TeV});
auto p = stack.GetNextParticle();
// low energy process returns 1 kg/m²
SECTION("interaction length") {
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(1));
CHECK(seq.GetInteractionLength(p) / kgMSq == Approx(3. / 4));
}
}
SECTION("high energy") {
stack.AddParticle(std::tuple<HEPEnergyType>{4_TeV});
auto p = stack.GetNextParticle();
// high energy process returns 2 kg/m²
SECTION("interaction length") {
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(2));
CHECK(seq.GetInteractionLength(p) / kgMSq == Approx(6. / 5));
}
// high energy process creates 2 secondaries
SECTION("SelectInteraction") {
typename SimpleStack::ParticleType theParticle =
stack.GetNextParticle(); // as in corsika::Cascade
StackTestView view(theParticle);
auto projectile = view.GetProjectile();
InverseGrammageType invLambda = 0 / kgMSq;
switchProcess.SelectInteraction(p, projectile, 0.01 / kgMSq, invLambda);
CHECK(view.getSize() == 2);
}
}
}
TEST_CASE("SwitchProcess from ProcessSequence") {
DummyProcess<1> innerA;
DummyProcess<2> innerB;
DummyProcess<3> outer;
DummyProcess<4> additional;
auto seq = innerA << innerB;
switch_process::SwitchProcess switchProcess(seq, outer, 1_TeV);
auto completeSeq = switchProcess << additional;
SimpleStack stack;
SECTION("low energy") {
stack.AddParticle(std::tuple<HEPEnergyType>{0.5_TeV});
auto p = stack.GetNextParticle();
SECTION("interaction length") {
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(2. / 3));
CHECK(completeSeq.GetInteractionLength(p) / kgMSq == Approx(4. / 7));
}
SECTION("SelectInteraction") {
std::vector<int> numberOfSecondaries;
for (int i = 0; i < 1000; ++i) {
typename SimpleStack::ParticleType theParticle =
stack.GetNextParticle(); // as in corsika::Cascade
StackTestView view(theParticle);
auto projectile = view.GetProjectile();
double r = i / 1000.;
InverseGrammageType invLambda = r * 7. / 4 / kgMSq;
InverseGrammageType accumulator = 0 / kgMSq;
completeSeq.SelectInteraction(p, projectile, invLambda, accumulator);
numberOfSecondaries.push_back(view.getSize());
}
auto const mean =
std::accumulate(numberOfSecondaries.cbegin(), numberOfSecondaries.cend(), 0.) /
numberOfSecondaries.size();
CHECK(mean == Approx(12. / 7.).margin(0.01));
}
}
SECTION("high energy") {
stack.AddParticle(std::tuple<HEPEnergyType>{3.0_TeV});
auto p = stack.GetNextParticle();
SECTION("interaction length") {
CHECK(switchProcess.GetInteractionLength(p) / kgMSq == Approx(3));
CHECK(completeSeq.GetInteractionLength(p) / kgMSq == Approx(12. / 7.));
}
SECTION("SelectInteraction") {
std::vector<int> numberOfSecondaries;
for (int i = 0; i < 1000; ++i) {
typename SimpleStack::ParticleType theParticle =
stack.GetNextParticle(); // as in corsika::Cascade
StackTestView view(theParticle);
auto projectile = view.GetProjectile();
double r = i / 1000.;
InverseGrammageType invLambda = r * 7. / 12. / kgMSq;
InverseGrammageType accumulator = 0 / kgMSq;
completeSeq.SelectInteraction(p, projectile, invLambda, accumulator);
numberOfSecondaries.push_back(view.getSize());
}
auto const mean =
std::accumulate(numberOfSecondaries.cbegin(), numberOfSecondaries.cend(), 0.) /
numberOfSecondaries.size();
CHECK(mean == Approx(24. / 7.).margin(0.01));
}
}
}
...@@ -48,8 +48,8 @@ using TestStack = ...@@ -48,8 +48,8 @@ using TestStack =
*/ */
#if defined(__clang__) #if defined(__clang__)
using TheTestStackView = using TheTestStackView =
SecondaryView<typename TestStack::StackImpl, StackWithHistoryInterface, SecondaryView<typename TestStack::stack_implementation_type,
history::HistorySecondaryProducer>; StackWithHistoryInterface, history::HistorySecondaryProducer>;
#elif defined(__GNUC__) || defined(__GNUG__) #elif defined(__GNUC__) || defined(__GNUG__)
using TheTestStackView = MakeView<TestStack, history::HistorySecondaryProducer>::type; using TheTestStackView = MakeView<TestStack, history::HistorySecondaryProducer>::type;
#endif #endif
......
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