OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
SplineTimeDependence Class Reference

#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)
 
 SplineTimeDependence ()=default
 
 ~SplineTimeDependence () override=default
 
double getValue (double time) override
 
double getIntegral (double time) override
 
SplineTimeDependenceclone () override
 
Inform & print (Inform &os) const
 
void setSpline (size_t splineOrder, const std::vector< double > &times, const std::vector< double > &values)
 
const std::vector< double > & getTimes () const
 
const std::vector< double > & getValues () const
 
size_t getSplineOrder () const
 

Static Public Member Functions

static std::shared_ptr< AbstractTimeDependencegetTimeDependence (const std::string &name)
 
static void setTimeDependence (const std::string &name, std::shared_ptr< AbstractTimeDependence > time_dep)
 
static std::string getName (const std::shared_ptr< AbstractTimeDependence > &time_dep)
 

Static Public Attributes

static constexpr size_t LinearInterpolation = 1
 
static constexpr size_t CubicInterpolation = 3
 

Private Attributes

std::unique_ptr< AbstractSplinespline_m
 
std::unique_ptr< AbstractSpline::AcceleratorsplineAcc_m
 
size_t splineOrder_m {LinearInterpolation}
 
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 37 of file SplineTimeDependence.h.

Constructor & Destructor Documentation

◆ SplineTimeDependence() [1/2]

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 20 of file SplineTimeDependence.cpp.

References setSpline().

Here is the call graph for this function:

◆ SplineTimeDependence() [2/2]

SplineTimeDependence::SplineTimeDependence ( )
default

Default Constructor makes a dependence of length 2 with values 0

Referenced by clone().

◆ ~SplineTimeDependence()

SplineTimeDependence::~SplineTimeDependence ( )
overridedefault

Destructor cleans up the GSL spline stuff

Member Function Documentation

◆ clone()

SplineTimeDependence * SplineTimeDependence::clone ( )
overridevirtual

Inheritable copy constructor

Returns
new SplineTimeDependence.

Implements AbstractTimeDependence.

Definition at line 26 of file SplineTimeDependence.cpp.

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

Referenced by TEST_F().

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 89 of file SplineTimeDependence.cpp.

References spline_m, splineAcc_m, and times_m.

Referenced by TEST_F(), and TEST_F().

◆ getName()

std::string AbstractTimeDependence::getName ( const 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
GeneralOpalExceptionif time_dep is not recognised

Definition at line 40 of file AbstractTimeDependence.cpp.

References AbstractTimeDependence::td_map.

Referenced by TEST(), and TEST().

◆ getSplineOrder()

size_t SplineTimeDependence::getSplineOrder ( ) const
inline

Definition at line 102 of file SplineTimeDependence.h.

References splineOrder_m.

◆ getTimeDependence()

std::shared_ptr< AbstractTimeDependence > AbstractTimeDependence::getTimeDependence ( const 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
GeneralOpalExceptionif name is not recognised

Definition at line 24 of file AbstractTimeDependence.cpp.

References AbstractTimeDependence::td_map.

Referenced by MultipoleT::initialiseTimeDependencies(), VariableRFCavity::initialiseTimeDependencies(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ getTimes()

const std::vector< double > & SplineTimeDependence::getTimes ( ) const
inline

Definition at line 100 of file SplineTimeDependence.h.

References times_m.

◆ 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 78 of file SplineTimeDependence.cpp.

References spline_m, splineAcc_m, and times_m.

Referenced by TEST_F(), TEST_F(), and TEST_F().

◆ getValues()

const std::vector< double > & SplineTimeDependence::getValues ( ) const
inline

Definition at line 101 of file SplineTimeDependence.h.

References values_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 32 of file SplineTimeDependence.cpp.

References spline_m, splineOrder_m, and times_m.

Referenced by operator<<().

◆ 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
timesa list of times in seconds
valuesa list of values corresponding to the times

Definition at line 42 of file SplineTimeDependence.cpp.

References CubicInterpolation, LinearInterpolation, spline_m, splineAcc_m, splineOrder_m, times_m, and values_m.

Referenced by SplineTimeDependence().

◆ setTimeDependence()

void AbstractTimeDependence::setTimeDependence ( const 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 35 of file AbstractTimeDependence.cpp.

References AbstractTimeDependence::td_map.

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

Member Data Documentation

◆ CubicInterpolation

constexpr size_t SplineTimeDependence::CubicInterpolation = 3
staticconstexpr

Definition at line 106 of file SplineTimeDependence.h.

Referenced by setSpline(), and OpalSplineTimeDependence::update().

◆ LinearInterpolation

constexpr size_t SplineTimeDependence::LinearInterpolation = 1
staticconstexpr

Definition at line 105 of file SplineTimeDependence.h.

Referenced by setSpline(), and OpalSplineTimeDependence::update().

◆ spline_m

std::unique_ptr<AbstractSpline> SplineTimeDependence::spline_m
private

Definition at line 109 of file SplineTimeDependence.h.

Referenced by getIntegral(), getValue(), print(), and setSpline().

◆ splineAcc_m

std::unique_ptr<AbstractSpline::Accelerator> SplineTimeDependence::splineAcc_m
private

Definition at line 110 of file SplineTimeDependence.h.

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

◆ splineOrder_m

size_t SplineTimeDependence::splineOrder_m {LinearInterpolation}
private

Definition at line 111 of file SplineTimeDependence.h.

Referenced by clone(), getSplineOrder(), print(), and setSpline().

◆ 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 87 of file AbstractTimeDependence.h.

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

◆ times_m

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

Definition at line 112 of file SplineTimeDependence.h.

Referenced by clone(), getIntegral(), getTimes(), getValue(), print(), and setSpline().

◆ values_m

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

Definition at line 113 of file SplineTimeDependence.h.

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


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