| [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)
|
|---|
| 89 | {}
|
|---|
| 90 |
|
|---|
| 91 | ManyBodyPotential_Tersoff::ManyBodyPotential_Tersoff(
|
|---|
| [ed2551] | 92 | const ParticleTypes_t &_ParticleTypes,
|
|---|
| [ffc368] | 93 | const double &_R,
|
|---|
| 94 | const double &_S,
|
|---|
| [e7579e] | 95 | const double &_A,
|
|---|
| 96 | const double &_B,
|
|---|
| [ffc368] | 97 | const double &_lambda,
|
|---|
| 98 | const double &_mu,
|
|---|
| [e7579e] | 99 | const double &_lambda3,
|
|---|
| 100 | const double &_alpha,
|
|---|
| 101 | const double &_beta,
|
|---|
| [ffc368] | 102 | const double &_chi,
|
|---|
| 103 | const double &_omega,
|
|---|
| [e7579e] | 104 | const double &_n,
|
|---|
| 105 | const double &_c,
|
|---|
| 106 | const double &_d,
|
|---|
| 107 | const double &_h,
|
|---|
| [56c5de4] | 108 | const double &_offset,
|
|---|
| [e7579e] | 109 | boost::function< std::vector<arguments_t>(const argument_t &, const double)> &_triplefunction) :
|
|---|
| [ed2551] | 110 | SerializablePotential(_ParticleTypes),
|
|---|
| [e7579e] | 111 | params(parameters_t(MAXPARAMS, 0.)),
|
|---|
| [752dc7] | 112 | R(_R),
|
|---|
| 113 | S(_S),
|
|---|
| [990a62] | 114 | lambda3(_lambda3),
|
|---|
| 115 | alpha(_alpha),
|
|---|
| 116 | chi(_chi),
|
|---|
| 117 | omega(_mu),
|
|---|
| [e7579e] | 118 | triplefunction(_triplefunction)
|
|---|
| 119 | {
|
|---|
| [ffc368] | 120 | // Info info(__func__);
|
|---|
| [752dc7] | 121 | // R = _R;
|
|---|
| 122 | // S = _S;
|
|---|
| [e7579e] | 123 | params[A] = _A;
|
|---|
| 124 | params[B] = _B;
|
|---|
| [ffc368] | 125 | params[lambda] = _lambda;
|
|---|
| 126 | params[mu] = _mu;
|
|---|
| [990a62] | 127 | // lambda3 = _lambda3;
|
|---|
| 128 | // alpha = _alpha;
|
|---|
| [e7579e] | 129 | params[beta] = _beta;
|
|---|
| [990a62] | 130 | // chi = _chi;
|
|---|
| 131 | // omega = _omega;
|
|---|
| [e7579e] | 132 | params[n] = _n;
|
|---|
| 133 | params[c] = _c;
|
|---|
| 134 | params[d] = _d;
|
|---|
| 135 | params[h] = _h;
|
|---|
| [56c5de4] | 136 | params[offset] = _offset;
|
|---|
| [e7579e] | 137 | }
|
|---|
| 138 |
|
|---|
| [086070] | 139 | void ManyBodyPotential_Tersoff::setParameters(const parameters_t &_params)
|
|---|
| 140 | {
|
|---|
| 141 | const size_t paramsDim = _params.size();
|
|---|
| 142 | ASSERT( paramsDim <= getParameterDimension(),
|
|---|
| 143 | "ManyBodyPotential_Tersoff::setParameters() - we need not more than "
|
|---|
| 144 | +toString(getParameterDimension())+" parameters.");
|
|---|
| 145 | for (size_t i=0; i< paramsDim; ++i)
|
|---|
| 146 | params[i] = _params[i];
|
|---|
| 147 |
|
|---|
| 148 | #ifndef NDEBUG
|
|---|
| 149 | parameters_t check_params(getParameters());
|
|---|
| 150 | check_params.resize(paramsDim); // truncate to same size
|
|---|
| 151 | ASSERT( check_params == _params,
|
|---|
| 152 | "ManyBodyPotential_Tersoff::setParameters() - failed, mismatch in to be set "
|
|---|
| 153 | +toString(_params)+" and set "+toString(check_params)+" params.");
|
|---|
| 154 | #endif
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| [4f82f8] | 157 | ManyBodyPotential_Tersoff::results_t
|
|---|
| [610c11] | 158 | ManyBodyPotential_Tersoff::operator()(
|
|---|
| 159 | const arguments_t &arguments
|
|---|
| 160 | ) const
|
|---|
| 161 | {
|
|---|
| [ffc368] | 162 | // Info info(__func__);
|
|---|
| [2e9486] | 163 | double result = 0.;
|
|---|
| 164 | for(arguments_t::const_iterator argiter = arguments.begin();
|
|---|
| 165 | argiter != arguments.end();
|
|---|
| 166 | ++argiter) {
|
|---|
| 167 | const argument_t &r_ij = *argiter;
|
|---|
| [b760bc3] | 168 | ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
|
|---|
| 169 | arguments_t(1, r_ij), getParticleTypes()),
|
|---|
| 170 | "ManyBodyPotential_Tersoff::operator() - types don't match with ones in arguments.");
|
|---|
| 171 |
|
|---|
| [2e9486] | 172 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| 173 | const double temp = (cutoff == 0.) ?
|
|---|
| 174 | 0. :
|
|---|
| 175 | cutoff * (
|
|---|
| 176 | function_prefactor(
|
|---|
| 177 | alpha,
|
|---|
| 178 | function_eta(r_ij))
|
|---|
| 179 | * function_smoother(
|
|---|
| 180 | params[A],
|
|---|
| 181 | params[lambda],
|
|---|
| 182 | r_ij.distance)
|
|---|
| 183 | +
|
|---|
| 184 | function_prefactor(
|
|---|
| 185 | params[beta],
|
|---|
| 186 | function_zeta(r_ij))
|
|---|
| 187 | * function_smoother(
|
|---|
| 188 | -params[B],
|
|---|
| 189 | params[mu],
|
|---|
| 190 | r_ij.distance)
|
|---|
| 191 | );
|
|---|
| 192 | result += temp;
|
|---|
| 193 | }
|
|---|
| [ffc368] | 194 | // LOG(2, "DEBUG: operator()(" << r_ij.distance << ") = " << result);
|
|---|
| [56c5de4] | 195 | return std::vector<result_t>(1, params[offset]+result);
|
|---|
| [610c11] | 196 | }
|
|---|
| 197 |
|
|---|
| [ffc368] | 198 | ManyBodyPotential_Tersoff::derivative_components_t
|
|---|
| 199 | ManyBodyPotential_Tersoff::derivative(
|
|---|
| 200 | const arguments_t &arguments
|
|---|
| 201 | ) const
|
|---|
| 202 | {
|
|---|
| 203 | // Info info(__func__);
|
|---|
| 204 | return ManyBodyPotential_Tersoff::derivative_components_t();
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | ManyBodyPotential_Tersoff::results_t
|
|---|
| 208 | ManyBodyPotential_Tersoff::parameter_derivative(
|
|---|
| 209 | const arguments_t &arguments,
|
|---|
| 210 | const size_t index
|
|---|
| 211 | ) const
|
|---|
| 212 | {
|
|---|
| 213 | // Info info(__func__);
|
|---|
| 214 | // ASSERT( arguments.size() == 1,
|
|---|
| [2e9486] | 215 | // "ManyBodyPotential_Tersoff::parameter_derivative() - requires exactly one argument.");
|
|---|
| [56c5de4] | 216 | if (index == offset)
|
|---|
| 217 | return results_t(1, 1.);
|
|---|
| 218 |
|
|---|
| [2e9486] | 219 | double result = 0.;
|
|---|
| 220 | for(arguments_t::const_iterator argiter = arguments.begin();
|
|---|
| 221 | argiter != arguments.end();
|
|---|
| 222 | ++argiter) {
|
|---|
| 223 | const argument_t &r_ij = *argiter;
|
|---|
| [b760bc3] | 224 | ASSERT( ParticleTypeChecker::checkArgumentsAgainstParticleTypes(
|
|---|
| 225 | arguments_t(1, r_ij), getParticleTypes()),
|
|---|
| 226 | "ManyBodyPotential_Tersoff::operator() - types don't match with ones in arguments.");
|
|---|
| [55fe788] | 227 |
|
|---|
| [ffc368] | 228 | switch (index) {
|
|---|
| [752dc7] | 229 | // case R:
|
|---|
| 230 | // {
|
|---|
| [2e9486] | 231 | // result += 0.;
|
|---|
| [752dc7] | 232 | // break;
|
|---|
| 233 | // }
|
|---|
| 234 | // case S:
|
|---|
| 235 | // {
|
|---|
| [2e9486] | 236 | // result += 0.;
|
|---|
| [752dc7] | 237 | // break;
|
|---|
| 238 | // }
|
|---|
| [ffc368] | 239 | case A:
|
|---|
| 240 | {
|
|---|
| [ca8d82] | 241 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 242 | result += (cutoff == 0.) ?
|
|---|
| [ca8d82] | 243 | 0. :
|
|---|
| 244 | cutoff *
|
|---|
| 245 | function_prefactor(
|
|---|
| 246 | alpha,
|
|---|
| 247 | function_eta(r_ij))
|
|---|
| 248 | * function_smoother(
|
|---|
| 249 | 1.,
|
|---|
| 250 | params[lambda],
|
|---|
| 251 | r_ij.distance);
|
|---|
| 252 | // cutoff * function_prefactor(
|
|---|
| 253 | // alpha,
|
|---|
| 254 | // function_eta(r_ij))
|
|---|
| 255 | // * function_smoother(
|
|---|
| 256 | // 1.,
|
|---|
| 257 | // params[mu],
|
|---|
| 258 | // r_ij.distance);
|
|---|
| [ffc368] | 259 | break;
|
|---|
| 260 | }
|
|---|
| 261 | case B:
|
|---|
| 262 | {
|
|---|
| [ca8d82] | 263 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 264 | result += (cutoff == 0.) ?
|
|---|
| [ca8d82] | 265 | 0. :
|
|---|
| 266 | cutoff * function_prefactor(
|
|---|
| 267 | params[beta],
|
|---|
| 268 | function_zeta(r_ij))
|
|---|
| 269 | * function_smoother(
|
|---|
| 270 | -1.,
|
|---|
| 271 | params[mu],
|
|---|
| 272 | r_ij.distance);
|
|---|
| 273 | // cutoff * function_prefactor(
|
|---|
| 274 | // beta,
|
|---|
| 275 | // function_zeta(r_ij))
|
|---|
| 276 | // * function_smoother(
|
|---|
| 277 | // -params[B],
|
|---|
| 278 | // params[mu],
|
|---|
| 279 | // r_ij.distance)/params[B];
|
|---|
| [ffc368] | 280 | break;
|
|---|
| 281 | }
|
|---|
| 282 | case lambda:
|
|---|
| 283 | {
|
|---|
| 284 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 285 | result += (cutoff == 0.) ?
|
|---|
| [ffc368] | 286 | 0. :
|
|---|
| [ca8d82] | 287 | -r_ij.distance * cutoff *
|
|---|
| 288 | function_prefactor(
|
|---|
| 289 | alpha,
|
|---|
| 290 | function_eta(r_ij))
|
|---|
| 291 | * function_smoother(
|
|---|
| 292 | params[A],
|
|---|
| 293 | params[lambda],
|
|---|
| 294 | r_ij.distance);
|
|---|
| [ffc368] | 295 | break;
|
|---|
| 296 | }
|
|---|
| 297 | case mu:
|
|---|
| 298 | {
|
|---|
| 299 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 300 | result += (cutoff == 0.) ?
|
|---|
| [ffc368] | 301 | 0. :
|
|---|
| [f904d5] | 302 | -r_ij.distance * cutoff *(
|
|---|
| [ffc368] | 303 | function_prefactor(
|
|---|
| 304 | params[beta],
|
|---|
| 305 | function_zeta(r_ij))
|
|---|
| 306 | * function_smoother(
|
|---|
| 307 | -params[B],
|
|---|
| 308 | params[mu],
|
|---|
| 309 | r_ij.distance)
|
|---|
| 310 | );
|
|---|
| 311 | break;
|
|---|
| 312 | }
|
|---|
| [990a62] | 313 | // case lambda3:
|
|---|
| 314 | // {
|
|---|
| [2e9486] | 315 | // result += 0.;
|
|---|
| [990a62] | 316 | // break;
|
|---|
| 317 | // }
|
|---|
| 318 | // case alpha:
|
|---|
| 319 | // {
|
|---|
| 320 | // const double temp =
|
|---|
| 321 | // pow(alpha*function_eta(r_ij), params[n]);
|
|---|
| 322 | // const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 323 | // result += (cutoff == 0.) || (alpha == 0. )?
|
|---|
| [990a62] | 324 | // 0. :
|
|---|
| 325 | // function_smoother(
|
|---|
| [ca8d82] | 326 | // params[A],
|
|---|
| [990a62] | 327 | // params[lambda],
|
|---|
| 328 | // r_ij.distance)
|
|---|
| 329 | // * (-.5) * alpha * (temp/alpha)
|
|---|
| 330 | // / (1. + temp)
|
|---|
| 331 | // ;
|
|---|
| 332 | // break;
|
|---|
| 333 | // }
|
|---|
| 334 | // case chi:
|
|---|
| 335 | // {
|
|---|
| [2e9486] | 336 | // result += 0.;
|
|---|
| [990a62] | 337 | // break;
|
|---|
| 338 | // }
|
|---|
| 339 | // case omega:
|
|---|
| 340 | // {
|
|---|
| [2e9486] | 341 | // result += 0.;
|
|---|
| [990a62] | 342 | // break;
|
|---|
| 343 | // }
|
|---|
| [ffc368] | 344 | case beta:
|
|---|
| 345 | {
|
|---|
| 346 | const double temp =
|
|---|
| 347 | pow(params[beta]*function_zeta(r_ij), params[n]);
|
|---|
| 348 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 349 | result += (cutoff == 0.) || (params[beta] == 0. )?
|
|---|
| [ffc368] | 350 | 0. : cutoff *
|
|---|
| 351 | function_smoother(
|
|---|
| 352 | -params[B],
|
|---|
| 353 | params[mu],
|
|---|
| 354 | r_ij.distance)
|
|---|
| [f904d5] | 355 | * (-.5)
|
|---|
| 356 | * function_prefactor(
|
|---|
| 357 | params[beta],
|
|---|
| 358 | function_zeta(r_ij))
|
|---|
| 359 | * (temp/params[beta])
|
|---|
| [ffc368] | 360 | / (1. + temp)
|
|---|
| 361 | ;
|
|---|
| 362 | break;
|
|---|
| 363 | }
|
|---|
| 364 | case n:
|
|---|
| 365 | {
|
|---|
| [bc55c9] | 366 | const double zeta = function_zeta(r_ij);
|
|---|
| 367 | const double temp = pow( params[beta]*zeta , params[n]);
|
|---|
| [ffc368] | 368 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [bc55c9] | 369 | const double tempres = ((cutoff == 0.) || (zeta == 0.)) ? // zeta must be caught if zero due to log
|
|---|
| [f904d5] | 370 | 0. : .5 * cutoff *
|
|---|
| [ffc368] | 371 | function_smoother(
|
|---|
| 372 | -params[B],
|
|---|
| 373 | params[mu],
|
|---|
| 374 | r_ij.distance)
|
|---|
| [f904d5] | 375 | * function_prefactor(
|
|---|
| 376 | params[beta],
|
|---|
| 377 | function_zeta(r_ij))
|
|---|
| [ffc368] | 378 | * ( log(1.+temp)/(params[n]*params[n]) - temp
|
|---|
| 379 | * (log(function_zeta(r_ij)) + log(params[beta]))
|
|---|
| 380 | /(params[n]*(1.+temp)))
|
|---|
| 381 | ;
|
|---|
| [bc55c9] | 382 | // if (tempres != tempres)
|
|---|
| 383 | // LOG(2, "DEBUG: tempres is NaN.");
|
|---|
| 384 | // LOG(2, "DEBUG: Adding " << tempres << " for p.d. w.r.t n, temp=" << temp << ", cutoff=" << cutoff);
|
|---|
| 385 | result += tempres;
|
|---|
| [ffc368] | 386 | break;
|
|---|
| 387 | }
|
|---|
| 388 | case c:
|
|---|
| 389 | {
|
|---|
| [f904d5] | 390 | const double zeta = function_zeta(r_ij);
|
|---|
| [ca8d82] | 391 | if (zeta == 0.)
|
|---|
| 392 | break;
|
|---|
| [f904d5] | 393 | const double temp =
|
|---|
| [ca8d82] | 394 | pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
|
|---|
| [f904d5] | 395 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 396 | const double tempres = (cutoff == 0.) ?
|
|---|
| [ca8d82] | 397 | 0. : cutoff *
|
|---|
| [f904d5] | 398 | function_smoother(
|
|---|
| 399 | -params[B],
|
|---|
| 400 | params[mu],
|
|---|
| 401 | r_ij.distance)
|
|---|
| 402 | * function_prefactor(
|
|---|
| 403 | params[beta],
|
|---|
| 404 | zeta)
|
|---|
| [ca8d82] | 405 | * (-1.) * temp / (1.+temp*zeta);
|
|---|
| 406 | double factor = function_derivative_c(r_ij);
|
|---|
| [2e9486] | 407 | result += tempres*factor;
|
|---|
| [bc55c9] | 408 | if (result != result)
|
|---|
| 409 | ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
|
|---|
| [ffc368] | 410 | break;
|
|---|
| 411 | }
|
|---|
| 412 | case d:
|
|---|
| 413 | {
|
|---|
| [f904d5] | 414 | const double zeta = function_zeta(r_ij);
|
|---|
| 415 | const double temp =
|
|---|
| [ca8d82] | 416 | pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
|
|---|
| [f904d5] | 417 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 418 | const double tempres = (cutoff == 0.) ?
|
|---|
| [ca8d82] | 419 | 0. : cutoff *
|
|---|
| [f904d5] | 420 | function_smoother(
|
|---|
| 421 | -params[B],
|
|---|
| 422 | params[mu],
|
|---|
| 423 | r_ij.distance)
|
|---|
| 424 | * function_prefactor(
|
|---|
| 425 | params[beta],
|
|---|
| 426 | zeta)
|
|---|
| [ca8d82] | 427 | * (-1.) * temp / (1.+temp*zeta);
|
|---|
| 428 | double factor = function_derivative_d(r_ij);
|
|---|
| [2e9486] | 429 | result += tempres*factor;
|
|---|
| [bc55c9] | 430 | if (result != result)
|
|---|
| 431 | ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
|
|---|
| [ffc368] | 432 | break;
|
|---|
| 433 | }
|
|---|
| 434 | case h:
|
|---|
| 435 | {
|
|---|
| [f904d5] | 436 | const double zeta = function_zeta(r_ij);
|
|---|
| 437 | const double temp =
|
|---|
| [ca8d82] | 438 | pow(zeta, params[n]-1.) * pow(params[beta],params[n]);
|
|---|
| [f904d5] | 439 | const double cutoff = function_cutoff(r_ij.distance);
|
|---|
| [2e9486] | 440 | const double tempres = (cutoff == 0.) ?
|
|---|
| [ca8d82] | 441 | 0. : cutoff *
|
|---|
| [f904d5] | 442 | function_smoother(
|
|---|
| 443 | -params[B],
|
|---|
| 444 | params[mu],
|
|---|
| 445 | r_ij.distance)
|
|---|
| 446 | * function_prefactor(
|
|---|
| 447 | params[beta],
|
|---|
| 448 | zeta)
|
|---|
| [ca8d82] | 449 | * (-1.) * temp / (1.+temp*zeta);
|
|---|
| 450 | double factor = function_derivative_h(r_ij);
|
|---|
| [2e9486] | 451 | result += tempres*factor;
|
|---|
| [bc55c9] | 452 | if (result != result)
|
|---|
| 453 | ELOG(1, "result is NaN, zeta=" << zeta << ", temp=" << temp << ", cutoff=" << cutoff << ", tempres=" << tempres << ", factor=" << factor);
|
|---|
| [ffc368] | 454 | break;
|
|---|
| 455 | }
|
|---|
| [56c5de4] | 456 | case offset:
|
|---|
| 457 | result += 1.;
|
|---|
| 458 | break;
|
|---|
| [ffc368] | 459 | default:
|
|---|
| 460 | break;
|
|---|
| 461 | }
|
|---|
| [bc55c9] | 462 | if (result != result)
|
|---|
| 463 | ELOG(1, "result is NaN.");
|
|---|
| [2e9486] | 464 | }
|
|---|
| 465 | return results_t(1,-result);
|
|---|
| [ffc368] | 466 | }
|
|---|
| 467 |
|
|---|
| [ca8d82] | 468 | ManyBodyPotential_Tersoff::result_t
|
|---|
| 469 | ManyBodyPotential_Tersoff::function_derivative_c(
|
|---|
| 470 | const argument_t &r_ij
|
|---|
| 471 | ) const
|
|---|
| 472 | {
|
|---|
| 473 | double result = 0.;
|
|---|
| 474 | std::vector<arguments_t> triples = triplefunction(r_ij, S);
|
|---|
| 475 | for (std::vector<arguments_t>::const_iterator iter = triples.begin();
|
|---|
| 476 | iter != triples.end(); ++iter) {
|
|---|
| 477 | ASSERT( iter->size() == 2,
|
|---|
| 478 | "ManyBodyPotential_Tersoff::function_derivative_c() - the triples result must contain exactly two distances.");
|
|---|
| 479 | const argument_t &r_ik = (*iter)[0];
|
|---|
| 480 | const argument_t &r_jk = (*iter)[1];
|
|---|
| 481 | const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
|
|---|
| 482 | const double cutoff = function_cutoff(r_ik.distance);
|
|---|
| 483 | result += (cutoff == 0.) ?
|
|---|
| 484 | 0. : cutoff * omega * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
|
|---|
| 485 | params[c]/Helpers::pow(params[d],2)
|
|---|
| 486 | - params[c] / ( Helpers::pow(params[d],2) + Helpers::pow(tempangle,2) )
|
|---|
| 487 | );
|
|---|
| 488 | }
|
|---|
| 489 | return result;
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | ManyBodyPotential_Tersoff::result_t
|
|---|
| 493 | ManyBodyPotential_Tersoff::function_derivative_d(
|
|---|
| 494 | const argument_t &r_ij
|
|---|
| 495 | ) const
|
|---|
| 496 | {
|
|---|
| 497 | double result = 0.;
|
|---|
| 498 | std::vector<arguments_t> triples = triplefunction(r_ij, S);
|
|---|
| 499 | for (std::vector<arguments_t>::const_iterator iter = triples.begin();
|
|---|
| 500 | iter != triples.end(); ++iter) {
|
|---|
| 501 | ASSERT( iter->size() == 2,
|
|---|
| 502 | "ManyBodyPotential_Tersoff::function_derivative_d() - the triples result must contain exactly two distances.");
|
|---|
| 503 | const argument_t &r_ik = (*iter)[0];
|
|---|
| 504 | const argument_t &r_jk = (*iter)[1];
|
|---|
| 505 | const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
|
|---|
| 506 | const double cutoff = function_cutoff(r_ik.distance);
|
|---|
| 507 | result += (cutoff == 0.) ?
|
|---|
| 508 | 0. : cutoff * omega * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
|
|---|
| 509 | - Helpers::pow(params[c],2)/Helpers::pow(params[d],3)
|
|---|
| 510 | + Helpers::pow(params[c],2) * params[d]
|
|---|
| 511 | / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
|
|---|
| 512 | );
|
|---|
| 513 | }
|
|---|
| 514 | return result;
|
|---|
| 515 | }
|
|---|
| 516 |
|
|---|
| 517 | ManyBodyPotential_Tersoff::result_t
|
|---|
| 518 | ManyBodyPotential_Tersoff::function_derivative_h(
|
|---|
| 519 | const argument_t &r_ij
|
|---|
| 520 | ) const
|
|---|
| 521 | {
|
|---|
| 522 | double result = 0.;
|
|---|
| 523 | std::vector<arguments_t> triples = triplefunction(r_ij, S);
|
|---|
| 524 | for (std::vector<arguments_t>::const_iterator iter = triples.begin();
|
|---|
| 525 | iter != triples.end(); ++iter) {
|
|---|
| 526 | ASSERT( iter->size() == 2,
|
|---|
| 527 | "ManyBodyPotential_Tersoff::function_derivative_h() - the triples result must contain exactly two distances.");
|
|---|
| 528 | const argument_t &r_ik = (*iter)[0];
|
|---|
| 529 | const argument_t &r_jk = (*iter)[1];
|
|---|
| 530 | const double tempangle = params[h] - function_theta(r_ij.distance, r_ik.distance, r_jk.distance);
|
|---|
| 531 | const double cutoff = function_cutoff(r_ik.distance);
|
|---|
| 532 | result += (cutoff == 0.) ?
|
|---|
| 533 | 0. : cutoff * omega * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3)) * (
|
|---|
| 534 | ( Helpers::pow(params[c],2)*tempangle )
|
|---|
| 535 | / Helpers::pow(Helpers::pow(params[d],2) + Helpers::pow(tempangle,2),2)
|
|---|
| 536 | );
|
|---|
| 537 | }
|
|---|
| 538 | return result;
|
|---|
| 539 | }
|
|---|
| 540 |
|
|---|
| [4f82f8] | 541 | ManyBodyPotential_Tersoff::result_t
|
|---|
| [610c11] | 542 | ManyBodyPotential_Tersoff::function_cutoff(
|
|---|
| 543 | const double &distance
|
|---|
| 544 | ) const
|
|---|
| 545 | {
|
|---|
| [ffc368] | 546 | // Info info(__func__);
|
|---|
| 547 | double result = 0.;
|
|---|
| [752dc7] | 548 | if (distance < R)
|
|---|
| [ffc368] | 549 | result = 1.;
|
|---|
| [752dc7] | 550 | else if (distance > S)
|
|---|
| [ffc368] | 551 | result = 0.;
|
|---|
| [610c11] | 552 | else {
|
|---|
| [752dc7] | 553 | result = (0.5 + 0.5 * cos( M_PI * (distance - R)/(S-R)));
|
|---|
| [610c11] | 554 | }
|
|---|
| [ffc368] | 555 | // LOG(2, "DEBUG: function_cutoff(" << distance << ") = " << result);
|
|---|
| 556 | return result;
|
|---|
| [610c11] | 557 | }
|
|---|
| 558 |
|
|---|
| [4f82f8] | 559 | ManyBodyPotential_Tersoff::result_t
|
|---|
| [610c11] | 560 | ManyBodyPotential_Tersoff::function_prefactor(
|
|---|
| 561 | const double &alpha,
|
|---|
| [ffc368] | 562 | const double &eta
|
|---|
| [610c11] | 563 | ) const
|
|---|
| 564 | {
|
|---|
| [ffc368] | 565 | // Info info(__func__);
|
|---|
| [990a62] | 566 | const double result = chi * pow(
|
|---|
| [ffc368] | 567 | (1. + pow(alpha * eta, params[n])),
|
|---|
| 568 | -1./(2.*params[n]));
|
|---|
| 569 | // LOG(2, "DEBUG: function_prefactor(" << alpha << "," << eta << ") = " << result);
|
|---|
| 570 | return result;
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | ManyBodyPotential_Tersoff::result_t
|
|---|
| 574 | ManyBodyPotential_Tersoff::function_smoother(
|
|---|
| 575 | const double &prefactor,
|
|---|
| 576 | const double &lambda,
|
|---|
| 577 | const double &distance
|
|---|
| 578 | ) const
|
|---|
| 579 | {
|
|---|
| 580 | // Info info(__func__);
|
|---|
| 581 | const double result = prefactor * exp(-lambda * distance);
|
|---|
| 582 | // LOG(2, "DEBUG: function_smoother(" << prefactor << "," << lambda << "," << distance << ") = " << result);
|
|---|
| 583 | return result;
|
|---|
| [610c11] | 584 | }
|
|---|
| 585 |
|
|---|
| [4f82f8] | 586 | ManyBodyPotential_Tersoff::result_t
|
|---|
| [610c11] | 587 | ManyBodyPotential_Tersoff::function_eta(
|
|---|
| 588 | const argument_t &r_ij
|
|---|
| 589 | ) const
|
|---|
| 590 | {
|
|---|
| [ffc368] | 591 | // Info info(__func__);
|
|---|
| [610c11] | 592 | result_t result = 0.;
|
|---|
| 593 |
|
|---|
| 594 | // get all triples within the cutoff
|
|---|
| [752dc7] | 595 | std::vector<arguments_t> triples = triplefunction(r_ij, S);
|
|---|
| [610c11] | 596 | for (std::vector<arguments_t>::const_iterator iter = triples.begin();
|
|---|
| 597 | iter != triples.end(); ++iter) {
|
|---|
| 598 | ASSERT( iter->size() == 2,
|
|---|
| 599 | "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain of exactly two distances.");
|
|---|
| 600 | const argument_t &r_ik = (*iter)[0];
|
|---|
| 601 | result += function_cutoff(r_ik.distance)
|
|---|
| [990a62] | 602 | * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
|
|---|
| [610c11] | 603 | }
|
|---|
| 604 |
|
|---|
| [ffc368] | 605 | // LOG(2, "DEBUG: function_eta(" << r_ij.distance << ") = " << result);
|
|---|
| [610c11] | 606 | return result;
|
|---|
| 607 | }
|
|---|
| 608 |
|
|---|
| [4f82f8] | 609 | ManyBodyPotential_Tersoff::result_t
|
|---|
| [610c11] | 610 | ManyBodyPotential_Tersoff::function_zeta(
|
|---|
| 611 | const argument_t &r_ij
|
|---|
| 612 | ) const
|
|---|
| 613 | {
|
|---|
| [ffc368] | 614 | // Info info(__func__);
|
|---|
| [610c11] | 615 | result_t result = 0.;
|
|---|
| 616 |
|
|---|
| 617 | // get all triples within the cutoff
|
|---|
| [752dc7] | 618 | std::vector<arguments_t> triples = triplefunction(r_ij, S);
|
|---|
| [610c11] | 619 | for (std::vector<arguments_t>::const_iterator iter = triples.begin();
|
|---|
| 620 | iter != triples.end(); ++iter) {
|
|---|
| 621 | ASSERT( iter->size() == 2,
|
|---|
| 622 | "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain exactly two distances.");
|
|---|
| 623 | const argument_t &r_ik = (*iter)[0];
|
|---|
| 624 | const argument_t &r_jk = (*iter)[1];
|
|---|
| 625 | result +=
|
|---|
| 626 | function_cutoff(r_ik.distance)
|
|---|
| [990a62] | 627 | * omega
|
|---|
| [610c11] | 628 | * function_angle(r_ij.distance, r_ik.distance, r_jk.distance)
|
|---|
| [990a62] | 629 | * exp( Helpers::pow(lambda3 * (r_ij.distance - r_ik.distance) ,3));
|
|---|
| [610c11] | 630 | }
|
|---|
| 631 |
|
|---|
| [ffc368] | 632 | // LOG(2, "DEBUG: function_zeta(" << r_ij.distance << ") = " << result);
|
|---|
| [610c11] | 633 | return result;
|
|---|
| 634 | }
|
|---|
| 635 |
|
|---|
| [4f82f8] | 636 | ManyBodyPotential_Tersoff::result_t
|
|---|
| [f904d5] | 637 | ManyBodyPotential_Tersoff::function_theta(
|
|---|
| [610c11] | 638 | const double &r_ij,
|
|---|
| 639 | const double &r_ik,
|
|---|
| 640 | const double &r_jk
|
|---|
| 641 | ) const
|
|---|
| 642 | {
|
|---|
| 643 | const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_ik,2) - Helpers::pow(r_jk,2);
|
|---|
| [ffc368] | 644 | const double divisor = 2.* r_ij * r_ik;
|
|---|
| 645 | if (divisor != 0.) {
|
|---|
| [f904d5] | 646 | LOG(2, "DEBUG: cos(theta)= " << angle/divisor);
|
|---|
| 647 | return angle/divisor;
|
|---|
| [ffc368] | 648 | } else
|
|---|
| 649 | return 0.;
|
|---|
| [610c11] | 650 | }
|
|---|
| [ffc368] | 651 |
|
|---|
| [f904d5] | 652 | ManyBodyPotential_Tersoff::result_t
|
|---|
| 653 | ManyBodyPotential_Tersoff::function_angle(
|
|---|
| 654 | const double &r_ij,
|
|---|
| 655 | const double &r_ik,
|
|---|
| 656 | const double &r_jk
|
|---|
| 657 | ) const
|
|---|
| 658 | {
|
|---|
| 659 | // Info info(__func__);
|
|---|
| 660 | const double result =
|
|---|
| 661 | 1.
|
|---|
| 662 | + (Helpers::pow(params[c]/params[d], 2))
|
|---|
| 663 | - Helpers::pow(params[c], 2)/(Helpers::pow(params[d], 2) +
|
|---|
| [ca8d82] | 664 | Helpers::pow(params[h] - function_theta(r_ij, r_ik, r_jk),2));
|
|---|
| [f904d5] | 665 |
|
|---|
| [ca8d82] | 666 | // LOG(2, "DEBUG: function_angle(" << r_ij << "," << r_ik << "," << r_jk << ") = " << result);
|
|---|
| [f904d5] | 667 | return result;
|
|---|
| 668 | }
|
|---|
| 669 |
|
|---|