Commit Julien 09/14/17

- Changes and corrections in the computation of the energy
- Issue with newton_pair in the compute of pair
This commit is contained in:
julient31 2017-09-14 16:16:33 -06:00
parent d144ab0164
commit 54832a8fe4
7 changed files with 84 additions and 123 deletions

View File

@ -35,7 +35,7 @@ lattice fcc 3.54
#Defining a geometric region of space. Sets ID(user's choice), style(block, sphere, ...), then, args depends on the style chosen
#(for block, one has x0, xf, y0, yf, z0, zf, in distance units)
region box block 0.0 5.0 0.0 5.0 0.0 5.0
region box block 0.0 2.0 0.0 2.0 0.0 2.0
#Creating a simulation box based on the specified region. Entries: number of atom types and box ref.
create_box 1 box
@ -53,8 +53,8 @@ create_atoms 1 box
mass 1 1.0
#set group all mass 1.0
#Setting spins orientation and moment
#set group all spin/random 11 1.72
set group all spin 1.72 1.0 0.0 0.0
set group all spin/random 11 1.72
#set group all spin 1.72 0.0 0.0 1.0
#Magneto-mechanic interactions for bulk fcc Cobalt
pair_style hybrid/overlay eam/alloy pair/spin 4.0
@ -77,7 +77,7 @@ neigh_modify every 1 check no delay 0
#Magnetic field fix
#Type | Intensity (T or eV) | Direction
fix 1 all force/spin zeeman 0.1 0.0 0.0 1.0
fix 1 all force/spin zeeman 0.0 0.0 0.0 1.0
#fix 1 all force/spin anisotropy 0.01 0.0 0.0 1.0
#fix 1 all force/spin anisotropy -0.1 0.0 0.0 1.0
#fix 1 all force/spin anisotropy 0.1 0.0 1.0 0.0
@ -86,10 +86,10 @@ fix 1 all force/spin zeeman 0.1 0.0 0.0 1.0
#Temp | Alpha_trans | Alpha_long | Seed
#fix 2 all langevin/spin 0.0 0.1 0.0 21
#fix 2 all langevin/spin 1.0 0.1 0.0 21
fix 2 all langevin/spin 0.1 0.01 0.0 21
fix 2 all langevin/spin 0.0 0.0 0.0 21
#Magnetic integration fix
fix 3 all integration/spin mpi
fix 3 all integration/spin serial
#compute real time, total magnetization, magnetic energy, and spin temperature
#Iteration | Time | Mx | My | Mz | |M| | Em | Tm
@ -111,10 +111,12 @@ timestep 0.0001
#######run########
##################
thermo 500
#Dump the positions and spin directions of magnetic particles (vmd format)
dump 1 all custom 100 dump_spin_MM.lammpstrj type x y z spx spy spz
dump 1 all custom 10 dump_spin_MM.lammpstrj type x y z spx spy spz
#Running the simulations for N timesteps
run 50000
run 100000
#run 1

View File

@ -100,9 +100,9 @@ void ComputeSpin::compute_vector()
mag[0] += sp[i][0];
mag[1] += sp[i][1];
mag[2] += sp[i][2];
magenergy += mumag[i]*sp[i][0]*fm[i][0];
magenergy += mumag[i]*sp[i][1]*fm[i][1];
magenergy += mumag[i]*sp[i][2]*fm[i][2];
magenergy += sp[i][0]*fm[i][0];
magenergy += sp[i][1]*fm[i][1];
magenergy += sp[i][2]*fm[i][2];
tx = sp[i][1]*fm[i][2]-sp[i][2]*fm[i][1];
ty = sp[i][2]*fm[i][0]-sp[i][0]*fm[i][2];
tz = sp[i][0]*fm[i][1]-sp[i][1]*fm[i][0];
@ -113,7 +113,7 @@ void ComputeSpin::compute_vector()
}
else error->all(FLERR,"Compute spin/compute declared magnetic quantities (sp and mumag flags)");
}
MPI_Allreduce(mag,magtot,4,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(&magenergy,&magenergytot,1,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(&tempnum,&tempnumtot,1,MPI_DOUBLE,MPI_SUM,world);

View File

@ -50,7 +50,9 @@ FixForceSpin::FixForceSpin(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, a
// 7 arguments for a force/spin fix command:
//(fix ID group force/spin magnitude (T or eV) style (zeeman or anisotropy) direction (3 cartesian coordinates)
//Magnetic interactions only coded for cartesian coordinates
// magnetic interactions coded for cartesian coordinates
hbar = force->hplanck/MY_2PI;
dynamic_group_allow = 1;
scalar_flag = 1;
@ -200,6 +202,9 @@ void FixForceSpin::post_force(int vflag)
fm[i][1] += fmi[1];
fm[i][2] += fmi[2];
emag -= mumag[i]*spi[0]*fmi[0];
emag -= mumag[i]*spi[1]*fmi[1];
emag -= mumag[i]*spi[2]*fmi[2];
}
}
@ -214,6 +219,8 @@ double *mumag = atom->mumag;
fmi[2] += mumag[i]*zmag;
}
/* ---------------------------------------------------------------------- */
void FixForceSpin::compute_anisotropy(int i, double * spi, double *fmi)
{
double scalar = Kax*spi[0] + Kay*spi[1] + Kaz*spi[2];
@ -255,5 +262,8 @@ double FixForceSpin::compute_scalar()
MPI_Allreduce(&emag,&emag_all,1,MPI_DOUBLE,MPI_SUM,world);
eflag = 1;
}
emag *= hbar;
return emag_all;
}

View File

@ -46,6 +46,7 @@ class FixForceSpin : public Fix {
double xmag, ymag, zmag; // temp. force variables
double degree2rad;
double hbar;
int ilevel_respa;
int time_origin;
int eflag;

View File

@ -206,14 +206,14 @@ void FixIntegrationSpin::initial_integrate(int vflag)
int *type = atom->type;
int *mask = atom->mask;
printf("before mechmag, spin 1: [%g,%g,%g] \n",f[1][0],f[1][1],f[1][2]);
// printf("before mechmag, spin 1: [%g,%g,%g] \n",f[1][0],f[1][1],f[1][2]);
// compute and add magneto-mech. force
if (magpair_flag == 1) {
if (exch_flag) lockpairspin->compute_magnetomech(0,vflag);
}
// if (magpair_flag == 1) {
// if (exch_flag) lockpairspin->compute_magnetomech(0,vflag);
// }
printf("after mechmag, spin 1: [%g,%g,%g] \n",f[1][0],f[1][1],f[1][2]);
// printf("after mechmag, spin 1: [%g,%g,%g] \n",f[1][0],f[1][1],f[1][2]);
// update half v all particles
for (int i = 0; i < nlocal; i++) {
@ -531,9 +531,9 @@ void FixIntegrationSpin::final_integrate()
int *mask = atom->mask;
// compute and add magneto-mech. force
if (magpair_flag == 1) {
if (exch_flag) lockpairspin->compute_magnetomech(0,0);
}
// if (magpair_flag == 1) {
// if (exch_flag) lockpairspin->compute_magnetomech(0,0);
// }
// update half v for all particles
for (int i = 0; i < nlocal; i++) {

View File

@ -39,10 +39,15 @@ using namespace MathConst;
PairSpin::PairSpin(LAMMPS *lmp) : Pair(lmp)
{
hbar = force->hplanck/MY_2PI;
newton_pair_spin = 0; // no newton pair for now
single_enable = 0;
exch_flag = 0;
dmi_flag = 0;
me_flag = 0;
no_virial_fdotr_compute = 1;
}
/* ---------------------------------------------------------------------- */
@ -82,92 +87,6 @@ PairSpin::~PairSpin()
}
}
/* ---------------------------------------------------------------------- */
void PairSpin::compute_magnetomech(int eflag, int vflag)
{
int i,j,ii,jj,inum,jnum,itype,jtype;
double evdwl,ecoul;
double xtmp,ytmp,ztmp;
double fix,fiy,fiz,fjx,fjy,fjz;
double cut_ex_2,cut_dmi_2,cut_me_2;
double rsq,rd;
int *ilist,*jlist,*numneigh,**firstneigh;
evdwl = ecoul = 0.0;
if (eflag || vflag) ev_setup(eflag,vflag);
else evflag = vflag_fdotr = 0;
double **x = atom->x;
double **f = atom->f;
double *mumag = atom->mumag;
double **sp = atom->sp;
int *type = atom->type;
int nlocal = atom->nlocal;
int newton_pair = force->newton_pair;
inum = list->inum;
ilist = list->ilist;
numneigh = list->numneigh;
firstneigh = list->firstneigh;
// pair magneto-mechanics interactions
// loop over neighbors of my atoms
for (ii = 0; ii < inum; ii++) {
i = ilist[ii];
xtmp = x[i][0];
ytmp = x[i][1];
ztmp = x[i][2];
jlist = firstneigh[i];
jnum = numneigh[i];
spi[0] = sp[i][0];
spi[1] = sp[i][1];
spi[2] = sp[i][2];
// loop on neighbors
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
j &= NEIGHMASK;
spj[0] = sp[j][0];
spj[1] = sp[j][1];
spj[2] = sp[j][2];
fi[0] = fi[1] = fi[2] = 0.0;
fj[0] = fj[1] = fj[2] = 0.0;
del[0] = del[1] = del[2] = 0.0;
del[0] = x[j][0] - xtmp;
del[1] = x[j][1] - ytmp;
del[2] = x[j][2] - ztmp;
rsq = del[0]*del[0] + del[1]*del[1] + del[2]*del[2]; //square or inter-atomic distance
itype = type[i];
jtype = type[j];
// mech. exchange interaction
if (exch_flag) {
cut_ex_2 = cut_spin_exchange[itype][jtype]*cut_spin_exchange[itype][jtype];
if (rsq <= cut_ex_2) {
compute_exchange_mech(i,j,rsq,del,fi,fj,spi,spj);
}
}
f[i][0] += fi[0];
f[i][1] += fi[1];
f[i][2] += fi[2];
// think about this sign, - or + ?
if (newton_pair || j < nlocal) {
f[j][0] += fj[0];
f[j][1] += fj[1];
f[j][2] += fj[2];
}
}
}
if (vflag_fdotr) virial_fdotr_compute();
}
/* ---------------------------------------------------------------------- */
void PairSpin::compute(int eflag, int vflag)
@ -175,16 +94,19 @@ void PairSpin::compute(int eflag, int vflag)
int i,j,ii,jj,inum,jnum,itype,jtype;
double evdwl,ecoul;
double xtmp,ytmp,ztmp;
double fix,fiy,fiz,fjx,fjy,fjz;
double fmix,fmiy,fmiz,fmjx,fmjy,fmjz;
double cut_ex_2,cut_dmi_2,cut_me_2;
double rsq,rd,delx,dely,delz;
double cut_ex_2,cut_dmi_2,cut_me_2,cut_spin_pair_global2;
double rsq,rd;
int *ilist,*jlist,*numneigh,**firstneigh;
evdwl = ecoul = 0.0;
if (eflag || vflag) ev_setup(eflag,vflag);
else evflag = vflag_fdotr = 0;
cut_spin_pair_global2 = cut_spin_pair_global*cut_spin_pair_global;
double **x = atom->x;
double **f = atom->f;
double **fm = atom->fm;
double *mumag = atom->mumag;
double **sp = atom->sp;
@ -209,7 +131,7 @@ void PairSpin::compute(int eflag, int vflag)
jnum = numneigh[i];
spi[0] = sp[i][0];
spi[1] = sp[i][1];
spi[2] = sp[i][2];
spi[2] = sp[i][2];
// loop on neighbors
for (jj = 0; jj < jnum; jj++) {
@ -219,14 +141,18 @@ void PairSpin::compute(int eflag, int vflag)
spj[1] = sp[j][1];
spj[2] = sp[j][2];
fi[0] = fi[1] = fi[2] = 0.0;
fj[0] = fj[1] = fj[2] = 0.0;
fmi[0] = fmi[1] = fmi[2] = 0.0;
fmj[0] = fmj[1] = fmj[2] = 0.0;
del[0] = del[1] = del[2] = 0.0;
delx = xtmp - x[j][0];
dely = ytmp - x[j][1];
delz = ztmp - x[j][2];
// square or inter-atomic distance
rsq = delx*delx + dely*dely + delz*delz;
del[0] = x[j][0] - xtmp;
del[1] = x[j][1] - ytmp;
del[2] = x[j][2] - ztmp;
// square of inter-atomic distance
rsq = del[0]*del[0] + del[1]*del[1] + del[2]*del[2];
itype = type[i];
jtype = type[j];
@ -236,6 +162,7 @@ void PairSpin::compute(int eflag, int vflag)
cut_ex_2 = cut_spin_exchange[itype][jtype]*cut_spin_exchange[itype][jtype];
if (rsq <= cut_ex_2) {
compute_exchange(i,j,rsq,fmi,fmj,spi,spj);
compute_exchange_mech(i,j,rsq,del,fi,fj,spi,spj);
}
}
// dm interaction
@ -253,15 +180,35 @@ void PairSpin::compute(int eflag, int vflag)
}
}
f[i][0] += fi[0];
f[i][1] += fi[1];
f[i][2] += fi[2];
fm[i][0] += fmi[0];
fm[i][1] += fmi[1];
fm[i][2] += fmi[2];
if (newton_pair || j < nlocal) {
/* if (newton_pair || j < nlocal) {*/
if (newton_pair_spin) {
f[j][0] += fj[0];
f[j][1] += fj[1];
f[j][2] += fj[2];
fm[j][0] += fmj[0];
fm[j][1] += fmj[1];
fm[j][2] += fmj[2];
}
if (eflag) {
if (rsq <= cut_spin_pair_global2) {
evdwl -= mumag[i]*spi[0]*fmi[0];
evdwl -= mumag[i]*spi[1]*fmi[1];
evdwl -= mumag[i]*spi[2]*fmi[2];
}
}
evdwl *= hbar;
if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair,
evdwl,ecoul,fi[0],fi[1],fi[2],del[0],del[1],del[2]);
}
}
@ -289,7 +236,7 @@ void PairSpin::compute_exchange(int i, int j, double rsq, double *fmi, double *
fmj[0] += Jex*spi[0];
fmj[1] += Jex*spi[1];
fmj[2] += Jex*spi[2];
}
/* ---------------------------------------------------------------------- */
@ -639,7 +586,7 @@ void PairSpin::read_restart(FILE *fp)
int i,j;
int me = comm->me;
for (i = 1; i <= atom->ntypes; i++)
for (i = 1; i <= atom->ntypes; i++) {
for (j = i; j <= atom->ntypes; j++) {
if (me == 0) fread(&setflag[i][j],sizeof(int),1,fp);
MPI_Bcast(&setflag[i][j],1,MPI_INT,0,world);
@ -658,6 +605,7 @@ void PairSpin::read_restart(FILE *fp)
MPI_Bcast(&cut_spin_exchange[i][j],1,MPI_DOUBLE,0,world);
}
}
}
}

View File

@ -29,7 +29,6 @@ class PairSpin : public Pair {
PairSpin(class LAMMPS *);
virtual ~PairSpin();
virtual void compute(int, int);
virtual void compute_magnetomech(int, int);
void settings(int, char **);
void coeff(int, char **);
void init_style();
@ -45,9 +44,7 @@ class PairSpin : public Pair {
void compute_dmi(int, int, double *, double *, double *, double *);
void compute_me(int, int, double *, double *, double *, double *);
//Test for seq. integ.
//protected:
int exch_flag,dmi_flag,me_flag;
int exch_flag, dmi_flag, me_flag;
double cut_spin_pair_global;
double cut_spin_dipolar_global;
@ -55,7 +52,10 @@ class PairSpin : public Pair {
double **cut_spin_dmi; // cutoff distance dmi
double **cut_spin_me; // cutoff distance me
protected:
protected:
int newton_pair_spin;
double hbar;
double **J1_mag, **J1_mech; // exchange coeffs Jij
double **J2, **J3; // J1 in eV, J2 adim, J3 in Ang