git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@4528 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2010-08-19 22:59:20 +00:00
parent 41d9b859e4
commit f4f39a21d8
5 changed files with 2492 additions and 0 deletions

View File

@ -5,7 +5,9 @@
if (test $1 = 1) then if (test $1 = 1) then
cp fix_qeq.cpp ..
cp pair_airebo.cpp .. cp pair_airebo.cpp ..
cp pair_comb.cpp ..
cp pair_eam.cpp .. cp pair_eam.cpp ..
cp pair_eam_alloy.cpp .. cp pair_eam_alloy.cpp ..
cp pair_eam_fs.cpp .. cp pair_eam_fs.cpp ..
@ -13,7 +15,9 @@ if (test $1 = 1) then
cp pair_tersoff.cpp .. cp pair_tersoff.cpp ..
cp pair_tersoff_zbl.cpp .. cp pair_tersoff_zbl.cpp ..
cp fix_qeq.h ..
cp pair_airebo.h .. cp pair_airebo.h ..
cp pair_comb.h ..
cp pair_eam.h .. cp pair_eam.h ..
cp pair_eam_alloy.h .. cp pair_eam_alloy.h ..
cp pair_eam_fs.h .. cp pair_eam_fs.h ..
@ -27,7 +31,9 @@ if (test $1 = 1) then
elif (test $1 = 0) then elif (test $1 = 0) then
rm ../fix_qeq.cpp
rm ../pair_airebo.cpp rm ../pair_airebo.cpp
rm ../pair_comb.cpp
rm ../pair_eam.cpp rm ../pair_eam.cpp
rm ../pair_eam_alloy.cpp rm ../pair_eam_alloy.cpp
rm ../pair_eam_fs.cpp rm ../pair_eam_fs.cpp
@ -35,7 +41,9 @@ elif (test $1 = 0) then
rm ../pair_tersoff.cpp rm ../pair_tersoff.cpp
rm ../pair_tersoff_zbl.cpp rm ../pair_tersoff_zbl.cpp
rm ../pair_qeq.h
rm ../pair_airebo.h rm ../pair_airebo.h
rm ../pair_comb.h
rm ../pair_eam.h rm ../pair_eam.h
rm ../pair_eam_alloy.h rm ../pair_eam_alloy.h
rm ../pair_eam_fs.h rm ../pair_eam_fs.h

248
src/MANYBODY/fix_qeq.cpp Normal file
View File

@ -0,0 +1,248 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Tzu-Ray Shan (U Florida, rayshan@ufl.edu)
------------------------------------------------------------------------- */
#include "mpi.h"
#include "math.h"
#include "stdlib.h"
#include "string.h"
#include "fix_qeq.h"
#include "atom.h"
#include "force.h"
#include "group.h"
#include "respa.h"
#include "pair_comb.h"
#include "update.h"
#include "memory.h"
#include "error.h"
using namespace LAMMPS_NS;
#define MIN(A,B) ((A) < (B)) ? (A) : (B)
#define MAX(A,B) ((A) > (B)) ? (A) : (B)
/* ---------------------------------------------------------------------- */
FixQEQ::FixQEQ(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg)
{
if (narg < 5) error->all("Illegal fix qeq command");
peratom_flag = 1;
size_peratom_cols = 0;
peratom_freq = 1;
nevery = force->inumeric(arg[3]);
precision = force->numeric(arg[4]);
if (nevery <= 0 || precision <= 0.0) error->all("Illegal fix qeq command");
MPI_Comm_rank(world,&me);
// optional args
fp = NULL;
int iarg = 5;
while (iarg < narg) {
if (strcmp(arg[iarg],"file") == 0) {
if (iarg+2 > narg) error->all("Illegal fix qeq command");
if (me == 0) {
fp = fopen(arg[iarg+1],"w");
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open fix qeq file %s",arg[iarg+1]);
error->one(str);
}
}
iarg += 2;
} else error->all("Illegal fix qeq command");
}
nmax = atom->nmax;
qf = (double *) memory->smalloc(nmax*sizeof(double),"qeq:qf");
q1 = (double *) memory->smalloc(nmax*sizeof(double),"qeq:q1");
q2 = (double *) memory->smalloc(nmax*sizeof(double),"qeq:q2");
vector_atom = qf;
// zero the vector since dump may access it on timestep 0
// zero the vector since a variable may access it before first run
int nlocal = atom->nlocal;
for (int i = 0; i < nlocal; i++) qf[i] = 0.0;
}
/* ---------------------------------------------------------------------- */
FixQEQ::~FixQEQ()
{
if (me == 0 && fp) fclose(fp);
memory->sfree(qf);
memory->sfree(q1);
memory->sfree(q2);
}
/* ---------------------------------------------------------------------- */
int FixQEQ::setmask()
{
int mask = 0;
mask |= POST_FORCE;
mask |= POST_FORCE_RESPA;
return mask;
}
/* ---------------------------------------------------------------------- */
void FixQEQ::init()
{
if (atom->q == NULL) error->all("Must use atom style charge with fix qeq");
comb = (PairComb *) force->pair_match("comb",1);
if (comb == NULL) error->all("Fix qeq must be used with pair_style comb");
if (strcmp(update->integrate_style,"respa") == 0)
nlevels_respa = ((Respa *) update->integrate)->nlevels;
ngroup = group->count(igroup);
if (ngroup == 0.0) error->all("Fix qeq group has no atoms");
}
/* ---------------------------------------------------------------------- */
void FixQEQ::setup(int vflag)
{
firstflag = 1;
if (strcmp(update->integrate_style,"verlet") == 0)
post_force(vflag);
else {
((Respa *) update->integrate)->copy_flevel_f(nlevels_respa-1);
post_force_respa(vflag,nlevels_respa-1,0);
((Respa *) update->integrate)->copy_f_flevel(nlevels_respa-1);
}
firstflag = 0;
}
/* ---------------------------------------------------------------------- */
void FixQEQ::post_force(int vflag)
{
int i,iloop,loopmax;
double heatpq,qmass,dtq,dtq2;
double enegchkall,enegmaxall;
if (update->ntimestep % nevery) return;
// reallocate work arrays if necessary
// qf = charge force
// q1 = charge displacement
// q2 = tmp storage of charge force for next iteration
if (atom->nmax > nmax) {
memory->sfree(qf);
memory->sfree(q1);
memory->sfree(q2);
nmax = atom->nmax;
qf = (double *) memory->smalloc(nmax*sizeof(double),"qeq:qf");
q1 = (double *) memory->smalloc(nmax*sizeof(double),"qeq:q1");
q2 = (double *) memory->smalloc(nmax*sizeof(double),"qeq:q2");
vector_atom = qf;
}
// more loops for first-time charge equilibrium
iloop = 0;
if (firstflag) loopmax = 1000;
else loopmax = 500;
// charge-equilibration loop
heatpq = 0.01;
qmass = 0.06;
dtq = 0.040;
dtq2 = 0.5*dtq*dtq/qmass;
double enegchk = 0.0;
double enegtot = 0.0;
double enegmax = 0.0;
double *q = atom->q;
int *mask = atom->mask;
int nlocal = atom->nlocal;
for (i = 0; i < nlocal; i++)
q1[i] = q2[i] = qf[i] = 0.0;
for (iloop = 0; iloop < loopmax; iloop ++ ) {
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit) {
q1[i] = qf[i]*dtq2 - heatpq*q1[i];
q[i] += q1[i];
}
enegtot = comb->yasu_char(qf,igroup);
enegtot /= ngroup;
enegchk = enegmax = 0.0;
for (i = 0; i < nlocal ; i++)
if (mask[i] & groupbit) {
q2[i] = enegtot-qf[i];
enegmax = MAX(enegmax,fabs(q2[i]));
enegchk += fabs(q2[i]);
qf[i] = q2[i];
}
MPI_Allreduce(&enegchk,&enegchkall,1,MPI_DOUBLE,MPI_SUM,world);
enegchk = enegchkall/ngroup;
MPI_Allreduce(&enegmax,&enegmaxall,1,MPI_DOUBLE,MPI_MAX,world);
enegmax = enegmaxall;
if (enegchk <= precision && enegmax <= 10.0*precision) break;
if (me == 0 && fp)
fprintf(fp,"Step: %d, loop: %d, enegtot %.6g, "
"enegmax %.6g, fq deviation: %.6g\n",
update->ntimestep,iloop,enegtot,enegmax,enegchk);
for (i = 0; i < nlocal; i++)
if (mask[i] & groupbit)
q1[i] += qf[i]*dtq2 - heatpq*q1[i];
}
if (me == 0 && fp) {
if (iloop == loopmax)
fprintf(fp,"Charges did not converge in %d iterations\n",iloop);
else
fprintf(fp,"Charges converged in %d iterations to %.10f\n",
iloop,enegchk);
}
}
/* ---------------------------------------------------------------------- */
void FixQEQ::post_force_respa(int vflag, int ilevel, int iloop)
{
if (ilevel == nlevels_respa-1) post_force(vflag);
}
/* ----------------------------------------------------------------------
memory usage of local atom-based arrays
------------------------------------------------------------------------- */
double FixQEQ::memory_usage()
{
double bytes = atom->nmax*3 * sizeof(double);
return bytes;
}

54
src/MANYBODY/fix_qeq.h Normal file
View File

@ -0,0 +1,54 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef FIX_CLASS
FixStyle(qeq,FixQEQ)
#else
#ifndef LMP_FIX_QEQ_H
#define LMP_FIX_QEQ_H
#include "stdio.h"
#include "fix.h"
namespace LAMMPS_NS {
class FixQEQ : public Fix {
public:
FixQEQ(class LAMMPS *, int, char **);
~FixQEQ();
int setmask();
void init();
void setup(int);
void post_force(int);
void post_force_respa(int,int,int);
double memory_usage();
private:
int me,firstflag;
double precision;
int nlevels_respa;
double ngroup;
FILE *fp;
class PairComb *comb;
int nmax;
double *qf,*q1,*q2;
};
}
#endif
#endif

2032
src/MANYBODY/pair_comb.cpp Normal file

File diff suppressed because it is too large Load Diff

150
src/MANYBODY/pair_comb.h Normal file
View File

@ -0,0 +1,150 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
Copyright (2003) Sandia Corporation. Under the terms of Contract
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
certain rights in this software. This software is distributed under
the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#ifdef PAIR_CLASS
PairStyle(comb,PairComb)
#else
#ifndef LMP_PAIR_COMB_H
#define LMP_PAIR_COMB_H
#include "pair.h"
namespace LAMMPS_NS {
class PairComb : public Pair {
friend class FixQEQ;
public:
PairComb(class LAMMPS *);
virtual ~PairComb();
void compute(int, int);
void settings(int, char **);
void coeff(int, char **);
void init_style();
double init_one(int, int);
double memory_usage();
private:
struct Param {
double lam11,lam12,lam21,lam22;
double c,d,h;
double gamma,powerm;
double powern,beta;
double biga1,biga2,bigb1,bigb2;
double bigd,bigr;
double cut,cutsq;
double c1,c2,c3,c4;
double plp1,plp3,plp6,a123,aconf;
double rlm1,rlm2;
double romiga,romigb,romigc,romigd,addrep;
double QU1,QL1,DU1,DL1,Qo1,dQ1,aB1,bB1,nD1,bD1;
double QU2,QL2,DU2,DL2,Qo2,dQ2,aB2,bB2,nD2,bD2;
double chi,dj,dk,dl,dm,esm1,esm2,cmn1,cmn2,cml1,cml2;
double coulcut, lcut, lcutsq, hfocor;
int ielement,jelement,kelement;
int powermint;
};
double PI,PI2,PI4,PIsq;
double cutmax; // max cutoff for all elements
int nelements; // # of unique elements
char **elements; // names of unique elements
int ***elem2param; // mapping from element triplets to parameters
int *map; // mapping from atom types to elements
int nparams; // # of stored parameter sets
int maxparam; // max # of parameter sets
double precision;
Param *params; // parameter set for an I-J-K interaction
int nmax;
double *qf;
double *esm, **fafb, **dfafb, **ddfafb, **phin, **dphin, **erpaw;
double *charge;
int **intype, *typeno;
int *NCo, cor_flag, cuo_flag, cuo_flag1, cuo_flag2;
void allocate();
virtual void read_file(char *);
void setup();
virtual void repulsive(Param *, double, double &, int,
double &, double, double);
double zeta(Param *, double, double, double *, double *);
void force_zeta(Param *, double, double, double &, double &,
int, double &, double,double);
void attractive(Param *, double, double, double, double *, double *,
double *, double *, double *);
double elp(Param *, double, double, double *, double *);
void flp(Param *, double, double, double *, double *, double *,
double *, double *);
double comb_fc(double, Param *);
double comb_fc_d(double, Param *);
double comb_fc2(double);
double comb_fc2_d(double);
double comb_fc3(double);
double comb_fc3_d(double);
virtual double comb_fa(double, Param *, double,double);
virtual double comb_fa_d(double, Param *, double,double);
double comb_bij(double, Param *);
double comb_bij_d(double, Param *);
double comb_gijk(double, Param *);
double comb_gijk_d(double, Param *);
void comb_zetaterm_d(double, double *, double, double *, double,
double *, double *, double *, Param *);
void costheta_d(double *, double, double *, double,
double *, double *, double *);
double self(Param *, double, double);
void sm_table();
void potal_calc(double &, double &, double &);
void tri_point(double, int &, int &, int &, double &, double &,
double &, int &);
void direct(int,int,int,int,double,double,double,double,double,double,
double,double,double,double &,double &);
void field(Param *,double,double,double,double &,double &);
double qfo_self(Param *, double, double);
void qfo_short(Param *, double, double, double, double, double &, double &);
void qfo_direct (int, int, int, int, double, double, double, double,
double, double &);
void qfo_field(Param *, double,double ,double ,double &, double &);
void qsolve(double *);
// double yasu_char(double *);
double yasu_char(double *, int &);
void Over_cor(Param *, double, int, double &, double &);
int pack_reverse_comm(int, int, double *);
void unpack_reverse_comm(int, int *, double *);
int pack_comm(int , int *, double *, int, int *);
void unpack_comm(int , int , double *);
// vector functions, inline for efficiency
inline double vec3_dot(double *x, double *y) {
return x[0]*y[0] + x[1]*y[1] + x[2]*y[2];
}
inline void vec3_add(double *x, double *y, double *z) {
z[0] = x[0]+y[0]; z[1] = x[1]+y[1]; z[2] = x[2]+y[2];
}
inline void vec3_scale(double k, double *x, double *y) {
y[0] = k*x[0]; y[1] = k*x[1]; y[2] = k*x[2];
}
inline void vec3_scaleadd(double k, double *x, double *y, double *z) {
z[0] = k*x[0]+y[0]; z[1] = k*x[1]+y[1]; z[2] = k*x[2]+y[2];
}
};
}
#endif
#endif