| 1 | /* | 
|---|
| 2 | * ManyBodyPotential_Tersoff.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Sep 26, 2012 | 
|---|
| 5 | *      Author: heber | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef MANYBODYPOTENTIAL_TERSOFF_HPP_ | 
|---|
| 9 | #define MANYBODYPOTENTIAL_TERSOFF_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <boost/function.hpp> | 
|---|
| 17 | #include <cmath> | 
|---|
| 18 | #include <limits> | 
|---|
| 19 |  | 
|---|
| 20 | #include "CodePatterns/Assert.hpp" | 
|---|
| 21 |  | 
|---|
| 22 | #include "Potentials/EmpiricalPotential.hpp" | 
|---|
| 23 | #include "FunctionApproximation/FunctionModel.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | /** This class is the implementation of the Tersoff potential function. | 
|---|
| 26 | * | 
|---|
| 27 | * \note The arguments_t argument list is here in the following order: | 
|---|
| 28 | * -# first \f$ r_{ij}$ \f$, | 
|---|
| 29 | * -# then all \f$ r_{ik}$ \f$ that are within the cutoff, i.e. \f$ r_{ik}$ < R + D\f$ | 
|---|
| 30 | * | 
|---|
| 31 | */ | 
|---|
| 32 | class ManyBodyPotential_Tersoff : virtual public EmpiricalPotential, virtual public FunctionModel | 
|---|
| 33 | { | 
|---|
| 34 | //!> grant unit test access to internal parts | 
|---|
| 35 | friend class ManyBodyPotential_TersoffTest; | 
|---|
| 36 | // some repeated typedefs to avoid ambiguities | 
|---|
| 37 | typedef FunctionModel::arguments_t arguments_t; | 
|---|
| 38 | typedef FunctionModel::result_t result_t; | 
|---|
| 39 | typedef FunctionModel::results_t results_t; | 
|---|
| 40 | typedef EmpiricalPotential::derivative_components_t derivative_components_t; | 
|---|
| 41 | typedef FunctionModel::parameters_t parameters_t; | 
|---|
| 42 | public: | 
|---|
| 43 | /** Constructor for class ManyBodyPotential_Tersoff. | 
|---|
| 44 | * | 
|---|
| 45 | * @param _triplefunction function that returns a list of triples (i.e. the | 
|---|
| 46 | *        two remaining distances) to a given pair of points (contained as | 
|---|
| 47 | *        indices within the argument) | 
|---|
| 48 | */ | 
|---|
| 49 | ManyBodyPotential_Tersoff( | 
|---|
| 50 | boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction | 
|---|
| 51 | ); | 
|---|
| 52 |  | 
|---|
| 53 | /** Constructor for class ManyBodyPotential_Tersoff. | 
|---|
| 54 | * | 
|---|
| 55 | * @param _R offset for cutoff | 
|---|
| 56 | * @param _S halfwidth for cutoff relative to \a _R | 
|---|
| 57 | * @param A | 
|---|
| 58 | * @param B | 
|---|
| 59 | * @param lambda | 
|---|
| 60 | * @param mu | 
|---|
| 61 | * @param lambda3 | 
|---|
| 62 | * @param alpha | 
|---|
| 63 | * @param beta | 
|---|
| 64 | * @param chi | 
|---|
| 65 | * @param omega | 
|---|
| 66 | * @param n | 
|---|
| 67 | * @param c | 
|---|
| 68 | * @param d | 
|---|
| 69 | * @param h | 
|---|
| 70 | * @param offset | 
|---|
| 71 | * @param _triplefunction function that returns a list of triples (i.e. the | 
|---|
| 72 | *        two remaining distances) to a given pair of points (contained as | 
|---|
| 73 | *        indices within the argument) | 
|---|
| 74 | */ | 
|---|
| 75 | ManyBodyPotential_Tersoff( | 
|---|
| 76 | const double &_R, | 
|---|
| 77 | const double &_S, | 
|---|
| 78 | const double &_A, | 
|---|
| 79 | const double &_B, | 
|---|
| 80 | const double &_lambda, | 
|---|
| 81 | const double &_mu, | 
|---|
| 82 | const double &_lambda3, | 
|---|
| 83 | const double &_alpha, | 
|---|
| 84 | const double &_beta, | 
|---|
| 85 | const double &_chi, | 
|---|
| 86 | const double &_omega, | 
|---|
| 87 | const double &_n, | 
|---|
| 88 | const double &_c, | 
|---|
| 89 | const double &_d, | 
|---|
| 90 | const double &_h, | 
|---|
| 91 | const double &_offset, | 
|---|
| 92 | boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction); | 
|---|
| 93 |  | 
|---|
| 94 | /** Destructor of class ManyBodyPotential_Tersoff. | 
|---|
| 95 | * | 
|---|
| 96 | */ | 
|---|
| 97 | virtual ~ManyBodyPotential_Tersoff() {} | 
|---|
| 98 |  | 
|---|
| 99 | /** Evaluates the Tersoff potential for the given arguments. | 
|---|
| 100 | * | 
|---|
| 101 | * @param arguments single distance | 
|---|
| 102 | * @return value of the potential function | 
|---|
| 103 | */ | 
|---|
| 104 | results_t operator()(const arguments_t &arguments) const; | 
|---|
| 105 |  | 
|---|
| 106 | /** Evaluates the derivative of the Tersoff potential with respect to the | 
|---|
| 107 | * input variables. | 
|---|
| 108 | * | 
|---|
| 109 | * @param arguments single distance | 
|---|
| 110 | * @return vector with components of the derivative | 
|---|
| 111 | */ | 
|---|
| 112 | derivative_components_t derivative(const arguments_t &arguments) const; | 
|---|
| 113 |  | 
|---|
| 114 | /** Evaluates the derivative of the function with the given \a arguments | 
|---|
| 115 | * with respect to a specific parameter indicated by \a index. | 
|---|
| 116 | * | 
|---|
| 117 | * \param arguments set of arguments as input variables to the function | 
|---|
| 118 | * \param index derivative of which parameter | 
|---|
| 119 | * \return result vector containing the derivative with respect to the given | 
|---|
| 120 | *         input | 
|---|
| 121 | */ | 
|---|
| 122 | results_t parameter_derivative(const arguments_t &arguments, const size_t index) const; | 
|---|
| 123 |  | 
|---|
| 124 | /** States whether lower and upper boundaries should be used to constraint | 
|---|
| 125 | * the parameter search for this function model. | 
|---|
| 126 | * | 
|---|
| 127 | * \return true - constraints should be used, false - else | 
|---|
| 128 | */ | 
|---|
| 129 | bool isBoxConstraint() const { | 
|---|
| 130 | return true; | 
|---|
| 131 | } | 
|---|
| 132 |  | 
|---|
| 133 | /** Returns a vector which are the lower boundaries for each parameter_t | 
|---|
| 134 | * of this FunctionModel. | 
|---|
| 135 | * | 
|---|
| 136 | * \return vector of parameter_t resembling lowest allowed values | 
|---|
| 137 | */ | 
|---|
| 138 | parameters_t getLowerBoxConstraints() const { | 
|---|
| 139 | parameters_t lowerbound(getParameterDimension(), -std::numeric_limits<double>::max()); | 
|---|
| 140 | //    lowerbound[R] = 0.; | 
|---|
| 141 | //    lowerbound[S] = 0.; | 
|---|
| 142 | //    lowerbound[lambda3] = 0.; | 
|---|
| 143 | //    lowerbound[alpha] = 0.; | 
|---|
| 144 | lowerbound[beta] = std::numeric_limits<double>::min(); | 
|---|
| 145 | lowerbound[n] = std::numeric_limits<double>::min(); | 
|---|
| 146 | lowerbound[c] = std::numeric_limits<double>::min(); | 
|---|
| 147 | lowerbound[d] = std::numeric_limits<double>::min(); | 
|---|
| 148 | return lowerbound; | 
|---|
| 149 | } | 
|---|
| 150 |  | 
|---|
| 151 | /** Returns a vector which are the upper boundaries for each parameter_t | 
|---|
| 152 | * of this FunctionModel. | 
|---|
| 153 | * | 
|---|
| 154 | * \return vector of parameter_t resembling highest allowed values | 
|---|
| 155 | */ | 
|---|
| 156 | parameters_t getUpperBoxConstraints() const { | 
|---|
| 157 | return parameters_t(getParameterDimension(), std::numeric_limits<double>::max()); | 
|---|
| 158 | } | 
|---|
| 159 |  | 
|---|
| 160 | private: | 
|---|
| 161 | /** Prohibit private default constructor. | 
|---|
| 162 | * | 
|---|
| 163 | * We essentially need the triplefunction, hence without this function cannot | 
|---|
| 164 | * be. | 
|---|
| 165 | */ | 
|---|
| 166 | ManyBodyPotential_Tersoff(); | 
|---|
| 167 |  | 
|---|
| 168 | private: | 
|---|
| 169 | /** This function represents the cutoff \f$ f_C \f$. | 
|---|
| 170 | * | 
|---|
| 171 | * @param distance variable of the function | 
|---|
| 172 | * @return a value in [0,1]. | 
|---|
| 173 | */ | 
|---|
| 174 | result_t function_cutoff( | 
|---|
| 175 | const double &distance | 
|---|
| 176 | ) const; | 
|---|
| 177 | /** This  function has the exponential feature from the Morse potential. | 
|---|
| 178 | * | 
|---|
| 179 | * @param prefactor prefactor parameter to exp function | 
|---|
| 180 | * @param lambda scale parameter of exp function's argument | 
|---|
| 181 | * @param distance variable of the function | 
|---|
| 182 | * @return | 
|---|
| 183 | */ | 
|---|
| 184 | result_t function_smoother( | 
|---|
| 185 | const double &prefactor, | 
|---|
| 186 | const double &lambda, | 
|---|
| 187 | const double &distance | 
|---|
| 188 | ) const; | 
|---|
| 189 |  | 
|---|
| 190 | /** This function represents \f$ (1 + \alpha^n \eta^n)^{-1/2n} \f$. | 
|---|
| 191 | * | 
|---|
| 192 | * @param alpha prefactor to eta function | 
|---|
| 193 | * @param r_ij distance argument | 
|---|
| 194 | * @param eta result value of eta or zeta | 
|---|
| 195 | * @return \f$ (1 + \alpha^n \eta^n)^{-1/2n} \f$ | 
|---|
| 196 | */ | 
|---|
| 197 | result_t function_prefactor( | 
|---|
| 198 | const double &alpha, | 
|---|
| 199 | const double &eta | 
|---|
| 200 | ) const; | 
|---|
| 201 |  | 
|---|
| 202 | result_t | 
|---|
| 203 | function_eta( | 
|---|
| 204 | const argument_t &r_ij | 
|---|
| 205 | ) const; | 
|---|
| 206 |  | 
|---|
| 207 | result_t | 
|---|
| 208 | function_zeta( | 
|---|
| 209 | const argument_t &r_ij | 
|---|
| 210 | ) const; | 
|---|
| 211 |  | 
|---|
| 212 | result_t | 
|---|
| 213 | function_theta( | 
|---|
| 214 | const double &r_ij, | 
|---|
| 215 | const double &r_ik, | 
|---|
| 216 | const double &r_jk | 
|---|
| 217 | ) const; | 
|---|
| 218 |  | 
|---|
| 219 | result_t | 
|---|
| 220 | function_angle( | 
|---|
| 221 | const double &r_ij, | 
|---|
| 222 | const double &r_ik, | 
|---|
| 223 | const double &r_jk | 
|---|
| 224 | ) const; | 
|---|
| 225 |  | 
|---|
| 226 | private: | 
|---|
| 227 | result_t | 
|---|
| 228 | function_derivative_c( | 
|---|
| 229 | const argument_t &r_ij | 
|---|
| 230 | ) const; | 
|---|
| 231 |  | 
|---|
| 232 | result_t | 
|---|
| 233 | function_derivative_d( | 
|---|
| 234 | const argument_t &r_ij | 
|---|
| 235 | ) const; | 
|---|
| 236 |  | 
|---|
| 237 | result_t | 
|---|
| 238 | function_derivative_h( | 
|---|
| 239 | const argument_t &r_ij | 
|---|
| 240 | ) const; | 
|---|
| 241 |  | 
|---|
| 242 | public: | 
|---|
| 243 | enum parameter_enum_t { | 
|---|
| 244 | A, | 
|---|
| 245 | B, | 
|---|
| 246 | lambda, | 
|---|
| 247 | mu, | 
|---|
| 248 | beta, | 
|---|
| 249 | n, | 
|---|
| 250 | c, | 
|---|
| 251 | d, | 
|---|
| 252 | h, | 
|---|
| 253 | offset, | 
|---|
| 254 | //    R, | 
|---|
| 255 | //    S, | 
|---|
| 256 | //    lambda3, | 
|---|
| 257 | //    alpha, | 
|---|
| 258 | //    chi, | 
|---|
| 259 | //    omega, | 
|---|
| 260 | MAXPARAMS | 
|---|
| 261 | }; | 
|---|
| 262 |  | 
|---|
| 263 | private: | 
|---|
| 264 | //!> parameter vector with parameters as in enum parameter_enum_t | 
|---|
| 265 | parameters_t params; | 
|---|
| 266 |  | 
|---|
| 267 | public: | 
|---|
| 268 | // some internal parameters which are fixed | 
|---|
| 269 | const double R; | 
|---|
| 270 | const double S; | 
|---|
| 271 | const double lambda3; | 
|---|
| 272 | const double alpha; | 
|---|
| 273 | const double chi; | 
|---|
| 274 | const double omega; | 
|---|
| 275 |  | 
|---|
| 276 | public: | 
|---|
| 277 | /** Setter for parameters as required by FunctionModel interface. | 
|---|
| 278 | * | 
|---|
| 279 | * \param _params given set of parameters | 
|---|
| 280 | */ | 
|---|
| 281 | void setParameters(const parameters_t &_params) | 
|---|
| 282 | { | 
|---|
| 283 | ASSERT( _params.size() <= getParameterDimension(), | 
|---|
| 284 | "ManyBodyPotential_Tersoff::setParameters() - we need not more than " | 
|---|
| 285 | +toString(getParameterDimension())+" parameters."); | 
|---|
| 286 | for (size_t i=0; i< _params.size(); ++i) | 
|---|
| 287 | params[i] = _params[i]; | 
|---|
| 288 | } | 
|---|
| 289 |  | 
|---|
| 290 | /** Getter for parameters as required by FunctionModel interface. | 
|---|
| 291 | * | 
|---|
| 292 | * \return set of parameters | 
|---|
| 293 | */ | 
|---|
| 294 | parameters_t getParameters() const | 
|---|
| 295 | { | 
|---|
| 296 | return params; | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 | /** Getter for the number of parameters of this model function. | 
|---|
| 300 | * | 
|---|
| 301 | * \return number of parameters | 
|---|
| 302 | */ | 
|---|
| 303 | size_t getParameterDimension() const | 
|---|
| 304 | { | 
|---|
| 305 | return MAXPARAMS; | 
|---|
| 306 | } | 
|---|
| 307 |  | 
|---|
| 308 | private: | 
|---|
| 309 | //!> bound function that obtains the triples for the internal coordinationb summation. | 
|---|
| 310 | const boost::function< std::vector< arguments_t >(const argument_t &, const double)> &triplefunction; | 
|---|
| 311 | }; | 
|---|
| 312 |  | 
|---|
| 313 |  | 
|---|
| 314 | #endif /* MANYBODYPOTENTIAL_TERSOFF_HPP_ */ | 
|---|