Skip to content
Snippets Groups Projects
Commit 03c71534 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Added documentation to class SwitchingFunction

parent ce0a3c98
No related branches found
No related tags found
No related merge requests found
...@@ -30,29 +30,67 @@ class Log; ...@@ -30,29 +30,67 @@ class Log;
class Keywords; class Keywords;
/// \ingroup TOOLBOX /// \ingroup TOOLBOX
/// Small class to compure switching functions in the form /// Small class to compure switching functions.
/// In the future we might extend it so as to be set using /// Switching functions are created using set() and
/// a string: /// then can be used with function calculate() or calculateSqr().
/// void set(std::string); /// Since this is typically computed on a distance vector,
/// which can then be parsed for more complex stuff, e.g. exponentials /// the second all (calculateSqr()) allows to skip the calculation
/// tabulated functions from file, matheval, etc... /// of a square root in some case, thus potentially increasing
/// performances.
class SwitchingFunction{ class SwitchingFunction{
/// This is to check that switching function has been initialized
bool init; bool init;
/// Type of function
enum {spline,exponential,gaussian,smap} type; enum {spline,exponential,gaussian,smap} type;
int nn,mm,a,b; /// Inverse of scaling length.
double invr0,d0,dmax,c,d; /// We store the inverse to avoid a division
double invr0_2,dmax_2; double invr0;
/// Minimum distance (before this, function is one)
double d0;
/// Maximum distance (after this, function is zero)
double dmax;
/// Exponents for rational function
int nn,mm;
/// Parameters for smap function
int a,b;
double c,d;
/// Square of invr0, useful in calculateSqr()
double invr0_2;
/// Square of dmax, useful in calculateSqr()
double dmax_2;
/// Parameters for stretching the function to zero at d_max
double stretch,shift; double stretch,shift;
/// Low-level tool to compute rational functions.
/// It is separated since it is called both by calculate() and calculateSqr()
double do_rational(double rdist,double&dfunc,int nn,int mm)const; double do_rational(double rdist,double&dfunc,int nn,int mm)const;
public: public:
static void registerKeywords( Keywords& keys ); static void registerKeywords( Keywords& keys );
/// Constructor
SwitchingFunction(); SwitchingFunction();
/// Set a "rational" switching function.
/// Notice that a d_max is set automatically to a value such that
/// f(d_max)=0.00001.
void set(int nn,int mm,double r_0,double d_0); void set(int nn,int mm,double r_0,double d_0);
/// Set an arbitrary switching function.
/// Parse the string in definition and possibly returns errors
/// in the errormsg string
void set(const std::string& definition, std::string& errormsg); void set(const std::string& definition, std::string& errormsg);
/// Returns a string with a description of the switching function
std::string description() const ; std::string description() 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 calculate(double x,double&df)const; double calculate(double x,double&df)const;
/// Compute the switching function.
/// Returns \f$ s(\sqrt{x})\f$ .
/// df will be set to the \f$ \frac{1}{\sqrt{x}}\frac{ds}{d\sqrt{x}}= 2 \frac{ds}{dx}\f$
/// (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)
double calculateSqr(double distance2,double&dfunc)const; double calculateSqr(double distance2,double&dfunc)const;
/// Returns d0
double get_d0() const; double get_d0() const;
/// Returns r0
double get_r0() const; double get_r0() const;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment