Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
PLMD::SwitchingFunction Class Reference

Small class to compure switching functions. More...

#include <SwitchingFunction.h>

Public Member Functions

 SwitchingFunction ()
 Constructor. More...
 
void set (int nn, int mm, double r_0, double d_0)
 Set a "rational" switching function. More...
 
void set (const std::string &definition, std::string &errormsg)
 Set an arbitrary switching function. More...
 
std::string description () const
 Returns a string with a description of the switching function. More...
 
double calculate (double x, double &df) const
 Compute the switching function. More...
 
double calculateSqr (double distance2, double &dfunc) const
 Compute the switching function. More...
 
double get_d0 () const
 Returns d0. More...
 
double get_r0 () const
 Returns r0. More...
 
double get_dmax () const
 Return dmax. More...
 

Static Public Member Functions

static void registerKeywords (Keywords &keys)
 

Private Types

enum  {
  rational, exponential, gaussian, smap,
  cubic, tanh
}
 Type of function. More...
 

Private Member Functions

double do_rational (double rdist, double &dfunc, int nn, int mm) const
 Low-level tool to compute rational functions. More...
 

Private Attributes

bool init
 This is to check that switching function has been initialized. More...
 
enum PLMD::SwitchingFunction:: { ... }  type
 Type of function. More...
 
double invr0
 Inverse of scaling length. More...
 
double d0
 Minimum distance (before this, function is one) More...
 
double dmax
 Maximum distance (after this, function is zero) More...
 
int nn
 Exponents for rational function. More...
 
int mm
 
int a
 Parameters for smap function. More...
 
int b
 
double c
 
double d
 
double invr0_2
 Square of invr0, useful in calculateSqr() More...
 
double dmax_2
 Square of dmax, useful in calculateSqr() More...
 
double stretch
 Parameters for stretching the function to zero at d_max. More...
 
double shift
 

Detailed Description

Small class to compure switching functions.

Switching functions are created using set() and then can be used with function calculate() or calculateSqr(). Since this is typically computed on a distance vector, the second all (calculateSqr()) allows to skip the calculation of a square root in some case, thus potentially increasing performances.

Member Enumeration Documentation

anonymous enum
private

Type of function.

Enumerator
rational 
exponential 
gaussian 
smap 
cubic 
tanh 

Constructor & Destructor Documentation

PLMD::SwitchingFunction::SwitchingFunction ( )

Constructor.

Member Function Documentation

double PLMD::SwitchingFunction::calculate ( double  x,
double &  df 
) const

Compute the switching function.

Returns s(x). df will be set to the value of the derivative of the switching function _divided_by_x

double PLMD::SwitchingFunction::calculateSqr ( double  distance2,
double &  dfunc 
) const

Compute the switching function.

Returns \( s(\sqrt{x})\) . df will be set to the \( \frac{1}{\sqrt{x}}\frac{ds}{d\sqrt{x}}= 2 \frac{ds}{dx}\) (same as calculate()). The advantage is that in some case the expensive square root can be avoided (namely for rational functions, if nn and mm are even and d0 is zero)

std::string PLMD::SwitchingFunction::description ( ) const

Returns a string with a description of the switching function.

double PLMD::SwitchingFunction::do_rational ( double  rdist,
double &  dfunc,
int  nn,
int  mm 
) const
private

Low-level tool to compute rational functions.

It is separated since it is called both by calculate() and calculateSqr()

double PLMD::SwitchingFunction::get_d0 ( ) const

Returns d0.

double PLMD::SwitchingFunction::get_dmax ( ) const

Return dmax.

double PLMD::SwitchingFunction::get_r0 ( ) const

Returns r0.

void PLMD::SwitchingFunction::registerKeywords ( Keywords keys)
static
void PLMD::SwitchingFunction::set ( int  nn,
int  mm,
double  r_0,
double  d_0 
)

Set a "rational" switching function.

Notice that a d_max is set automatically to a value such that f(d_max)=0.00001.

void PLMD::SwitchingFunction::set ( const std::string &  definition,
std::string &  errormsg 
)

Set an arbitrary switching function.

Parse the string in definition and possibly returns errors in the errormsg string

Member Data Documentation

int PLMD::SwitchingFunction::a
private

Parameters for smap function.

int PLMD::SwitchingFunction::b
private
double PLMD::SwitchingFunction::c
private
double PLMD::SwitchingFunction::d
private
double PLMD::SwitchingFunction::d0
private

Minimum distance (before this, function is one)

double PLMD::SwitchingFunction::dmax
private

Maximum distance (after this, function is zero)

double PLMD::SwitchingFunction::dmax_2
private

Square of dmax, useful in calculateSqr()

bool PLMD::SwitchingFunction::init
private

This is to check that switching function has been initialized.

double PLMD::SwitchingFunction::invr0
private

Inverse of scaling length.

We store the inverse to avoid a division

double PLMD::SwitchingFunction::invr0_2
private

Square of invr0, useful in calculateSqr()

int PLMD::SwitchingFunction::mm
private
int PLMD::SwitchingFunction::nn
private

Exponents for rational function.

double PLMD::SwitchingFunction::shift
private
double PLMD::SwitchingFunction::stretch
private

Parameters for stretching the function to zero at d_max.

enum { ... } PLMD::SwitchingFunction::type

Type of function.


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