OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
OpalSplineTimeDependence.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>
21
23 "The \"SPLINE_TIME_DEPENDENCE\" element defines "
24 "an array of times and corresponding values for time lookup, "
25 "for use in time-dependent elements. Lookup is supported at "
26 "first order or third order with quadratic smoothing.";
27
28// I investigated using a StringArray or RealArray here;
29// Don't seem to have capacity to handle variables, so for now not implemented
31 : OpalElement(static_cast<int>(SIZE), "SPLINE_TIME_DEPENDENCE", doc_string.c_str()) {
33 "ORDER",
34 "Order of the lookup - either 1 for linear interpolation, "
35 "or 3 for cubic interpolation with quadratic smoothing. "
36 "Other values make an error.",
37 1);
38
40 "TIMES",
41 "Array of real times in ns. There must be at least \"ORDER\"+1 "
42 "elements in the array and they must be strictly monotically "
43 "increasing");
44
46 "VALUES",
47 "Array of real values. The length of \"VALUES\" must be the "
48 "same as the length of \"TIMES\".");
49
51}
52
54 return new OpalSplineTimeDependence(name, this);
55}
56
57void OpalSplineTimeDependence::print(std::ostream& out) const { OpalElement::print(out); }
58
60 const std::string& name, OpalSplineTimeDependence* parent)
61 : OpalElement(name, parent) {}
62
64 const double order = Attributes::getReal(itsAttr[ORDER]);
67 throw OpalException(
68 "OpalSplineTimeDependence::update",
69 "SPLINE_TIME_DEPENDENCE \"ORDER\" should be 1 or 3.");
70 }
71 // Note we set array defaults as it seems that the default object must be valid
72 std::vector<double> times;
73 if (itsAttr[TIMES]) {
75 } else {
76 times = {0.0, 1.0}; // A default time array
77 }
78 std::vector<double> values;
79 if (itsAttr[VALUES]) {
81 } else {
82 values = {0.0, 0.0}; // A default value array
83 }
84 const auto spline =
85 std::make_shared<SplineTimeDependence>(static_cast<size_t>(order), times, values);
87}
@ 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
static const std::string doc_string
OpalSplineTimeDependence * clone(const std::string &name) override
void print(std::ostream &) const override
static constexpr size_t CubicInterpolation
static constexpr size_t LinearInterpolation
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.