OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
OpalPolynomialTimeDependence.cpp
Go to the documentation of this file.
1//
2// Copyright (c) 2026, Paul Scherrer Institute, Villigen PSI, Switzerland
3// All rights reserved
4//
5// This file is part of OPAL.
6//
7// OPAL is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// You should have received a copy of the GNU General License
13// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
14//
15
17#include <string>
20
22 "The \"POLYNOMIAL_TIME_DEPENDENCE\" element defines "
23 "polynomial coefficients for time dependent RF phase, "
24 "frequency, amplitude, etc, given by "
25 "f(t) = P0+P1*t+P2*t^2+P3*t^3 where t is the time in ns";
26
27// Use either P0..P3 or COEFFICIENTS. If COEFFICIENTS are present, P0..P3 are ignored.
29 : OpalElement(static_cast<int>(SIZE), "POLYNOMIAL_TIME_DEPENDENCE", doc_string.c_str()) {
30 itsAttr[P0] = Attributes::makeReal("P0", "Constant term in the polynomial expansion.");
31 itsAttr[P1] =
32 Attributes::makeReal("P1", "First order (linear) term in the polynomial expansion.");
34 "P2", "Second order (quadratic) term in the polynomial expansion.");
35 itsAttr[P3] =
36 Attributes::makeReal("P3", "Third order (cubic) term in the polynomial expansion.");
38 "COEFFICIENTS", "Polynomial coefficients as an array with arbitrary length.");
39
41}
42
46
47void OpalPolynomialTimeDependence::print(std::ostream& out) const { OpalElement::print(out); }
48
52
54 // getOpalName() comes from AbstractObjects/Object.h
55 if (itsAttr[COEFFICIENTS] && (itsAttr[P0] || itsAttr[P1] || itsAttr[P2] || itsAttr[P3])) {
56 // Only use P0..P3 or COEFFICIENTS, not both
57 throw std::invalid_argument(
58 "OpalPolynomialTimeDependence::Update: "
59 "Use P0..P3 or COEFFICIENTS to specify the coefficients, not both.");
60 }
61 std::vector<double> polynomial_coefficients = Attributes::getRealArray(itsAttr[COEFFICIENTS]);
62 if (polynomial_coefficients.empty()) {
63 polynomial_coefficients.push_back(Attributes::getReal(itsAttr[P0]));
64 polynomial_coefficients.push_back(Attributes::getReal(itsAttr[P1]));
65 polynomial_coefficients.push_back(Attributes::getReal(itsAttr[P2]));
66 polynomial_coefficients.push_back(Attributes::getReal(itsAttr[P3]));
67 }
69 getOpalName(), std::make_shared<PolynomialTimeDependence>(polynomial_coefficients));
70}
@ SIZE
Definition IndexMap.cpp:179
static void setTimeDependence(const std::string &name, std::shared_ptr< AbstractTimeDependence > time_dep)
const std::string & getOpalName() const
Return object name.
Definition Object.cpp:267
std::vector< Attribute > itsAttr
The object attributes.
Definition Object.h:210
virtual void print(std::ostream &) const
Print the object.
void registerOwnership() const
OpalPolynomialTimeDependence * clone(const std::string &name) override
void print(std::ostream &) const override
double getReal(const Attribute &attr)
Return real value.
Attribute makeReal(const std::string &name, const std::string &help)
Make real attribute.
Attribute makeRealArray(const std::string &name, const std::string &help)
Create real array attribute.
std::vector< double > getRealArray(const Attribute &attr)
Get array value.