| 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 | 
 | 
|---|
| 41 | #include <boost/bind.hpp>
 | 
|---|
| 42 | #include <cmath>
 | 
|---|
| 43 | 
 | 
|---|
| 44 | #include "CodePatterns/Assert.hpp"
 | 
|---|
| 45 | 
 | 
|---|
| 46 | #include "Potentials/helpers.hpp"
 | 
|---|
| 47 | 
 | 
|---|
| 48 | EmpiricalPotential::result_t
 | 
|---|
| 49 | ManyBodyPotential_Tersoff::operator()(
 | 
|---|
| 50 |     const arguments_t &arguments
 | 
|---|
| 51 |     ) const
 | 
|---|
| 52 | {
 | 
|---|
| 53 |   const double &distance = arguments[0].distance;
 | 
|---|
| 54 |   const double cutoff = function_cutoff(distance);
 | 
|---|
| 55 |   const double result = (cutoff == 0.) ? 0. : cutoff * (
 | 
|---|
| 56 |       function_prefactor(
 | 
|---|
| 57 |           manybodyparameter_alpha,
 | 
|---|
| 58 |           boost::bind(&ManyBodyPotential_Tersoff::function_eta,
 | 
|---|
| 59 |               boost::cref(*this),
 | 
|---|
| 60 |               boost::cref(arguments[0])))
 | 
|---|
| 61 |       * function_smoother(
 | 
|---|
| 62 |           distance,
 | 
|---|
| 63 |           manybodyparameter_A,
 | 
|---|
| 64 |           manybodyparameter_lambda1)
 | 
|---|
| 65 |       +
 | 
|---|
| 66 |       function_prefactor(
 | 
|---|
| 67 |           manybodyparameter_beta,
 | 
|---|
| 68 |           boost::bind(&ManyBodyPotential_Tersoff::function_zeta,
 | 
|---|
| 69 |               boost::cref(*this),
 | 
|---|
| 70 |               boost::cref(arguments[0])))
 | 
|---|
| 71 |       * function_smoother(
 | 
|---|
| 72 |           distance,
 | 
|---|
| 73 |           -manybodyparameter_B,
 | 
|---|
| 74 |           manybodyparameter_lambda2)
 | 
|---|
| 75 |   );
 | 
|---|
| 76 |   return result;
 | 
|---|
| 77 | }
 | 
|---|
| 78 | 
 | 
|---|
| 79 | EmpiricalPotential::result_t
 | 
|---|
| 80 | ManyBodyPotential_Tersoff::function_cutoff(
 | 
|---|
| 81 |     const double &distance
 | 
|---|
| 82 |   ) const
 | 
|---|
| 83 | {
 | 
|---|
| 84 |   const double offset = (distance - cutoff_offset);
 | 
|---|
| 85 |   if (offset < - cutoff_halfwidth)
 | 
|---|
| 86 |     return 1.;
 | 
|---|
| 87 |   else if (offset > cutoff_halfwidth)
 | 
|---|
| 88 |     return 0.;
 | 
|---|
| 89 |   else {
 | 
|---|
| 90 |     return (0.5 - 0.5 * sin( .5 * M_PI * offset/cutoff_halfwidth));
 | 
|---|
| 91 |   }
 | 
|---|
| 92 | }
 | 
|---|
| 93 | 
 | 
|---|
| 94 | EmpiricalPotential::result_t
 | 
|---|
| 95 | ManyBodyPotential_Tersoff::function_prefactor(
 | 
|---|
| 96 |     const double &alpha,
 | 
|---|
| 97 |     boost::function<result_t()> etafunction
 | 
|---|
| 98 |   ) const
 | 
|---|
| 99 | {
 | 
|---|
| 100 |   return pow(
 | 
|---|
| 101 |       (1. + Helpers::pow(alpha * etafunction(), manybodyparameter_n)),
 | 
|---|
| 102 |       -1./(2.*manybodyparameter_n));
 | 
|---|
| 103 | }
 | 
|---|
| 104 | 
 | 
|---|
| 105 | EmpiricalPotential::result_t
 | 
|---|
| 106 | ManyBodyPotential_Tersoff::function_eta(
 | 
|---|
| 107 |     const argument_t &r_ij
 | 
|---|
| 108 |   ) const
 | 
|---|
| 109 | {
 | 
|---|
| 110 |   result_t result = 0.;
 | 
|---|
| 111 | 
 | 
|---|
| 112 |   // get all triples within the cutoff
 | 
|---|
| 113 |   std::vector<arguments_t> triples = triplefunction(r_ij, cutoff_offset+cutoff_halfwidth);
 | 
|---|
| 114 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 115 |       iter != triples.end(); ++iter) {
 | 
|---|
| 116 |     ASSERT( iter->size() == 2,
 | 
|---|
| 117 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain of exactly two distances.");
 | 
|---|
| 118 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 119 |     result += function_cutoff(r_ik.distance)
 | 
|---|
| 120 |         * exp( Helpers::pow(manybodyparameter_lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| 121 |   }
 | 
|---|
| 122 | 
 | 
|---|
| 123 |   return result;
 | 
|---|
| 124 | }
 | 
|---|
| 125 | 
 | 
|---|
| 126 | EmpiricalPotential::result_t
 | 
|---|
| 127 | ManyBodyPotential_Tersoff::function_zeta(
 | 
|---|
| 128 |     const argument_t &r_ij
 | 
|---|
| 129 |   ) const
 | 
|---|
| 130 | {
 | 
|---|
| 131 |   result_t result = 0.;
 | 
|---|
| 132 | 
 | 
|---|
| 133 |   // get all triples within the cutoff
 | 
|---|
| 134 |   std::vector<arguments_t> triples = triplefunction(r_ij, cutoff_offset+cutoff_halfwidth);
 | 
|---|
| 135 |   for (std::vector<arguments_t>::const_iterator iter = triples.begin();
 | 
|---|
| 136 |       iter != triples.end(); ++iter) {
 | 
|---|
| 137 |     ASSERT( iter->size() == 2,
 | 
|---|
| 138 |         "ManyBodyPotential_Tersoff::function_zeta() - the triples result must contain exactly two distances.");
 | 
|---|
| 139 |     const argument_t &r_ik = (*iter)[0];
 | 
|---|
| 140 |     const argument_t &r_jk = (*iter)[1];
 | 
|---|
| 141 |     result +=
 | 
|---|
| 142 |         function_cutoff(r_ik.distance)
 | 
|---|
| 143 |         * function_angle(r_ij.distance, r_ik.distance, r_jk.distance)
 | 
|---|
| 144 |         * exp( Helpers::pow(manybodyparameter_lambda3 * (r_ij.distance - r_ik.distance) ,3));
 | 
|---|
| 145 |   }
 | 
|---|
| 146 | 
 | 
|---|
| 147 |   return result;
 | 
|---|
| 148 | }
 | 
|---|
| 149 | 
 | 
|---|
| 150 | EmpiricalPotential::result_t
 | 
|---|
| 151 | ManyBodyPotential_Tersoff::function_angle(
 | 
|---|
| 152 |     const double &r_ij,
 | 
|---|
| 153 |     const double &r_ik,
 | 
|---|
| 154 |     const double &r_jk
 | 
|---|
| 155 |   ) const
 | 
|---|
| 156 | {
 | 
|---|
| 157 |   const double angle = Helpers::pow(r_ij,2) + Helpers::pow(r_ik,2) - Helpers::pow(r_jk,2);
 | 
|---|
| 158 |   const double divisor = r_ij * r_ik;
 | 
|---|
| 159 |   const double result =
 | 
|---|
| 160 |       1.
 | 
|---|
| 161 |       + (Helpers::pow(manybodyparameter_c, 2)/Helpers::pow(manybodyparameter_d, 2))
 | 
|---|
| 162 |       - Helpers::pow(manybodyparameter_c, 2)/(Helpers::pow(manybodyparameter_d, 2) +
 | 
|---|
| 163 |           Helpers::pow(manybodyparameter_h - cos(angle/divisor),2));
 | 
|---|
| 164 |   return result;
 | 
|---|
| 165 | }
 | 
|---|