IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 02081138 authored by Nikos Karastathis's avatar Nikos Karastathis :ocean: Committed by Ralf Ulrich
Browse files

specify environments used in unit tests

parent 0283fb7b
No related branches found
No related tags found
1 merge request!418No set up files new
...@@ -18,43 +18,52 @@ ...@@ -18,43 +18,52 @@
#include <limits> #include <limits>
namespace corsika::setup::testing { namespace corsika {
/** using DummyEnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
using DummyEnvironment = Environment<DummyEnvironmentInterface>;
namespace setup::testing {
/**
* \function setup_environment * \function setup_environment
* *
* standard environment for unit testing. * standard environment for unit testing.
* *
*/ */
inline std::tuple<std::unique_ptr<setup::Environment>, CoordinateSystemPtr const*, inline std::tuple<std::unique_ptr<DummyEnvironment>, CoordinateSystemPtr const*,
setup::Environment::BaseNodeType*> DummyEnvironment::BaseNodeType*>
setup_environment(Code const vTargetCode, setup_environment(Code const vTargetCode,
MagneticFluxType const& BfieldZ = MagneticFluxType::zero()) { MagneticFluxType const& BfieldZ = MagneticFluxType::zero()) {
auto env = std::make_unique<setup::Environment>(); auto env = std::make_unique<DummyEnvironment>();
auto& universe = *(env->getUniverse()); auto& universe = *(env->getUniverse());
CoordinateSystemPtr const& cs = env->getCoordinateSystem(); CoordinateSystemPtr const& cs = env->getCoordinateSystem();
/** /**
* our world is a sphere at 0,0,0 with R=infty * our world is a sphere at 0,0,0 with R=infty
*/ */
auto world = setup::Environment::createNode<Sphere>(Point{cs, 0_m, 0_m, 0_m}, 100_km); auto world =
DummyEnvironment::createNode<Sphere>(Point{cs, 0_m, 0_m, 0_m}, 100_km);
/** /**
* construct suited environment medium model: * construct suited environment medium model:
*/ */
using MyHomogeneousModel = MediumPropertyModel< using MyHomogeneousModel = MediumPropertyModel<
UniformMagneticField<HomogeneousMedium<setup::EnvironmentInterface>>>; UniformMagneticField<HomogeneousMedium<DummyEnvironmentInterface>>>;
world->setModelProperties<MyHomogeneousModel>(
Medium::AirDry1Atm, Vector(cs, 0_T, 0_T, BfieldZ), 1_kg / (1_m * 1_m * 1_m),
NuclearComposition(std::vector<Code>{vTargetCode}, std::vector<double>{1.}));
world->setModelProperties<MyHomogeneousModel>( DummyEnvironment::BaseNodeType* nodePtr = world.get();
Medium::AirDry1Atm, Vector(cs, 0_T, 0_T, BfieldZ), 1_kg / (1_m * 1_m * 1_m), universe.addChild(std::move(world));
NuclearComposition(std::vector<Code>{vTargetCode}, std::vector<double>{1.}));
setup::Environment::BaseNodeType* nodePtr = world.get(); return std::make_tuple(std::move(env), &cs, nodePtr);
universe.addChild(std::move(world)); }
return std::make_tuple(std::move(env), &cs, nodePtr); } // namespace setup::testing
}
} // namespace corsika::setup::testing } // namespace corsika
...@@ -11,8 +11,13 @@ ...@@ -11,8 +11,13 @@
#include <corsika/framework/geometry/Point.hpp> #include <corsika/framework/geometry/Point.hpp>
#include <corsika/framework/geometry/RootCoordinateSystem.hpp> #include <corsika/framework/geometry/RootCoordinateSystem.hpp>
#include <corsika/framework/geometry/Vector.hpp> #include <corsika/framework/geometry/Vector.hpp>
#include <corsika/framework/geometry/CoordinateSystem.hpp>
#include <corsika/setup/SetupStack.hpp> #include <corsika/media/UniformMagneticField.hpp>
#include <corsika/media/MediumPropertyModel.hpp>
#include <corsika/media/HomogeneousMedium.hpp>
#include <tests/common/SetupStack.hpp>
#include <SetupStack.hpp>
/** /**
* \file SetupTestStack * \file SetupTestStack
...@@ -20,34 +25,41 @@ ...@@ -20,34 +25,41 @@
* standard stack setup for unit tests. * standard stack setup for unit tests.
*/ */
namespace corsika::setup::testing { namespace corsika {
/** using DummyEnvironmentInterface = IMediumPropertyModel<IMagneticFieldModel<IMediumModel>>;
using DummyEnvironment = Environment<DummyEnvironmentInterface>;
namespace setup::testing {
/**
* \function setup_stack * \function setup_stack
* *
* standard stack setup for unit tests. * standard stack setup for unit tests.
* *
* \return a tuple with element 0 being a Stack object filled with * \return a tuple with element 0 being a Stack object filled with
* one particle, and element 1 the StackView on it. * one particle, and element 1 the StackView on it.
*/ */
inline std::tuple<std::unique_ptr<test::Stack>, std::unique_ptr<test::StackView>>
setup_stack(Code const vProjectileType, HEPEnergyType const vMomentum,
DummyEnvironment::BaseNodeType* const vNodePtr,
CoordinateSystemPtr const& cs) {
inline std::tuple<std::unique_ptr<setup::Stack>, std::unique_ptr<setup::StackView>> auto stack = std::make_unique<test::Stack>();
setup_stack(Code const vProjectileType, HEPEnergyType const vMomentum,
setup::Environment::BaseNodeType* const vNodePtr,
CoordinateSystemPtr const& cs) {
auto stack = std::make_unique<setup::Stack>(); Point const origin(cs, {0_m, 0_m, 0_m});
MomentumVector const pLab(cs, {vMomentum, 0_GeV, 0_GeV});
HEPMassType const mass = get_mass(vProjectileType);
HEPEnergyType const Ekin = sqrt(vMomentum * vMomentum + mass * mass) - mass;
Point const origin(cs, {0_m, 0_m, 0_m}); auto particle = stack->addParticle(
MomentumVector const pLab(cs, {vMomentum, 0_GeV, 0_GeV}); std::make_tuple(vProjectileType, Ekin, pLab.normalized(), origin, 0_ns));
HEPMassType const mass = get_mass(vProjectileType); particle.setNode(vNodePtr);
HEPEnergyType const Ekin = sqrt(vMomentum * vMomentum + mass * mass) - mass; return std::make_tuple(std::move(stack),
std::make_unique<test::StackView>(particle));
}
auto particle = stack->addParticle( } // namespace setup::testing
std::make_tuple(vProjectileType, Ekin, pLab.normalized(), origin, 0_ns));
particle.setNode(vNodePtr);
return std::make_tuple(std::move(stack),
std::make_unique<setup::StackView>(particle));
}
} // namespace corsika::setup::testing } // namespace corsika
\ No newline at end of file
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