本文整理汇总了C++中AtomVec::pack_restart方法的典型用法代码示例。如果您正苦于以下问题:C++ AtomVec::pack_restart方法的具体用法?C++ AtomVec::pack_restart怎么用?C++ AtomVec::pack_restart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AtomVec
的用法示例。
在下文中一共展示了AtomVec::pack_restart方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
void WriteRestart::write(char *file)
{
// special case where reneighboring is not done in integrator
// on timestep restart file is written (due to build_once being set)
// if box is changing, must be reset, else restart file will have
// wrong box size and atoms will be lost when restart file is read
// other calls to pbc and domain and comm are not made,
// b/c they only make sense if reneighboring is actually performed
if (neighbor->build_once) domain->reset_box();
// natoms = sum of nlocal = value to write into restart file
// if unequal and thermo lostflag is "error", don't write restart file
bigint nblocal = atom->nlocal;
if(region)
{
nblocal = 0.;
for (int i = 0; i < atom->nlocal; i++)
if(region->match(atom->x[i][0],atom->x[i][1],atom->x[i][2]))
nblocal += 1;
}
MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world);
if (natoms != atom->natoms && output->thermo->lostflag == ERROR && !region)
error->all(FLERR,"Atom count is inconsistent, cannot write restart file");
// check if filename contains "%"
int multiproc;
if (strchr(file,'%')) multiproc = 1;
else multiproc = 0;
// open single restart file or base file for multiproc case
if (me == 0) {
char *hfile;
if (multiproc) {
hfile = new char[strlen(file) + 16];
char *ptr = strchr(file,'%');
*ptr = '\0';
sprintf(hfile,"%s%s%s",file,"base",ptr+1);
*ptr = '%';
} else hfile = file;
fp = fopen(hfile,"wb");
if (fp == NULL) {
char str[512];
sprintf(str,"Cannot open restart file %s",hfile);
error->one(FLERR,str);
}
if (multiproc) delete [] hfile;
}
// proc 0 writes header, groups, ntype-length arrays, force field
// all procs write fix info
if (me == 0) {
header();
group->write_restart(fp);
type_arrays();
force_fields();
}
modify->write_restart(fp);
// communication buffer for all my atom's info
// max_size = largest buffer needed by any proc
int max_size;
int send_size = atom->avec->size_restart();
MPI_Allreduce(&send_size,&max_size,1,MPI_INT,MPI_MAX,world);
double *buf;
if (me == 0) memory->create(buf,max_size,"write_restart:buf");
else memory->create(buf,send_size,"write_restart:buf");
// pack my atom data into buf
AtomVec *avec = atom->avec;
int n = 0;
if(!region)
{
for (int i = 0; i < atom->nlocal; i++) n += avec->pack_restart(i,&buf[n]);
}
else
{
for (int i = 0; i < atom->nlocal; i++)
if(region->match(atom->x[i][0],atom->x[i][1],atom->x[i][2]))
n += avec->pack_restart(i,&buf[n]);
send_size = n;
}
// if any fix requires it, remap each atom's coords via PBC
// is because fix changes atom coords (excepting an integrate fix)
// just remap in buffer, not actual atoms
if (modify->restart_pbc_any) {
//.........这里部分代码省略.........
示例2: write
//.........这里部分代码省略.........
file_layout(send_size);
// header info is complete
// if multiproc output:
// close header file, open multiname file on each writing proc,
// write PROCSPERFILE into new file
if (multiproc) {
if (me == 0) fclose(fp);
char *multiname = new char[strlen(file) + 16];
char *ptr = strchr(file,'%');
*ptr = '\0';
sprintf(multiname,"%s%d%s",file,icluster,ptr+1);
*ptr = '%';
if (filewriter) {
fp = fopen(multiname,"wb");
if (fp == NULL) {
char str[128];
sprintf(str,"Cannot open restart file %s",multiname);
error->one(FLERR,str);
}
write_int(PROCSPERFILE,nclusterprocs);
}
delete [] multiname;
}
// pack my atom data into buf
AtomVec *avec = atom->avec;
int n = 0;
for (int i = 0; i < atom->nlocal; i++) n += avec->pack_restart(i,&buf[n]);
// if any fix requires it, remap each atom's coords via PBC
// is because fix changes atom coords (excepting an integrate fix)
// just remap in buffer, not actual atoms
if (modify->restart_pbc_any) {
int triclinic = domain->triclinic;
double *lo,*hi,*period;
if (triclinic == 0) {
lo = domain->boxlo;
hi = domain->boxhi;
period = domain->prd;
} else {
lo = domain->boxlo_lamda;
hi = domain->boxhi_lamda;
period = domain->prd_lamda;
}
int xperiodic = domain->xperiodic;
int yperiodic = domain->yperiodic;
int zperiodic = domain->zperiodic;
double *x;
int m = 0;
for (int i = 0; i < atom->nlocal; i++) {
x = &buf[m+1];
if (triclinic) domain->x2lamda(x,x);
if (xperiodic) {
if (x[0] < lo[0]) x[0] += period[0];
if (x[0] >= hi[0]) x[0] -= period[0];