OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Stepper.h
Go to the documentation of this file.
1 //
2 // Class Stepper
3 // Time integrator base class
4 //
5 // Copyright (c) 2017, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
6 // All rights reserved
7 //
8 // This file is part of OPAL.
9 //
10 // OPAL is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
17 //
18 #ifndef STEPPER_H
19 #define STEPPER_H
20 
22 #include "Algorithms/Vektor.h"
23 
24 #include <functional>
25 
35 template <typename FieldFunction, typename ... Arguments>
36 class Stepper {
37 
38 public:
39 
40  Stepper(const FieldFunction& fieldfunc) : fieldfunc_m(fieldfunc) { }
41 
42  virtual bool advance(PartBunchBase<double, 3>* bunch,
43  const size_t& i,
44  const double& t,
45  const double dt,
46  Arguments& ... args) const
47  {
48  bool isGood = doAdvance_m(bunch, i, t, dt, args...);
49 
50  bool isNaN = false;
51  for (int j = 0; j < 3; ++j) {
52  if (std::isnan(bunch->R[i](j)) ||
53  std::isnan(bunch->P[i](j)) ||
54  std::abs(bunch->R[i](j)) > 1.0e10 ||
55  std::abs(bunch->P[i](j)) > 1.0e10) {
56  isNaN = true;
57  break;
58  }
59  }
60 
61  bool isBad = (!isGood || isNaN);
62  if ( isBad ) {
63  bunch->Bin[i] = -1;
64  }
65  return isBad;
66  };
67  virtual ~Stepper() {};
68 
69 protected:
70  const FieldFunction& fieldfunc_m;
71 
72 private:
74  const size_t& i,
75  const double& t,
76  const double dt,
77  Arguments& ... args) const = 0;
78 };
79 
80 #endif
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
T isnan(T x)
isnan function with adjusted return type
Definition: matheval.hpp:66
ParticlePos_t & R
ParticleAttrib< int > Bin
ParticleAttrib< Vector_t > P
virtual bool doAdvance_m(PartBunchBase< double, 3 > *bunch, const size_t &i, const double &t, const double dt, Arguments &... args) const =0
Stepper(const FieldFunction &fieldfunc)
Definition: Stepper.h:40
const FieldFunction & fieldfunc_m
Definition: Stepper.h:67
virtual bool advance(PartBunchBase< double, 3 > *bunch, const size_t &i, const double &t, const double dt, Arguments &... args) const
Definition: Stepper.h:42
virtual ~Stepper()
Definition: Stepper.h:67