OPALX (Object Oriented Parallel Accelerator Library for Exascale) MINIorX
OPALX
endfieldmodel::Tanh Class Reference

Calculate the Tanh function (e.g. More...

#include <Tanh.h>

Inheritance diagram for endfieldmodel::Tanh:
Inheritance graph
Collaboration diagram for endfieldmodel::Tanh:
Collaboration graph

Public Member Functions

 Tanh (double x0, double lambda, int max_index)
 Create a double tanh function. More...
 
 Tanh ()
 Default constructor (initialises x0 and lambda to 0) More...
 
 Tanh (const Tanh &rhs)
 Copy constructor. More...
 
 ~Tanh ()
 Destructor (no mallocs so does nothing) More...
 
Tanhclone () const
 Inherited copy constructor. More...
 
void rescale (double scaleFactor)
 Rescale the end field by a factor x0. More...
 
double function (double x, int n) const
 Double Tanh is given by
\(d(x) = \). More...
 
double getCentreLength () const
 Nominal flat top length is twice x0 (one x0 in each direction) More...
 
double getEndLength () const
 Return nominal fringe field length. More...
 
double getTanh (double x, int n) const
 Returns the value of tanh((x+x0)/lambda) or its \(n^{th}\) derivative. More...
 
double getNegTanh (double x, int n) const
 Returns the value of tanh((x-x0)/lambda) or its \(n^{th}\) derivative. More...
 
double getLambda () const
 Return lambda (end length) More...
 
double getX0 () const
 Return x0 (flat top length) More...
 
void setLambda (double lambda)
 Set lambda (end length) More...
 
void setX0 (double x0)
 Set x0 (flat top length) More...
 
virtual void setMaximumDerivative (size_t n)
 Set the maximum derivative prior to tracking. More...
 
std::ostream & print (std::ostream &out) const
 Prints a human readable string to out. More...
 

Static Public Member Functions

static std::vector< std::vector< int > > getTanhDiffIndices (size_t n)
 Get all the tanh differential indices \(I_{pq}\). More...
 
static void setTanhDiffIndices (size_t n)
 Set the value of tanh differential indices to nth order differentials. More...
 
static std::shared_ptr< EndFieldModelgetEndFieldModel (std::string name)
 Look up the EndFieldModel that has a given name. More...
 
static void setEndFieldModel (std::string name, std::shared_ptr< EndFieldModel > efm)
 Add a value to the lookup table. More...
 
static std::string getName (std::shared_ptr< EndFieldModel > efm)
 Get the name corresponding to a given EndFieldModel. More...
 

Private Attributes

double _x0
 
double _lambda
 

Static Private Attributes

static std::vector< std::vector< std::vector< int > > > _tdi
 _tdi indexes powers of tanh in d^n tanh/dx^n as sum of powers of tanh More...
 
static std::map< std::string, std::shared_ptr< EndFieldModel > > efm_map
 

Detailed Description

Calculate the Tanh function (e.g.

for multipole end fields).

DoubleTanh function is given by
\(T(x) = (tanh( (x+x0)/\lambda )-tanh( (x-x0)/\lambda ))/2\)
The derivatives of tanh(x) are given by
\(d^p tanh(x)/dx^p = \sum_q I_{pq} tanh^{q}(x)\)
where \(I_{pq}\) are calculated using some recursion relation. Using these expressions, one can calculate a recursion relation for higher order derivatives and hence calculate analytical derivatives at arbitrary order.

Definition at line 48 of file Tanh.h.

Constructor & Destructor Documentation

◆ Tanh() [1/3]

endfieldmodel::Tanh::Tanh ( double  x0,
double  lambda,
int  max_index 
)

Create a double tanh function.

Here x0 is the centre length and lambda is the end length. max_index is used to set up for differentiation - don't try to calculate higher differentials than exist in max_index.

Definition at line 39 of file Tanh.cpp.

References setTanhDiffIndices().

Here is the call graph for this function:

◆ Tanh() [2/3]

endfieldmodel::Tanh::Tanh ( )
inline

Default constructor (initialises x0 and lambda to 0)

Definition at line 59 of file Tanh.h.

References setTanhDiffIndices().

Referenced by clone().

Here is the call graph for this function:

◆ Tanh() [3/3]

endfieldmodel::Tanh::Tanh ( const Tanh rhs)
inline

Copy constructor.

Definition at line 62 of file Tanh.h.

◆ ~Tanh()

endfieldmodel::Tanh::~Tanh ( )

Destructor (no mallocs so does nothing)

Definition at line 43 of file Tanh.cpp.

Member Function Documentation

◆ clone()

Tanh * endfieldmodel::Tanh::clone ( ) const
virtual

Inherited copy constructor.

Implements endfieldmodel::EndFieldModel.

Definition at line 45 of file Tanh.cpp.

References Tanh().

Here is the call graph for this function:

◆ function()

double endfieldmodel::Tanh::function ( double  x,
int  n 
) const
virtual

Double Tanh is given by
\(d(x) = \).

Implements endfieldmodel::EndFieldModel.

Definition at line 72 of file Tanh.cpp.

References getNegTanh(), and getTanh().

Here is the call graph for this function:

◆ getCentreLength()

double endfieldmodel::Tanh::getCentreLength ( ) const
inlinevirtual

Nominal flat top length is twice x0 (one x0 in each direction)

Implements endfieldmodel::EndFieldModel.

Definition at line 79 of file Tanh.h.

References getX0().

Here is the call graph for this function:

◆ getEndFieldModel()

std::shared_ptr< EndFieldModel > endfieldmodel::EndFieldModel::getEndFieldModel ( std::string  name)
staticinherited

Look up the EndFieldModel that has a given name.

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

Definition at line 63 of file EndFieldModel.cpp.

References endfieldmodel::EndFieldModel::efm_map.

Referenced by ScalingFFAMagnet::setupEndField().

◆ getEndLength()

double endfieldmodel::Tanh::getEndLength ( ) const
inlinevirtual

Return nominal fringe field length.

Implements endfieldmodel::EndFieldModel.

Definition at line 82 of file Tanh.h.

References getLambda().

Here is the call graph for this function:

◆ getLambda()

double endfieldmodel::Tanh::getLambda ( ) const
inline

Return lambda (end length)

Definition at line 101 of file Tanh.h.

References _lambda.

Referenced by MultipoleT::apply(), getEndLength(), MultipoleT::getFringeLength(), MultipoleTBase::getFringeLength(), and MultipoleT::transformCoords().

◆ getName()

std::string endfieldmodel::EndFieldModel::getName ( std::shared_ptr< EndFieldModel efm)
staticinherited

Get the name corresponding to a given EndFieldModel.

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

Definition at line 77 of file EndFieldModel.cpp.

References endfieldmodel::EndFieldModel::efm_map.

◆ getNegTanh()

double endfieldmodel::Tanh::getNegTanh ( double  x,
int  n 
) const

Returns the value of tanh((x-x0)/lambda) or its \(n^{th}\) derivative.

Definition at line 61 of file Tanh.cpp.

References _lambda, _tdi, and _x0.

Referenced by function(), MultipoleTBase::getFringeDeriv(), and MultipoleT::getFringeDeriv().

◆ getTanh()

double endfieldmodel::Tanh::getTanh ( double  x,
int  n 
) const

Returns the value of tanh((x+x0)/lambda) or its \(n^{th}\) derivative.

Definition at line 50 of file Tanh.cpp.

References _lambda, _tdi, and _x0.

Referenced by function(), MultipoleTBase::getFringeDeriv(), and MultipoleT::getFringeDeriv().

◆ getTanhDiffIndices()

std::vector< std::vector< int > > endfieldmodel::Tanh::getTanhDiffIndices ( size_t  n)
static

Get all the tanh differential indices \(I_{pq}\).

Returns vector of vector of ints where p indexes the differential and q indexes the tanh power - so

Definition at line 107 of file Tanh.cpp.

References _tdi, and setTanhDiffIndices().

Here is the call graph for this function:

◆ getX0()

double endfieldmodel::Tanh::getX0 ( ) const
inline

Return x0 (flat top length)

Definition at line 104 of file Tanh.h.

References _x0.

Referenced by MultipoleT::apply(), getCentreLength(), and MultipoleT::transformCoords().

◆ print()

std::ostream & endfieldmodel::Tanh::print ( std::ostream &  out) const
virtual

Prints a human readable string to out.

Implements endfieldmodel::EndFieldModel.

Definition at line 119 of file Tanh.cpp.

References _lambda, and _x0.

◆ rescale()

void endfieldmodel::Tanh::rescale ( double  scaleFactor)
virtual

Rescale the end field by a factor x0.

Implements endfieldmodel::EndFieldModel.

Definition at line 112 of file Tanh.cpp.

References _lambda, and _x0.

◆ setEndFieldModel()

void endfieldmodel::EndFieldModel::setEndFieldModel ( std::string  name,
std::shared_ptr< EndFieldModel efm 
)
staticinherited

Add a value to the lookup table.

Parameters
namename of the EndFieldModel. If name already exists in the map, it is overwritten with the new value.
efmshared_ptr to the EndFieldModel.

Definition at line 72 of file EndFieldModel.cpp.

References endfieldmodel::EndFieldModel::efm_map.

◆ setLambda()

void endfieldmodel::Tanh::setLambda ( double  lambda)
inline

Set lambda (end length)

Definition at line 107 of file Tanh.h.

References _lambda.

Referenced by OpalVerticalFFAMagnet::update().

◆ setMaximumDerivative()

void endfieldmodel::Tanh::setMaximumDerivative ( size_t  n)
virtual

Set the maximum derivative prior to tracking.

Implements endfieldmodel::EndFieldModel.

Definition at line 76 of file Tanh.cpp.

References setTanhDiffIndices().

Here is the call graph for this function:

◆ setTanhDiffIndices()

void endfieldmodel::Tanh::setTanhDiffIndices ( size_t  n)
static

Set the value of tanh differential indices to nth order differentials.

Definition at line 81 of file Tanh.cpp.

References _tdi, and endfieldmodel::CompactVector().

Referenced by getTanhDiffIndices(), setMaximumDerivative(), Tanh(), and OpalVerticalFFAMagnet::update().

Here is the call graph for this function:

◆ setX0()

void endfieldmodel::Tanh::setX0 ( double  x0)
inline

Set x0 (flat top length)

Definition at line 110 of file Tanh.h.

References _x0.

Referenced by OpalVerticalFFAMagnet::update().

Member Data Documentation

◆ _lambda

double endfieldmodel::Tanh::_lambda
private

Definition at line 118 of file Tanh.h.

Referenced by getLambda(), getNegTanh(), getTanh(), print(), rescale(), and setLambda().

◆ _tdi

std::vector< std::vector< std::vector< int > > > endfieldmodel::Tanh::_tdi
staticprivate

_tdi indexes powers of tanh in d^n tanh/dx^n as sum of powers of tanh

For some reason we index as n, +a, -a, but the third index is redundant

Definition at line 124 of file Tanh.h.

Referenced by getNegTanh(), getTanh(), getTanhDiffIndices(), and setTanhDiffIndices().

◆ _x0

double endfieldmodel::Tanh::_x0
private

Definition at line 118 of file Tanh.h.

Referenced by getNegTanh(), getTanh(), getX0(), print(), rescale(), and setX0().

◆ efm_map

std::map< std::string, std::shared_ptr< EndFieldModel > > endfieldmodel::EndFieldModel::efm_map
staticprivateinherited

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