Unverified Commit dee63187 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

refactoring of SPIN pair class initialization to increase code reuse

parent dcb1b650
Loading
Loading
Loading
Loading
+27 −11
Changes for src/SPIN/pair_spin.cpp: 27 added lines, 11 removed lines.
Original line number Diff line number Diff line
@@ -24,13 +24,17 @@
#include "pair_spin.h"
#include <cstring>
#include "atom.h"
#include "comm.h"
#include "error.h"
#include "fix.h"
#include "force.h"
#include "math_const.h"
#include "modify.h"
#include "neighbor.h"
#include "neigh_request.h"
#include "pair.h"
#include "update.h"
#include "fix_nve_spin.h"

using namespace LAMMPS_NS;
using namespace MathConst;
@@ -41,7 +45,9 @@ PairSpin::PairSpin(LAMMPS *lmp) : Pair(lmp)
{
  hbar = force->hplanck/MY_2PI;
  single_enable = 0;
  respa_enable = 0;
  no_virial_fdotr_compute = 1;
  lattice_flag = 0;
}

/* ---------------------------------------------------------------------- */
@@ -57,11 +63,10 @@ void PairSpin::settings(int narg, char **/*arg*/)
  if (narg < 1 || narg > 2)
    error->all(FLERR,"Incorrect number of args in pair_style pair/spin command");

  // pair/spin need the metal unit style
  // pair spin/* need the metal unit style

  if (strcmp(update->unit_style,"metal") != 0)
    error->all(FLERR,"pair/spin style requires metal units");

    error->all(FLERR,"Spin pair styles require metal units");
}

/* ----------------------------------------------------------------------
@@ -73,13 +78,24 @@ void PairSpin::init_style()
  if (!atom->sp_flag)
    error->all(FLERR,"Pair spin requires atom/spin style");

  // checking if nve/spin is a listed fix
  // checking if nve/spin or neb/spin is a listed fix

  bool have_fix = ((modify->find_fix_by_style("^nve/spin") != -1)
                   || (modify->find_fix_by_style("^neb/spin") != -1));
  
  if (!have_fix && (comm->me == 0))
    error->warning(FLERR,"Using spin pair style without nve/spin or neb/spin");

  // need a full neighbor list

  int irequest = neighbor->request(this,instance_me);
  neighbor->requests[irequest]->half = 0;
  neighbor->requests[irequest]->full = 1;

  // get the lattice_flag from nve/spin

  int ifix = modify->find_fix_by_style("^nve/spin");
  if (ifix >=0)
    lattice_flag = ((FixNVESpin *) modify->fix[ifix])->lattice_flag;

  int ifix = 0;
  while (ifix < modify->nfix) {
    if (strcmp(modify->fix[ifix]->style,"nve/spin") == 0) break;
    ifix++;
  }
  if (ifix == modify->nfix)
    error->all(FLERR,"pair/spin style requires nve/spin");
}
+1 −0
Changes for src/SPIN/pair_spin.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ friend class FixNVESpin;

 protected:
  double hbar;				// Planck constant (eV.ps.rad-1)
  int lattice_flag;			// flag for mech force computation

  virtual void allocate() {}
};
+4 −57
Changes for src/SPIN/pair_spin_dipole_cut.cpp: 4 added lines, 57 removed lines.
Original line number Diff line number Diff line
@@ -27,11 +27,8 @@
#include <cstring>
#include "atom.h"
#include "comm.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "fix.h"
#include "fix_nve_spin.h"
#include "force.h"
#include "math_const.h"
#include "memory.h"
@@ -45,14 +42,9 @@ using namespace MathConst;

/* ---------------------------------------------------------------------- */

PairSpinDipoleCut::PairSpinDipoleCut(LAMMPS *lmp) : PairSpin(lmp),
lockfixnvespin(NULL)
PairSpinDipoleCut::PairSpinDipoleCut(LAMMPS *lmp) : PairSpin(lmp)
{
  single_enable = 0;
  spinflag = 1;
  respa_enable = 0;
  no_virial_fdotr_compute = 1;
  lattice_flag = 0;

  hbar = force->hplanck/MY_2PI;			      // eV/(rad.THz)
  mub = 9.274e-4;                             // in A.Ang^2
@@ -60,7 +52,6 @@ lockfixnvespin(NULL)
  mub2mu0 = mub * mub * mu_0 / (4.0*MY_PI);   // in eV.Ang^3
  //mub2mu0 = mub * mub * mu_0 / (4.0*MY_PI);	// in eV
  mub2mu0hbinv = mub2mu0 / hbar;              // in rad.THz

}

/* ----------------------------------------------------------------------
@@ -82,14 +73,7 @@ PairSpinDipoleCut::~PairSpinDipoleCut()

void PairSpinDipoleCut::settings(int narg, char **arg)
{
  if (narg < 1 || narg > 2)
    error->all(FLERR,"Incorrect args in pair_style command");

  if (strcmp(update->unit_style,"metal") != 0)
    error->all(FLERR,"Spin simulations require metal unit style");

  if (!atom->sp) 
    error->all(FLERR,"Pair/spin style requires atom attribute sp");
  PairSpin::settings(narg,arg);

  cut_spin_long_global = force->numeric(FLERR,arg[0]);
  
@@ -137,43 +121,6 @@ void PairSpinDipoleCut::coeff(int narg, char **arg)
  if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients");
}

/* ----------------------------------------------------------------------
   init specific to this pair style
------------------------------------------------------------------------- */

void PairSpinDipoleCut::init_style()
{
  if (!atom->sp_flag)
    error->all(FLERR,"Pair spin requires atom/spin style");
  
  // need a full neighbor list

  int irequest = neighbor->request(this,instance_me);
  neighbor->requests[irequest]->half = 0;
  neighbor->requests[irequest]->full = 1;
  
  // checking if nve/spin or neb/spin are a listed fix

  int ifix = 0;
  while (ifix < modify->nfix) {
    if (strcmp(modify->fix[ifix]->style,"nve/spin") == 0) break;
    if (strcmp(modify->fix[ifix]->style,"neb/spin") == 0) break;
    ifix++;
  }
  if ((ifix == modify->nfix) && (comm->me == 0))
    error->warning(FLERR,"Using pair/spin style without nve/spin or neb/spin");

  // get the lattice_flag from nve/spin

  for (int i = 0; i < modify->nfix; i++) {
    if (strcmp(modify->fix[i]->style,"nve/spin") == 0) {
      lockfixnvespin = (FixNVESpin *) modify->fix[i];
      lattice_flag = lockfixnvespin->lattice_flag;
    }
  }

}

/* ----------------------------------------------------------------------
   init for one type pair i,j and corresponding j,i
------------------------------------------------------------------------- */
@@ -410,7 +357,7 @@ void PairSpinDipoleCut::compute_single_pair(int ii, double fmi[3])
   compute dipolar interaction between spins i and j
------------------------------------------------------------------------- */

void PairSpinDipoleCut::compute_dipolar(int i, int j, double eij[3], 
void PairSpinDipoleCut::compute_dipolar(int /* i */, int /* j */, double eij[3], 
    double fmi[3], double spi[4], double spj[4], double r3inv)
{
  double sjdotr;
@@ -430,7 +377,7 @@ void PairSpinDipoleCut::compute_dipolar(int i, int j, double eij[3],
   atom i and atom j
------------------------------------------------------------------------- */

void PairSpinDipoleCut::compute_dipolar_mech(int i, int j, double eij[3],
void PairSpinDipoleCut::compute_dipolar_mech(int /* i */, int /* j */, double eij[3],
    double fi[3], double spi[3], double spj[3], double r2inv)
{
  double sisj,sieij,sjeij;
+2 −6
Changes for src/SPIN/pair_spin_dipole_cut.h: 2 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -29,12 +29,11 @@ class PairSpinDipoleCut : public PairSpin {
  double cut_coul;
  double **sigma;

  PairSpinDipoleCut(class LAMMPS *);
  ~PairSpinDipoleCut();
  PairSpinDipoleCut(LAMMPS *);
  virtual ~PairSpinDipoleCut();
  void settings(int, char **);
  void coeff(int, char **);
  double init_one(int, int);
  void init_style();
  void *extract(const char *, int &); 
  
  void compute(int, int);
@@ -64,9 +63,6 @@ class PairSpinDipoleCut : public PairSpin {
  double g_ewald;
  int ewald_order;

  int lattice_flag;			// flag for mech force computation
  class FixNVESpin *lockfixnvespin;	// ptr for setups

  void allocate();
};

+5 −46
Changes for src/SPIN/pair_spin_dipole_long.cpp: 5 added lines, 46 removed lines.
Original line number Diff line number Diff line
@@ -22,11 +22,8 @@
#include <cstring>
#include "atom.h"
#include "comm.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "neigh_request.h"
#include "fix.h"
#include "fix_nve_spin.h"
#include "force.h"
#include "kspace.h"
#include "math_const.h"
@@ -35,7 +32,6 @@
#include "error.h"
#include "update.h"


using namespace LAMMPS_NS;
using namespace MathConst;

@@ -49,14 +45,9 @@ using namespace MathConst;

/* ---------------------------------------------------------------------- */

PairSpinDipoleLong::PairSpinDipoleLong(LAMMPS *lmp) : PairSpin(lmp),
lockfixnvespin(NULL)
PairSpinDipoleLong::PairSpinDipoleLong(LAMMPS *lmp) : PairSpin(lmp)
{
  single_enable = 0;
  ewaldflag = pppmflag = spinflag = 1;
  respa_enable = 0;
  no_virial_fdotr_compute = 1;
  lattice_flag = 0;

  hbar = force->hplanck/MY_2PI;                 // eV/(rad.THz)
  mub = 9.274e-4;                               // in A.Ang^2
@@ -86,11 +77,7 @@ PairSpinDipoleLong::~PairSpinDipoleLong()

void PairSpinDipoleLong::settings(int narg, char **arg)
{
  if (narg < 1 || narg > 2)
    error->all(FLERR,"Incorrect args in pair_style command");

  if (strcmp(update->unit_style,"metal") != 0)
    error->all(FLERR,"Spin simulations require metal unit style");
  PairSpin::settings(narg,arg);

  cut_spin_long_global = force->numeric(FLERR,arg[0]);
  
@@ -106,7 +93,6 @@ void PairSpinDipoleLong::settings(int narg, char **arg)
      }
    }
  }

}

/* ----------------------------------------------------------------------
@@ -144,34 +130,7 @@ void PairSpinDipoleLong::coeff(int narg, char **arg)

void PairSpinDipoleLong::init_style()
{
  if (!atom->sp_flag)
    error->all(FLERR,"Pair spin requires atom/spin style");
  
  // need a full neighbor list

  int irequest = neighbor->request(this,instance_me);
  neighbor->requests[irequest]->half = 0;
  neighbor->requests[irequest]->full = 1;
  
  // checking if nve/spin or neb/spin are a listed fix

  int ifix = 0;
  while (ifix < modify->nfix) {
    if (strcmp(modify->fix[ifix]->style,"nve/spin") == 0) break;
    if (strcmp(modify->fix[ifix]->style,"neb/spin") == 0) break;
    ifix++;
  }
  if ((ifix == modify->nfix) && (comm->me == 0))
    error->warning(FLERR,"Using pair/spin style without nve/spin or neb/spin");

  // get the lattice_flag from nve/spin

  for (int i = 0; i < modify->nfix; i++) {
    if (strcmp(modify->fix[i]->style,"nve/spin") == 0) {
      lockfixnvespin = (FixNVESpin *) modify->fix[i];
      lattice_flag = lockfixnvespin->lattice_flag;
    }
  }
  PairSpin::init_style();

  // insure use of KSpace long-range solver, set g_ewald

@@ -468,7 +427,7 @@ void PairSpinDipoleLong::compute_single_pair(int ii, double fmi[3])
   compute dipolar interaction between spins i and j
------------------------------------------------------------------------- */

void PairSpinDipoleLong::compute_long(int i, int j, double eij[3], 
void PairSpinDipoleLong::compute_long(int /* i */, int /* j */, double eij[3], 
    double bij[4], double fmi[3], double spi[4], double spj[4])
{
  double sjeij,pre;
@@ -491,7 +450,7 @@ void PairSpinDipoleLong::compute_long(int i, int j, double eij[3],
   atom i and atom j
------------------------------------------------------------------------- */

void PairSpinDipoleLong::compute_long_mech(int i, int j, double eij[3],
void PairSpinDipoleLong::compute_long_mech(int /* i */, int /* j */, double eij[3],
    double bij[4], double fi[3], double spi[3], double spj[3])
{
  double sisj,sieij,sjeij,b2,b3;
Loading