From 455bb933c8b59177b73d911b686db814f6ba6a64 Mon Sep 17 00:00:00 2001 From: julient31 Date: Mon, 12 Apr 2021 16:18:22 -0600 Subject: [PATCH] adding modifications for more than one fix langevin/spin in fix nve/spin --- .../llg_exchange.py | 2 +- .../validation_nvt/in.spin.nvt_lattice | 4 +- .../validation_nvt/in.spin.nvt_spin | 9 ++- src/SPIN/fix_langevin_spin.cpp | 12 ++++ src/SPIN/fix_langevin_spin.h | 3 +- src/SPIN/fix_nve_spin.cpp | 67 ++++++++++++++----- src/SPIN/fix_nve_spin.h | 12 ++-- src/SPIN/fix_precession_spin.cpp | 1 - 8 files changed, 83 insertions(+), 27 deletions(-) diff --git a/examples/SPIN/test_problems/validation_damped_exchange/llg_exchange.py b/examples/SPIN/test_problems/validation_damped_exchange/llg_exchange.py index 5b93ac5c2d..a4cba3a940 100755 --- a/examples/SPIN/test_problems/validation_damped_exchange/llg_exchange.py +++ b/examples/SPIN/test_problems/validation_damped_exchange/llg_exchange.py @@ -6,7 +6,7 @@ import matplotlib.pyplot as plt import mpmath as mp hbar=0.658212 # Planck's constant (eV.fs/rad) -# J0=0.05 # per-neighbor exchange interaction (eV) +J0=0.05 # per-neighbor exchange interaction (eV) # exchange interaction parameters J1 = 11.254 # in eV diff --git a/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_lattice b/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_lattice index 2375c0ff8d..6f995fa071 100644 --- a/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_lattice +++ b/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_lattice @@ -30,8 +30,8 @@ neighbor 0.1 bin neigh_modify every 10 check yes delay 20 fix 1 all precession/spin zeeman 0.0 0.0 0.0 1.0 -fix 2 all langevin 200.0 200.0 1.0 48279 -fix 3 all langevin/spin 0.0 0.00001 321 +fix 2 all langevin 200.0 200.0 0.1 48279 +fix 3 all langevin/spin 0.0 0.0 321 fix 4 all nve/spin lattice moving timestep 0.001 diff --git a/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_spin b/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_spin index 6b65df7109..b33789cec6 100644 --- a/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_spin +++ b/examples/SPIN/test_problems/validation_nvt/in.spin.nvt_spin @@ -21,16 +21,19 @@ mass 1 55.845 set group all spin 2.2 0.0 0.0 1.0 velocity all create 0 4928459 rot yes dist gaussian -pair_style hybrid/overlay eam/alloy spin/exchange 3.5 +# pair_style hybrid/overlay eam/alloy spin/exchange 3.5 +pair_style hybrid/overlay eam/alloy spin/exchange 4.0 spin/neel 4.0 pair_coeff * * eam/alloy Fe_Mishin2006.eam.alloy Fe pair_coeff * * spin/exchange exchange 3.4 0.1 0.2171 1.841 +pair_coeff * * spin/neel neel 4.0 0.02 0.0 1.841 0.0 0.0 1.0 neighbor 0.1 bin neigh_modify every 10 check yes delay 20 fix 1 all precession/spin zeeman 0.0 0.0 0.0 1.0 -fix 2 all langevin/spin 200.0 0.01 321 -fix 3 all nve/spin lattice moving +fix 2 all langevin 0.0 0.0 0.0 48279 +fix 3 all langevin/spin 200.0 0.01 321 +fix 4 all nve/spin lattice moving timestep 0.001 # compute and output options diff --git a/src/SPIN/fix_langevin_spin.cpp b/src/SPIN/fix_langevin_spin.cpp index c9cb0fa2ec..209eaa5632 100644 --- a/src/SPIN/fix_langevin_spin.cpp +++ b/src/SPIN/fix_langevin_spin.cpp @@ -24,6 +24,7 @@ #include "fix_langevin_spin.h" #include #include +#include "atom.h" #include "comm.h" #include "error.h" #include "force.h" @@ -163,3 +164,14 @@ void FixLangevinSpin::add_temperature(double fmi[3]) fmi[1] *= gil_factor; fmi[2] *= gil_factor; } + +/* ---------------------------------------------------------------------- */ + +void FixLangevinSpin::compute_single_langevin(int i, double spi[3], double fmi[3]) +{ + int *mask = atom->mask; + if (mask[i] & groupbit) { + if (tdamp_flag) add_tdamping(spi,fmi); + if (temp_flag) add_temperature(fmi); + } +} diff --git a/src/SPIN/fix_langevin_spin.h b/src/SPIN/fix_langevin_spin.h index c73b33353b..89267f7d4d 100644 --- a/src/SPIN/fix_langevin_spin.h +++ b/src/SPIN/fix_langevin_spin.h @@ -26,7 +26,7 @@ namespace LAMMPS_NS { class FixLangevinSpin : public Fix { public: - int tdamp_flag,ldamp_flag,temp_flag; // damping and temperature flags + int tdamp_flag,temp_flag; // damping and temperature flags FixLangevinSpin(class LAMMPS *, int, char **); virtual ~FixLangevinSpin(); @@ -35,6 +35,7 @@ class FixLangevinSpin : public Fix { void setup(int); void add_tdamping(double *, double *); // add transverse damping void add_temperature(double *); // add temperature + void compute_single_langevin(int, double *, double *); protected: double alpha_t; // transverse mag. damping diff --git a/src/SPIN/fix_nve_spin.cpp b/src/SPIN/fix_nve_spin.cpp index 97e3237fda..266f0bd690 100644 --- a/src/SPIN/fix_nve_spin.cpp +++ b/src/SPIN/fix_nve_spin.cpp @@ -60,7 +60,8 @@ enum{NONE}; FixNVESpin::FixNVESpin(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), - pair(nullptr), spin_pairs(nullptr), + pair(nullptr), spin_pairs(nullptr), locklangevinspin(nullptr), + locksetforcespin(nullptr), lockprecessionspin(nullptr), rsec(nullptr), stack_head(nullptr), stack_foot(nullptr), backward_stacks(nullptr), forward_stacks(nullptr) { @@ -76,7 +77,7 @@ FixNVESpin::FixNVESpin(LAMMPS *lmp, int narg, char **arg) : npairspin = 0; // test nprec - nprecspin = 0; + nprecspin = nlangspin = nsetspin = 0; // checking if map array or hash is defined @@ -128,7 +129,6 @@ FixNVESpin::FixNVESpin(LAMMPS *lmp, int narg, char **arg) : maglangevin_flag = 0; tdamp_flag = temp_flag = 0; setforce_spin_flag = 0; - } /* ---------------------------------------------------------------------- */ @@ -141,6 +141,8 @@ FixNVESpin::~FixNVESpin() memory->destroy(forward_stacks); memory->destroy(backward_stacks); delete [] spin_pairs; + delete [] locklangevinspin; + delete [] lockprecessionspin; } /* ---------------------------------------------------------------------- */ @@ -261,19 +263,51 @@ void FixNVESpin::init() if (count2 != nprecspin) error->all(FLERR,"Incorrect number of fix precession/spin"); - // ptrs on the FixLangevinSpin class - + // set ptrs for fix langevin/spin styles + + // loop 1: obtain # of fix langevin/spin styles + for (iforce = 0; iforce < modify->nfix; iforce++) { if (strstr(modify->fix[iforce]->style,"langevin/spin")) { - maglangevin_flag = 1; - locklangevinspin = (FixLangevinSpin *) modify->fix[iforce]; + nlangspin++; } } + + // init length of vector of ptrs to precession/spin styles - if (maglangevin_flag) { - if (locklangevinspin->tdamp_flag == 1) tdamp_flag = 1; - if (locklangevinspin->temp_flag == 1) temp_flag = 1; + if (nlangspin > 0) { + locklangevinspin = new FixLangevinSpin*[nprecspin]; } + + // loop 2: fill vector with ptrs to precession/spin styles + + count2 = 0; + if (nlangspin > 0) { + for (iforce = 0; iforce < modify->nfix; iforce++) { + if (strstr(modify->fix[iforce]->style,"langevin/spin")) { + maglangevin_flag = 1; + locklangevinspin[count2] = (FixLangevinSpin *) modify->fix[iforce]; + count2++; + } + } + } + + if (count2 != nlangspin) + error->all(FLERR,"Incorrect number of fix precession/spin"); + + // // ptrs on the FixLangevinSpin class + + // for (iforce = 0; iforce < modify->nfix; iforce++) { + // if (strstr(modify->fix[iforce]->style,"langevin/spin")) { + // maglangevin_flag = 1; + // locklangevinspin = (FixLangevinSpin *) modify->fix[iforce]; + // } + // } + + // if (maglangevin_flag) { + // if (locklangevinspin->tdamp_flag == 1) tdamp_flag = 1; + // if (locklangevinspin->temp_flag == 1) temp_flag = 1; + // } // ptrs FixSetForceSpin classes @@ -515,12 +549,15 @@ void FixNVESpin::ComputeInteractionsSpin(int i) // update langevin damping and random force if (maglangevin_flag) { // mag. langevin - if (tdamp_flag) { // transverse damping - locklangevinspin->add_tdamping(spi,fmi); - } - if (temp_flag) { // spin temperature - locklangevinspin->add_temperature(fmi); + for (int k = 0; k < nlangspin; k++) { + locklangevinspin[k]->compute_single_langevin(i,spi,fmi); } + // if (tdamp_flag) { // transverse damping + // locklangevinspin->add_tdamping(spi,fmi); + // } + // if (temp_flag) { // spin temperature + // locklangevinspin->add_temperature(fmi); + // } } // update setforce of magnetic interactions diff --git a/src/SPIN/fix_nve_spin.h b/src/SPIN/fix_nve_spin.h index a4b89c1727..ac5bc57b25 100644 --- a/src/SPIN/fix_nve_spin.h +++ b/src/SPIN/fix_nve_spin.h @@ -61,11 +61,15 @@ friend class PairSpin; int tdamp_flag, temp_flag; int setforce_spin_flag; - // pointers to magnetic fixes + // pointers to fix langevin/spin styles - // class FixPrecessionSpin *lockprecessionspin; - class FixLangevinSpin *locklangevinspin; - class FixSetForceSpin *locksetforcespin; + int nlangspin; + class FixLangevinSpin **locklangevinspin; + + // pointers to fix setforce/spin styles + + int nsetspin; + class FixSetForceSpin *locksetforcespin; // to be done // pointers to fix precession/spin styles diff --git a/src/SPIN/fix_precession_spin.cpp b/src/SPIN/fix_precession_spin.cpp index 873a21ea66..a6bb19907a 100644 --- a/src/SPIN/fix_precession_spin.cpp +++ b/src/SPIN/fix_precession_spin.cpp @@ -433,7 +433,6 @@ void FixPrecessionSpin::compute_anisotropy(double spi[3], double fmi[3]) fmi[0] += scalar*Kax; fmi[1] += scalar*Kay; fmi[2] += scalar*Kaz; - // printf("fm pres1: %g %g %g \n",fmi[0],fmi[1],fmi[2]); } /* ---------------------------------------------------------------------- */