| [610c11] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  * 
 | 
|---|
 | 7 |  *
 | 
|---|
 | 8 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 9 |  *
 | 
|---|
 | 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 13 |  *    (at your option) any later version.
 | 
|---|
 | 14 |  *
 | 
|---|
 | 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 18 |  *    GNU General Public License for more details.
 | 
|---|
 | 19 |  *
 | 
|---|
 | 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>. 
 | 
|---|
 | 22 |  */
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | /*
 | 
|---|
 | 25 |  * ManyBodyPotential_Tersoff.cpp
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  *  Created on: Sep 26, 2012
 | 
|---|
 | 28 |  *      Author: heber
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | // include config.h
 | 
|---|
 | 33 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 34 | #include <config.h>
 | 
|---|
 | 35 | #endif
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | #include "ManyBodyPotential_Tersoff.hpp"
 | 
|---|
 | 40 | 
 | 
|---|
| [ed2551] | 41 | #include <boost/assign/list_of.hpp> // for 'map_list_of()'
 | 
|---|
| [610c11] | 42 | #include <boost/bind.hpp>
 | 
|---|
 | 43 | #include <cmath>
 | 
|---|
| [ed2551] | 44 | #include <string>
 | 
|---|
| [610c11] | 45 | 
 | 
|---|
 | 46 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| [ffc368] | 47 | //#include "CodePatterns/Info.hpp"
 | 
|---|
| [f904d5] | 48 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [610c11] | 49 | 
 | 
|---|
 | 50 | #include "Potentials/helpers.hpp"
 | 
|---|
| [b760bc3] | 51 | #include "Potentials/ParticleTypeCheckers.hpp"
 | 
|---|
| [610c11] | 52 | 
 | 
|---|
| [ed2551] | 53 | // static definitions
 | 
|---|
 | 54 | const ManyBodyPotential_Tersoff::ParameterNames_t
 | 
|---|
 | 55 | ManyBodyPotential_Tersoff::ParameterNames =
 | 
|---|
 | 56 |       boost::assign::list_of<std::string>
 | 
|---|
 | 57 |       ("A")
 | 
|---|
 | 58 |       ("B")
 | 
|---|
 | 59 |       ("lambda")
 | 
|---|
 | 60 |       ("mu")
 | 
|---|
 | 61 |       ("beta")
 | 
|---|
 | 62 |       ("n")
 | 
|---|
 | 63 |       ("c")
 | 
|---|
 | 64 |       ("d")
 | 
|---|
 | 65 |       ("h")
 | 
|---|
 | 66 |       ("offset")
 | 
|---|
 | 67 | //      ("R")
 | 
|---|
 | 68 | //      ("S")
 | 
|---|
 | 69 | //      ("lambda3")
 | 
|---|
 | 70 | //      ("alpha")
 | 
|---|
 | 71 | //      ("chi")
 | 
|---|
 | 72 | //      ("omega")
 | 
|---|
 | 73 |     ;
 | 
|---|
 | 74 | const std::string ManyBodyPotential_Tersoff::potential_token("tersoff");
 | 
|---|
 | 75 | 
 | 
|---|
| [e7579e] | 76 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff(
 | 
|---|
| [ed2551] | 77 |     const ParticleTypes_t &_ParticleTypes,
 | 
|---|
| [e7579e] | 78 |     boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction
 | 
|---|
 | 79 |     ) :
 | 
|---|
| [ed2551] | 80 |     SerializablePotential(_ParticleTypes),
 | 
|---|
| [e7579e] | 81 |     params(parameters_t(MAXPARAMS, 0.)),
 | 
|---|
| [752dc7] | 82 |     R(3.2),
 | 
|---|
 | 83 |     S(3.5),
 | 
|---|
| [990a62] | 84 |     lambda3(0.),
 | 
|---|
 | 85 |     alpha(0.),
 | 
|---|
 | 86 |     chi(1.),
 | 
|---|
 | 87 |     omega(1.),
 | 
|---|
| [e7579e] | 88 |     triplefunction(_triplefunction)
 | 
|---|
| [dbf8c8] | 89 | {
 | 
|---|
 | 90 |   // have some decent defaults for parameter_derivative checking
 | 
|---|
 | 91 |   params[A] = 3000.;
 | 
|---|
 | 92 |   params[B] = 300.;
 | 
|---|
 | 93 |   params[lambda] = 5.;
 | 
|---|
 | 94 |   params[mu] = 3.;
 | 
|---|
 | 95 |   params[beta] = 2.;
 | 
|---|
 | 96 |   params[n] = 1.;
 | 
|---|
 | 97 |   params[c] = 0.01;
 | 
|---|
 | 98 |   params[d] = 1.;
 | 
|---|
 | 99 |   params[h] = 0.01;
 | 
|---|
 | 100 |   params[offset] = 0.01;
 | 
|---|
 | 101 | }
 | 
|---|
| [e7579e] | 102 | 
 | 
|---|
 | 103 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff(
 | 
|---|
| [ed2551] | 104 |     const ParticleTypes_t &_ParticleTypes,
 | 
|---|
| [ffc368] | 105 |     const double &_R,
 | 
|---|
 | 106 |     const double &_S,
 | 
|---|
| [e7579e] | 107 |     const double &_A,
 | 
|---|
 | 108 |     const double &_B,
 | 
|---|
| [ffc368] | 109 |     const double &_lambda,
 | 
|---|
 | 110 |     const double &_mu,
 | 
|---|
| [e7579e] | 111 |     const double &_lambda3,
 | 
|---|
 | 112 |     const double &_alpha,
 | 
|---|
 | 113 |     const double &_beta,
 | 
|---|
| [ffc368] | 114 |     const double &_chi,
 | 
|---|
 | 115 |     const double &_omega,
 | 
|---|
| [e7579e] | 116 |     const double &_n,
 | 
|---|
 | 117 |     const double &_c,
 | 
|---|
 | 118 |     const double &_d,
 | 
|---|
 | 119 |     const double &_h,
 | 
|---|
| [56c5de4] | 120 |     const double &_offset,
 | 
|---|
| [e7579e] | 121 |     boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
 | 
|---|
| [ed2551] | 122 |   SerializablePotential(_ParticleTypes),
 | 
|---|
| [e7579e] | 123 |   params(parameters_t(MAXPARAMS, 0.)),
 | 
|---|
| [752dc7] | 124 |   R(_R),
 | 
|---|
 | 125 |   S(_S),
 | 
|---|
| [990a62] | 126 |   lambda3(_lambda3),
 | 
|---|
 | 127 |   alpha(_alpha),
 | 
|---|
 | 128 |   chi(_chi),
 | 
|---|
 | 129 |   omega(_mu),
 | 
|---|
| [e7579e] | 130 |   triplefunction(_triplefunction)
 | 
|---|
 | 131 | {
 | 
|---|
| [ffc368] | 132 | //  Info info(__func__);
 | 
|---|
| [752dc7] | 133 | //  R = _R;
 | 
|---|
 | 134 | //  S = _S;
 | 
|---|
| [e7579e] | 135 |   params[A] = _A;
 | 
|---|
 | 136 |   params[B] = _B;
 | 
|---|
| [ffc368] | 137 |   params[lambda] = _lambda;
 | 
|---|
 | 138 |   params[mu] = _mu;
 | 
|---|
| [990a62] | 139 | //  lambda3 = _lambda3;
 | 
|---|
 | 140 | //  alpha = _alpha;
 | 
|---|
| [e7579e] | 141 |   params[beta] = _beta;
 | 
|---|
| [990a62] | 142 | //  chi = _chi;
 | 
|---|
 | 143 | //  omega = _omega;
 | 
|---|
| [e7579e] | 144 |   params[n] = _n;
 | 
|---|
 | 145 |   params[c] = _c;
 | 
|---|
 | 146 |   params[d] = _d;
 | 
|---|
 | 147 |   params[h] = _h;
 | 
|---|
| [56c5de4] | 148 |   params[offset] = _offset;
 | 
|---|
| [e7579e] | 149 | }
 | 
|---|
 | 150 | 
 | 
|---|
| [086070] | 151 | void ManyBodyPotential_Tersoff::setParameters(const parameters_t &_params)
 | 
|---|
 | 152 | {
 | 
|---|
 | 153 |   const size_t paramsDim = _params.size();
 | 
|---|
 | 154 |   ASSERT( paramsDim <= getParameterDimension(),
 | 
|---|
 | 155 |       "ManyBodyPotential_Tersoff::setParameters() - we need not more than "
 | 
|---|
 | 156 |       +toString(getParameterDimension())+" parameters.");
 | 
|---|
 | 157 |   for (size_t i=0; i< paramsDim; ++i)
 | 
|---|
 | 158 |     params[i] = _params[i];
 | 
|---|
 | 159 | 
 | 
|---|
 | 160 | #ifndef NDEBUG
 | 
|---|
 | 161 |   parameters_t check_params(getParameters());
 | 
|---|
 | 162 |   check_params.resize(paramsDim); // truncate to same size
 | 
|---|
 | 163 |   ASSERT( check_params == _params,
 | 
|---|
 | 164 |       "ManyBodyPotential_Tersoff::setParameters() - failed, mismatch in to be set "
 | 
|---|
 | 165 |       +toString(_params)+" and set "+toString(check_params)+" params.");
 | 
|---|
 | 166 | #endif
 | 
|---|
 | 167 | }
 | 
|---|
 | 168 | 
 | 
|---|
| [4f82f8] | 169 | ManyBodyPotential_Tersoff::results_t
 | 
|---|
| [610c11] | 170 | ManyBodyPotential_Tersoff::operator()(
 | 
|---|
 | 171 |     const arguments_t &arguments
 | 
|---|
 | 172 |     ) const
 | 
|---|
 | 173 | {
 | 
|---|
| [ffc368] | 174 | //  Info info(__func__);
 | 
|---|
| [2e9486] | 175 |   double result = 0.;
 | 
|---|
 | 176 |   for(arguments_t::const_iterator argiter = arguments.begin();
 | 
|---|
 | 177 |       argiter != arguments.end();
 | 
|---|
 | 178 |       ++argiter) {
 | 
|---|
 | 179 |     const argument_t &r_ij = *argiter;
 | 
|---|
| [b760bc3] | 180 |     ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
 | 
|---|
 | 181 |         arguments_t(1, r_ij), getParticleTypes()),
 | 
|---|
 | 182 |         "ManyBodyPotential_Tersoff::operator() - types don't match with ones in arguments.");
 | 
|---|
 | 183 |  
 | 
|---|
| [2e9486] | 184 |     const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
 | 185 |     const double temp = (cutoff == 0.) ?
 | 
|---|
 | 186 |         0. :
 | 
|---|
 | 187 |         cutoff * (
 | 
|---|
 | 188 |             function_prefactor(
 | 
|---|
 | 189 |                 alpha,
 | 
|---|
 | 190 |                 function_eta(r_ij))
 | 
|---|
 | 191 |             * function_smoother(
 | 
|---|
 | 192 |                 params[A],
 | 
|---|
 | 193 |                 params[lambda],
 | 
|---|
 | 194 |                 r_ij.distance)
 | 
|---|
 | 195 |             +
 | 
|---|
 | 196 |             function_prefactor(
 | 
|---|
 | 197 |                 params[beta],
 | 
|---|
 | 198 |                 function_zeta(r_ij))
 | 
|---|
 | 199 |             * function_smoother(
 | 
|---|
 | 200 |                 -params[B],
 | 
|---|
 | 201 |                 params[mu],
 | 
|---|
 | 202 |                 r_ij.distance)
 | 
|---|
 | 203 |         );
 | 
|---|
 | 204 |     result += temp;
 | 
|---|
 | 205 |   }
 | 
|---|
| [ffc368] | 206 | //  LOG(2, "DEBUG: operator()(" << r_ij.distance << ") = " << result);
 | 
|---|
| [56c5de4] | 207 |   return std::vector<result_t>(1, params[offset]+result);
 | 
|---|
| [610c11] | 208 | }
 | 
|---|
 | 209 | 
 | 
|---|
| [ffc368] | 210 | ManyBodyPotential_Tersoff::derivative_components_t
 | 
|---|
 | 211 | ManyBodyPotential_Tersoff::derivative(
 | 
|---|
 | 212 |     const arguments_t &arguments
 | 
|---|
 | 213 |     ) const
 | 
|---|
 | 214 | {
 | 
|---|
 | 215 | //  Info info(__func__);
 | 
|---|
 | 216 |   return ManyBodyPotential_Tersoff::derivative_components_t();
 | 
|---|
 | 217 | }
 | 
|---|
 | 218 | 
 | 
|---|
 | 219 | ManyBodyPotential_Tersoff::results_t
 | 
|---|
 | 220 | ManyBodyPotential_Tersoff::parameter_derivative(
 | 
|---|
 | 221 |     const arguments_t &arguments,
 | 
|---|
 | 222 |     const size_t index
 | 
|---|
 | 223 |     ) const
 | 
|---|
 | 224 | {
 | 
|---|
 | 225 | //  Info info(__func__);
 | 
|---|
 | 226 | //  ASSERT( arguments.size() == 1,
 | 
|---|
| [2e9486] | 227 | //      "ManyBodyPotential_Tersoff::parameter_derivative() - requires exactly one argument.");
 | 
|---|
| [56c5de4] | 228 |   if (index == offset)
 | 
|---|
 | 229 |     return results_t(1, 1.);
 | 
|---|
 | 230 | 
 | 
|---|
| [2e9486] | 231 |   double result = 0.;
 | 
|---|
 | 232 |   for(arguments_t::const_iterator argiter = arguments.begin();
 | 
|---|
 | 233 |       argiter != arguments.end();
 | 
|---|
 | 234 |       ++argiter) {
 | 
|---|
 | 235 |     const argument_t &r_ij = *argiter;
 | 
|---|
| [b760bc3] | 236 |     ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
 | 
|---|
 | 237 |         arguments_t(1, r_ij), getParticleTypes()),
 | 
|---|
 | 238 |         "ManyBodyPotential_Tersoff::operator() - types don't match with ones in arguments.");
 | 
|---|
| [55fe788] | 239 | 
 | 
|---|
| [ffc368] | 240 |   switch (index) {
 | 
|---|
| [752dc7] | 241 | //    case R:
 | 
|---|
 | 242 | //    {
 | 
|---|
| [2e9486] | 243 | //      result += 0.;
 | 
|---|
| [752dc7] | 244 | //      break;
 | 
|---|
 | 245 | //    }
 | 
|---|
 | 246 | //    case S:
 | 
|---|
 | 247 | //    {
 | 
|---|
| [2e9486] | 248 | //      result += 0.;
 | 
|---|
| [752dc7] | 249 | //      break;
 | 
|---|
 | 250 | //    }
 | 
|---|
| [ffc368] | 251 |     case A:
 | 
|---|
 | 252 |     {
 | 
|---|
| [ca8d82] | 253 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 254 |       result += (cutoff == 0.) ?
 | 
|---|
| [ca8d82] | 255 |           0. :
 | 
|---|
 | 256 |           cutoff *
 | 
|---|
 | 257 |               function_prefactor(
 | 
|---|
 | 258 |                   alpha,
 | 
|---|
 | 259 |                   function_eta(r_ij))
 | 
|---|
 | 260 |               * function_smoother(
 | 
|---|
 | 261 |                   1.,
 | 
|---|
 | 262 |                   params[lambda],
 | 
|---|
 | 263 |                   r_ij.distance);
 | 
|---|
 | 264 | //          cutoff * function_prefactor(
 | 
|---|
 | 265 | //              alpha,
 | 
|---|
 | 266 | //              function_eta(r_ij))
 | 
|---|
 | 267 | //          * function_smoother(
 | 
|---|
 | 268 | //              1.,
 | 
|---|
 | 269 | //              params[mu],
 | 
|---|
 | 270 | //              r_ij.distance);
 | 
|---|
| [ffc368] | 271 |       break;
 | 
|---|
 | 272 |     }
 | 
|---|
 | 273 |     case B:
 | 
|---|
 | 274 |     {
 | 
|---|
| [ca8d82] | 275 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 276 |       result += (cutoff == 0.) ?
 | 
|---|
| [ca8d82] | 277 |           0. :
 | 
|---|
 | 278 |           cutoff * function_prefactor(
 | 
|---|
 | 279 |               params[beta],
 | 
|---|
 | 280 |               function_zeta(r_ij))
 | 
|---|
 | 281 |           * function_smoother(
 | 
|---|
 | 282 |               -1.,
 | 
|---|
 | 283 |               params[mu],
 | 
|---|
 | 284 |               r_ij.distance);
 | 
|---|
 | 285 | //          cutoff * function_prefactor(
 | 
|---|
 | 286 | //              beta,
 | 
|---|
 | 287 | //              function_zeta(r_ij))
 | 
|---|
 | 288 | //          * function_smoother(
 | 
|---|
 | 289 | //              -params[B],
 | 
|---|
 | 290 | //              params[mu],
 | 
|---|
 | 291 | //              r_ij.distance)/params[B];
 | 
|---|
| [ffc368] | 292 |       break;
 | 
|---|
 | 293 |     }
 | 
|---|
 | 294 |     case lambda:
 | 
|---|
 | 295 |     {
 | 
|---|
 | 296 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 297 |       result += (cutoff == 0.) ?
 | 
|---|
| [ffc368] | 298 |           0. :
 | 
|---|
| [ca8d82] | 299 |           -r_ij.distance * cutoff *
 | 
|---|
 | 300 |               function_prefactor(
 | 
|---|
 | 301 |                   alpha,
 | 
|---|
 | 302 |                   function_eta(r_ij))
 | 
|---|
 | 303 |               * function_smoother(
 | 
|---|
 | 304 |                   params[A],
 | 
|---|
 | 305 |                   params[lambda],
 | 
|---|
 | 306 |                   r_ij.distance);
 | 
|---|
| [ffc368] | 307 |       break;
 | 
|---|
 | 308 |     }
 | 
|---|
 | 309 |     case mu:
 | 
|---|
 | 310 |     {
 | 
|---|
 | 311 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 312 |       result += (cutoff == 0.) ?
 | 
|---|
| [ffc368] | 313 |           0. :
 | 
|---|
| [f904d5] | 314 |           -r_ij.distance * cutoff *(
 | 
|---|
| [ffc368] | 315 |           function_prefactor(
 | 
|---|
 | 316 |               params[beta],
 | 
|---|
 | 317 |               function_zeta(r_ij))
 | 
|---|
 | 318 |           * function_smoother(
 | 
|---|
 | 319 |               -params[B],
 | 
|---|
 | 320 |               params[mu],
 | 
|---|
 | 321 |               r_ij.distance)
 | 
|---|
 | 322 |       );
 | 
|---|
 | 323 |       break;
 | 
|---|
 | 324 |     }
 | 
|---|
| [990a62] | 325 | //    case lambda3:
 | 
|---|
 | 326 | //    {
 | 
|---|
| [2e9486] | 327 | //      result += 0.;
 | 
|---|
| [990a62] | 328 | //      break;
 | 
|---|
 | 329 | //    }
 | 
|---|
 | 330 | //    case alpha:
 | 
|---|
 | 331 | //    {
 | 
|---|
 | 332 | //      const double temp =
 | 
|---|
 | 333 | //          pow(alpha*function_eta(r_ij), params[n]);
 | 
|---|
 | 334 | //      const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 335 | //      result += (cutoff == 0.) || (alpha == 0. )?
 | 
|---|
| [990a62] | 336 | //          0. :
 | 
|---|
 | 337 | //          function_smoother(
 | 
|---|
| [ca8d82] | 338 | //              params[A],
 | 
|---|
| [990a62] | 339 | //              params[lambda],
 | 
|---|
 | 340 | //              r_ij.distance)
 | 
|---|
 | 341 | //          * (-.5) * alpha * (temp/alpha)
 | 
|---|
 | 342 | //          / (1. + temp)
 | 
|---|
 | 343 | //          ;
 | 
|---|
 | 344 | //      break;
 | 
|---|
 | 345 | //    }
 | 
|---|
 | 346 | //    case chi:
 | 
|---|
 | 347 | //    {
 | 
|---|
| [2e9486] | 348 | //      result += 0.;
 | 
|---|
| [990a62] | 349 | //      break;
 | 
|---|
 | 350 | //    }
 | 
|---|
 | 351 | //    case omega:
 | 
|---|
 | 352 | //    {
 | 
|---|
| [2e9486] | 353 | //      result += 0.;
 | 
|---|
| [990a62] | 354 | //      break;
 | 
|---|
 | 355 | //    }
 | 
|---|
| [ffc368] | 356 |     case beta:
 | 
|---|
 | 357 |     {
 | 
|---|
 | 358 |       const double temp =
 | 
|---|
 | 359 |           pow(params[beta]*function_zeta(r_ij), params[n]);
 | 
|---|
 | 360 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 361 |       result += (cutoff == 0.) || (params[beta] == 0. )?
 | 
|---|
| [ffc368] | 362 |           0. : cutoff *
 | 
|---|
 | 363 |           function_smoother(
 | 
|---|
 | 364 |               -params[B],
 | 
|---|
 | 365 |               params[mu],
 | 
|---|
 | 366 |               r_ij.distance)
 | 
|---|
| [f904d5] | 367 |           * (-.5)
 | 
|---|
 | 368 |           * function_prefactor(
 | 
|---|
 | 369 |               params[beta],
 | 
|---|
 | 370 |               function_zeta(r_ij))
 | 
|---|
 | 371 |           * (temp/params[beta])
 | 
|---|
| [ffc368] | 372 |           / (1. + temp)
 | 
|---|
 | 373 |           ;
 | 
|---|
 | 374 |       break;
 | 
|---|
 | 375 |     }
 | 
|---|
 | 376 |     case n:
 | 
|---|
 | 377 |     {
 | 
|---|
| [bc55c9] | 378 |       const double zeta = function_zeta(r_ij);
 | 
|---|
 | 379 |       const double temp = pow( params[beta]*zeta , params[n]);
 | 
|---|
| [ffc368] | 380 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [bc55c9] | 381 |       const double tempres = ((cutoff == 0.) || (zeta == 0.)) ? // zeta must be caught if zero due to log
 | 
|---|
| [f904d5] | 382 |           0. : .5 * cutoff *
 | 
|---|
| [ffc368] | 383 |           function_smoother(
 | 
|---|
 | 384 |               -params[B],
 | 
|---|
 | 385 |               params[mu],
 | 
|---|
 | 386 |               r_ij.distance)
 | 
|---|
| [f904d5] | 387 |           * function_prefactor(
 | 
|---|
 | 388 |               params[beta],
 | 
|---|
 | 389 |               function_zeta(r_ij))
 | 
|---|
| [ffc368] | 390 |           * ( log(1.+temp)/(params[n]*params[n]) - temp
 | 
|---|
 | 391 |               * (log(function_zeta(r_ij)) + log(params[beta]))
 | 
|---|
 | 392 |               /(params[n]*(1.+temp)))
 | 
|---|
 | 393 |           ;
 | 
|---|
| [bc55c9] | 394 | //      if (tempres != tempres)
 | 
|---|
 | 395 | //      LOG(2, "DEBUG: tempres is NaN."); 
 | 
|---|
 | 396 | //      LOG(2, "DEBUG: Adding " << tempres << " for p.d. w.r.t n, temp=" << temp << ", cutoff=" << cutoff);
 | 
|---|
 | 397 |       result += tempres;
 | 
|---|
| [ffc368] | 398 |       break;
 | 
|---|
 | 399 |     }
 | 
|---|
 | 400 |     case c:
 | 
|---|
 | 401 |     {
 | 
|---|
| [f904d5] | 402 |       const double zeta = function_zeta(r_ij);
 | 
|---|
| [ca8d82] | 403 |       if (zeta == 0.)
 | 
|---|
 | 404 |         break;
 | 
|---|
| [f904d5] | 405 |       const double temp =
 | 
|---|
| [ca8d82] | 406 |           pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| [f904d5] | 407 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 408 |       const double tempres = (cutoff == 0.) ?
 | 
|---|
| [ca8d82] | 409 |           0. : cutoff *
 | 
|---|
| [f904d5] | 410 |           function_smoother(
 | 
|---|
 | 411 |               -params[B],
 | 
|---|
 | 412 |               params[mu],
 | 
|---|
 | 413 |               r_ij.distance)
 | 
|---|
 | 414 |           * function_prefactor(
 | 
|---|
 | 415 |               params[beta],
 | 
|---|
 | 416 |               zeta)
 | 
|---|
| [ca8d82] | 417 |            * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
 | 418 |       double factor = function_derivative_c(r_ij);
 | 
|---|
| [2e9486] | 419 |       result += tempres*factor;
 | 
|---|
| [bc55c9] | 420 |       if (result != result)
 | 
|---|
 | 421 |         ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| [ffc368] | 422 |       break;
 | 
|---|
 | 423 |     }
 | 
|---|
 | 424 |     case d:
 | 
|---|
 | 425 |     {
 | 
|---|
| [f904d5] | 426 |       const double zeta = function_zeta(r_ij);
 | 
|---|
 | 427 |       const double temp =
 | 
|---|
| [ca8d82] | 428 |           pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| [f904d5] | 429 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 430 |       const double tempres = (cutoff == 0.) ?
 | 
|---|
| [ca8d82] | 431 |           0. : cutoff *
 | 
|---|
| [f904d5] | 432 |           function_smoother(
 | 
|---|
 | 433 |               -params[B],
 | 
|---|
 | 434 |               params[mu],
 | 
|---|
 | 435 |               r_ij.distance)
 | 
|---|
 | 436 |           * function_prefactor(
 | 
|---|
 | 437 |               params[beta],
 | 
|---|
 | 438 |               zeta)
 | 
|---|
| [ca8d82] | 439 |            * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
 | 440 |       double factor = function_derivative_d(r_ij);
 | 
|---|
| [2e9486] | 441 |       result += tempres*factor;
 | 
|---|
| [bc55c9] | 442 |       if (result != result)
 | 
|---|
 | 443 |         ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| [ffc368] | 444 |       break;
 | 
|---|
 | 445 |     }
 | 
|---|
 | 446 |     case h:
 | 
|---|
 | 447 |     {
 | 
|---|
| [f904d5] | 448 |       const double zeta = function_zeta(r_ij);
 | 
|---|
 | 449 |       const double temp =
 | 
|---|
| [ca8d82] | 450 |           pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
 | 
|---|
| [f904d5] | 451 |       const double cutoff = function_cutoff(r_ij.distance);
 | 
|---|
| [2e9486] | 452 |       const double tempres = (cutoff == 0.) ?
 | 
|---|
| [ca8d82] | 453 |           0. : cutoff *
 | 
|---|
| [f904d5] | 454 |           function_smoother(
 | 
|---|
 | 455 |               -params[B],
 | 
|---|
 | 456 |               params[mu],
 | 
|---|
 | 457 |               r_ij.distance)
 | 
|---|
 | 458 |           * function_prefactor(
 | 
|---|
 | 459 |               params[beta],
 | 
|---|
 | 460 |               zeta)
 | 
|---|
| [ca8d82] | 461 |            * (-1.) * temp / (1.+temp*zeta);
 | 
|---|
 | 462 |       double factor = function_derivative_h(r_ij);
 | 
|---|
| [2e9486] | 463 |       result += tempres*factor;
 | 
|---|
| [bc55c9] | 464 |       if (result != result)
 | 
|---|
 | 465 |         ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
 | 
|---|
| [ffc368] | 466 |       break;
 | 
|---|
 | 467 |     }
 | 
|---|
| [56c5de4] | 468 |     case offset:
 | 
|---|
 | 469 |       result += 1.;
 | 
|---|
 | 470 |       break;
 | 
|---|
| [ffc368] | 471 |     default:
 | 
|---|
 | 472 |       break;
 | 
|---|
 | 473 |   }
 | 
|---|
| [bc55c9] | 474 |   if (result != result)
 | 
|---|
 | 475 |     ELOG(1, "result is NaN.");
 | 
|---|
| [2e9486] | 476 |   }
 | 
|---|
 | 477 |   return results_t(1,-result);
 | 
|---|
| [ffc368] | 478 | }
 | 
|---|
 | 479 | 
 | 
|---|
| [ca8d82] | 480 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
 | 481 | ManyBodyPotential_Tersoff::function_derivative_c(
 | 
|---|
 | 482 |     const argument_t &r_ij
 | 
|---|
 | 483 |   ) const
 | 
|---|
 | 484 | {
 | 
|---|
 | 485 |   double result = 0.;
 | 
|---|
 | 486 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
 | 487 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
 | 488 |       iter != triples.end(); ++iter) {
 | 
|---|
 | 489 |     ASSERT( iter->size() == 2,
 | 
|---|
 | 490 |         "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
 | 
|---|
 | 491 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
 | 492 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
 | 493 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
 | 494 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
 | 495 |     result += (cutoff == 0.) ?
 | 
|---|
 | 496 |         0. : cutoff * omega * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
 | 497 |             params[c]/Helpers::pow(params[d],2)
 | 
|---|
 | 498 |             - params[c] / ( Helpers::pow(params[d],2) + Helpers::pow(tempangle,2) )
 | 
|---|
 | 499 |         );
 | 
|---|
 | 500 |   }
 | 
|---|
 | 501 |   return result;
 | 
|---|
 | 502 | }
 | 
|---|
 | 503 | 
 | 
|---|
 | 504 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
 | 505 | ManyBodyPotential_Tersoff::function_derivative_d(
 | 
|---|
 | 506 |     const argument_t &r_ij
 | 
|---|
 | 507 |   ) const
 | 
|---|
 | 508 | {
 | 
|---|
 | 509 |   double result = 0.;
 | 
|---|
 | 510 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
 | 511 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
 | 512 |       iter != triples.end(); ++iter) {
 | 
|---|
 | 513 |     ASSERT( iter->size() == 2,
 | 
|---|
 | 514 |         "ManyBodyPotential_Tersoff::function_derivative_d() - the triples result must contain exactly two distances.");
 | 
|---|
 | 515 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
 | 516 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
 | 517 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
 | 518 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
 | 519 |     result += (cutoff == 0.) ?
 | 
|---|
 | 520 |         0. : cutoff * omega  * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
 | 521 |           - Helpers::pow(params[c],2)/Helpers::pow(params[d],3)
 | 
|---|
 | 522 |           + Helpers::pow(params[c],2) * params[d]
 | 
|---|
 | 523 |             / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
 | 
|---|
 | 524 |         );
 | 
|---|
 | 525 |   }
 | 
|---|
 | 526 |   return result;
 | 
|---|
 | 527 | }
 | 
|---|
 | 528 | 
 | 
|---|
 | 529 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
 | 530 | ManyBodyPotential_Tersoff::function_derivative_h(
 | 
|---|
 | 531 |     const argument_t &r_ij
 | 
|---|
 | 532 |   ) const
 | 
|---|
 | 533 | {
 | 
|---|
 | 534 |   double result = 0.;
 | 
|---|
 | 535 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
 | 536 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
 | 537 |       iter != triples.end(); ++iter) {
 | 
|---|
 | 538 |     ASSERT( iter->size() == 2,
 | 
|---|
 | 539 |         "ManyBodyPotential_Tersoff::function_derivative_h() - the triples result must contain exactly two distances.");
 | 
|---|
 | 540 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
 | 541 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
 | 542 |     const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
 | 
|---|
 | 543 |     const double cutoff = function_cutoff(r_ik.distance);
 | 
|---|
 | 544 |     result += (cutoff == 0.) ?
 | 
|---|
 | 545 |         0. : cutoff * omega  * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
 | 
|---|
 | 546 |           ( Helpers::pow(params[c],2)*tempangle )
 | 
|---|
 | 547 |             / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
 | 
|---|
 | 548 |         );
 | 
|---|
 | 549 |   }
 | 
|---|
 | 550 |   return result;
 | 
|---|
 | 551 | }
 | 
|---|
 | 552 | 
 | 
|---|
| [4f82f8] | 553 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| [610c11] | 554 | ManyBodyPotential_Tersoff::function_cutoff(
 | 
|---|
 | 555 |     const double &distance
 | 
|---|
 | 556 |   ) const
 | 
|---|
 | 557 | {
 | 
|---|
| [ffc368] | 558 | //  Info info(__func__);
 | 
|---|
 | 559 |   double result = 0.;
 | 
|---|
| [752dc7] | 560 |   if (distance < R)
 | 
|---|
| [ffc368] | 561 |     result = 1.;
 | 
|---|
| [752dc7] | 562 |   else if (distance > S)
 | 
|---|
| [ffc368] | 563 |     result = 0.;
 | 
|---|
| [610c11] | 564 |   else {
 | 
|---|
| [752dc7] | 565 |     result = (0.5 + 0.5 * cos( M_PI * (distance - R)/(S-R)));
 | 
|---|
| [610c11] | 566 |   }
 | 
|---|
| [ffc368] | 567 | //  LOG(2, "DEBUG: function_cutoff(" << distance << ") = " << result);
 | 
|---|
 | 568 |   return result;
 | 
|---|
| [610c11] | 569 | }
 | 
|---|
 | 570 | 
 | 
|---|
| [4f82f8] | 571 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| [610c11] | 572 | ManyBodyPotential_Tersoff::function_prefactor(
 | 
|---|
 | 573 |     const double &alpha,
 | 
|---|
| [ffc368] | 574 |     const double &eta
 | 
|---|
| [610c11] | 575 |   ) const
 | 
|---|
 | 576 | {
 | 
|---|
| [ffc368] | 577 | //  Info info(__func__);
 | 
|---|
| [990a62] | 578 |   const double result = chi * pow(
 | 
|---|
| [ffc368] | 579 |       (1. + pow(alpha * eta, params[n])),
 | 
|---|
 | 580 |       -1./(2.*params[n]));
 | 
|---|
 | 581 | //  LOG(2, "DEBUG: function_prefactor(" << alpha << "," << eta << ") = " << result);
 | 
|---|
 | 582 |   return result;
 | 
|---|
 | 583 | }
 | 
|---|
 | 584 | 
 | 
|---|
 | 585 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
 | 586 | ManyBodyPotential_Tersoff::function_smoother(
 | 
|---|
 | 587 |     const double &prefactor,
 | 
|---|
 | 588 |     const double &lambda,
 | 
|---|
 | 589 |     const double &distance
 | 
|---|
 | 590 |     ) const
 | 
|---|
 | 591 | {
 | 
|---|
 | 592 | //  Info info(__func__);
 | 
|---|
 | 593 |   const double result = prefactor * exp(-lambda * distance);
 | 
|---|
 | 594 | //  LOG(2, "DEBUG: function_smoother(" << prefactor << "," << lambda << "," << distance << ") = " << result);
 | 
|---|
 | 595 |   return result;
 | 
|---|
| [610c11] | 596 | }
 | 
|---|
 | 597 | 
 | 
|---|
| [4f82f8] | 598 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| [610c11] | 599 | ManyBodyPotential_Tersoff::function_eta(
 | 
|---|
 | 600 |     const argument_t &r_ij
 | 
|---|
 | 601 |   ) const
 | 
|---|
 | 602 | {
 | 
|---|
| [ffc368] | 603 | //  Info info(__func__);
 | 
|---|
| [610c11] | 604 |   result_t result = 0.;
 | 
|---|
 | 605 | 
 | 
|---|
 | 606 |   // get all triples within the cutoff
 | 
|---|
| [752dc7] | 607 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| [610c11] | 608 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
 | 609 |       iter != triples.end(); ++iter) {
 | 
|---|
 | 610 |     ASSERT( iter->size() == 2,
 | 
|---|
 | 611 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain of exactly two distances.");
 | 
|---|
 | 612 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
 | 613 |     result += function_cutoff(r_ik.distance)
 | 
|---|
| [990a62] | 614 |         * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| [610c11] | 615 |   }
 | 
|---|
 | 616 | 
 | 
|---|
| [ffc368] | 617 | //  LOG(2, "DEBUG: function_eta(" << r_ij.distance << ") = " << result);
 | 
|---|
| [610c11] | 618 |   return result;
 | 
|---|
 | 619 | }
 | 
|---|
 | 620 | 
 | 
|---|
| [4f82f8] | 621 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| [610c11] | 622 | ManyBodyPotential_Tersoff::function_zeta(
 | 
|---|
 | 623 |     const argument_t &r_ij
 | 
|---|
 | 624 |   ) const
 | 
|---|
 | 625 | {
 | 
|---|
| [ffc368] | 626 | //  Info info(__func__);
 | 
|---|
| [610c11] | 627 |   result_t result = 0.;
 | 
|---|
 | 628 | 
 | 
|---|
 | 629 |   // get all triples within the cutoff
 | 
|---|
| [752dc7] | 630 |   std::vector<arguments_t> triples = triplefunction(r_ij, S);
 | 
|---|
| [610c11] | 631 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
 | 632 |       iter != triples.end(); ++iter) {
 | 
|---|
 | 633 |     ASSERT( iter->size() == 2,
 | 
|---|
 | 634 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain exactly two distances.");
 | 
|---|
 | 635 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
 | 636 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
 | 637 |     result +=
 | 
|---|
 | 638 |         function_cutoff(r_ik.distance)
 | 
|---|
| [990a62] | 639 |         * omega
 | 
|---|
| [610c11] | 640 |         * function_angle(r_ij.distance, r_ik.distance, r_jk.distance)
 | 
|---|
| [990a62] | 641 |         * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| [610c11] | 642 |   }
 | 
|---|
 | 643 | 
 | 
|---|
| [ffc368] | 644 | //  LOG(2, "DEBUG: function_zeta(" << r_ij.distance << ") = " << result);
 | 
|---|
| [610c11] | 645 |   return result;
 | 
|---|
 | 646 | }
 | 
|---|
 | 647 | 
 | 
|---|
| [4f82f8] | 648 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
| [f904d5] | 649 | ManyBodyPotential_Tersoff::function_theta(
 | 
|---|
| [610c11] | 650 |     const double &r_ij,
 | 
|---|
 | 651 |     const double &r_ik,
 | 
|---|
 | 652 |     const double &r_jk
 | 
|---|
 | 653 |   ) const
 | 
|---|
 | 654 | {
 | 
|---|
 | 655 |   const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_ik,2) - Helpers::pow(r_jk,2);
 | 
|---|
| [ffc368] | 656 |   const double divisor = 2.* r_ij * r_ik;
 | 
|---|
 | 657 |   if (divisor != 0.) {
 | 
|---|
| [f904d5] | 658 |     LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
 | 
|---|
 | 659 |     return angle/divisor;
 | 
|---|
| [ffc368] | 660 |   } else
 | 
|---|
 | 661 |     return 0.;
 | 
|---|
| [610c11] | 662 | }
 | 
|---|
| [ffc368] | 663 | 
 | 
|---|
| [f904d5] | 664 | ManyBodyPotential_Tersoff::result_t
 | 
|---|
 | 665 | ManyBodyPotential_Tersoff::function_angle(
 | 
|---|
 | 666 |     const double &r_ij,
 | 
|---|
 | 667 |     const double &r_ik,
 | 
|---|
 | 668 |     const double &r_jk
 | 
|---|
 | 669 |   ) const
 | 
|---|
 | 670 | {
 | 
|---|
 | 671 | //  Info info(__func__);
 | 
|---|
 | 672 |   const double result =
 | 
|---|
 | 673 |       1.
 | 
|---|
 | 674 |       + (Helpers::pow(params[c]/params[d], 2))
 | 
|---|
 | 675 |       - Helpers::pow(params[c], 2)/(Helpers::pow(params[d], 2) +
 | 
|---|
| [ca8d82] | 676 |           Helpers::pow(params[h] - function_theta(r_ij, r_ik, r_jk),2));
 | 
|---|
| [f904d5] | 677 | 
 | 
|---|
| [ca8d82] | 678 | //  LOG(2, "DEBUG: function_angle(" << r_ij << "," << r_ik << "," << r_jk << ") = " << result);
 | 
|---|
| [f904d5] | 679 |   return result;
 | 
|---|
 | 680 | }
 | 
|---|
 | 681 | 
 | 
|---|