[6bb72a] | 1 | /*
|
---|
| 2 | * PairPotential_Harmonic.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Sep 26, 2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef PAIRPOTENTIAL_HARMONIC_HPP_
|
---|
| 9 | #define PAIRPOTENTIAL_HARMONIC_HPP_
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[d03292] | 17 | #include <limits>
|
---|
| 18 |
|
---|
[1dca9a] | 19 | #include "CodePatterns/Assert.hpp"
|
---|
[6bb72a] | 20 |
|
---|
| 21 | #include "Potentials/EmpiricalPotential.hpp"
|
---|
[ed2551] | 22 | #include "Potentials/SerializablePotential.hpp"
|
---|
[4f82f8] | 23 | #include "FunctionApproximation/FunctionModel.hpp"
|
---|
[6bb72a] | 24 |
|
---|
| 25 | /** This is the implementation of a harmonic pair potential.
|
---|
| 26 | *
|
---|
| 27 | * This evaluates \f$ k \cdot (r -r_0)^2 \f$.
|
---|
| 28 | *
|
---|
| 29 | */
|
---|
[ed2551] | 30 | class PairPotential_Harmonic :
|
---|
| 31 | virtual public EmpiricalPotential,
|
---|
| 32 | virtual public FunctionModel,
|
---|
| 33 | virtual public SerializablePotential
|
---|
[6bb72a] | 34 | {
|
---|
[3c1465] | 35 | //!> grant unit test access to internal parts
|
---|
| 36 | friend class PairPotential_HarmonicTest;
|
---|
[3ccea3] | 37 | // some repeated typedefs to avoid ambiguities
|
---|
| 38 | typedef FunctionModel::arguments_t arguments_t;
|
---|
| 39 | typedef FunctionModel::result_t result_t;
|
---|
| 40 | typedef FunctionModel::results_t results_t;
|
---|
| 41 | typedef EmpiricalPotential::derivative_components_t derivative_components_t;
|
---|
[1dca9a] | 42 | typedef FunctionModel::parameters_t parameters_t;
|
---|
[6bb72a] | 43 | public:
|
---|
[ed2551] | 44 | PairPotential_Harmonic(const ParticleTypes_t &_ParticleTypes);
|
---|
[6bb72a] | 45 | PairPotential_Harmonic(
|
---|
[ed2551] | 46 | const ParticleTypes_t &_ParticleTypes,
|
---|
[6bb72a] | 47 | const double _spring_constant,
|
---|
[65c42c] | 48 | const double _equilibrium_distance,
|
---|
[1dca9a] | 49 | const double _energy_offset);
|
---|
[6bb72a] | 50 | virtual ~PairPotential_Harmonic() {}
|
---|
| 51 |
|
---|
[4f82f8] | 52 | /** Setter for parameters as required by FunctionModel interface.
|
---|
| 53 | *
|
---|
| 54 | * \param _params given set of parameters
|
---|
| 55 | */
|
---|
[086070] | 56 | void setParameters(const parameters_t &_params);
|
---|
[4f82f8] | 57 |
|
---|
| 58 | /** Getter for parameters as required by FunctionModel interface.
|
---|
| 59 | *
|
---|
| 60 | * \return set of parameters
|
---|
| 61 | */
|
---|
[1dca9a] | 62 | parameters_t getParameters() const
|
---|
| 63 | {
|
---|
| 64 | return params;
|
---|
| 65 | }
|
---|
[4f82f8] | 66 |
|
---|
| 67 | /** Getter for the number of parameters of this model function.
|
---|
| 68 | *
|
---|
| 69 | * \return number of parameters
|
---|
| 70 | */
|
---|
| 71 | size_t getParameterDimension() const
|
---|
| 72 | {
|
---|
[65c42c] | 73 | return 3;
|
---|
[4f82f8] | 74 | }
|
---|
| 75 |
|
---|
[6bb72a] | 76 | /** Evaluates the harmonic potential function for the given arguments.
|
---|
| 77 | *
|
---|
| 78 | * @param arguments single distance
|
---|
| 79 | * @return value of the potential function
|
---|
| 80 | */
|
---|
[4f82f8] | 81 | results_t operator()(const arguments_t &arguments) const;
|
---|
[6bb72a] | 82 |
|
---|
| 83 | /** Evaluates the derivative of the potential function.
|
---|
| 84 | *
|
---|
| 85 | * @param arguments single distance
|
---|
| 86 | * @return vector with derivative with respect to the input degrees of freedom
|
---|
| 87 | */
|
---|
| 88 | derivative_components_t derivative(const arguments_t &arguments) const;
|
---|
| 89 |
|
---|
[3ccea3] | 90 | /** Evaluates the derivative of the function with the given \a arguments
|
---|
| 91 | * with respect to a specific parameter indicated by \a index.
|
---|
| 92 | *
|
---|
| 93 | * \param arguments set of arguments as input variables to the function
|
---|
| 94 | * \param index derivative of which parameter
|
---|
| 95 | * \return result vector containing the derivative with respect to the given
|
---|
| 96 | * input
|
---|
| 97 | */
|
---|
[5b5724] | 98 | results_t parameter_derivative(const arguments_t &arguments, const size_t index) const;
|
---|
[3ccea3] | 99 |
|
---|
[d03292] | 100 | /** States whether lower and upper boundaries should be used to constraint
|
---|
| 101 | * the parameter search for this function model.
|
---|
| 102 | *
|
---|
| 103 | * \return true - constraints should be used, false - else
|
---|
| 104 | */
|
---|
| 105 | bool isBoxConstraint() const {
|
---|
| 106 | return true;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /** Returns a vector which are the lower boundaries for each parameter_t
|
---|
| 110 | * of this FunctionModel.
|
---|
| 111 | *
|
---|
| 112 | * \return vector of parameter_t resembling lowest allowed values
|
---|
| 113 | */
|
---|
| 114 | parameters_t getLowerBoxConstraints() const {
|
---|
| 115 | parameters_t lowerbounds(getParameterDimension(), -std::numeric_limits<double>::max());
|
---|
| 116 | lowerbounds[equilibrium_distance] = 0.;
|
---|
| 117 | return lowerbounds;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /** Returns a vector which are the upper boundaries for each parameter_t
|
---|
| 121 | * of this FunctionModel.
|
---|
| 122 | *
|
---|
| 123 | * \return vector of parameter_t resembling highest allowed values
|
---|
| 124 | */
|
---|
| 125 | parameters_t getUpperBoxConstraints() const {
|
---|
| 126 | return parameters_t(getParameterDimension(), std::numeric_limits<double>::max());
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[6efcae] | 129 | /** Return the token name of this specific potential.
|
---|
| 130 | *
|
---|
| 131 | * \return token name of the potential
|
---|
| 132 | */
|
---|
[ed2551] | 133 | const std::string& getToken() const
|
---|
| 134 | { return potential_token; }
|
---|
| 135 |
|
---|
| 136 | /** Returns a vector of parameter names.
|
---|
| 137 | *
|
---|
| 138 | * This is required from the specific implementation
|
---|
| 139 | *
|
---|
| 140 | * \return vector of strings containing parameter names
|
---|
| 141 | */
|
---|
| 142 | const ParameterNames_t& getParameterNames() const
|
---|
| 143 | { return ParameterNames; }
|
---|
[6efcae] | 144 |
|
---|
[1dca9a] | 145 | enum parameter_enum_t {
|
---|
| 146 | spring_constant=0,
|
---|
| 147 | equilibrium_distance=1,
|
---|
| 148 | energy_offset=2,
|
---|
| 149 | MAXPARAMS
|
---|
| 150 | };
|
---|
[f48ad3] | 151 | private:
|
---|
[1dca9a] | 152 | //!> parameter vector with parameters as in enum parameter_enum_t
|
---|
| 153 | parameters_t params;
|
---|
[ed2551] | 154 |
|
---|
| 155 | //!> static definitions of the parameter name for this potential
|
---|
| 156 | static const ParameterNames_t ParameterNames;
|
---|
| 157 |
|
---|
| 158 | //!> static token of this potential type
|
---|
| 159 | static const std::string potential_token;
|
---|
[6bb72a] | 160 | };
|
---|
| 161 |
|
---|
| 162 | #endif /* PAIRPOTENTIAL_HARMONIC_HPP_ */
|
---|