IAP GITLAB

Skip to content
Snippets Groups Projects
staticsequence_example.cpp 2.56 KiB
Newer Older
 * (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 <array>
#include <iomanip>
#include <iostream>
#include <corsika/framework/process/ProcessSequence.hpp>
#include <corsika/framework/geometry/Point.hpp>
#include <corsika/framework/geometry/RootCoordinateSystem.hpp>
#include <corsika/framework/geometry/Vector.hpp>
Ralf Ulrich's avatar
Ralf Ulrich committed
using namespace corsika;
using namespace std;

const int nData = 10;
class Process1 : public ContinuousProcess<Process1> {
public:
  Process1() {}
  template <typename D, typename T>
  ProcessReturn doContinuous(D& d, T&, bool const) const {
Ralf Ulrich's avatar
Ralf Ulrich committed
    for (int i = 0; i < nData; ++i) d.p[i] += 1;
    return ProcessReturn::Ok;
class Process2 : public ContinuousProcess<Process2> {
public:
  Process2() {}
  template <typename D, typename T>
  inline ProcessReturn doContinuous(D& d, T&, bool const) const {
Ralf Ulrich's avatar
Ralf Ulrich committed
    for (int i = 0; i < nData; ++i) d.p[i] -= 0.1 * i;
    return ProcessReturn::Ok;
class Process3 : public ContinuousProcess<Process3> {
public:
  Process3() {}
  template <typename D, typename T>
  inline ProcessReturn doContinuous(D&, T&, bool const) const {
    return ProcessReturn::Ok;
class Process4 : public ContinuousProcess<Process4> {
public:
Ralf Ulrich's avatar
Ralf Ulrich committed
  Process4(const double v)
      : fV(v) {}
  template <typename D, typename T>
  inline ProcessReturn doContinuous(D& d, T&, bool const) const {
Ralf Ulrich's avatar
Ralf Ulrich committed
    for (int i = 0; i < nData; ++i) d.p[i] *= fV;
    return ProcessReturn::Ok;
private:
Ralf Ulrich's avatar
Ralf Ulrich committed
  double fV;
struct DummyData {
Ralf Ulrich's avatar
Ralf Ulrich committed
  double p[nData] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
};
struct DummyStack {
  void clear() {}
Ralf Ulrich's avatar
Ralf Ulrich committed
struct DummyTrajectory {};
  //              = 0
  Process1 m1;      // + 1.0
  Process2 m2;      // - (0.1*i)
  Process3 m3;      // * 1.0
  Process4 m4(1.5); // * 1.5
  auto sequence = make_sequence(m1, m2, m3, m4);
Ralf Ulrich's avatar
Ralf Ulrich committed

  DummyData particle;
  DummyTrajectory track;
  double check[nData] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

  const int nEv = 10;
  for (int iEv = 0; iEv < nEv; ++iEv) {
    sequence.doContinuous(particle, track, ContinuousProcessIndex(0));
    for (int i = 0; i < nData; ++i) {
      check[i] += 1. - 0.1 * i;
      check[i] *= 1.5;
    }
  }
Ralf Ulrich's avatar
Ralf Ulrich committed

  for (int i = 0; i < nData; ++i) { assert(particle.p[i] == check[i]); }
Ralf Ulrich's avatar
Ralf Ulrich committed

  cout << " done (checking...) " << endl;
ralfulrich's avatar
ralfulrich committed
  logging::set_level(logging::level::info);

  std::cout << "staticsequence_example" << std::endl;
  modular();
  return 0;
}