git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@3568 f3b2605a-c512-4ea7-a41b-209d697bcdaa

This commit is contained in:
sjplimp 2009-12-17 23:52:50 +00:00
parent f0512a96c8
commit 5f3af95136
8 changed files with 107 additions and 63 deletions

View File

@ -249,7 +249,7 @@ void ComputePropertyAtom::compute_peratom()
buf = vector;
(this->*pack_choice[0])(0);
} else {
buf = array[0];
if (array) buf = array[0];
for (int n = 0; n < nvalues; n++)
(this->*pack_choice[n])(n);
}

View File

@ -14,15 +14,13 @@
#include "string.h"
#include "compute_property_local.h"
#include "atom.h"
#include "atom_vec.h"
#include "update.h"
#include "force.h"
#include "domain.h"
#include "memory.h"
#include "error.h"
#include "comm.h"
using namespace LAMMPS_NS;
// customize by adding keyword
@ -110,7 +108,7 @@ ComputePropertyLocal::ComputePropertyLocal(LAMMPS *lmp, int narg, char **arg) :
error->all("Compute property/local cannot use these inputs together");
kindflag = DIHEDRAL;
} else if (strcmp(arg[iarg],"datom4") == 0) {
pack_choice[i] = &ComputePropertyLocal::pack_datom3;
pack_choice[i] = &ComputePropertyLocal::pack_datom4;
if (kindflag != NONE && kindflag != DIHEDRAL)
error->all("Compute property/local cannot use these inputs together");
kindflag = DIHEDRAL;
@ -136,7 +134,7 @@ ComputePropertyLocal::ComputePropertyLocal(LAMMPS *lmp, int narg, char **arg) :
error->all("Compute property/local cannot use these inputs together");
kindflag = IMPROPER;
} else if (strcmp(arg[iarg],"iatom4") == 0) {
pack_choice[i] = &ComputePropertyLocal::pack_iatom3;
pack_choice[i] = &ComputePropertyLocal::pack_iatom4;
if (kindflag != NONE && kindflag != IMPROPER)
error->all("Compute property/local cannot use these inputs together");
kindflag = IMPROPER;
@ -149,6 +147,17 @@ ComputePropertyLocal::ComputePropertyLocal(LAMMPS *lmp, int narg, char **arg) :
} else error->all("Invalid keyword in compute property/local command");
}
// error check
if (kindflag == BOND && atom->avec->bonds_allow == 0)
error->all("Compute property/local for property that isn't allocated");
if (kindflag == ANGLE && atom->avec->angles_allow == 0)
error->all("Compute property/local for property that isn't allocated");
if (kindflag == DIHEDRAL && atom->avec->dihedrals_allow == 0)
error->all("Compute property/local for property that isn't allocated");
if (kindflag == IMPROPER && atom->avec->impropers_allow == 0)
error->all("Compute property/local for property that isn't allocated");
nmax = 0;
vector = NULL;
array = NULL;
@ -207,7 +216,7 @@ void ComputePropertyLocal::compute_local()
buf = vector;
(this->*pack_choice[0])(0);
} else {
buf = array[0];
if (array) buf = array[0];
for (int n = 0; n < nvalues; n++)
(this->*pack_choice[n])(n);
}

View File

@ -52,6 +52,7 @@ Dump::Dump(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp)
format = NULL;
format_user = NULL;
clearstep = 0;
sort_flag = 0;
append_flag = 0;

View File

@ -37,6 +37,7 @@ class Dump : protected Pointers {
int sort_flag; // 1 if write in sorted order, 0 if not
int append_flag; // 1 if open file in append mode, 0 if not
int singlefile_opened; // 1 = one big file, already opened, else 0
int clearstep; // 1 if dump invokes computes, 0 if not
char *format_default; // default format string
char *format_user; // format string set by user

View File

@ -51,6 +51,8 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
{
if (narg == 5) error->all("No dump custom arguments specified");
clearstep = 1;
nevery = atoi(arg[3]);
size_one = nfield = narg-5;
@ -81,7 +83,7 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
variable = NULL;
vbuf = NULL;
// process keywords
// process attributes
parse_fields(narg,arg);
@ -974,7 +976,7 @@ void DumpCustom::parse_fields(int narg, char **arg)
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all("Invalid keyword in dump custom command");
error->all("Invalid attribute in dump custom command");
argindex[i] = atoi(ptr+1);
*ptr = '\0';
} else argindex[i] = 0;
@ -1008,7 +1010,7 @@ void DumpCustom::parse_fields(int narg, char **arg)
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all("Invalid keyword in dump custom command");
error->all("Invalid attribute in dump custom command");
argindex[i] = atoi(ptr+1);
*ptr = '\0';
} else argindex[i] = 0;
@ -1048,7 +1050,7 @@ void DumpCustom::parse_fields(int narg, char **arg)
field2index[i] = add_variable(suffix);
delete [] suffix;
} else error->all("Invalid keyword in dump custom command");
} else error->all("Invalid attribute in dump custom command");
}
}
@ -1173,7 +1175,7 @@ int DumpCustom::modify_param(int narg, char **arg)
memory->srealloc(thresh_value,(nthresh+1)*sizeof(double),
"dump:thresh_value");
// set keyword type of threshhold
// set attribute type of threshhold
// customize by adding to if statement
if (strcmp(arg[1],"id") == 0) thresh_array[nthresh] = ID;
@ -1258,25 +1260,25 @@ int DumpCustom::modify_param(int narg, char **arg)
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all("Invalid keyword in dump custom command");
error->all("Invalid attribute in dump modify command");
argindex[nfield+nthresh] = atoi(ptr+1);
*ptr = '\0';
} else argindex[nfield+nthresh] = 0;
n = modify->find_compute(suffix);
if (n < 0) error->all("Could not find dump custom compute ID");
if (n < 0) error->all("Could not find dump modify compute ID");
if (modify->compute[n]->peratom_flag == 0)
error->all("Dump custom compute ID does not compute per-atom info");
error->all("Dump modify compute ID does not compute per-atom info");
if (argindex[nfield+nthresh] == 0 &&
modify->compute[n]->size_peratom_cols > 0)
error->all("Dump custom compute ID does not compute per-atom vector");
error->all("Dump modify compute ID does not compute per-atom vector");
if (argindex[nfield+nthresh] > 0 &&
modify->compute[n]->size_peratom_cols == 0)
error->all("Dump custom compute ID does not compute per-atom array");
error->all("Dump modify compute ID does not compute per-atom array");
if (argindex[nfield+nthresh] > 0 &&
argindex[nfield+nthresh] > modify->compute[n]->size_peratom_cols)
error->all("Dump custom compute ID vector is not large enough");
error->all("Dump modify compute ID vector is not large enough");
field2index[nfield+nthresh] = add_compute(suffix);
delete [] suffix;
@ -1300,25 +1302,25 @@ int DumpCustom::modify_param(int narg, char **arg)
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all("Invalid keyword in dump custom command");
error->all("Invalid attribute in dump modify command");
argindex[nfield+nthresh] = atoi(ptr+1);
*ptr = '\0';
} else argindex[nfield+nthresh] = 0;
n = modify->find_fix(suffix);
if (n < 0) error->all("Could not find dump custom fix ID");
if (n < 0) error->all("Could not find dump modify fix ID");
if (modify->fix[n]->peratom_flag == 0)
error->all("Dump custom fix ID does not compute per-atom info");
error->all("Dump modify fix ID does not compute per-atom info");
if (argindex[nfield+nthresh] == 0 &&
modify->fix[n]->size_peratom_cols > 0)
error->all("Dump custom fix ID does not compute per-atom vector");
error->all("Dump modify fix ID does not compute per-atom vector");
if (argindex[nfield+nthresh] > 0 &&
modify->fix[n]->size_peratom_cols == 0)
error->all("Dump custom fix ID does not compute per-atom array");
error->all("Dump modify fix ID does not compute per-atom array");
if (argindex[nfield+nthresh] > 0 &&
argindex[nfield+nthresh] > modify->fix[n]->size_peratom_cols)
error->all("Dump custom fix ID vector is not large enough");
error->all("Dump modify fix ID vector is not large enough");
field2index[nfield+nthresh] = add_fix(suffix);
delete [] suffix;
@ -1341,9 +1343,9 @@ int DumpCustom::modify_param(int narg, char **arg)
argindex[nfield+nthresh] = 0;
n = input->variable->find(suffix);
if (n < 0) error->all("Could not find dump custom variable name");
if (n < 0) error->all("Could not find dump modify variable name");
if (input->variable->atomstyle(n) == 0)
error->all("Dump custom variable is not atom-style variable");
error->all("Dump modify variable is not atom-style variable");
field2index[nfield+nthresh] = add_variable(suffix);
delete [] suffix;
@ -1457,9 +1459,9 @@ void DumpCustom::pack_variable(int n)
}
/* ----------------------------------------------------------------------
one method for every keyword dump custom can output
one method for every attribute dump custom can output
the atom property is packed into buf starting at n with stride size_one
customize a new keyword by adding a method
customize a new attribute by adding a method
------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */

View File

@ -24,12 +24,8 @@
#include "memory.h"
#include "error.h"
#include "comm.h"
using namespace LAMMPS_NS;
enum{INDEX,COMPUTE,FIX};
enum{INT,DOUBLE};
#define INVOKED_LOCAL 16
@ -41,6 +37,8 @@ DumpLocal::DumpLocal(LAMMPS *lmp, int narg, char **arg) :
{
if (narg == 5) error->all("No dump local arguments specified");
clearstep = 1;
nevery = atoi(arg[3]);
size_one = nfield = narg-5;
@ -60,7 +58,7 @@ DumpLocal::DumpLocal(LAMMPS *lmp, int narg, char **arg) :
id_fix = NULL;
fix = NULL;
// process keywords
// process attributes
parse_fields(narg,arg);
@ -88,7 +86,12 @@ DumpLocal::DumpLocal(LAMMPS *lmp, int narg, char **arg) :
strcat(columns," ");
}
label = "BONDS";
// setup default label string
char *str = "ENTRIES";
n = strlen(str) + 1;
label = new char[n];
strcpy(label,str);
}
/* ---------------------------------------------------------------------- */
@ -112,6 +115,7 @@ DumpLocal::~DumpLocal()
delete [] vformat;
delete [] columns;
delete [] label;
}
/* ---------------------------------------------------------------------- */
@ -145,17 +149,17 @@ void DumpLocal::init()
int icompute;
for (int i = 0; i < ncompute; i++) {
icompute = modify->find_compute(id_compute[i]);
if (icompute < 0) error->all("Could not find dump custom compute ID");
if (icompute < 0) error->all("Could not find dump local compute ID");
compute[i] = modify->compute[icompute];
}
int ifix;
for (int i = 0; i < nfix; i++) {
ifix = modify->find_fix(id_fix[i]);
if (ifix < 0) error->all("Could not find dump custom fix ID");
if (ifix < 0) error->all("Could not find dump local fix ID");
fix[i] = modify->fix[ifix];
if (nevery % modify->fix[ifix]->peratom_freq)
error->all("Dump custom and fix not computed at compatible times");
if (nevery % modify->fix[ifix]->local_freq)
error->all("Dump local and fix not computed at compatible times");
}
// open single file, one time only
@ -165,6 +169,21 @@ void DumpLocal::init()
/* ---------------------------------------------------------------------- */
int DumpLocal::modify_param(int narg, char **arg)
{
if (strcmp(arg[0],"label") == 0) {
if (narg < 2) error->all("Illegal dump_modify command");
delete [] label;
int n = strlen(arg[1]) + 1;
label = new char[n];
strcpy(label,arg[1]);
return 2;
}
return 0;
}
/* ---------------------------------------------------------------------- */
void DumpLocal::write_header(int ndump)
{
if (me == 0) {
@ -172,7 +191,7 @@ void DumpLocal::write_header(int ndump)
fprintf(fp,"%d\n",update->ntimestep);
fprintf(fp,"ITEM: NUMBER OF %s\n",label);
fprintf(fp,"%d\n",ndump);
fprintf(fp,"ITEM: %s\n",label);
fprintf(fp,"ITEM: %s %s\n",label,columns);
}
}
@ -190,11 +209,29 @@ int DumpLocal::count()
if (!(compute[i]->invoked_flag & INVOKED_LOCAL)) {
compute[i]->compute_local();
compute[i]->invoked_flag |= INVOKED_LOCAL;
nmine = compute[i]->size_local_rows;
}
}
}
// nmine = # of local values I contribute
// must be consistent for all input fields
nmine = -1;
int icompute;
for (int i = 0; i < ncompute; i++) {
if (nmine < 0) nmine = compute[i]->size_local_rows;
else if (nmine != compute[i]->size_local_rows)
error->one("Dump local count is not consistent across input fields");
}
int ifix;
for (int i = 0; i < nfix; i++) {
if (nmine < 0) nmine = fix[i]->size_local_rows;
else if (nmine != fix[i]->size_local_rows)
error->one("Dump local count is not consistent across input fields");
}
return nmine;
}
@ -227,6 +264,8 @@ void DumpLocal::write_data(int n, double *buf)
void DumpLocal::parse_fields(int narg, char **arg)
{
int computefixflag = 0;
// customize by adding to if statement
int i;
@ -241,6 +280,7 @@ void DumpLocal::parse_fields(int narg, char **arg)
// if no trailing [], then arg is set to 0, else arg is int between []
} else if (strncmp(arg[iarg],"c_",2) == 0) {
computefixflag = 1;
pack_choice[i] = &DumpLocal::pack_compute;
vtype[i] = DOUBLE;
@ -251,7 +291,7 @@ void DumpLocal::parse_fields(int narg, char **arg)
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all("Invalid keyword in dump local command");
error->all("Invalid attribute in dump local command");
argindex[i] = atoi(ptr+1);
*ptr = '\0';
} else argindex[i] = 0;
@ -275,6 +315,7 @@ void DumpLocal::parse_fields(int narg, char **arg)
// if no trailing [], then arg is set to 0, else arg is between []
} else if (strncmp(arg[iarg],"f_",2) == 0) {
computefixflag = 1;
pack_choice[i] = &DumpLocal::pack_fix;
vtype[i] = DOUBLE;
@ -285,7 +326,7 @@ void DumpLocal::parse_fields(int narg, char **arg)
char *ptr = strchr(suffix,'[');
if (ptr) {
if (suffix[strlen(suffix)-1] != ']')
error->all("Invalid keyword in dump local command");
error->all("Invalid attribute in dump local command");
argindex[i] = atoi(ptr+1);
*ptr = '\0';
} else argindex[i] = 0;
@ -305,8 +346,11 @@ void DumpLocal::parse_fields(int narg, char **arg)
field2index[i] = add_fix(suffix);
delete [] suffix;
} else error->all("Invalid keyword in dump local command");
} else error->all("Invalid attribute in dump local command");
}
if (computefixflag == 0)
error->all("Dump local attributes contain no compute or fix");
}
/* ----------------------------------------------------------------------
@ -407,9 +451,9 @@ void DumpLocal::pack_fix(int n)
}
/* ----------------------------------------------------------------------
one method for every keyword dump local can output
one method for every attribute dump local can output
the local value is packed into buf starting at n with stride size_one
customize a new keyword by adding a method
customize a new attribute by adding a method
------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------- */

View File

@ -48,8 +48,7 @@ class DumpLocal : public Dump {
char **id_fix; // their IDs
class Fix **fix; // list of ptrs to the Fix objects
// private methods
int modify_param(int, char **);
void write_header(int);
int count();
int pack();

View File

@ -137,10 +137,7 @@ void Output::setup(int flag)
if (ndump && update->restrict_output == 0) {
for (int idump = 0; idump < ndump; idump++) {
if (strcmp(dump[idump]->style,"custom") == 0 ||
strcmp(dump[idump]->style,"cfg") == 0 ||
strcmp(dump[idump]->style,"local") == 0)
modify->clearstep_compute();
if (dump[idump]->clearstep) modify->clearstep_compute();
if ((ntimestep % dump_every[idump] == 0 &&
last_dump[idump] != ntimestep) || last_dump[idump] < 0) {
dump[idump]->write();
@ -148,10 +145,7 @@ void Output::setup(int flag)
}
next_dump[idump] =
(ntimestep/dump_every[idump])*dump_every[idump] + dump_every[idump];
if (strcmp(dump[idump]->style,"custom") == 0 ||
strcmp(dump[idump]->style,"cfg") == 0 ||
strcmp(dump[idump]->style,"local") == 0)
modify->addstep_compute(next_dump[idump]);
if (dump[idump]->clearstep) modify->addstep_compute(next_dump[idump]);
if (idump) next_dump_any = MYMIN(next_dump_any,next_dump[idump]);
else next_dump_any = next_dump[0];
}
@ -208,17 +202,11 @@ void Output::write(int ntimestep)
if (next_dump_any == ntimestep) {
for (int idump = 0; idump < ndump; idump++) {
if (next_dump[idump] == ntimestep && last_dump[idump] != ntimestep) {
if (strcmp(dump[idump]->style,"custom") == 0 ||
strcmp(dump[idump]->style,"cfg") == 0 ||
strcmp(dump[idump]->style,"local") == 0)
modify->clearstep_compute();
if (dump[idump]->clearstep) modify->clearstep_compute();
dump[idump]->write();
last_dump[idump] = ntimestep;
next_dump[idump] += dump_every[idump];
if (strcmp(dump[idump]->style,"custom") == 0 ||
strcmp(dump[idump]->style,"cfg") == 0 ||
strcmp(dump[idump]->style,"local") == 0)
modify->addstep_compute(next_dump[idump]);
if (dump[idump]->clearstep) modify->addstep_compute(next_dump[idump]);
}
if (idump) next_dump_any = MYMIN(next_dump_any,next_dump[idump]);
else next_dump_any = next_dump[0];