OPAL (Object Oriented Parallel Accelerator Library)  2024.1
OPAL
PyEndFieldModel.h
Go to the documentation of this file.
1 #ifndef PYELEMENTS_PYENDFIELDMODEL_H
2 #define PYELEMENTS_PYENDFIELDMODEL_H
3 
6 
7 namespace PyOpal {
8 namespace PyEndFieldModel {
9 
10 std::string functionDocstring =
11 "update the Enge object and then calculate the enge function or derivative\n"
12 "- x [float]: position at which to evaluate the function\n"
13 "- n [int]: derivative to calculate; 0 will return the enge function, 1 will\n"
14 " return the 1st derivative, etc. Note that floating point precision\n"
15 " becomes increasingly limiting for n > 10 or so.\n"
16 "Returns the function value or derivative.\n";
17 
18 template <class C>
19 double function(PyOpalObjectNS::PyOpalObject<C> pyobject, double x, int n) {
20  if (n < 0) {
21  throw OpalException("n must be positive as it indexes the derivative",
22  "PyEndFieldModel::function");
23  }
24  std::shared_ptr<C> objectPtr = pyobject.getOpalShared();
25  objectPtr->update();
26  std::string name = objectPtr->getOpalName();
27  std::shared_ptr<endfieldmodel::EndFieldModel> model = endfieldmodel::EndFieldModel::getEndFieldModel(name);
28  model->setMaximumDerivative(n);
29  double value = model->function(x, n);
30  return value;
31 }
32 
33 }
34 }
35 
36 #endif // PYELEMENTS_PYENDFIELDMODEL_H
The base class for all OPAL exceptions.
Definition: OpalException.h:28
const std::string name
static std::shared_ptr< EndFieldModel > getEndFieldModel(std::string name)