void *lammps_extract_compute(void *ptr, char *id, int style, int type) { LAMMPS *lmp = (LAMMPS *) ptr; int icompute = lmp->modify->find_compute(id); if (icompute < 0) return NULL; Compute *compute = lmp->modify->compute[icompute]; if (style == 0) { if (type == 0) { if (!compute->scalar_flag) return NULL; if (compute->invoked_scalar != lmp->update->ntimestep) compute->compute_scalar(); return (void *) &compute->scalar; } if (type == 1) { if (!compute->vector_flag) return NULL; if (compute->invoked_vector != lmp->update->ntimestep) compute->compute_vector(); return (void *) compute->vector; } if (type == 2) { if (!compute->array_flag) return NULL; if (compute->invoked_array != lmp->update->ntimestep) compute->compute_array(); return (void *) compute->array; } } if (style == 1) { if (!compute->peratom_flag) return NULL; if (type == 1) { if (compute->invoked_peratom != lmp->update->ntimestep) compute->compute_peratom(); return (void *) compute->vector_atom; } if (type == 2) { if (compute->invoked_peratom != lmp->update->ntimestep) compute->compute_peratom(); return (void *) compute->array_atom; } } if (style == 2) { if (!compute->local_flag) return NULL; if (type == 1) { if (compute->invoked_local != lmp->update->ntimestep) compute->compute_local(); return (void *) compute->vector_local; } if (type == 2) { if (compute->invoked_local != lmp->update->ntimestep) compute->compute_local(); return (void *) compute->array_local; } } return NULL; }
void ComputeSlice::extract_one(int m, double *vec, int stride) { int i,j; // invoke the appropriate compute if needed if (which[m] == COMPUTE) { Compute *compute = modify->compute[value2index[m]]; if (argindex[m] == 0) { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } double *cvector = compute->vector; j = 0; for (i = nstart; i < nstop; i += nskip) { vec[j] = cvector[i-1]; j += stride; } } else { if (!(compute->invoked_flag & INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= INVOKED_ARRAY; } double **carray = compute->array; int icol = argindex[m]-1; j = 0; for (i = nstart; i < nstop; i += nskip) { vec[j] = carray[i-1][icol]; j += stride; } } // access fix fields, check if fix frequency is a match } else if (which[m] == FIX) { if (update->ntimestep % modify->fix[value2index[m]]->global_freq) error->all(FLERR,"Fix used in compute slice not computed at compatible time"); Fix *fix = modify->fix[value2index[m]]; if (argindex[m] == 0) { j = 0; for (i = nstart; i < nstop; i += nskip) { vec[j] = fix->compute_vector(i-1); j += stride; } } else { int icol = argindex[m]-1; j = 0; for (i = nstart; i < nstop; i += nskip) { vec[j] = fix->compute_array(i-1,icol); j += stride; } } } }
void FixAveHisto::end_of_step() { int i,j,m; // skip if not step which requires doing something // error check if timestep was reset in an invalid manner bigint ntimestep = update->ntimestep; if (ntimestep < nvalid_last || ntimestep > nvalid) error->all(FLERR,"Invalid timestep reset for fix ave/histo"); if (ntimestep != nvalid) return; nvalid_last = nvalid; // zero if first step if (irepeat == 0) { stats[0] = stats[1] = 0.0; stats[2] = BIG; stats[3] = -BIG; for (i = 0; i < nbins; i++) bin[i] = 0.0; } // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); for (i = 0; i < nvalues; i++) { m = value2index[i]; j = argindex[i]; // atom attributes if (which[i] == X) bin_atoms(&atom->x[0][j],3); else if (which[i] == V) bin_atoms(&atom->v[0][j],3); else if (which[i] == F) bin_atoms(&atom->f[0][j],3); // invoke compute if not previously invoked if (which[i] == COMPUTE) { Compute *compute = modify->compute[m]; if (kind == GLOBAL && mode == SCALAR) { if (j == 0) { if (!(compute->invoked_flag & INVOKED_SCALAR)) { compute->compute_scalar(); compute->invoked_flag |= INVOKED_SCALAR; } bin_one(compute->scalar); } else { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } bin_one(compute->vector[j-1]); } } else if (kind == GLOBAL && mode == VECTOR) { if (j == 0) { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } bin_vector(compute->size_vector,compute->vector,1); } else { if (!(compute->invoked_flag & INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= INVOKED_ARRAY; } if (compute->array) bin_vector(compute->size_array_rows,&compute->array[0][j-1], compute->size_array_cols); } } else if (kind == PERATOM) { if (!(compute->invoked_flag & INVOKED_PERATOM)) { compute->compute_peratom(); compute->invoked_flag |= INVOKED_PERATOM; } if (j == 0) bin_atoms(compute->vector_atom,1); else if (compute->array_atom) bin_atoms(&compute->array_atom[0][j-1],compute->size_peratom_cols); } else if (kind == LOCAL) { if (!(compute->invoked_flag & INVOKED_LOCAL)) { compute->compute_local(); compute->invoked_flag |= INVOKED_LOCAL; } if (j == 0) bin_vector(compute->size_local_rows,compute->vector_local,1); else if (compute->array_local) bin_vector(compute->size_local_rows,&compute->array_local[0][j-1], compute->size_local_cols); } // access fix fields, guaranteed to be ready } else if (which[i] == FIX) { Fix *fix = modify->fix[m]; if (kind == GLOBAL && mode == SCALAR) { if (j == 0) bin_one(fix->compute_scalar()); else bin_one(fix->compute_vector(j-1)); } else if (kind == GLOBAL && mode == VECTOR) { if (j == 0) { int n = fix->size_vector; for (i = 0; i < n; i++) bin_one(fix->compute_vector(i)); } else { int n = fix->size_vector; for (i = 0; i < n; i++) bin_one(fix->compute_array(i,j-1)); } } else if (kind == PERATOM) { if (j == 0) bin_atoms(fix->vector_atom,1); else if (fix->array_atom) bin_atoms(fix->array_atom[j-1],fix->size_peratom_cols); } else if (kind == LOCAL) { if (j == 0) bin_vector(fix->size_local_rows,fix->vector_local,1); else if (fix->array_local) bin_vector(fix->size_local_rows,&fix->array_local[0][j-1], fix->size_local_cols); } // evaluate equal-style variable } else if (which[i] == VARIABLE && kind == GLOBAL) { bin_one(input->variable->compute_equal(m)); } else if (which[i] == VARIABLE && kind == PERATOM) { if (atom->nlocal > maxatom) { memory->destroy(vector); maxatom = atom->nmax; memory->create(vector,maxatom,"ave/histo:vector"); } input->variable->compute_atom(m,igroup,vector,1,0); bin_atoms(vector,1); } } // done if irepeat < nrepeat // else reset irepeat and nvalid irepeat++; if (irepeat < nrepeat) { nvalid += nevery; modify->addstep_compute(nvalid); return; } irepeat = 0; nvalid = ntimestep + nfreq - (nrepeat-1)*nevery; modify->addstep_compute(nvalid); // merge histogram stats across procs if necessary if (kind == PERATOM || kind == LOCAL) { MPI_Allreduce(stats,stats_all,2,MPI_DOUBLE,MPI_SUM,world); MPI_Allreduce(&stats[2],&stats_all[2],1,MPI_DOUBLE,MPI_MIN,world); MPI_Allreduce(&stats[3],&stats_all[3],1,MPI_DOUBLE,MPI_MAX,world); MPI_Allreduce(bin,bin_all,nbins,MPI_DOUBLE,MPI_SUM,world); stats[0] = stats_all[0]; stats[1] = stats_all[1]; stats[2] = stats_all[2]; stats[3] = stats_all[3]; for (i = 0; i < nbins; i++) bin[i] = bin_all[i]; } // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, combine with nwindow most recent Nfreq timestep values if (ave == ONE) { stats_total[0] = stats[0]; stats_total[1] = stats[1]; stats_total[2] = stats[2]; stats_total[3] = stats[3]; for (i = 0; i < nbins; i++) bin_total[i] = bin[i]; } else if (ave == RUNNING) { stats_total[0] += stats[0]; stats_total[1] += stats[1]; stats_total[2] = MIN(stats_total[2],stats[2]); stats_total[3] = MAX(stats_total[3],stats[3]); for (i = 0; i < nbins; i++) bin_total[i] += bin[i]; } else if (ave == WINDOW) { stats_total[0] += stats[0]; if (window_limit) stats_total[0] -= stats_list[iwindow][0]; stats_list[iwindow][0] = stats[0]; stats_total[1] += stats[1]; if (window_limit) stats_total[1] -= stats_list[iwindow][1]; stats_list[iwindow][1] = stats[1]; if (window_limit) m = nwindow; else m = iwindow+1; stats_list[iwindow][2] = stats[2]; stats_total[2] = stats_list[0][2]; for (i = 1; i < m; i++) stats_total[2] = MIN(stats_total[2],stats_list[i][2]); stats_list[iwindow][3] = stats[3]; stats_total[3] = stats_list[0][3]; for (i = 1; i < m; i++) stats_total[3] = MAX(stats_total[3],stats_list[i][3]); for (i = 0; i < nbins; i++) { bin_total[i] += bin[i]; if (window_limit) bin_total[i] -= bin_list[iwindow][i]; bin_list[iwindow][i] = bin[i]; } iwindow++; if (iwindow == nwindow) { iwindow = 0; window_limit = 1; } } // output result to file if (fp && me == 0) { if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT " %d %g %g %g %g\n",ntimestep,nbins, stats_total[0],stats_total[1],stats_total[2],stats_total[3]); if (stats_total[0] != 0.0) for (i = 0; i < nbins; i++) fprintf(fp,"%d %g %g %g\n", i+1,coord[i],bin_total[i],bin_total[i]/stats_total[0]); else for (i = 0; i < nbins; i++) fprintf(fp,"%d %g %g %g\n",i+1,coord[i],0.0,0.0); fflush(fp); if (overwrite) { long fileend = ftell(fp); ftruncate(fileno(fp),fileend); } } }
void FixAveTime::invoke_vector(bigint ntimestep) { int i,j,m; // zero if first step if (irepeat == 0) for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array[i][j] = 0.0; // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); for (j = 0; j < nvalues; j++) { m = value2index[j]; // invoke compute if not previously invoked if (which[j] == COMPUTE) { Compute *compute = modify->compute[m]; if (argindex[j] == 0) { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } double *cvector = compute->vector; for (i = 0; i < nrows; i++) column[i] = cvector[i]; } else { if (!(compute->invoked_flag & INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= INVOKED_ARRAY; } double **carray = compute->array; int icol = argindex[j]-1; for (i = 0; i < nrows; i++) column[i] = carray[i][icol]; } // access fix fields, guaranteed to be ready } else if (which[j] == FIX) { Fix *fix = modify->fix[m]; if (argindex[j] == 0) for (i = 0; i < nrows; i++) column[i] = fix->compute_vector(i); else { int icol = argindex[j]-1; for (i = 0; i < nrows; i++) column[i] = fix->compute_array(i,icol); } } // add columns of values to array or just set directly if offcol is set if (offcol[j]) { for (i = 0; i < nrows; i++) array[i][j] = column[i]; } else { for (i = 0; i < nrows; i++) array[i][j] += column[i]; } } // done if irepeat < nrepeat // else reset irepeat and nvalid irepeat++; if (irepeat < nrepeat) { nvalid += nevery; modify->addstep_compute(nvalid); return; } irepeat = 0; nvalid = ntimestep+nfreq - (nrepeat-1)*nevery; modify->addstep_compute(nvalid); // average the final result for the Nfreq timestep double repeat = nrepeat; for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) if (offcol[j] == 0) array[i][j] /= repeat; // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, combine with nwindow most recent Nfreq timestep values if (ntimestep >= startstep) { if (ave == ONE) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array_total[i][j] = array[i][j]; norm = 1; } else if (ave == RUNNING) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array_total[i][j] += array[i][j]; norm++; } else if (ave == WINDOW) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) { array_total[i][j] += array[i][j]; if (window_limit) array_total[i][j] -= array_list[iwindow][i][j]; array_list[iwindow][i][j] = array[i][j]; } iwindow++; if (iwindow == nwindow) { iwindow = 0; window_limit = 1; } if (window_limit) norm = nwindow; else norm = iwindow; } } // insure any columns with offcol set are effectively set to last value for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) if (offcol[j]) array_total[i][j] = norm*array[i][j]; // output result to file if (fp && me == 0) { fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrows); for (i = 0; i < nrows; i++) { fprintf(fp,"%d",i+1); for (j = 0; j < nvalues; j++) fprintf(fp," %g",array_total[i][j]/norm); fprintf(fp,"\n"); } fflush(fp); } }
void FixAveTime::invoke_scalar(bigint ntimestep) { int i,m; double scalar; // zero if first step if (irepeat == 0) for (i = 0; i < nvalues; i++) vector[i] = 0.0; // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); for (i = 0; i < nvalues; i++) { m = value2index[i]; // invoke compute if not previously invoked if (which[i] == COMPUTE) { Compute *compute = modify->compute[m]; if (argindex[i] == 0) { if (!(compute->invoked_flag & INVOKED_SCALAR)) { compute->compute_scalar(); compute->invoked_flag |= INVOKED_SCALAR; } scalar = compute->scalar; } else { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } scalar = compute->vector[argindex[i]-1]; } // access fix fields, guaranteed to be ready } else if (which[i] == FIX) { if (argindex[i] == 0) scalar = modify->fix[m]->compute_scalar(); else scalar = modify->fix[m]->compute_vector(argindex[i]-1); // evaluate equal-style variable } else if (which[i] == VARIABLE) scalar = input->variable->compute_equal(m); // add value to vector or just set directly if offcol is set if (offcol[i]) vector[i] = scalar; else vector[i] += scalar; } // done if irepeat < nrepeat // else reset irepeat and nvalid irepeat++; if (irepeat < nrepeat) { nvalid += nevery; modify->addstep_compute(nvalid); return; } irepeat = 0; nvalid = ntimestep + nfreq - (nrepeat-1)*nevery; modify->addstep_compute(nvalid); // average the final result for the Nfreq timestep double repeat = nrepeat; for (i = 0; i < nvalues; i++) if (offcol[i] == 0) vector[i] /= repeat; // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, combine with nwindow most recent Nfreq timestep values if (ntimestep >= startstep) { if (ave == ONE) { for (i = 0; i < nvalues; i++) vector_total[i] = vector[i]; norm = 1; } else if (ave == RUNNING) { for (i = 0; i < nvalues; i++) vector_total[i] += vector[i]; norm++; } else if (ave == WINDOW) { for (i = 0; i < nvalues; i++) { vector_total[i] += vector[i]; if (window_limit) vector_total[i] -= vector_list[iwindow][i]; vector_list[iwindow][i] = vector[i]; } iwindow++; if (iwindow == nwindow) { iwindow = 0; window_limit = 1; } if (window_limit) norm = nwindow; else norm = iwindow; } } // insure any columns with offcol set are effectively set to last value for (i = 0; i < nvalues; i++) if (offcol[i]) vector_total[i] = norm*vector[i]; // output result to file if (fp && me == 0) { fprintf(fp,BIGINT_FORMAT,ntimestep); for (i = 0; i < nvalues; i++) fprintf(fp," %g",vector_total[i]/norm); fprintf(fp,"\n"); fflush(fp); } }
void FixAveTime::invoke_vector(bigint ntimestep) { int i,j,m; // first sample within single Nfreq epoch // zero out arrays that accumulate over many samples, but not across epochs // invoke setup_chunks() to determine current nchunk // re-allocate per-chunk arrays if needed // invoke lock() in two cases: // if nrepeat > 1: so nchunk cannot change until Nfreq epoch is over, // will be unlocked on last repeat of this Nfreq // if ave = RUNNING/WINDOW and not yet locked: // set forever, will be unlocked in fix destructor // wrap setup_chunks in clearstep/addstep b/c it may invoke computes // both nevery and nfreq are future steps, // since call below to cchunk->ichunk() // does not re-invoke internal cchunk compute on this same step if (irepeat == 0) { if (any_variable_length) { modify->clearstep_compute(); int nrows_new = column_length(1); modify->addstep_compute(ntimestep+nevery); modify->addstep_compute(ntimestep+nfreq); if (all_variable_length && nrows_new != nrows) { nrows = nrows_new; memory->destroy(column); memory->create(column,nrows,"ave/time:column"); allocate_arrays(); } bigint ntimestep = update->ntimestep; int lockforever_flag = 0; for (i = 0; i < nvalues; i++) { if (!varlen[i]) continue; if (nrepeat > 1 && ave == ONE) { Compute *compute = modify->compute[value2index[i]]; compute->lock(this,ntimestep,ntimestep+(nrepeat-1)*nevery); } else if ((ave == RUNNING || ave == WINDOW) && !lockforever) { Compute *compute = modify->compute[value2index[i]]; compute->lock(this,update->ntimestep,-1); lockforever_flag = 1; } } if (lockforever_flag) lockforever = 1; } for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array[i][j] = 0.0; } // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); for (j = 0; j < nvalues; j++) { m = value2index[j]; // invoke compute if not previously invoked if (which[j] == COMPUTE) { Compute *compute = modify->compute[m]; if (argindex[j] == 0) { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } double *cvector = compute->vector; for (i = 0; i < nrows; i++) column[i] = cvector[i]; } else { if (!(compute->invoked_flag & INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= INVOKED_ARRAY; } double **carray = compute->array; int icol = argindex[j]-1; for (i = 0; i < nrows; i++) column[i] = carray[i][icol]; } // access fix fields, guaranteed to be ready } else if (which[j] == FIX) { Fix *fix = modify->fix[m]; if (argindex[j] == 0) for (i = 0; i < nrows; i++) column[i] = fix->compute_vector(i); else { int icol = argindex[j]-1; for (i = 0; i < nrows; i++) column[i] = fix->compute_array(i,icol); } } // add columns of values to array or just set directly if offcol is set if (offcol[j]) { for (i = 0; i < nrows; i++) array[i][j] = column[i]; } else { for (i = 0; i < nrows; i++) array[i][j] += column[i]; } } // done if irepeat < nrepeat // else reset irepeat and nvalid irepeat++; if (irepeat < nrepeat) { nvalid += nevery; modify->addstep_compute(nvalid); return; } irepeat = 0; nvalid = ntimestep+nfreq - (nrepeat-1)*nevery; modify->addstep_compute(nvalid); // unlock any variable length computes at end of Nfreq epoch // do not unlock if ave = RUNNING or WINDOW if (any_variable_length && nrepeat > 1 && ave == ONE) { for (i = 0; i < nvalues; i++) { if (!varlen[i]) continue; Compute *compute = modify->compute[value2index[i]]; compute->unlock(this); } } // average the final result for the Nfreq timestep double repeat = nrepeat; for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) if (offcol[j] == 0) array[i][j] /= repeat; // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, combine with nwindow most recent Nfreq timestep values if (ave == ONE) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array_total[i][j] = array[i][j]; norm = 1; } else if (ave == RUNNING) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array_total[i][j] += array[i][j]; norm++; } else if (ave == WINDOW) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) { array_total[i][j] += array[i][j]; if (window_limit) array_total[i][j] -= array_list[iwindow][i][j]; array_list[iwindow][i][j] = array[i][j]; } iwindow++; if (iwindow == nwindow) { iwindow = 0; window_limit = 1; } if (window_limit) norm = nwindow; else norm = iwindow; } // insure any columns with offcol set are effectively set to last value for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) if (offcol[j]) array_total[i][j] = norm*array[i][j]; // output result to file if (fp && me == 0) { if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrows); for (i = 0; i < nrows; i++) { fprintf(fp,"%d",i+1); for (j = 0; j < nvalues; j++) fprintf(fp,format,array_total[i][j]/norm); fprintf(fp,"\n"); } fflush(fp); if (overwrite) { long fileend = ftell(fp); if (fileend > 0) ftruncate(fileno(fp),fileend); } } }
void FixAveTime::invoke_scalar(bigint ntimestep) { int i,m; double scalar; // zero if first sample within single Nfreq epoch // NOTE: doc this // are not checking for returned length, just initialize it // check for exceeding length is done below if (irepeat == 0) { if (any_variable_length) { modify->clearstep_compute(); column_length(1); modify->addstep_compute(ntimestep+nevery); modify->addstep_compute(ntimestep+nfreq); } for (i = 0; i < nvalues; i++) vector[i] = 0.0; } // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); for (i = 0; i < nvalues; i++) { m = value2index[i]; // invoke compute if not previously invoked if (which[i] == COMPUTE) { Compute *compute = modify->compute[m]; if (argindex[i] == 0) { if (!(compute->invoked_flag & INVOKED_SCALAR)) { compute->compute_scalar(); compute->invoked_flag |= INVOKED_SCALAR; } scalar = compute->scalar; } else { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } // insure no out-of-range access to variable-length compute vector if (varlen[i] && compute->size_vector < argindex[i]) scalar = 0.0; else scalar = compute->vector[argindex[i]-1]; } // access fix fields, guaranteed to be ready } else if (which[i] == FIX) { if (argindex[i] == 0) scalar = modify->fix[m]->compute_scalar(); else scalar = modify->fix[m]->compute_vector(argindex[i]-1); // evaluate equal-style variable } else if (which[i] == VARIABLE) scalar = input->variable->compute_equal(m); // add value to vector or just set directly if offcol is set if (offcol[i]) vector[i] = scalar; else vector[i] += scalar; } // done if irepeat < nrepeat // else reset irepeat and nvalid irepeat++; if (irepeat < nrepeat) { nvalid += nevery; modify->addstep_compute(nvalid); return; } irepeat = 0; nvalid = ntimestep + nfreq - (nrepeat-1)*nevery; modify->addstep_compute(nvalid); // average the final result for the Nfreq timestep double repeat = nrepeat; for (i = 0; i < nvalues; i++) if (offcol[i] == 0) vector[i] /= repeat; // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, combine with nwindow most recent Nfreq timestep values if (ave == ONE) { for (i = 0; i < nvalues; i++) vector_total[i] = vector[i]; norm = 1; } else if (ave == RUNNING) { for (i = 0; i < nvalues; i++) vector_total[i] += vector[i]; norm++; } else if (ave == WINDOW) { for (i = 0; i < nvalues; i++) { vector_total[i] += vector[i]; if (window_limit) vector_total[i] -= vector_list[iwindow][i]; vector_list[iwindow][i] = vector[i]; } iwindow++; if (iwindow == nwindow) { iwindow = 0; window_limit = 1; } if (window_limit) norm = nwindow; else norm = iwindow; } // insure any columns with offcol set are effectively set to last value for (i = 0; i < nvalues; i++) if (offcol[i]) vector_total[i] = norm*vector[i]; // output result to file if (fp && me == 0) { clearerr(fp); if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT,ntimestep); for (i = 0; i < nvalues; i++) fprintf(fp,format,vector_total[i]/norm); fprintf(fp,"\n"); if (ferror(fp)) error->one(FLERR,"Error writing out time averaged data"); fflush(fp); if (overwrite) { long fileend = ftell(fp); if (fileend > 0) ftruncate(fileno(fp),fileend); } } }
void ComputeChunkSpreadAtom::compute_peratom() { invoked_peratom = update->ntimestep; // grow local vector_atom or array_atom if necessary if (atom->nmax > nmax) { if (nvalues == 1) { memory->destroy(vector_atom); nmax = atom->nmax; memory->create(vector_atom,nmax,"chunk/spread/atom:vector_atom"); } else { memory->destroy(array_atom); nmax = atom->nmax; memory->create(array_atom,nmax,nvalues,"chunk/spread/atom:array_atom"); } } // compute chunk/atom assigns atoms to chunk IDs // extract ichunk index vector from compute // ichunk = 1 to Nchunk for included atoms, 0 for excluded atoms int nchunk = cchunk->setup_chunks(); cchunk->compute_ichunk(); int *ichunk = cchunk->ichunk; // loop over values, access compute or fix // loop over atoms, use chunk ID of each atom to store value from compute/fix int *mask = atom->mask; int nlocal = atom->nlocal; int i,m,n,index,nstride; double *ptr; for (m = 0; m < nvalues; m++) { n = value2index[m]; // copy compute/fix values into vector_atom or array_atom // nstride between values for each atom if (nvalues == 1) { ptr = vector_atom; nstride = 1; } else { ptr = &array_atom[0][m]; nstride = nvalues; } // invoke compute if not previously invoked if (which[m] == COMPUTE) { Compute *compute = modify->compute[n]; if (argindex[m] == 0) { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } double *cvector = compute->vector; for (i = 0; i < nlocal; i++, ptr += nstride) { *ptr = 0.0; if (!(mask[i] & groupbit)) continue; index = ichunk[i]-1; if (index < 0 || index >= nchunk) continue; *ptr = cvector[index]; } } else { if (!(compute->invoked_flag & INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= INVOKED_ARRAY; } int icol = argindex[m]-1; double **carray = compute->array; for (i = 0; i < nlocal; i++, ptr += nstride) { *ptr = 0.0; if (!(mask[i] & groupbit)) continue; index = ichunk[i]-1; if (index < 0 || index >= nchunk) continue; *ptr = carray[index][icol]; } } // access fix data, check if fix frequency is a match // are assuming the fix global vector/array is per-chunk data // check if index exceeds fix output length/rows } else if (which[m] == FIX) { Fix *fix = modify->fix[n]; if (update->ntimestep % fix->global_freq) error->all(FLERR,"Fix used in compute chunk/spread/atom not " "computed at compatible time"); if (argindex[m] == 0) { int nfix = fix->size_vector; for (i = 0; i < nlocal; i++, ptr += nstride) { *ptr = 0.0; if (!(mask[i] & groupbit)) continue; index = ichunk[i]-1; if (index < 0 || index >= nchunk || index >= nfix) continue; *ptr = fix->compute_vector(index); } } else { int icol = argindex[m]-1; int nfix = fix->size_array_rows; for (i = 0; i < nlocal; i++, ptr += nstride) { *ptr = 0.0; if (!(mask[i] & groupbit)) continue; index = ichunk[i]-1; if (index < 0 || index >= nchunk || index >= nfix) continue; *ptr = fix->compute_array(index,icol); } } } } }
void FixAveCorrelate::end_of_step() { int i,j,m; double scalar; // skip if not step which requires doing something // error check if timestep was reset in an invalid manner bigint ntimestep = update->ntimestep; if (ntimestep < nvalid_last || ntimestep > nvalid) error->all(FLERR,"Invalid timestep reset for fix ave/correlate"); if (ntimestep != nvalid) return; nvalid_last = nvalid; // accumulate results of computes,fixes,variables to origin // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); // lastindex = index in values ring of latest time sample lastindex++; if (lastindex == nrepeat) lastindex = 0; for (i = 0; i < nvalues; i++) { m = value2index[i]; // invoke compute if not previously invoked if (which[i] == COMPUTE) { Compute *compute = modify->compute[m]; if (argindex[i] == 0) { if (!(compute->invoked_flag & INVOKED_SCALAR)) { compute->compute_scalar(); compute->invoked_flag |= INVOKED_SCALAR; } scalar = compute->scalar; } else { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } scalar = compute->vector[argindex[i]-1]; } // access fix fields, guaranteed to be ready } else if (which[i] == FIX) { if (argindex[i] == 0) scalar = modify->fix[m]->compute_scalar(); else scalar = modify->fix[m]->compute_vector(argindex[i]-1); // evaluate equal-style variable } else if (which[i] == VARIABLE) scalar = input->variable->compute_equal(m); values[lastindex][i] = scalar; } // fistindex = index in values ring of earliest time sample // nsample = number of time samples in values ring if (nsample < nrepeat) nsample++; else { firstindex++; if (firstindex == nrepeat) firstindex = 0; } nvalid += nevery; modify->addstep_compute(nvalid); // calculate all Cij() enabled by latest values accumulate(); if (ntimestep % nfreq) return; // save results in save_count and save_corr for (i = 0; i < nrepeat; i++) { save_count[i] = count[i]; if (count[i]) for (j = 0; j < npair; j++) save_corr[i][j] = prefactor*corr[i][j]/count[i]; else for (j = 0; j < npair; j++) save_corr[i][j] = 0.0; } // output result to file if (fp && me == 0) { if (overwrite) fseek(fp,filepos,SEEK_SET); fprintf(fp,BIGINT_FORMAT " %d\n",ntimestep,nrepeat); for (i = 0; i < nrepeat; i++) { fprintf(fp,"%d %d %d",i+1,i*nevery,count[i]); if (count[i]) for (j = 0; j < npair; j++) fprintf(fp," %g",prefactor*corr[i][j]/count[i]); else for (j = 0; j < npair; j++) fprintf(fp," 0.0"); fprintf(fp,"\n"); } fflush(fp); if (overwrite) { long fileend = ftell(fp); ftruncate(fileno(fp),fileend); } } // zero accumulation if requested // recalculate Cij(0) if (ave == ONE) { for (i = 0; i < nrepeat; i++) { count[i] = 0; for (j = 0; j < npair; j++) corr[i][j] = 0.0; } nsample = 1; accumulate(); } }
void FixSAEDVTK::invoke_vector(bigint ntimestep) { // zero if first step int icompute = modify->find_compute(ids); if (icompute < 0) error->all(FLERR,"Compute ID for fix saed/vtk does not exist"); if (irepeat == 0) for (int i = 0; i < nrows; i++) vector[i] = 0.0; // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); // invoke compute if not previously invoked Compute *compute = modify->compute[icompute]; if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } double *vector = compute->vector; // done if irepeat < nrepeat // else reset irepeat and nvalid irepeat++; if (irepeat < nrepeat) { nvalid += nevery; modify->addstep_compute(nvalid); return; } irepeat = 0; nvalid = ntimestep+nfreq - (nrepeat-1)*nevery; modify->addstep_compute(nvalid); // average the final result for the Nfreq timestep double repeat = nrepeat; for ( int i = 0; i < nrows; i++) vector[i] /= repeat; // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, combine with nwindow most recent Nfreq timestep values if (ave == ONE) { for (int i = 0; i < nrows; i++) vector_total[i] = vector[i]; norm = 1; } else if (ave == RUNNING) { for (int i = 0; i < nrows; i++) vector_total[i] += vector[i]; norm++; } else if (ave == WINDOW) { for (int i = 0; i < nrows; i++) { vector_total[i] += vector[i]; if (window_limit) vector_total[i] -= vector_list[iwindow][i]; vector_list[iwindow][i] = vector[i]; } iwindow++; if (iwindow == nwindow) { iwindow = 0; window_limit = 1; } if (window_limit) norm = nwindow; else norm = iwindow; } // output result to file if (fp && me == 0) { if (nOutput > 0) { fclose(fp); char nName [128]; sprintf(nName,"%s.%d.vtk",filename,nOutput); fp = fopen(nName,"w"); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open fix saed/vtk file %s",nName); error->one(FLERR,str); } } fprintf(fp,"# vtk DataFile Version 3.0 c_%s\n",ids); fprintf(fp,"Image data set\n"); fprintf(fp,"ASCII\n"); fprintf(fp,"DATASET STRUCTURED_POINTS\n"); fprintf(fp,"DIMENSIONS %d %d %d\n", Dim[0], Dim[1], Dim[2]); fprintf(fp,"ASPECT_RATIO %g %g %g\n", dK[0], dK[1], dK[2]); fprintf(fp,"ORIGIN %g %g %g\n", Knmin[0] * dK[0], Knmin[1] * dK[1], Knmin[2] * dK[2]); fprintf(fp,"POINT_DATA %d\n", Dim[0] * Dim[1] * Dim[2] ); fprintf(fp,"SCALARS intensity float\n"); fprintf(fp,"LOOKUP_TABLE default\n"); filepos = ftell(fp); if (overwrite) fseek(fp,filepos,SEEK_SET); // Finding the intersection of the reciprical space and Ewald sphere int NROW1 = 0; int NROW2 = 0; double dinv2 = 0.0; double r = 0.0; double K[3]; // Zone flag to capture entire recrocal space volume if ( (Zone[0] == 0) && (Zone[1] == 0) && (Zone[2] == 0) ){ for (int k = Knmin[2]; k <= Knmax[2]; k++) { for (int j = Knmin[1]; j <= Knmax[1]; j++) { for (int i = Knmin[0]; i <= Knmax[0]; i++) { K[0] = i * dK[0]; K[1] = j * dK[1]; K[2] = k * dK[2]; dinv2 = (K[0] * K[0] + K[1] * K[1] + K[2] * K[2]); if (dinv2 < Kmax * Kmax) { fprintf(fp,"%g\n",vector_total[NROW1]/norm); fflush(fp); NROW1++; NROW2++; } else { fprintf(fp,"%d\n",-1); fflush(fp); NROW2++; } } } } } else { for (int k = Knmin[2]; k <= Knmax[2]; k++) { for (int j = Knmin[1]; j <= Knmax[1]; j++) { for (int i = Knmin[0]; i <= Knmax[0]; i++) { K[0] = i * dK[0]; K[1] = j * dK[1]; K[2] = k * dK[2]; dinv2 = (K[0] * K[0] + K[1] * K[1] + K[2] * K[2]); if (dinv2 < Kmax * Kmax) { r=0.0; for (int m=0; m<3; m++) r += pow(K[m] - Zone[m],2.0); r = sqrt(r); if ( (r > (R_Ewald - dR_Ewald) ) && (r < (R_Ewald + dR_Ewald) ) ){ fprintf(fp,"%g\n",vector_total[NROW1]/norm); fflush(fp); NROW2++; NROW1++; } else { fprintf(fp,"%d\n",-1); fflush(fp); NROW2++; } } else { fprintf(fp,"%d\n",-1); fflush(fp); NROW2++; } } } } } } nOutput++; }
void FixAveTimeSAED::invoke_vector(bigint ntimestep) { int i,j,m; // zero if first step if (irepeat == 0) for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array[i][j] = 0.0; // accumulate results of computes,fixes,variables to local copy // compute/fix/variable may invoke computes so wrap with clear/add modify->clearstep_compute(); for (j = 0; j < nvalues; j++) { m = value2index[j]; // invoke compute if not previously invoked if (which[j] == COMPUTE) { Compute *compute = modify->compute[m]; if (argindex[j] == 0) { if (!(compute->invoked_flag & INVOKED_VECTOR)) { compute->compute_vector(); compute->invoked_flag |= INVOKED_VECTOR; } double *cvector = compute->vector; for (i = 0; i < nrows; i++) column[i] = cvector[i]; } else { if (!(compute->invoked_flag & INVOKED_ARRAY)) { compute->compute_array(); compute->invoked_flag |= INVOKED_ARRAY; } double **carray = compute->array; int icol = argindex[j]-1; for (i = 0; i < nrows; i++) column[i] = carray[i][icol]; } } // add columns of values to array or just set directly if offcol is set if (offcol[j]) { for (i = 0; i < nrows; i++) array[i][j] = column[i]; } else { for (i = 0; i < nrows; i++) array[i][j] += column[i]; } } // done if irepeat < nrepeat // else reset irepeat and nvalid irepeat++; if (irepeat < nrepeat) { nvalid += nevery; modify->addstep_compute(nvalid); return; } irepeat = 0; nvalid = ntimestep+nfreq - (nrepeat-1)*nevery; modify->addstep_compute(nvalid); // average the final result for the Nfreq timestep double repeat = nrepeat; for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) if (offcol[j] == 0) array[i][j] /= repeat; // if ave = ONE, only single Nfreq timestep value is needed // if ave = RUNNING, combine with all previous Nfreq timestep values // if ave = WINDOW, combine with nwindow most recent Nfreq timestep values if (ave == ONE) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array_total[i][j] = array[i][j]; norm = 1; } else if (ave == RUNNING) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) array_total[i][j] += array[i][j]; norm++; } else if (ave == WINDOW) { for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) { array_total[i][j] += array[i][j]; if (window_limit) array_total[i][j] -= array_list[iwindow][i][j]; array_list[iwindow][i][j] = array[i][j]; } iwindow++; if (iwindow == nwindow) { iwindow = 0; window_limit = 1; } if (window_limit) norm = nwindow; else norm = iwindow; } // insure any columns with offcol set are effectively set to last value for (i = 0; i < nrows; i++) for (j = 0; j < nvalues; j++) if (offcol[j]) array_total[i][j] = norm*array[i][j]; // output result to file if (fp && me == 0) { if (nOutput > 0) { fclose(fp); char nName [128]; sprintf(nName,"%s.%d.vtk",filename,nOutput); fp = fopen(nName,"w"); if (fp == NULL) { char str[128]; sprintf(str,"Cannot open fix ave/time file %s",nName); error->one(FLERR,str); } } for (int i = 0; i < nvalues; i++) { if (which[i] == COMPUTE) { fprintf(fp,"# vtk DataFile Version 3.0 c_%s\n",ids[i]); fprintf(fp,"Image data set\n"); fprintf(fp,"ASCII\n"); fprintf(fp,"DATASET STRUCTURED_POINTS\n"); fprintf(fp,"DIMENSIONS %d %d %d\n", Dim[0], Dim[1], Dim[2]); fprintf(fp,"ASPECT_RATIO %g %g %g\n", dK[0], dK[1], dK[2]); fprintf(fp,"ORIGIN %g %g %g\n", Knmin[0] * dK[0], Knmin[1] * dK[1], Knmin[2] * dK[2]); fprintf(fp,"POINT_DATA %d\n", Dim[0] * Dim[1] * Dim[2] ); fprintf(fp,"SCALARS intensity float\n"); fprintf(fp,"LOOKUP_TABLE default\n"); } else break; if (argindex[i]) fprintf(fp,"[%d]",argindex[i]); } filepos = ftell(fp); if (overwrite) fseek(fp,filepos,SEEK_SET); // Finding the intersection of the reciprical space and Ewald sphere int NROW1 = 0; int NROW2 = 0; double dinv2 = 0.0; double r = 0.0; double K[3]; // Zone flag to capture entire recrocal space volume if ( (Zone[0] == 0) && (Zone[1] == 0) && (Zone[2] == 0) ){ for (int k = Knmin[2]; k <= Knmax[2]; k++) { for (int j = Knmin[1]; j <= Knmax[1]; j++) { for (int i = Knmin[0]; i <= Knmax[0]; i++) { K[0] = i * dK[0]; K[1] = j * dK[1]; K[2] = k * dK[2]; dinv2 = (K[0] * K[0] + K[1] * K[1] + K[2] * K[2]); if (dinv2 < Kmax * Kmax) { fprintf(fp,"%g\n",array_total[NROW1][0]/norm); fflush(fp); NROW1++; NROW2++; } else { fprintf(fp,"%d\n",-1); fflush(fp); NROW2++; } } } } } else { for (int k = Knmin[2]; k <= Knmax[2]; k++) { for (int j = Knmin[1]; j <= Knmax[1]; j++) { for (int i = Knmin[0]; i <= Knmax[0]; i++) { K[0] = i * dK[0]; K[1] = j * dK[1]; K[2] = k * dK[2]; dinv2 = (K[0] * K[0] + K[1] * K[1] + K[2] * K[2]); if (dinv2 < Kmax * Kmax) { r=0.0; for (int m=0; m<3; m++) r += pow(K[m] - Zone[m],2.0); r = sqrt(r); if ( (r > (R_Ewald - dR_Ewald) ) && (r < (R_Ewald + dR_Ewald) ) ){ fprintf(fp,"%g\n",array_total[NROW1][0]/norm); fflush(fp); NROW2++; NROW1++; } else { fprintf(fp,"%d\n",-1); fflush(fp); NROW2++; } } else { fprintf(fp,"%d\n",-1); fflush(fp); NROW2++; } } } } } if (me == 0) { if (screen)cout << " FIX AVE TIME SAED ---- n = " << NROW1 << endl; } } nOutput++; }