File: CbEam.h

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (209 lines) | stat: -rw-r--r-- 6,915 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef CBEAM_H
#define CBEAM_H

#include <iostream>
#include <cstdlib>
#include "CbPotential.h"
#include "LammpsInterface.h"
#include "MANYBODY/pair_eam.h"

namespace ATC
{

  /**
   *  @class  CbEam
   *  @brief  Class for computing Cauchy-Born quantities for an Embeded-Atom Method material
   *          (A factor of one-half is already included to split the
   *           bond energy between atoms)
   */

  class CbEam : public CbPotential
  {
  public:
    //! Constructor
    CbEam(void) : CbPotential(Interactions(PAIRWISE,EAM)) {
      // get pointer to lammps' pair_eam object
      lammps_eam = ATC::LammpsInterface::instance()->pair_eam();
      nrho  = &lammps_eam->nrho;
      nr    = &lammps_eam->nr;
      nfrho = &lammps_eam->nfrho;
      nrhor = &lammps_eam->nrhor;
      nz2r  = &lammps_eam->nz2r;
      type2frho = lammps_eam->type2frho;
      type2rhor = lammps_eam->type2rhor;
      type2z2r  = lammps_eam->type2z2r;
      dr    = &lammps_eam->dr;
      rdr   = &lammps_eam->rdr;
      drho  = &lammps_eam->drho;
      rdrho = &lammps_eam->rdrho;
      rhor_spline = &lammps_eam->rhor_spline;
      frho_spline = &lammps_eam->frho_spline;
      z2r_spline  = &lammps_eam->z2r_spline;
      cutmax = &lammps_eam->cutmax;
    }

    //! Returns the cutoff readius of the EAM potential functions rho and z2r.
    double cutoff_radius() const { return *cutmax; }
    //! Returns the EAM pair energy
    double phi(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*z2r_spline)[type2z2r[1][1]][m];
      double z2 = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6];
      return z2/r;
    }
    //! Returns the first derivative of the pair energy.
    double phi_r(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*z2r_spline)[type2z2r[1][1]][m];
      double z2 = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6];
      double z2p = (coeff[0]*p + coeff[1])*p + coeff[2];
      return (1.0/r)*(z2p-z2/r);
    }
    //! Returns the second derivative of the pair energy.
    double phi_rr(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*z2r_spline)[type2z2r[1][1]][m];
      double z2 = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6];
      double z2p = (coeff[0]*p + coeff[1])*p + coeff[2];
      double z2pp = (*rdr)*(2.0*coeff[0]*p + coeff[1]);
      return (1.0/r)*(z2pp-2.0*z2p/r+2.0*z2/(r*r));
    }
    //! Returns the third derivative of the pair energy.
    double phi_rrr(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*z2r_spline)[type2z2r[1][1]][m];
      double z2 = ((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6];
      double z2p = (coeff[0]*p + coeff[1])*p + coeff[2];
      double z2pp = (*rdr)*(2.0*coeff[0]*p + coeff[1]);
      double z2ppp = (*rdr)*(*rdr)*2.0*coeff[0];
      return (1.0/r)*(z2ppp-3.0*z2pp/r+6.0*z2p/(r*r)-6.0*z2/(r*r*r));
    }
    //! Returns the EAM atomic charge density.
    double rho(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*rhor_spline)[type2rhor[1][1]][m];
      return (((coeff[3]*p + coeff[4])*p + coeff[5])*p + coeff[6]);
    }
   //! Returns the first derivative of the atomic charge density.
    double rho_r(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*rhor_spline)[type2rhor[1][1]][m];
      return ((coeff[0]*p + coeff[1])*p + coeff[2]);
    }
    //! Returns the second derivative of the atomic charge density.
    double rho_rr(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*rhor_spline)[type2rhor[1][1]][m];
      return ((*rdr)*(2.0*coeff[0]*p + coeff[1]));
    }
    //! Returns the third derivative of the atomic charge density.
    double rho_rrr(const double &r) const
    {
      double p = r*(*rdr) + 1.0;
      int m = static_cast<int> (p);
      m = MIN(m,(*nr)-1);
      p -= m;
      p = MIN(p,1.0);
      // for now, assume itype = jtype = 1
      double *coeff = (*rhor_spline)[type2rhor[1][1]][m];
      return ((*rdr)*(*rdr)*2.0*coeff[0]);
    }
    //! Returns the EAM embedding energy.
    double F(const double &p) const
    {
      double q = p*(*rdrho) + 1.0;
      int m = static_cast<int> (q);
      m = MIN(m,(*nrho)-1);
      q -= m;
      q = MIN(q,1.0);
      // for now, assume itype = 1
      double *coeff = (*frho_spline)[type2frho[1]][m];
      return (((coeff[3]*q + coeff[4])*q + coeff[5])*q + coeff[6]);
    }
   //! Returns the first derivative of the embedding energy.
    double F_p(const double &p) const
    {
      double q = p*(*rdrho) + 1.0;
      int m = static_cast<int> (q);
      m = MIN(m,(*nrho)-1);
      q -= m;
      q = MIN(q,1.0);
      // for now, assume itype = 1
      double *coeff = (*frho_spline)[type2frho[1]][m];
      return ((coeff[0]*q + coeff[1])*q + coeff[2]);
    }
    //! Returns the second derivative of the atomic charge density.
    double F_pp(const double &p) const
    {
      double q = p*(*rdrho) + 1.0;
      int m = static_cast<int> (q);
      m = MIN(m,(*nrho)-1);
      q -= m;
      q = MIN(q,1.0);
      // for now, assume itype = 1
      double *coeff = (*frho_spline)[type2frho[1]][m];
      return ((*rdrho)*(2.0*coeff[0]*q + coeff[1]));
    }
    //! Returns the third derivative of the atomic charge density.
    double F_ppp(const double &p) const
    {
      double q = p*(*rdrho) + 1.0;
      int m = static_cast<int> (q);
      m = MIN(m,(*nrho)-1);
      q -= m;
      q = MIN(q,1.0);
      // for now, assume itype = 1
      double *coeff = (*frho_spline)[type2frho[1]][m];
      return ((*rdrho)*(*rdrho)*2.0*coeff[0]);
    }
    int *nrho,*nr,*nfrho,*nrhor,*nz2r;
    int *type2frho,**type2rhor,**type2z2r;
    double *cutmax;
    double *dr,*rdr,*drho,*rdrho;
    double ****rhor_spline,****frho_spline,****z2r_spline;
    LAMMPS_NS::PairEAM* lammps_eam;
  };
}
#endif