atomicrex  0.1
An advanced atomistic model building tool
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
atomicrex::FunctionBase Class Referenceabstract

Base class for all one-dimensional functions that can be fitted. More...

#include <Functions.h>

Inheritance diagram for atomicrex::FunctionBase:
atomicrex::FitObject atomicrex::NumericalIntegration atomicrex::FunctionConstant atomicrex::FunctionExpA atomicrex::FunctionExpB atomicrex::FunctionExpGaussian atomicrex::FunctionInverseArgument atomicrex::FunctionMorseA atomicrex::FunctionMorseB atomicrex::FunctionMorseC atomicrex::FunctionPoly atomicrex::FunctionProduct atomicrex::FunctionSpline atomicrex::FunctionSum atomicrex::ParsedFunction

Public Types

enum  NormalizationMode { NONE, SPHERICAL_INTEGRAL, UNITY_ORIGIN }
 

Public Member Functions

 FunctionBase (const FPString &id, FitJob *job, const FPString &tag=FPString())
 Constructor.
 
bool hasCutoff () const
 Returns whether this function has a cutoff.
 
double cutoff () const
 
void setCutoff (double cutoff)
 
double prefactor () const
 Returns the constant prefactor the function is multiplied with.
 
double evaluate (double r)
 Evaluates the function at the given r and multiplies the value with the proper normalization factor.
 
double evaluate (double r, double &deriv)
 Evaluates the function and its derivative at the given r and multiplies the values with the proper normalization factor.
 
void writeTabulated (std::ostream &out, double rmin, double rmax, double dr)
 Write tabulated function to stream for visualization with Gnuplot. More...
 
NormalizationMode normalizationMode () const
 Returns the normalization mode set for this function.
 
void setNormalizationMode (NormalizationMode mode)
 Specifies the normalization mode to be used for this function.
 
void computePrefactor ()
 
virtual void dofValueChanged (DegreeOfFreedom &dof) override
 
const std::shared_ptr< FunctionBase > & screeningFunction () const
 Returns the screening function applied to this function, or NULL.
 
void setScreeningFunction (const std::shared_ptr< FunctionBase > &func)
 
void verifyDerivative ()
 
void checkDerivativeNumerically (double r)
 
double centralDerivative (double r, double h, double &abserr_trunc, double &abserr_round)
 
virtual void parse (XML::Element functionElement) override
 Parses function parameters from the given XML element.
 
virtual XML::OElement generateXMLDefinition (const FPString &elementName)
 Produces an XML representation of the function's current parameters and DOFs.
 
- Public Member Functions inherited from atomicrex::FitObject
virtual ~FitObject ()=default
 Virtual destructor.
 
double relativeWeight () const
 Returns the relative fit weight assigned to this object.
 
void setRelativeWeight (double weight)
 Assigns a relative fit weight to this object.
 
virtual void assignAbsoluteWeights (double absoluteWeight)
 Recursively assigns absolute weights to the properties of this object and its sub-objects.
 
virtual bool computeProperties (bool isFitting)
 Computes all enabled properties of the object.
 
const std::vector< FitProperty * > & properties () const
 Returns a list of fitting properties of this object.
 
void listAllProperties (std::vector< FitProperty *> &list) const
 Builds a list of properties of this object and all its sub-objects.
 
FitPropertypropertyById (const FPString &id) const
 Returns the property with the given ID.
 
const std::vector< DegreeOfFreedom * > & DOF () const
 Returns a list of degrees of freedom of this object.
 
void listAllDOF (std::vector< DegreeOfFreedom *> &list) const
 Builds a list of degrees of freedom of this object and all its sub-objects.
 
DegreeOfFreedomDOFById (const FPString &id, const FPString &tag=FPString()) const
 Returns the degree of freedom with the given ID (and tag).
 
const std::vector< FitObject * > & fitObjects () const
 Returns the list of FitObjects which are part of this group.
 
void registerSubObject (FitObject *subobject, bool deleteOnShutdown=false)
 Registers a sub-object.
 
virtual void print (MsgLogger &stream)
 Outputs the name of the object.
 
bool fitEnabled () const
 Returns whether this object and it's children are included in the fit.
 
void setFitEnabled (bool enable)
 Sets whether this object and it's children are included in the fit.
 
bool outputEnabled () const
 
void setOutputEnabled (bool enable)
 
const FPStringid () const
 Returns the identifier of this object instance.
 
void setId (const FPString &id)
 Sets the main identification tag.
 
const FPStringtag () const
 Returns the assigned tag string.
 
void setTag (const FPString &tag)
 Sets the complementary identification tag.
 
FitJobjob () const
 Returns a pointer to the job to which this object belongs.
 
FitObjectparent () const
 Returns the parent of this object in the hierarchy.
 
- Public Member Functions inherited from atomicrex::NumericalIntegration
template<typename DifferentialForm >
double integrate (double a, double b, DifferentialForm diffForm)
 
virtual double integrate (double a, double b)
 
virtual double integrateSpherical (double a, double b)
 

Static Public Member Functions

static std::shared_ptr< FunctionBasecreateAndParse (XML::Element functionElement, const FPString &id, FitJob *job)
 Parses an XML element and creates a function object out of it.
 

Protected Member Functions

virtual double evaluateInternal (double r) override=0
 
virtual double evaluateInternal (double r, double &deriv)=0
 
virtual std::vector< DegreeOfFreedom * > DOFToExport ()
 
- Protected Member Functions inherited from atomicrex::FitObject
 FitObject ()
 Default Constructor.
 
 FitObject (const FPString &id, FitJob *job, const FPString &tag=FPString())
 Constructor.
 
void registerProperty (FitProperty *prop, bool deleteOnShutdown=false)
 Registers a property of this object.
 
void registerDOF (DegreeOfFreedom *dof)
 Registers a DOF of this object.
 

Protected Attributes

double _cutoff
 The function cutoff.
 
double _prefactor
 The constant prefactor used to normalize the function.
 
NormalizationMode _normalizationMode
 Controls the type of normalization applied to the function.
 
std::shared_ptr< FunctionBase_screeningFunction
 Optional screening function.
 
- Protected Attributes inherited from atomicrex::FitObject
bool _fitEnabled = true
 Controls whether this object and it's children are included in the fit.
 
bool _outputEnabled = true
 
FitJob_job = nullptr
 Pointer to the job this object belongs to.
 
FPString _id
 The identifier string of this object instance.
 
double _relativeWeight = 1.0
 The relative fit weight assigned to this object.
 

Detailed Description

Base class for all one-dimensional functions that can be fitted.

Optionally, a function can be normalized by multiplying it with a constant pre-factor, and a screening function can be imposed.

Member Enumeration Documentation

◆ NormalizationMode

Enumerator
NONE 

Do not perform any normalization; use unmodified function.

SPHERICAL_INTEGRAL 

Spherical integral over [0,cutoff] is unity, $\int dx f(x) = 1$.

UNITY_ORIGIN 

Function is one at origin, $f(0) = 1$.

Member Function Documentation

◆ centralDerivative()

double atomicrex::FunctionBase::centralDerivative ( double  r,
double  h,
double &  abserr_trunc,
double &  abserr_round 
)

Compute the numerical derivative at the given r using the 5-point rule ( $-h$, $-h/2$, $0$, $+h/2$, $+h$). Note that the value at the central point is not used.

◆ checkDerivativeNumerically()

void atomicrex::FunctionBase::checkDerivativeNumerically ( double  r)

Performs a validation of the analytical derivative by comparing it to a numerically computed derivative at the given r. Throws an exception if the analytical derivative does not match.

◆ computePrefactor()

void atomicrex::FunctionBase::computePrefactor ( )

Normalizes the function by computing the constant prefactor. This function is called once every time the parameters of the function have changed.

◆ cutoff()

double atomicrex::FunctionBase::cutoff ( ) const
inline

Returns the cutoff of this function. The function will evaluate to flat zero for positions beyond this cutoff.

◆ DOFToExport()

virtual std::vector<DegreeOfFreedom*> atomicrex::FunctionBase::DOFToExport ( )
inlineprotectedvirtual

Returns the list of DOFs that should be exported as part of the <fit-dof> element. By default, all DOFs of the function are exported in this way. Subclasses may override this method to implement custom output formats for certain DOFs.

Reimplemented in atomicrex::FunctionSpline, and atomicrex::FunctionPoly.

◆ dofValueChanged()

virtual void atomicrex::FunctionBase::dofValueChanged ( DegreeOfFreedom dof)
inlineoverridevirtual

This function is called by the DOFs of this object each time their value changes. Setting the prefactor to zero will trigger its recalculation next time evaluateNormalized() is called.

Reimplemented from atomicrex::FitObject.

Reimplemented in atomicrex::FunctionSpline, atomicrex::FunctionPoly, and atomicrex::ParsedFunction.

◆ evaluateInternal() [1/2]

virtual double atomicrex::FunctionBase::evaluateInternal ( double  r)
overrideprotectedpure virtual

◆ evaluateInternal() [2/2]

virtual double atomicrex::FunctionBase::evaluateInternal ( double  r,
double &  deriv 
)
protectedpure virtual

◆ setCutoff()

void atomicrex::FunctionBase::setCutoff ( double  cutoff)
inline

Sets the cutoff of this function. The function will evaluate to flat zero for positions beyond this cutoff.

◆ setScreeningFunction()

void atomicrex::FunctionBase::setScreeningFunction ( const std::shared_ptr< FunctionBase > &  func)
inline

Applies the given screening function to this function. This function becomes the owner of the screening function and will delete it when done.

◆ verifyDerivative()

void atomicrex::FunctionBase::verifyDerivative ( )

Makes sure that the analytical first derivative is correct by comparing its value at various point to the numeric first derivative.

◆ writeTabulated()

void atomicrex::FunctionBase::writeTabulated ( std::ostream &  out,
double  rmin,
double  rmax,
double  dr 
)

Write tabulated function to stream for visualization with Gnuplot.

Parameters
out[in]output stream
rmin[in]lower limit of range for input variable
rmax[in]upper limit of range for input variable
dr[in]spacing of input variable

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