OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
SplineTimeDependence Class Reference

Time dependence that follows a spline. More...

#include <SplineTimeDependence.h>

Inheritance diagram for SplineTimeDependence:
Inheritance graph
Collaboration diagram for SplineTimeDependence:
Collaboration graph

Public Member Functions

 SplineTimeDependence (size_t splineOrder, const std::vector< double > &times, const std::vector< double > &values)
 Constructor. More...
 
 SplineTimeDependence (const SplineTimeDependence &rhs)
 Copy Constructor. More...
 
 SplineTimeDependence ()=default
 Default Constructor makes a dependence of length 2 with values 0. More...
 
 ~SplineTimeDependence () override
 Destructor cleans up the GSL spline stuff. More...
 
double getValue (double time) override
 Return the value of the spline at a given time. More...
 
double getIntegral (double time) override
 Return the integral of the spline from 0 to the given time. More...
 
SplineTimeDependenceclone () override
 Inheritable copy constructor. More...
 
Informprint (Inform &os) const
 Print summary information about the time dependence. More...
 
void setSpline (size_t splineOrder, const std::vector< double > &times, const std::vector< double > &values)
 Set the spline, deleting any existing spline data. More...
 

Static Public Member Functions

static std::shared_ptr< AbstractTimeDependencegetTimeDependence (std::string name)
 Look up the time dependence that has a given name. More...
 
static void setTimeDependence (std::string name, std::shared_ptr< AbstractTimeDependence > time_dep)
 Add a value to the lookup table. More...
 
static std::string getName (std::shared_ptr< AbstractTimeDependence > time_dep)
 Get the name corresponding to a given time_dep. More...
 

Private Attributes

gsl_spline * spline_m {}
 
gsl_interp_accel * acc_m {}
 
size_t splineOrder_m {1}
 
std::vector< double > times_m
 
std::vector< double > values_m
 

Static Private Attributes

static std::map< std::string, std::shared_ptr< AbstractTimeDependence > > td_map
 

Detailed Description

Time dependence that follows a spline.

Interpolation is supported at linear or cubic order..

Interpolation is done using gsl_spline routines (1st or 3rd order).

Nb: I tried to use PolynomialPatch, as it is arbitrary order interpolation, but it turns out that only works for regular grids.

Definition at line 50 of file SplineTimeDependence.h.

Constructor & Destructor Documentation

◆ SplineTimeDependence() [1/3]

SplineTimeDependence::SplineTimeDependence ( size_t  splineOrder,
const std::vector< double > &  times,
const std::vector< double > &  values 
)

Constructor.

Parameters
splineOrderthe order of the spline used to fit the time dependence; either 1 (linear interpolation) or 3 (cubic spline with quadratic smoothing)
timesthe times of successive elements in the time dependence
valuesthe values at each time step.

It is an error if times and values are not of equal length, times and values length < splineOrder + 1, or times do not increase strictly monotonically.

Definition at line 33 of file SplineTimeDependence.cpp.

References setSpline(), and Expressions::times.

Here is the call graph for this function:

◆ SplineTimeDependence() [2/3]

SplineTimeDependence::SplineTimeDependence ( const SplineTimeDependence rhs)

Copy Constructor.

Definition at line 38 of file SplineTimeDependence.cpp.

References setSpline(), splineOrder_m, times_m, and values_m.

Here is the call graph for this function:

◆ SplineTimeDependence() [3/3]

SplineTimeDependence::SplineTimeDependence ( )
default

Default Constructor makes a dependence of length 2 with values 0.

Referenced by clone().

◆ ~SplineTimeDependence()

SplineTimeDependence::~SplineTimeDependence ( )
override

Destructor cleans up the GSL spline stuff.

Definition at line 42 of file SplineTimeDependence.cpp.

References acc_m, and spline_m.

Member Function Documentation

◆ clone()

SplineTimeDependence * SplineTimeDependence::clone ( )
overridevirtual

Inheritable copy constructor.

Returns
new SplineTimeDependence.

Implements AbstractTimeDependence.

Definition at line 51 of file SplineTimeDependence.cpp.

References splineOrder_m, SplineTimeDependence(), times_m, and values_m.

Here is the call graph for this function:

◆ getIntegral()

double SplineTimeDependence::getIntegral ( double  time)
overridevirtual

Return the integral of the spline from 0 to the given time.

Parameters
timetime at which the spline is referenced.

Implements AbstractTimeDependence.

Definition at line 120 of file SplineTimeDependence.cpp.

References acc_m, spline_m, and times_m.

◆ getName()

std::string AbstractTimeDependence::getName ( std::shared_ptr< AbstractTimeDependence time_dep)
staticinherited

Get the name corresponding to a given time_dep.

Parameters
time_deptime dependence to lookup
Returns
name corresponding to the time dependence. Note that this just does a dumb loop over the stored map values; so O(N).
Exceptions
GeneralClassicExceptionif time_dep is not recognised

Definition at line 50 of file AbstractTimeDependence.cpp.

References AbstractTimeDependence::td_map.

◆ getTimeDependence()

std::shared_ptr< AbstractTimeDependence > AbstractTimeDependence::getTimeDependence ( std::string  name)
staticinherited

Look up the time dependence that has a given name.

Parameters
namename of the time dependence
Returns
shared_ptr to the appropriate time dependence.
Exceptions
GeneralClassicExceptionif name is not recognised

Definition at line 36 of file AbstractTimeDependence.cpp.

References name, and AbstractTimeDependence::td_map.

Referenced by PyOpal::PyAbstractTimeDependence::function(), VariableRFCavity::initialise(), MultipoleT::initialiseTimeDepencencies(), and ParallelCyclotronTracker::visitRFCavity().

◆ getValue()

double SplineTimeDependence::getValue ( double  time)
overridevirtual

Return the value of the spline at a given time.

Parameters
timetime at which the spline is referenced. If time is off either end of the spline, the last few values are used to extrapolate past the end of the spline.

Implements AbstractTimeDependence.

Definition at line 110 of file SplineTimeDependence.cpp.

References acc_m, spline_m, and times_m.

◆ print()

Inform & SplineTimeDependence::print ( Inform os) const

Print summary information about the time dependence.

Parameters
os"Inform" stream to which the information is printed.

Definition at line 57 of file SplineTimeDependence.cpp.

References endl(), spline_m, splineOrder_m, and times_m.

Referenced by operator<<().

Here is the call graph for this function:

◆ setSpline()

void SplineTimeDependence::setSpline ( size_t  splineOrder,
const std::vector< double > &  times,
const std::vector< double > &  values 
)

Set the spline, deleting any existing spline data.

Parameters
splineOrder1 for linear, 3 for cubic, all other values invalid
timesthe times of successive elements in the time dependence
valuesthe values at each time step.

Definition at line 67 of file SplineTimeDependence.cpp.

References acc_m, spline_m, Expressions::times, times_m, and values_m.

Referenced by SplineTimeDependence().

◆ setTimeDependence()

void AbstractTimeDependence::setTimeDependence ( std::string  name,
std::shared_ptr< AbstractTimeDependence time_dep 
)
staticinherited

Add a value to the lookup table.

Parameters
namename of the time dependence. If name already exists in the map, it is overwritten with the new value.
time_depshared_ptr to the time dependence.

Definition at line 45 of file AbstractTimeDependence.cpp.

References name, and AbstractTimeDependence::td_map.

Referenced by OpalPolynomialTimeDependence::update(), OpalSinusoidalTimeDependence::update(), and OpalSplineTimeDependence::update().

Member Data Documentation

◆ acc_m

gsl_interp_accel* SplineTimeDependence::acc_m {}
private

Definition at line 113 of file SplineTimeDependence.h.

Referenced by getIntegral(), getValue(), setSpline(), and ~SplineTimeDependence().

◆ spline_m

gsl_spline* SplineTimeDependence::spline_m {}
private

◆ splineOrder_m

size_t SplineTimeDependence::splineOrder_m {1}
private

Definition at line 114 of file SplineTimeDependence.h.

Referenced by clone(), print(), and SplineTimeDependence().

◆ td_map

std::map< std::string, std::shared_ptr< AbstractTimeDependence > > AbstractTimeDependence::td_map
staticprivateinherited
Initial value:
=
std::map<std::string, std::shared_ptr<AbstractTimeDependence> >()

Definition at line 100 of file AbstractTimeDependence.h.

Referenced by AbstractTimeDependence::getName(), AbstractTimeDependence::getTimeDependence(), and AbstractTimeDependence::setTimeDependence().

◆ times_m

std::vector<double> SplineTimeDependence::times_m
private

◆ values_m

std::vector<double> SplineTimeDependence::values_m
private

Definition at line 116 of file SplineTimeDependence.h.

Referenced by clone(), setSpline(), and SplineTimeDependence().


The documentation for this class was generated from the following files: