From b1dd616a2f7fcd87b6ba7dc2c7bf03cefe40aca1 Mon Sep 17 00:00:00 2001 From: julient31 Date: Wed, 21 Apr 2021 07:43:00 -0600 Subject: [PATCH] correcting a small typo in the checks, and adding a note in the documentation of fix precession/spin about the error if a (0,0,0) vector is given as an input. --- doc/src/fix_precession_spin.rst | 12 +++++++++++- src/SPIN/fix_precession_spin.cpp | 27 ++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/doc/src/fix_precession_spin.rst b/doc/src/fix_precession_spin.rst index 2d6d8e2f7b..183753db5f 100644 --- a/doc/src/fix_precession_spin.rst +++ b/doc/src/fix_precession_spin.rst @@ -127,7 +127,7 @@ details on cubic anisotropies. Style *stt* is used to simulate the interaction between the spins and a spin-transfer torque. -See equation(7) of :ref:`(Chirac) ` for more details about the +See equation (7) of :ref:`(Chirac) ` for more details about the implemented spin-transfer torque term. In all cases, the choice of :math:`(x y z)` only imposes the vector @@ -137,6 +137,16 @@ normalized). Those styles can be combined within one single command line. +.. note:: + + The norm of all vectors defined with the precession/spin command + have to be non-zero. For example, defining + "fix 1 all precession/spin zeeman 0.1 0.0 0.0 0.0" would result + in an error message. + Since those vector components are used to compute the inverse of the + field (or anisotropy) vector norm, setting a zero-vector would result + in a division by zero. + ---------- Restart, fix_modify, output, run start/stop, minimize info diff --git a/src/SPIN/fix_precession_spin.cpp b/src/SPIN/fix_precession_spin.cpp index 01df9d3750..7cfbe6e1a7 100644 --- a/src/SPIN/fix_precession_spin.cpp +++ b/src/SPIN/fix_precession_spin.cpp @@ -143,7 +143,8 @@ FixPrecessionSpin::FixPrecessionSpin(LAMMPS *lmp, int narg, char **arg) : double norm2,inorm; if (zeeman_flag) { norm2 = nhx*nhx + nhy*nhy + nhz*nhz; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); nhx *= inorm; nhy *= inorm; @@ -152,7 +153,8 @@ FixPrecessionSpin::FixPrecessionSpin(LAMMPS *lmp, int narg, char **arg) : if (stt_flag) { norm2 = nsttx*nsttx + nstty*nstty + nsttz*nsttz; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); nsttx *= inorm; nstty *= inorm; @@ -161,7 +163,8 @@ FixPrecessionSpin::FixPrecessionSpin(LAMMPS *lmp, int narg, char **arg) : if (aniso_flag) { norm2 = nax*nax + nay*nay + naz*naz; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); nax *= inorm; nay *= inorm; @@ -170,21 +173,24 @@ FixPrecessionSpin::FixPrecessionSpin(LAMMPS *lmp, int narg, char **arg) : if (cubic_flag) { norm2 = nc1x*nc1x + nc1y*nc1y + nc1z*nc1z; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); nc1x *= inorm; nc1y *= inorm; nc1z *= inorm; norm2 = nc2x*nc2x + nc2y*nc2y + nc2z*nc2z; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); nc2x *= inorm; nc2y *= inorm; nc2z *= inorm; norm2 = nc3x*nc3x + nc3y*nc3y + nc3z*nc3z; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); nc3x *= inorm; nc3y *= inorm; @@ -193,14 +199,16 @@ FixPrecessionSpin::FixPrecessionSpin(LAMMPS *lmp, int narg, char **arg) : if (hexaniso_flag) { norm2 = n6x*n6x + n6y*n6y + n6z*n6z; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); n6x *= inorm; n6y *= inorm; n6z *= inorm; norm2 = m6x*m6x + m6y*m6y + m6z*m6z; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); m6x *= inorm; m6y *= inorm; @@ -210,7 +218,8 @@ FixPrecessionSpin::FixPrecessionSpin(LAMMPS *lmp, int narg, char **arg) : l6z = (n6y*m6x-n6x*m6y); norm2 = l6x*l6x + l6y*l6y + l6z*l6z; - if (norm2 == 0.0) else error->all(FLERR,"Illegal precession/spin command"); + if (norm2 == 0.0) + error->all(FLERR,"Illegal precession/spin command"); inorm = 1.0/sqrt(norm2); l6x *= inorm; l6y *= inorm;