add var keyword to fix_deposit
borrowed from create_atoms
This commit is contained in:
@ -20,6 +20,7 @@
|
||||
#include "domain.h"
|
||||
#include "error.h"
|
||||
#include "fix.h"
|
||||
#include "input.h"
|
||||
#include "lattice.h"
|
||||
#include "math_const.h"
|
||||
#include "math_extra.h"
|
||||
@ -29,6 +30,7 @@
|
||||
#include "random_park.h"
|
||||
#include "region.h"
|
||||
#include "update.h"
|
||||
#include "variable.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
@ -209,6 +211,10 @@ FixDeposit::~FixDeposit()
|
||||
delete [] idrigid;
|
||||
delete [] idshake;
|
||||
delete [] idregion;
|
||||
delete [] vstr;
|
||||
delete [] xstr;
|
||||
delete [] ystr;
|
||||
delete [] zstr;
|
||||
memory->destroy(coords);
|
||||
memory->destroy(imageflags);
|
||||
}
|
||||
@ -361,6 +367,8 @@ void FixDeposit::pre_exchange()
|
||||
} while (iregion->match(coord[0],coord[1],coord[2]) == 0);
|
||||
} else error->all(FLERR,"Unknown particle distribution in fix deposit");
|
||||
|
||||
if (varflag && vartest(coord[0],coord[1],coord[2]) == 0) continue;
|
||||
|
||||
// adjust vertical coord by offset
|
||||
|
||||
if (dimension == 2) coord[1] += offset;
|
||||
@ -583,8 +591,10 @@ void FixDeposit::pre_exchange()
|
||||
|
||||
// warn if not successful b/c too many attempts
|
||||
|
||||
if (!success && comm->me == 0)
|
||||
error->warning(FLERR,"Particle deposition was unsuccessful");
|
||||
if (warnflag && !success && comm->me == 0) {
|
||||
error->warning(FLERR,"One or more particle depositions were unsuccessful");
|
||||
warnflag = 0;
|
||||
}
|
||||
|
||||
// reset global natoms,nbonds,etc
|
||||
// increment maxtag_all and maxmol_all if necessary
|
||||
@ -661,6 +671,8 @@ void FixDeposit::options(int narg, char **arg)
|
||||
|
||||
iregion = nullptr;
|
||||
idregion = nullptr;
|
||||
varflag = 0;
|
||||
vstr = xstr = ystr = zstr = nullptr;
|
||||
mode = ATOM;
|
||||
molfrac = nullptr;
|
||||
rigidflag = 0;
|
||||
@ -680,6 +692,7 @@ void FixDeposit::options(int narg, char **arg)
|
||||
scaleflag = 1;
|
||||
targetflag = 0;
|
||||
orientflag = 0;
|
||||
warnflag = 1;
|
||||
rx = 0.0;
|
||||
ry = 0.0;
|
||||
rz = 0.0;
|
||||
@ -693,6 +706,27 @@ void FixDeposit::options(int narg, char **arg)
|
||||
idregion = utils::strdup(arg[iarg+1]);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg], "var") == 0) {
|
||||
if (iarg + 2 > narg) utils::missing_cmd_args(FLERR, "create_atoms var", error);
|
||||
delete[] vstr;
|
||||
vstr = utils::strdup(arg[iarg + 1]);
|
||||
varflag = 1;
|
||||
iarg += 2;
|
||||
} else if (strcmp(arg[iarg], "set") == 0) {
|
||||
if (iarg + 3 > narg) utils::missing_cmd_args(FLERR, "create_atoms set", error);
|
||||
if (strcmp(arg[iarg + 1], "x") == 0) {
|
||||
delete[] xstr;
|
||||
xstr = utils::strdup(arg[iarg + 2]);
|
||||
} else if (strcmp(arg[iarg + 1], "y") == 0) {
|
||||
delete[] ystr;
|
||||
ystr = utils::strdup(arg[iarg + 2]);
|
||||
} else if (strcmp(arg[iarg + 1], "z") == 0) {
|
||||
delete[] zstr;
|
||||
zstr = utils::strdup(arg[iarg + 2]);
|
||||
} else
|
||||
error->all(FLERR, "Unknown create_atoms set option {}", arg[iarg + 2]);
|
||||
iarg += 3;
|
||||
|
||||
} else if (strcmp(arg[iarg],"mol") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal fix deposit command");
|
||||
int imol = atom->find_molecule(arg[iarg+1]);
|
||||
@ -815,6 +849,39 @@ void FixDeposit::options(int narg, char **arg)
|
||||
iarg += 4;
|
||||
} else error->all(FLERR,"Illegal fix deposit command");
|
||||
}
|
||||
|
||||
// error check and further setup for variable test
|
||||
|
||||
if (!vstr && (xstr || ystr || zstr))
|
||||
error->all(FLERR, "Incomplete use of variables in create_atoms command");
|
||||
if (vstr && (!xstr && !ystr && !zstr))
|
||||
error->all(FLERR, "Incomplete use of variables in create_atoms command");
|
||||
|
||||
if (varflag) {
|
||||
vvar = input->variable->find(vstr);
|
||||
if (vvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", vstr);
|
||||
if (!input->variable->equalstyle(vvar))
|
||||
error->all(FLERR, "Variable for create_atoms is invalid style");
|
||||
|
||||
if (xstr) {
|
||||
xvar = input->variable->find(xstr);
|
||||
if (xvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", xstr);
|
||||
if (!input->variable->internalstyle(xvar))
|
||||
error->all(FLERR, "Variable for create_atoms is invalid style");
|
||||
}
|
||||
if (ystr) {
|
||||
yvar = input->variable->find(ystr);
|
||||
if (yvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", ystr);
|
||||
if (!input->variable->internalstyle(yvar))
|
||||
error->all(FLERR, "Variable for create_atoms is invalid style");
|
||||
}
|
||||
if (zstr) {
|
||||
zvar = input->variable->find(zstr);
|
||||
if (zvar < 0) error->all(FLERR, "Variable {} for create_atoms does not exist", zstr);
|
||||
if (!input->variable->internalstyle(zvar))
|
||||
error->all(FLERR, "Variable for create_atoms is invalid style");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
@ -908,3 +975,20 @@ void *FixDeposit::extract(const char *str, int &itype)
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
test a generated atom position against variable evaluation
|
||||
first set x,y,z values in internal variables
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int FixDeposit::vartest(double x, double y, double z)
|
||||
{
|
||||
if (xstr) input->variable->internal_set(xvar, x);
|
||||
if (ystr) input->variable->internal_set(yvar, y);
|
||||
if (zstr) input->variable->internal_set(zvar, z);
|
||||
|
||||
double value = input->variable->compute_equal(vvar);
|
||||
|
||||
if (value == 0.0) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -40,7 +40,8 @@ class FixDeposit : public Fix {
|
||||
private:
|
||||
int ninsert, ntype, nfreq, seed;
|
||||
int globalflag, localflag, maxattempt, rateflag, scaleflag, targetflag;
|
||||
int mode, rigidflag, shakeflag, idnext, distflag, orientflag;
|
||||
int mode, rigidflag, shakeflag, idnext, distflag, orientflag, warnflag;
|
||||
int varflag, vvar, xvar, yvar, zvar;
|
||||
double lo, hi, deltasq, nearsq, rate, sigma;
|
||||
double vxlo, vxhi, vylo, vyhi, vzlo, vzhi;
|
||||
double xlo, xhi, ylo, yhi, zlo, zhi, xmid, ymid, zmid;
|
||||
@ -48,6 +49,8 @@ class FixDeposit : public Fix {
|
||||
class Region *iregion;
|
||||
char *idregion;
|
||||
char *idrigid, *idshake;
|
||||
char *vstr, *xstr, *ystr, *zstr;
|
||||
char *xstr_copy, *ystr_copy, *zstr_copy;
|
||||
|
||||
class Molecule **onemols;
|
||||
int nmol, natom_max;
|
||||
@ -64,6 +67,7 @@ class FixDeposit : public Fix {
|
||||
|
||||
void find_maxid();
|
||||
void options(int, char **);
|
||||
int vartest(double, double, double); // evaluate a variable with new atom position
|
||||
};
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
Reference in New Issue
Block a user