NAMD
Macros | Typedefs | Functions
HomePatch.C File Reference
#include "NamdTypes.h"
#include "common.h"
#include "time.h"
#include <math.h>
#include "charm++.h"
#include "qd.h"
#include "SimParameters.h"
#include "HomePatch.h"
#include "AtomMap.h"
#include "Node.h"
#include "PatchMap.inl"
#include "main.h"
#include "ProxyMgr.decl.h"
#include "ProxyMgr.h"
#include "Migration.h"
#include "Molecule.h"
#include "PatchMgr.h"
#include "Sequencer.h"
#include "Broadcasts.h"
#include "LdbCoordinator.h"
#include "ReductionMgr.h"
#include "Sync.h"
#include "Random.h"
#include "Priorities.h"
#include "ComputeNonbondedUtil.h"
#include "ComputeGBIS.inl"
#include "SortAtoms.h"
#include "MigrationCUDAKernel.h"
#include "ComputeQM.h"
#include "ComputeQMMgr.decl.h"
#include "NamdEventsProfiling.h"
#include "Debug.h"
#include <vector>
#include <algorithm>

Go to the source code of this file.

Macros

#define TINY   1.0e-20;
 
#define MAXHGS   10
 
#define MIN_DEBUG_LEVEL   2
 
#define MASS_EPSILON   (1.0e-35)
 
#define FIX_FOR_WATER
 

Typedefs

typedef int HGArrayInt[MAXHGS]
 
typedef BigReal HGArrayBigReal[MAXHGS]
 
typedef zVector HGArrayVector[MAXHGS]
 
typedef BigReal HGMatrixBigReal[MAXHGS][MAXHGS]
 
typedef zVector HGMatrixVector[MAXHGS][MAXHGS]
 

Functions

int average (CompAtom *qtilde, const HGArrayVector &q, BigReal *lambda, const int n, const int m, const HGArrayBigReal &imass, const HGArrayBigReal &length2, const HGArrayInt &ial, const HGArrayInt &ibl, const HGArrayVector &refab, const BigReal tolf, const int ntrial)
 
void mollify (CompAtom *qtilde, const HGArrayVector &q0, const BigReal *lambda, HGArrayVector &force, const int n, const int m, const HGArrayBigReal &imass, const HGArrayInt &ial, const HGArrayInt &ibl, const HGArrayVector &refab)
 
void MSHAKE_CUDA (int *, const int size, const RattleParam *rattleParam, BigReal *refx, BigReal *refy, BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, const BigReal tol2, const int maxiter, bool &done, bool &consFailure)
 
static int compDistance (const void *a, const void *b)
 
void PatchDataSOA_initialize (PatchDataSOA *p)
 
size_t PatchDataSOA_set_size (PatchDataSOA *p, int natoms, int padding)
 
void PatchDataSOA_set_buffer (PatchDataSOA *p, void *mybuffer)
 
void lubksb (HGMatrixBigReal &a, int n, HGArrayInt &indx, HGArrayBigReal &b)
 
void ludcmp (HGMatrixBigReal &a, int n, HGArrayInt &indx, BigReal *d)
 
void G_q (const HGArrayVector &refab, HGMatrixVector &gqij, const int n, const int m, const HGArrayInt &ial, const HGArrayInt &ibl)
 

Macro Definition Documentation

◆ FIX_FOR_WATER

#define FIX_FOR_WATER

Redistribute forces from lone pair site onto its host atoms.

Atoms are "labeled" i, j, k, l, where atom i is the lone pair. Positions of atoms are ri, rj, rk, rl. Forces of atoms are fi, fj, fk, fl; updated forces are returned. Accumulate updates to the virial.

The forces on the atoms are updated so that:

  • the force fi on the lone pair site is 0
  • the net force fi+fj+fk+fl is conserved
  • the net torque cross(ri,fi)+cross(rj,fj)+cross(rk,fk)+cross(rl,fl) is conserved

If "midpt" is true (nonzero), then use the midpoint of rk and rl (e.g. rk and rl are the hydrogen atoms for water). Otherwise use planes defined by ri,rj,rk and rj,rk,rl.

Having "midpt" set true corresponds in CHARMM to having a negative distance parameter in Lphost.

Use FIX_FOR_WATER below to fix the case that occurs when the lone pair site for water lies on the perpendicular bisector of rk and rl, making the cross(r,s) zero.

Definition at line 2791 of file HomePatch.C.

◆ MASS_EPSILON

#define MASS_EPSILON   (1.0e-35)

Definition at line 80 of file HomePatch.C.

◆ MAXHGS

#define MAXHGS   10

Definition at line 55 of file HomePatch.C.

◆ MIN_DEBUG_LEVEL

#define MIN_DEBUG_LEVEL   2

Definition at line 56 of file HomePatch.C.

◆ TINY

#define TINY   1.0e-20;

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 54 of file HomePatch.C.

Referenced by ludcmp().

Typedef Documentation

◆ HGArrayBigReal

typedef BigReal HGArrayBigReal[MAXHGS]

Definition at line 66 of file HomePatch.C.

◆ HGArrayInt

typedef int HGArrayInt[MAXHGS]

Definition at line 65 of file HomePatch.C.

◆ HGArrayVector

typedef zVector HGArrayVector[MAXHGS]

Definition at line 67 of file HomePatch.C.

◆ HGMatrixBigReal

typedef BigReal HGMatrixBigReal[MAXHGS][MAXHGS]

Definition at line 68 of file HomePatch.C.

◆ HGMatrixVector

typedef zVector HGMatrixVector[MAXHGS][MAXHGS]

Definition at line 69 of file HomePatch.C.

Function Documentation

◆ average()

int average ( CompAtom qtilde,
const HGArrayVector q,
BigReal lambda,
const int  n,
const int  m,
const HGArrayBigReal imass,
const HGArrayBigReal length2,
const HGArrayInt ial,
const HGArrayInt ibl,
const HGArrayVector refab,
const BigReal  tolf,
const int  ntrial 
)

Definition at line 6470 of file HomePatch.C.

References endi(), G_q(), iINFO(), iout, lubksb(), ludcmp(), and CompAtom::position.

Referenced by PressureProfileReduction::getData(), HomePatch::mollyAverage(), PressureProfileReduction::PressureProfileReduction(), and PressureProfileReduction::~PressureProfileReduction().

6470  {
6471  // input: n = length of hydrogen group to be averaged (shaked)
6472  // q[n] = vector array of original positions
6473  // m = number of constraints
6474  // imass[n] = inverse mass for each atom
6475  // length2[m] = square of reference bond length for each constraint
6476  // ial[m] = atom a in each constraint
6477  // ibl[m] = atom b in each constraint
6478  // refab[m] = vector of q_ial(i) - q_ibl(i) for each constraint
6479  // tolf = function error tolerance for Newton's iteration
6480  // ntrial = max number of Newton's iterations
6481  // output: lambda[m] = double array of lagrange multipliers (used by mollify)
6482  // qtilde[n] = vector array of averaged (shaked) positions
6483 
6484  int k,k1,i,j;
6485  BigReal errx,errf,d,tolx;
6486 
6487  HGArrayInt indx;
6488  HGArrayBigReal p;
6489  HGArrayBigReal fvec;
6490  HGMatrixBigReal fjac;
6491  HGArrayVector avgab;
6492  HGMatrixVector grhs;
6493  HGMatrixVector auxrhs;
6494  HGMatrixVector glhs;
6495 
6496  // iout <<iINFO << "average: n="<<n<<" m="<<m<<std::endl<<endi;
6497  tolx=tolf;
6498 
6499  // initialize lambda, globalGrhs
6500 
6501  for (i=0;i<m;i++) {
6502  lambda[i]=0.0;
6503  }
6504 
6505  // define grhs, auxrhs for all iterations
6506  // grhs= g_x(q)
6507  //
6508  G_q(refab,grhs,n,m,ial,ibl);
6509  for (k=1;k<=ntrial;k++) {
6510  // usrfun(qtilde,q0,lambda,fvec,fjac,n,water);
6511  HGArrayBigReal gij;
6512  // this used to be main loop of usrfun
6513  // compute qtilde given q0, lambda, IMASSes
6514  {
6515  BigReal multiplier;
6516  HGArrayVector tmp;
6517  for (i=0;i<m;i++) {
6518  multiplier = lambda[i];
6519  // auxrhs = M^{-1}grhs^{T}
6520  for (j=0;j<n;j++) {
6521  auxrhs[i][j]=multiplier*imass[j]*grhs[i][j];
6522  }
6523  }
6524  for (j=0;j<n;j++) {
6525  // tmp[j]=0.0;
6526  for (i=0;i<m;i++) {
6527  tmp[j]+=auxrhs[i][j];
6528  }
6529  }
6530 
6531  for (j=0;j<n;j++) {
6532  qtilde[j].position=q[j]+tmp[j];
6533  }
6534  // delete [] tmp;
6535  }
6536 
6537  for ( i = 0; i < m; i++ ) {
6538  avgab[i] = qtilde[ial[i]].position - qtilde[ibl[i]].position;
6539  }
6540 
6541  // iout<<iINFO << "Calling Jac" << std::endl<<endi;
6542  // Jac(qtilde, q0, fjac,n,water);
6543  {
6544  // Vector glhs[3*n+3];
6545 
6546  HGMatrixVector grhs2;
6547 
6548  G_q(avgab,glhs,n,m,ial,ibl);
6549 #ifdef DEBUG0
6550  iout<<iINFO << "G_q:" << std::endl<<endi;
6551  for (i=0;i<m;i++) {
6552  iout<<iINFO << glhs[i*n+0] << " " << glhs[i*n+1] << " " << glhs[i*n+2] << std::endl<<endi;
6553  }
6554 #endif
6555  // G_q(refab,grhs2,m,ial,ibl);
6556  // update with the masses
6557  for (j=0; j<n; j++) { // number of atoms
6558  for (i=0; i<m;i++) { // number of constraints
6559  grhs2[i][j] = grhs[i][j]*imass[j];
6560  }
6561  }
6562 
6563  // G_q(qtilde) * M^-1 G_q'(q0) =
6564  // G_q(qtilde) * grhs'
6565  for (i=0;i<m;i++) { // number of constraints
6566  for (j=0;j<m;j++) { // number of constraints
6567  fjac[i][j] = 0;
6568  for (k1=0;k1<n;k1++) {
6569  fjac[i][j] += glhs[i][k1]*grhs2[j][k1];
6570  }
6571  }
6572  }
6573 #ifdef DEBUG0
6574  iout<<iINFO << "glhs" <<endi;
6575  for(i=0;i<9;i++) {
6576  iout<<iINFO << glhs[i] << ","<<endi;
6577  }
6578  iout<<iINFO << std::endl<<endi;
6579  for(i=0;i<9;i++) {
6580  iout<<iINFO << grhs2[i] << ","<<endi;
6581  }
6582  iout<<iINFO << std::endl<<endi;
6583 #endif
6584  // delete[] grhs2;
6585  }
6586  // end of Jac calculation
6587 #ifdef DEBUG0
6588  iout<<iINFO << "Jac" << std::endl<<endi;
6589  for (i=0;i<m;i++)
6590  for (j=0;j<m;j++)
6591  iout<<iINFO << fjac[i][j] << " "<<endi;
6592  iout<< std::endl<<endi;
6593 #endif
6594  // calculate constraints in gij for n constraints this being a water
6595  // G(qtilde, gij, n, water);
6596  for (i=0;i<m;i++) {
6597  gij[i]=avgab[i]*avgab[i]-length2[i];
6598  }
6599 #ifdef DEBUG0
6600  iout<<iINFO << "G" << std::endl<<endi;
6601  iout<<iINFO << "( "<<endi;
6602  for(i=0;i<m-1;i++) {
6603  iout<<iINFO << gij[i] << ", "<<endi;
6604  }
6605  iout<<iINFO << gij[m-1] << ")" << std::endl<<endi;
6606 #endif
6607  // fill the return vector
6608  for(i=0;i<m;i++) {
6609  fvec[i] = gij[i];
6610  }
6611  // free up the constraints
6612  // delete[] gij;
6613  // continue Newton's iteration
6614  errf=0.0;
6615  for (i=0;i<m;i++) errf += fabs(fvec[i]);
6616 #ifdef DEBUG0
6617  iout<<iINFO << "errf: " << errf << std::endl<<endi;
6618 #endif
6619  if (errf <= tolf) {
6620  break;
6621  }
6622  for (i=0;i<m;i++) p[i] = -fvec[i];
6623  // iout<<iINFO << "Doing dcmp in average " << std::endl<<endi;
6624  ludcmp(fjac,m,indx,&d);
6625  lubksb(fjac,m,indx,p);
6626 
6627  errx=0.0;
6628  for (i=0;i<m;i++) {
6629  errx += fabs(p[i]);
6630  }
6631  for (i=0;i<m;i++)
6632  lambda[i] += p[i];
6633 
6634 #ifdef DEBUG0
6635  iout<<iINFO << "lambda:" << lambda[0]
6636  << " " << lambda[1] << " " << lambda[2] << std::endl<<endi;
6637  iout<<iINFO << "errx: " << errx << std::endl<<endi;
6638 #endif
6639  if (errx <= tolx) break;
6640 #ifdef DEBUG0
6641  iout<<iINFO << "Qtilde:" << std::endl<<endi;
6642  iout<<iINFO << qtilde[0].position << " " << qtilde[1].position << " " << qtilde[2].position << std::endl<<endi;
6643 #endif
6644  }
6645 #ifdef DEBUG
6646  iout<<iINFO << "LAMBDA:" << lambda[0] << " " << lambda[1] << " " << lambda[2] << std::endl<<endi;
6647 #endif
6648 
6649  return k; //
6650 }
std::ostream & iINFO(std::ostream &s)
Definition: InfoStream.C:81
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
Position position
Definition: NamdTypes.h:78
BigReal HGMatrixBigReal[MAXHGS][MAXHGS]
Definition: HomePatch.C:68
#define iout
Definition: InfoStream.h:51
BigReal HGArrayBigReal[MAXHGS]
Definition: HomePatch.C:66
zVector HGMatrixVector[MAXHGS][MAXHGS]
Definition: HomePatch.C:69
void lubksb(HGMatrixBigReal &a, int n, HGArrayInt &indx, HGArrayBigReal &b)
Definition: HomePatch.C:6385
int HGArrayInt[MAXHGS]
Definition: HomePatch.C:65
void ludcmp(HGMatrixBigReal &a, int n, HGArrayInt &indx, BigReal *d)
Definition: HomePatch.C:6408
void G_q(const HGArrayVector &refab, HGMatrixVector &gqij, const int n, const int m, const HGArrayInt &ial, const HGArrayInt &ibl)
Definition: HomePatch.C:6458
zVector HGArrayVector[MAXHGS]
Definition: HomePatch.C:67
double BigReal
Definition: common.h:123

◆ compDistance()

static int compDistance ( const void *  a,
const void *  b 
)
static

Definition at line 497 of file HomePatch.C.

Referenced by HomePatch::buildSpanningTree().

498 {
499  int d1 = abs(*(int *)a - CkMyPe());
500  int d2 = abs(*(int *)b - CkMyPe());
501  if (d1 < d2)
502  return -1;
503  else if (d1 == d2)
504  return 0;
505  else
506  return 1;
507 }

◆ G_q()

void G_q ( const HGArrayVector refab,
HGMatrixVector gqij,
const int  n,
const int  m,
const HGArrayInt ial,
const HGArrayInt ibl 
)
inline

Definition at line 6458 of file HomePatch.C.

Referenced by average(), and mollify().

6459  {
6460  int i;
6461  // step through the rows of the matrix
6462  for(i=0;i<m;i++) {
6463  gqij[i][ial[i]]=2.0*refab[i];
6464  gqij[i][ibl[i]]=-gqij[i][ial[i]];
6465  }
6466 };

◆ lubksb()

void lubksb ( HGMatrixBigReal a,
int  n,
HGArrayInt indx,
HGArrayBigReal b 
)
inline

Definition at line 6385 of file HomePatch.C.

Referenced by average(), and mollify().

6387 {
6388  int i,ii=-1,ip,j;
6389  double sum;
6390 
6391  for (i=0;i<n;i++) {
6392  ip=indx[i];
6393  sum=b[ip];
6394  b[ip]=b[i];
6395  if (ii >= 0)
6396  for (j=ii;j<i;j++) sum -= a[i][j]*b[j];
6397  else if (sum) ii=i;
6398  b[i]=sum;
6399  }
6400  for (i=n-1;i>=0;i--) {
6401  sum=b[i];
6402  for (j=i+1;j<n;j++) sum -= a[i][j]*b[j];
6403  b[i]=sum/a[i][i];
6404  }
6405 }

◆ ludcmp()

void ludcmp ( HGMatrixBigReal a,
int  n,
HGArrayInt indx,
BigReal d 
)
inline

Definition at line 6408 of file HomePatch.C.

References NAMD_die(), and TINY.

Referenced by average(), and mollify().

6409 {
6410 
6411  int i,imax,j,k;
6412  double big,dum,sum,temp;
6413  HGArrayBigReal vv;
6414  *d=1.0;
6415  for (i=0;i<n;i++) {
6416  big=0.0;
6417  for (j=0;j<n;j++)
6418  if ((temp=fabs(a[i][j])) > big) big=temp;
6419  if (big == 0.0) NAMD_die("Singular matrix in routine ludcmp\n");
6420  vv[i]=1.0/big;
6421  }
6422  for (j=0;j<n;j++) {
6423  for (i=0;i<j;i++) {
6424  sum=a[i][j];
6425  for (k=0;k<i;k++) sum -= a[i][k]*a[k][j];
6426  a[i][j]=sum;
6427  }
6428  big=0.0;
6429  for (i=j;i<n;i++) {
6430  sum=a[i][j];
6431  for (k=0;k<j;k++)
6432  sum -= a[i][k]*a[k][j];
6433  a[i][j]=sum;
6434  if ( (dum=vv[i]*fabs(sum)) >= big) {
6435  big=dum;
6436  imax=i;
6437  }
6438  }
6439  if (j != imax) {
6440  for (k=0;k<n;k++) {
6441  dum=a[imax][k];
6442  a[imax][k]=a[j][k];
6443  a[j][k]=dum;
6444  }
6445  *d = -(*d);
6446  vv[imax]=vv[j];
6447  }
6448  indx[j]=imax;
6449  if (a[j][j] == 0.0) a[j][j]=TINY;
6450  if (j != n-1) {
6451  dum=1.0/(a[j][j]);
6452  for (i=j+1;i<n;i++) a[i][j] *= dum;
6453  }
6454  }
6455 }
#define TINY
Definition: HomePatch.C:54
BigReal HGArrayBigReal[MAXHGS]
Definition: HomePatch.C:66
void NAMD_die(const char *err_msg)
Definition: common.C:147

◆ mollify()

void mollify ( CompAtom qtilde,
const HGArrayVector q0,
const BigReal lambda,
HGArrayVector force,
const int  n,
const int  m,
const HGArrayBigReal imass,
const HGArrayInt ial,
const HGArrayInt ibl,
const HGArrayVector refab 
)

Definition at line 6652 of file HomePatch.C.

References G_q(), lubksb(), ludcmp(), and CompAtom::position.

Referenced by HomePatch::mollyMollify().

6652  {
6653  int i,j,k;
6654  BigReal d;
6655  HGMatrixBigReal fjac;
6656  Vector zero(0.0,0.0,0.0);
6657 
6658  HGArrayVector tmpforce;
6659  HGArrayVector tmpforce2;
6660  HGArrayVector y;
6661  HGMatrixVector grhs;
6662  HGMatrixVector glhs;
6663  HGArrayBigReal aux;
6664  HGArrayInt indx;
6665 
6666  for(i=0;i<n;i++) {
6667  tmpforce[i]=imass[i]*force[i];
6668  }
6669 
6670  HGMatrixVector grhs2;
6671  HGArrayVector avgab;
6672 
6673  for ( i = 0; i < m; i++ ) {
6674  avgab[i] = qtilde[ial[i]].position - qtilde[ibl[i]].position;
6675  }
6676 
6677  G_q(avgab,glhs,n,m,ial,ibl);
6678  G_q(refab,grhs,n,m,ial,ibl);
6679  // update with the masses
6680  for (j=0; j<n; j++) { // number of atoms
6681  for (i=0; i<m;i++) { // number of constraints
6682  grhs2[i][j] = grhs[i][j]*imass[j];
6683  }
6684  }
6685 
6686  // G_q(qtilde) * M^-1 G_q'(q0) =
6687  // G_q(qtilde) * grhs'
6688  for (i=0;i<m;i++) { // number of constraints
6689  for (j=0;j<m;j++) { // number of constraints
6690  fjac[j][i] = 0;
6691  for (k=0;k<n;k++) {
6692  fjac[j][i] += glhs[i][k]*grhs2[j][k];
6693  }
6694  }
6695  }
6696 
6697  // aux=gqij*tmpforce
6698  // globalGrhs::computeGlobalGrhs(q0,n,water);
6699  // G_q(refab,grhs,m,ial,ibl);
6700  for(i=0;i<m;i++) {
6701  aux[i]=0.0;
6702  for(j=0;j<n;j++) {
6703  aux[i]+=grhs[i][j]*tmpforce[j];
6704  }
6705  }
6706 
6707  ludcmp(fjac,m,indx,&d);
6708  lubksb(fjac,m,indx,aux);
6709 
6710  for(j=0;j<n;j++) {
6711  y[j] = zero;
6712  for(i=0;i<m;i++) {
6713  y[j] += aux[i]*glhs[i][j];
6714  }
6715  }
6716  for(i=0;i<n;i++) {
6717  y[i]=force[i]-y[i];
6718  }
6719 
6720  // gqq12*y
6721  for(i=0;i<n;i++) {
6722  tmpforce2[i]=imass[i]*y[i];
6723  }
6724 
6725  // here we assume that tmpforce is initialized to zero.
6726  for (i=0;i<n;i++) {
6727  tmpforce[i]=zero;
6728  }
6729 
6730  for (j=0;j<m;j++) {
6731  Vector tmpf = 2.0*lambda[j]*(tmpforce2[ial[j]]-tmpforce2[ibl[j]]);
6732  tmpforce[ial[j]] += tmpf;
6733  tmpforce[ibl[j]] -= tmpf;
6734  }
6735  // c-ji the other bug for 2 constraint water was this line (2-4-99)
6736  // for(i=0;i<m;i++) {
6737  for(i=0;i<n;i++) {
6738  force[i]=tmpforce[i]+y[i];
6739  }
6740 
6741 }
Definition: Vector.h:72
Position position
Definition: NamdTypes.h:78
BigReal HGMatrixBigReal[MAXHGS][MAXHGS]
Definition: HomePatch.C:68
BigReal HGArrayBigReal[MAXHGS]
Definition: HomePatch.C:66
zVector HGMatrixVector[MAXHGS][MAXHGS]
Definition: HomePatch.C:69
void lubksb(HGMatrixBigReal &a, int n, HGArrayInt &indx, HGArrayBigReal &b)
Definition: HomePatch.C:6385
int HGArrayInt[MAXHGS]
Definition: HomePatch.C:65
void ludcmp(HGMatrixBigReal &a, int n, HGArrayInt &indx, BigReal *d)
Definition: HomePatch.C:6408
void G_q(const HGArrayVector &refab, HGMatrixVector &gqij, const int n, const int m, const HGArrayInt &ial, const HGArrayInt &ibl)
Definition: HomePatch.C:6458
zVector HGArrayVector[MAXHGS]
Definition: HomePatch.C:67
double BigReal
Definition: common.h:123

◆ MSHAKE_CUDA()

void MSHAKE_CUDA ( int *  ,
const int  size,
const RattleParam rattleParam,
BigReal refx,
BigReal refy,
BigReal refz,
BigReal posx,
BigReal posy,
BigReal posz,
const BigReal  tol2,
const int  maxiter,
bool &  done,
bool &  consFailure 
)

◆ PatchDataSOA_initialize()

void PatchDataSOA_initialize ( PatchDataSOA p)

Initialize fundamental parts of PatchDataSOA.

Definition at line 2366 of file HomePatch.C.

References PatchDataSOA::buffer, PatchDataSOA::maxAtoms, PatchDataSOA::numAtoms, and PatchDataSOA::numBytes.

2366  {
2367  p->buffer = NULL;
2368  p->numBytes = 0;
2369  p->numAtoms = 0;
2370  p->maxAtoms = 0;
2371 }
int32 maxAtoms
max number of atoms available, multiple of MAXFACTOR
Definition: NamdTypes.h:457
size_t numBytes
number of bytes allocated for soa_buffer
Definition: NamdTypes.h:455
unsigned char * buffer
Definition: NamdTypes.h:375
int32 numAtoms
number of atoms
Definition: NamdTypes.h:456

◆ PatchDataSOA_set_buffer()

void PatchDataSOA_set_buffer ( PatchDataSOA p,
void *  mybuffer 
)

Caller provides the buffer space to be used. Set all pointers relative to this provided address, pointing into the buffer space.

Definition at line 2397 of file HomePatch.C.

References PatchDataSOA::atomFixed, PatchDataSOA::buffer, PatchDataSOA::charge, PatchDataSOA::exclId, PatchDataSOA::f_global_x, PatchDataSOA::f_global_y, PatchDataSOA::f_global_z, PatchDataSOA::f_nbond_x, PatchDataSOA::f_nbond_y, PatchDataSOA::f_nbond_z, PatchDataSOA::f_normal_x, PatchDataSOA::f_normal_y, PatchDataSOA::f_normal_z, PatchDataSOA::f_saved_nbond_x, PatchDataSOA::f_saved_nbond_y, PatchDataSOA::f_saved_nbond_z, PatchDataSOA::f_saved_slow_x, PatchDataSOA::f_saved_slow_y, PatchDataSOA::f_saved_slow_z, PatchDataSOA::f_slow_x, PatchDataSOA::f_slow_y, PatchDataSOA::f_slow_z, PatchDataSOA::fixedPosition_x, PatchDataSOA::fixedPosition_y, PatchDataSOA::fixedPosition_z, PatchDataSOA::gaussrand_x, PatchDataSOA::gaussrand_y, PatchDataSOA::gaussrand_z, PatchDataSOA::groupFixed, PatchDataSOA::hydrogenGroupSize, PatchDataSOA::id, PatchDataSOA::isWater, PatchDataSOA::langevinParam, PatchDataSOA::langScalRandBBK2, PatchDataSOA::langScalVelBBK2, PatchDataSOA::mass, PatchDataSOA::maxAtoms, PatchDataSOA::migrationGroupSize, PatchDataSOA::nonbondedGroupSize, Node::Object(), PatchDataSOA::partition, PatchDataSOA::pos_x, PatchDataSOA::pos_y, PatchDataSOA::pos_z, PatchDataSOA::posNew_x, PatchDataSOA::posNew_y, PatchDataSOA::posNew_z, PatchDataSOA::recipMass, PatchDataSOA::rigidBondLength, PatchDataSOA::sigId, Node::simParameters, simParams, PatchDataSOA::sortOrder, PatchDataSOA::status, PatchDataSOA::transform_i, PatchDataSOA::transform_j, PatchDataSOA::transform_k, PatchDataSOA::unsortOrder, PatchDataSOA::vdwType, PatchDataSOA::vel_x, PatchDataSOA::vel_y, PatchDataSOA::vel_z, PatchDataSOA::velNew_x, PatchDataSOA::velNew_y, and PatchDataSOA::velNew_z.

2400  {
2402  p->buffer = (unsigned char *) mybuffer;
2403  unsigned char *t = p->buffer;
2404  p->pos_x = (double *) t;
2405  t += p->maxAtoms * sizeof(double);
2406  p->pos_y = (double *) t;
2407  t += p->maxAtoms * sizeof(double);
2408  p->pos_z = (double *) t;
2409  t += p->maxAtoms * sizeof(double);
2410  p->charge = (float *) t;
2411  t += p->maxAtoms * sizeof(float);
2412  p->vdwType = (int *) t;
2413  t += p->maxAtoms * sizeof(int);
2414  p->partition = (int *) t;
2415  t += p->maxAtoms * sizeof(int);
2416  p->nonbondedGroupSize = (int *) t;
2417  t += p->maxAtoms * sizeof(int);
2418  p->hydrogenGroupSize = (int *) t;
2419  t += p->maxAtoms * sizeof(int);
2420  p->isWater = (int *) t;
2421  t += p->maxAtoms * sizeof(int);
2422  p->sortOrder = (int *) t;
2423  t += p->maxAtoms * sizeof(int);
2424  p->unsortOrder = (int *) t;
2425  t += p->maxAtoms * sizeof(int);
2426  p->id = (int *) t;
2427  t += p->maxAtoms * sizeof(int);
2428  p->exclId = (int *) t;
2429  t += p->maxAtoms * sizeof(int);
2430  p->sigId = (int *) t;
2431  t += p->maxAtoms * sizeof(int);
2432  p->atomFixed = (int *) t;
2433  t += p->maxAtoms * sizeof(int);
2434  p->groupFixed = (int *) t;
2435  t += p->maxAtoms * sizeof(int);
2436  p->vel_x = (double *) t;
2437  t += p->maxAtoms * sizeof(double);
2438  p->vel_y = (double *) t;
2439  t += p->maxAtoms * sizeof(double);
2440  p->vel_z = (double *) t;
2441  t += p->maxAtoms * sizeof(double);
2442  p->fixedPosition_x = (double *) t;
2443  t += p->maxAtoms * sizeof(double);
2444  p->fixedPosition_y = (double *) t;
2445  t += p->maxAtoms * sizeof(double);
2446  p->fixedPosition_z = (double *) t;
2447  t += p->maxAtoms * sizeof(double);
2448  p->recipMass = (double *) t;
2449  t += p->maxAtoms * sizeof(double);
2450  p->mass = (float *) t;
2451  t += p->maxAtoms * sizeof(float);
2452  p->langevinParam = (float *) t;
2453  t += p->maxAtoms * sizeof(float);
2454  p->status = (int *) t;
2455  t += p->maxAtoms * sizeof(int);
2456  p->transform_i = (int *) t;
2457  t += p->maxAtoms * sizeof(int);
2458  p->transform_j = (int *) t;
2459  t += p->maxAtoms * sizeof(int);
2460  p->transform_k = (int *) t;
2461  t += p->maxAtoms * sizeof(int);
2462  p->migrationGroupSize = (int *) t;
2463  t += p->maxAtoms * sizeof(int);
2464  p->rigidBondLength = (float *) t;
2465  t += p->maxAtoms * sizeof(float);
2466  p->langScalVelBBK2 = (float *) t;
2467  t += p->maxAtoms * sizeof(float);
2468  p->langScalRandBBK2 = (float *) t;
2469  t += p->maxAtoms * sizeof(float);
2470  p->gaussrand_x = (float *) t;
2471  t += p->maxAtoms * sizeof(float);
2472  p->gaussrand_y = (float *) t;
2473  t += p->maxAtoms * sizeof(float);
2474  p->gaussrand_z = (float *) t;
2475  t += p->maxAtoms * sizeof(float);
2476  p->f_normal_x = (double *) t;
2477  t += p->maxAtoms * sizeof(double);
2478  p->f_normal_y = (double *) t;
2479  t += p->maxAtoms * sizeof(double);
2480  p->f_normal_z = (double *) t;
2481  t += p->maxAtoms * sizeof(double);
2482  p->f_nbond_x = (double *) t;
2483  t += p->maxAtoms * sizeof(double);
2484  p->f_nbond_y = (double *) t;
2485  t += p->maxAtoms * sizeof(double);
2486  p->f_nbond_z = (double *) t;
2487  t += p->maxAtoms * sizeof(double);
2488  p->f_slow_x = (double *) t;
2489  t += p->maxAtoms * sizeof(double);
2490  p->f_slow_y = (double *) t;
2491  t += p->maxAtoms * sizeof(double);
2492  p->f_slow_z = (double *) t;
2493  t += p->maxAtoms * sizeof(float);
2494  if (simParams->colvarsOn || simParams->tclForcesOn || (simParams->IMDon && ! (simParams->IMDignore || simParams->IMDignoreForces))){
2495  p->f_global_x = (double *) t;
2496  t += p->maxAtoms * sizeof(double);
2497  p->f_global_y = (double *) t;
2498  t += p->maxAtoms * sizeof(double);
2499  p->f_global_z = (double *) t;
2500  t += p->maxAtoms * sizeof(double);
2501  }
2502  p->f_saved_nbond_x = (double *) t;
2503  t += p->maxAtoms * sizeof(double);
2504  p->f_saved_nbond_y = (double *) t;
2505  t += p->maxAtoms * sizeof(double);
2506  p->f_saved_nbond_z = (double *) t;
2507  t += p->maxAtoms * sizeof(double);
2508  p->f_saved_slow_x = (double *) t;
2509  t += p->maxAtoms * sizeof(double);
2510  p->f_saved_slow_y = (double *) t;
2511  t += p->maxAtoms * sizeof(double);
2512  p->f_saved_slow_z = (double *) t;
2513  t += p->maxAtoms * sizeof(double);
2514  p->velNew_x = (double *) t;
2515  t += p->maxAtoms * sizeof(double);
2516  p->velNew_y = (double *) t;
2517  t += p->maxAtoms * sizeof(double);
2518  p->velNew_z = (double *) t;
2519  t += p->maxAtoms * sizeof(double);
2520  p->posNew_x = (double *) t;
2521  t += p->maxAtoms * sizeof(double);
2522  p->posNew_y = (double *) t;
2523  t += p->maxAtoms * sizeof(double);
2524  p->posNew_z = (double *) t;
2525 }
static Node * Object()
Definition: Node.h:86
double * vel_y
Definition: NamdTypes.h:397
int32 * isWater
Definition: NamdTypes.h:386
double * f_normal_z
Definition: NamdTypes.h:430
int32 * groupFixed
Definition: NamdTypes.h:394
double * f_normal_y
Definition: NamdTypes.h:429
double * posNew_z
Definition: NamdTypes.h:453
int32 * exclId
Definition: NamdTypes.h:391
int32 * unsortOrder
Definition: NamdTypes.h:389
double * f_saved_slow_z
Definition: NamdTypes.h:445
double * f_slow_y
Definition: NamdTypes.h:435
SimParameters * simParameters
Definition: Node.h:181
double * f_global_z
Definition: NamdTypes.h:439
int32 maxAtoms
max number of atoms available, multiple of MAXFACTOR
Definition: NamdTypes.h:457
double * f_saved_slow_y
Definition: NamdTypes.h:444
float * langScalVelBBK2
derived from langevinParam
Definition: NamdTypes.h:419
double * f_saved_slow_x
Definition: NamdTypes.h:443
float * gaussrand_y
Definition: NamdTypes.h:424
double * pos_y
Definition: NamdTypes.h:378
double * velNew_z
Definition: NamdTypes.h:450
double * fixedPosition_y
Definition: NamdTypes.h:401
int32 * migrationGroupSize
Definition: NamdTypes.h:414
float * mass
Definition: NamdTypes.h:405
double * f_global_y
Definition: NamdTypes.h:438
double * f_nbond_y
Definition: NamdTypes.h:432
double * f_nbond_z
Definition: NamdTypes.h:433
int32 * hydrogenGroupSize
Definition: NamdTypes.h:385
double * f_normal_x
Definition: NamdTypes.h:428
float * langevinParam
Definition: NamdTypes.h:406
float * gaussrand_x
fill with Gaussian distributed random numbers
Definition: NamdTypes.h:423
int32 * vdwType
Definition: NamdTypes.h:382
int32 * sortOrder
Definition: NamdTypes.h:388
float * gaussrand_z
Definition: NamdTypes.h:425
double * vel_x
Jim recommends double precision velocity.
Definition: NamdTypes.h:396
int32 * id
Definition: NamdTypes.h:390
float * charge
Definition: NamdTypes.h:381
int32 * transform_i
Definition: NamdTypes.h:410
double * f_saved_nbond_x
Definition: NamdTypes.h:440
int32 * partition
Definition: NamdTypes.h:383
double * f_saved_nbond_z
Definition: NamdTypes.h:442
double * posNew_y
Definition: NamdTypes.h:452
float * rigidBondLength
Definition: NamdTypes.h:416
int32 * transform_k
Definition: NamdTypes.h:412
double * recipMass
derived from mass
Definition: NamdTypes.h:404
#define simParams
Definition: Output.C:131
double * velNew_y
Definition: NamdTypes.h:449
double * fixedPosition_x
Definition: NamdTypes.h:400
double * pos_z
Definition: NamdTypes.h:379
double * f_slow_x
Definition: NamdTypes.h:434
double * pos_x
Definition: NamdTypes.h:377
int32 * transform_j
Definition: NamdTypes.h:411
double * vel_z
Definition: NamdTypes.h:398
int32 * sigId
Definition: NamdTypes.h:392
double * f_saved_nbond_y
Definition: NamdTypes.h:441
double * f_nbond_x
Definition: NamdTypes.h:431
unsigned char * buffer
Definition: NamdTypes.h:375
double * f_global_x
Definition: NamdTypes.h:437
double * fixedPosition_z
Definition: NamdTypes.h:402
int32 * status
Definition: NamdTypes.h:408
float * langScalRandBBK2
from langevinParam and recipMass
Definition: NamdTypes.h:420
double * posNew_x
Definition: NamdTypes.h:451
int32 * atomFixed
Definition: NamdTypes.h:393
int32 * nonbondedGroupSize
Definition: NamdTypes.h:384
double * f_slow_z
Definition: NamdTypes.h:436
double * velNew_x
temp storage for rigid bond constraints
Definition: NamdTypes.h:448

◆ PatchDataSOA_set_size()

size_t PatchDataSOA_set_size ( PatchDataSOA p,
int  natoms,
int  pad = MAXFACTOR 
)

Set sizes based on number of atoms and padding factor. Sets internally numAtoms, maxAtoms, and numBytes. Returns numBytes.

Definition at line 2373 of file HomePatch.C.

References PatchDataSOA::maxAtoms, PatchDataSOA::numAtoms, PatchDataSOA::numBytes, Node::Object(), Node::simParameters, and simParams.

2377  {
2378  if (natoms > p->maxAtoms) {
2379  // maxAtoms extends numAtoms to next multiple of padding
2380  p->maxAtoms = ((natoms + padding - 1) / padding) * padding;
2381  // set numBytes to allow each array to have maxAtoms space
2382  // count up total number of double, float, and int arrays
2383  // XXX TODO : these magic numbers are bad for maintability
2385  // XXX TODO: For Colvars, tclForces, IMD or any GlobalMaster
2386  // client that requires the global forces, we need extra 3 buffers
2387  // to save the x, y and z components of the forces, and therefore
2388  // the number of double fields should be increased by 3 (from 31 to 34).
2389  int numdoubles = (simParams->colvarsOn || simParams->tclForcesOn || simParams->IMDon) ? 34: 31;
2390  p->numBytes = p->maxAtoms *
2391  (numdoubles * sizeof(double) + 9*sizeof(float) + 17*sizeof(int));
2392  }
2393  p->numAtoms = natoms;
2394  return p->numBytes;
2395 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
int32 maxAtoms
max number of atoms available, multiple of MAXFACTOR
Definition: NamdTypes.h:457
size_t numBytes
number of bytes allocated for soa_buffer
Definition: NamdTypes.h:455
#define simParams
Definition: Output.C:131
int32 numAtoms
number of atoms
Definition: NamdTypes.h:456