NAMD
Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
HomePatch Class Reference

#include <HomePatch.h>

Inheritance diagram for HomePatch:
Patch

Classes

struct  checkpoint_t
 
struct  RattleList
 

Public Member Functions

 ~HomePatch ()
 
void registerProxy (RegisterProxyMsg *)
 
void unregisterProxy (UnregisterProxyMsg *)
 
void receiveResults (ProxyResultVarsizeMsg *msg)
 
void receiveResults (ProxyResultMsg *msg)
 
void receiveResult (ProxyGBISP1ResultMsg *msg)
 
void receiveResult (ProxyGBISP2ResultMsg *msg)
 
void receiveResults (ProxyCombinedResultRawMsg *msg)
 
void depositMigration (MigrateAtomsMsg *)
 
void useSequencer (Sequencer *sequencerPtr)
 
void runSequencer (void)
 
void positionsReady (int doMigration=0)
 
void positionsReady_SOA (int doMigration=0)
 
void positionsReady_GPU (int doMigration=0, int startup=0)
 
void updateAtomCount (const int n, const int reallocate)
 
void updateAtomBuffers ()
 
void saveForce (const int ftag=Results::normal)
 
void addForceToMomentum (FullAtom *__restrict atom_arr, const Force *__restrict force_arr, const BigReal dt, int num_atoms) __attribute__((__noinline__))
 
void addForceToMomentum3 (FullAtom *__restrict atom_arr, const Force *__restrict force_arr1, const Force *__restrict force_arr2, const Force *__restrict force_arr3, const BigReal dt1, const BigReal dt2, const BigReal dt3, int num_atoms) __attribute__((__noinline__))
 
void addVelocityToPosition (FullAtom *__restrict atom_arr, const BigReal dt, int num_atoms) __attribute__((__noinline__))
 
int hardWallDrude (const BigReal, Tensor *virial, SubmitReduction *)
 
void addRattleForce (const BigReal invdt, Tensor &wc)
 
void buildRattleList ()
 
int rattle1old (const BigReal, Tensor *virial, SubmitReduction *)
 
int rattle1 (const BigReal, Tensor *virial, SubmitReduction *)
 
void rattle2 (const BigReal, Tensor *virial)
 
void minimize_rattle2 (const BigReal, Tensor *virial, bool forces=false)
 
void buildRattleList_SOA ()
 
int rattle1_SOA (const BigReal, Tensor *virial, SubmitReduction *)
 
void mollyAverage ()
 
void mollyMollify (Tensor *virial)
 
void loweAndersenVelocities ()
 
void loweAndersenFinish ()
 
void setGBISIntrinsicRadii ()
 
void gbisComputeAfterP1 ()
 
void gbisComputeAfterP2 ()
 
void gbisP2Ready ()
 
void gbisP3Ready ()
 
void setLcpoType ()
 
void checkpoint (void)
 
void revert (void)
 
void exchangeCheckpoint (int scriptTask, int &bpc)
 
void recvCheckpointReq (int task, const char *key, int replica, int pe)
 
void recvCheckpointLoad (CheckpointAtomsMsg *msg)
 
void recvCheckpointStore (CheckpointAtomsMsg *msg)
 
void recvCheckpointAck ()
 
void exchangeAtoms (int scriptTask)
 
void recvExchangeReq (int req)
 
void recvExchangeMsg (ExchangeAtomsMsg *msg)
 
void replaceForces (ExtForce *f)
 
void qmSwapAtoms ()
 
void submitLoadStats (int timestep)
 
FullAtomListgetAtomList ()
 
ScaledPosition getMin ()
 
ScaledPosition getMax ()
 
void buildSpanningTree (void)
 
void sendNodeAwareSpanningTree ()
 
void recvNodeAwareSpanningTree (ProxyNodeAwareSpanningTreeMsg *msg)
 
void sendSpanningTree ()
 
void recvSpanningTree (int *t, int n)
 
void sendProxies ()
 
- Public Member Functions inherited from Patch
 Patch (PatchID pd)
 
int hasNewAtoms ()
 
virtual ~Patch ()
 
Box< Patch, CompAtom > * registerPositionPickup (Compute *cid)
 
void unregisterPositionPickup (Compute *cid, Box< Patch, CompAtom > **const box)
 
Box< Patch, CompAtom > * registerAvgPositionPickup (Compute *cid)
 
void unregisterAvgPositionPickup (Compute *cid, Box< Patch, CompAtom > **const box)
 
Box< Patch, CompAtom > * registerVelocityPickup (Compute *cid)
 
void unregisterVelocityPickup (Compute *cid, Box< Patch, CompAtom > **const box)
 
Box< Patch, Real > * registerIntRadPickup (Compute *cid)
 
void unregisterIntRadPickup (Compute *cid, Box< Patch, Real > **const box)
 
Box< Patch, GBReal > * registerPsiSumDeposit (Compute *cid)
 
void unregisterPsiSumDeposit (Compute *cid, Box< Patch, GBReal > **const box)
 
Box< Patch, Real > * registerBornRadPickup (Compute *cid)
 
void unregisterBornRadPickup (Compute *cid, Box< Patch, Real > **const box)
 
Box< Patch, GBReal > * registerDEdaSumDeposit (Compute *cid)
 
void unregisterDEdaSumDeposit (Compute *cid, Box< Patch, GBReal > **const box)
 
Box< Patch, Real > * registerDHdrPrefixPickup (Compute *cid)
 
void unregisterDHdrPrefixPickup (Compute *cid, Box< Patch, Real > **const box)
 
Box< Patch, int > * registerLcpoTypePickup (Compute *cid)
 
void unregisterLcpoTypePickup (Compute *cid, Box< Patch, int > **const box)
 
Box< Patch, Results > * registerForceDeposit (Compute *cid)
 
void unregisterForceDeposit (Compute *cid, Box< Patch, Results > **const box)
 
void positionsReady (int n=0, int startup=1)
 
void positionBoxClosed (void)
 
void forceBoxClosed (void)
 
void avgPositionBoxClosed (void)
 
void velocityBoxClosed (void)
 
void intRadBoxClosed (void)
 
void psiSumBoxClosed (void)
 
void bornRadBoxClosed (void)
 
void dEdaSumBoxClosed (void)
 
void dHdrPrefixBoxClosed (void)
 
void gbisP2Ready ()
 
void gbisP3Ready ()
 
void lcpoTypeBoxClosed (void)
 
int getNumAtoms () const
 
int getNumFixedAtoms () const
 
void setNumFixedAtoms (int numFixed)
 
PatchID getPatchID () const
 
int getNumComputes () const
 
CompAtomExtgetCompAtomExtInfo ()
 
CompAtomgetCompAtomInfo ()
 
CudaAtomgetCudaAtomList ()
 

Public Attributes

int marginViolations
 
bool gridForceIdxChecked
 
std::vector< int > settleList
 
std::vector< RattleListrattleList
 
std::vector< RattleParamrattleParam
 
std::vector< int > noconstList
 
bool rattleListValid
 
bool rattleListValid_SOA
 
std::vector< VectorvelNew
 
std::vector< VectorposNew
 
int checkpoint_task
 
std::map< std::string, checkpoint_t * > checkpoints
 
int exchange_dst
 
int exchange_src
 
int exchange_req
 
ExchangeAtomsMsgexchange_msg
 
LDObjHandle ldObjHandle
 
- Public Attributes inherited from Patch
Latticelattice
 
Flags flags
 

Protected Member Functions

virtual void boxClosed (int)
 
void doPairlistCheck ()
 
void doGroupSizeCheck ()
 
void doGroupSizeCheck_SOA ()
 
void doMarginCheck ()
 
void doMarginCheck_SOA ()
 
void doAtomMigration ()
 

Protected Attributes

int inMigration
 
int numMlBuf
 
MigrateAtomsMsgmsgbuf [PatchMap::MaxOneAway]
 
- Protected Attributes inherited from Patch
const PatchID patchID
 
int numAtoms
 
int numFixedAtoms
 
CompAtomList p
 
CompAtomList p_avg
 
CompAtomList v
 
AtomMapperatomMapper
 
RealList intRad
 
GBRealList psiSum
 
GBRealList psiFin
 
RealList bornRad
 
RealList dHdrPrefix
 
GBRealList dEdaSum
 
IntList lcpoType
 
CompAtomExtList pExt
 
CompAtomavgPositionPtrBegin
 
CompAtomavgPositionPtrEnd
 
CompAtomvelocityPtrBegin
 
CompAtomvelocityPtrEnd
 
CudaAtomcudaAtomPtr
 
ForceList f [Results::maxNumForces]
 
Results results
 
int computesSortedByPriority
 
int firstHoldableCompute
 
OwnerBox< Patch, CompAtompositionBox
 
ComputePtrList positionComputeList
 
OwnerBox< Patch, CompAtomavgPositionBox
 
ComputePtrList avgPositionComputeList
 
OwnerBox< Patch, CompAtomvelocityBox
 
ComputePtrList velocityComputeList
 
OwnerBox< Patch, RealintRadBox
 
ComputePtrList intRadComputeList
 
OwnerBox< Patch, GBRealpsiSumBox
 
ComputePtrList psiSumComputeList
 
OwnerBox< Patch, RealbornRadBox
 
ComputePtrList bornRadComputeList
 
OwnerBox< Patch, GBRealdEdaSumBox
 
ComputePtrList dEdaSumComputeList
 
OwnerBox< Patch, RealdHdrPrefixBox
 
ComputePtrList dHdrPrefixComputeList
 
OwnerBox< Patch, int > lcpoTypeBox
 
ComputePtrList lcpoTypeComputeList
 
OwnerBox< Patch, ResultsforceBox
 
ComputePtrList forceComputeList
 
int boxesOpen
 
int _hasNewAtoms
 
int * child
 
int nChild
 

Friends

class PatchMgr
 
class Sequencer
 
class SequencerCUDA
 
class ComputeGlobal
 

Detailed Description

Definition at line 329 of file HomePatch.h.

Constructor & Destructor Documentation

◆ ~HomePatch()

HomePatch::~HomePatch ( )

Definition at line 357 of file HomePatch.C.

References Patch::atomMapper, ResizeArray< Elem >::begin(), ResizeArray< Elem >::end(), and AtomMapper::unregisterIDsFullAtom().

358 {
359  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
360 #ifdef NODEAWARE_PROXY_SPANNINGTREE
361  ptnTree.resize(0);
362  #ifdef USE_NODEPATCHMGR
363  delete [] nodeChildren;
364  #endif
365 #endif
366  delete [] child;
367 }
AtomMapper * atomMapper
Definition: Patch.h:159
iterator begin(void)
Definition: ResizeArray.h:36
iterator end(void)
Definition: ResizeArray.h:37
void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:100

Member Function Documentation

◆ addForceToMomentum()

void HomePatch::addForceToMomentum ( FullAtom *__restrict  atom_arr,
const Force *__restrict  force_arr,
const BigReal  dt,
int  num_atoms 
)

Definition at line 3319 of file HomePatch.C.

References Node::Object(), Node::simParameters, and simParams.

Referenced by Sequencer::addForceToMomentum().

3324  {
3326 
3327  if ( simParams->fixedAtomsOn ) {
3328  for ( int i = 0; i < num_atoms; ++i ) {
3329  if ( atom_arr[i].atomFixed ) {
3330  atom_arr[i].velocity = 0;
3331  } else {
3332  BigReal dt_mass = dt * atom_arr[i].recipMass; // dt/mass
3333  atom_arr[i].velocity.x += force_arr[i].x * dt_mass;
3334  atom_arr[i].velocity.y += force_arr[i].y * dt_mass;
3335  atom_arr[i].velocity.z += force_arr[i].z * dt_mass;
3336  }
3337  }
3338  } else {
3339  for ( int i = 0; i < num_atoms; ++i ) {
3340  BigReal dt_mass = dt * atom_arr[i].recipMass; // dt/mass
3341  atom_arr[i].velocity.x += force_arr[i].x * dt_mass;
3342  atom_arr[i].velocity.y += force_arr[i].y * dt_mass;
3343  atom_arr[i].velocity.z += force_arr[i].z * dt_mass;
3344  }
3345  }
3346 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Velocity velocity
Definition: NamdTypes.h:211
BigReal x
Definition: Vector.h:74
#define simParams
Definition: Output.C:131
BigReal y
Definition: Vector.h:74
double recipMass
Definition: NamdTypes.h:213
double BigReal
Definition: common.h:123

◆ addForceToMomentum3()

void HomePatch::addForceToMomentum3 ( FullAtom *__restrict  atom_arr,
const Force *__restrict  force_arr1,
const Force *__restrict  force_arr2,
const Force *__restrict  force_arr3,
const BigReal  dt1,
const BigReal  dt2,
const BigReal  dt3,
int  num_atoms 
)

Definition at line 3348 of file HomePatch.C.

References Node::Object(), Node::simParameters, and simParams.

Referenced by Sequencer::addForceToMomentum3().

3357  {
3359 
3360  if ( simParams->fixedAtomsOn ) {
3361  for ( int i = 0; i < num_atoms; ++i ) {
3362  if ( atom_arr[i].atomFixed ) {
3363  atom_arr[i].velocity = 0;
3364  } else {
3365  BigReal rmass = atom_arr[i].recipMass; // 1/mass
3366  atom_arr[i].velocity.x += (force_arr1[i].x*dt1
3367  + force_arr2[i].x*dt2 + force_arr3[i].x*dt3) * rmass;
3368  atom_arr[i].velocity.y += (force_arr1[i].y*dt1
3369  + force_arr2[i].y*dt2 + force_arr3[i].y*dt3) * rmass;
3370  atom_arr[i].velocity.z += (force_arr1[i].z*dt1
3371  + force_arr2[i].z*dt2 + force_arr3[i].z*dt3) * rmass;
3372  }
3373  }
3374  } else {
3375  for ( int i = 0; i < num_atoms; ++i ) {
3376  BigReal rmass = atom_arr[i].recipMass; // 1/mass
3377  atom_arr[i].velocity.x += (force_arr1[i].x*dt1
3378  + force_arr2[i].x*dt2 + force_arr3[i].x*dt3) * rmass;
3379  atom_arr[i].velocity.y += (force_arr1[i].y*dt1
3380  + force_arr2[i].y*dt2 + force_arr3[i].y*dt3) * rmass;
3381  atom_arr[i].velocity.z += (force_arr1[i].z*dt1
3382  + force_arr2[i].z*dt2 + force_arr3[i].z*dt3) * rmass;
3383  }
3384  }
3385 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Velocity velocity
Definition: NamdTypes.h:211
BigReal x
Definition: Vector.h:74
#define simParams
Definition: Output.C:131
BigReal y
Definition: Vector.h:74
double recipMass
Definition: NamdTypes.h:213
double BigReal
Definition: common.h:123

◆ addRattleForce()

void HomePatch::addRattleForce ( const BigReal  invdt,
Tensor wc 
)

Definition at line 3778 of file HomePatch.C.

References Patch::f, Results::normal, Patch::numAtoms, outer(), and velNew.

Referenced by rattle1().

3778  {
3779  for (int ig = 0; ig < numAtoms; ++ig ) {
3780  Force df = (velNew[ig] - atom[ig].velocity) * ( atom[ig].mass * invdt );
3781  Tensor vir = outer(df, atom[ig].position);
3782  wc += vir;
3783  f[Results::normal][ig] += df;
3784  atom[ig].velocity = velNew[ig];
3785  }
3786 }
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
Definition: Vector.h:72
int numAtoms
Definition: Patch.h:151
Definition: Tensor.h:15
std::vector< Vector > velNew
Definition: HomePatch.h:457
ForceList f[Results::maxNumForces]
Definition: Patch.h:214

◆ addVelocityToPosition()

void HomePatch::addVelocityToPosition ( FullAtom *__restrict  atom_arr,
const BigReal  dt,
int  num_atoms 
)

Definition at line 3387 of file HomePatch.C.

References Node::Object(), Node::simParameters, and simParams.

Referenced by Sequencer::addVelocityToPosition().

3391  {
3393  if ( simParams->fixedAtomsOn ) {
3394  for ( int i = 0; i < num_atoms; ++i ) {
3395  if ( ! atom_arr[i].atomFixed ) {
3396  atom_arr[i].position.x += atom_arr[i].velocity.x * dt;
3397  atom_arr[i].position.y += atom_arr[i].velocity.y * dt;
3398  atom_arr[i].position.z += atom_arr[i].velocity.z * dt;
3399  }
3400  }
3401  } else {
3402  for ( int i = 0; i < num_atoms; ++i ) {
3403  atom_arr[i].position.x += atom_arr[i].velocity.x * dt;
3404  atom_arr[i].position.y += atom_arr[i].velocity.y * dt;
3405  atom_arr[i].position.z += atom_arr[i].velocity.z * dt;
3406  }
3407  }
3408 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Position position
Definition: NamdTypes.h:78
Velocity velocity
Definition: NamdTypes.h:211
BigReal x
Definition: Vector.h:74
#define simParams
Definition: Output.C:131
BigReal y
Definition: Vector.h:74

◆ boxClosed()

void HomePatch::boxClosed ( int  box)
protectedvirtual

Implements Patch.

Definition at line 370 of file HomePatch.C.

References Sequencer::awaken(), Patch::boxesOpen, DebugM, Patch::dEdaSumBox, Flags::doGBIS, Flags::doNonbonded, Patch::f, Patch::flags, ExtForce::force, OwnerBox< Owner, Data >::isOpen(), Results::maxNumForces, Results::normal, Patch::numAtoms, Node::Object(), Patch::patchID, Patch::psiSumBox, Node::simParameters, simParams, and ResizeArray< Elem >::size().

370  {
371  // begin gbis
372  if (box == 5) {// end of phase 1
373  phase1BoxClosedCalled = true;
374  if (!psiSumBox.isOpen() && numGBISP1Arrived == proxy.size()) {
375  if (flags.doGBIS && flags.doNonbonded) {
376  // fprintf(stderr, "Calling awaken() on patch %d: 1\n", this->patchID);
377  sequencer->awaken();
378  }
379  } else {
380  //need to wait until proxies arrive before awakening
381  }
382  } else if (box == 6) {// intRad
383  //do nothing
384  } else if (box == 7) {// bornRad
385  //do nothing
386  } else if (box == 8) {// end of phase 2
387  phase2BoxClosedCalled = true;
388  //if no proxies, AfterP1 can't be called from receive
389  //so it will be called from here
390  if (!dEdaSumBox.isOpen() && numGBISP2Arrived == proxy.size()) {
391  if (flags.doGBIS && flags.doNonbonded) {
392  // fprintf(stderr, "Calling awaken() on patch %d: 2\n", this->patchID);
393  sequencer->awaken();
394  }
395  } else {
396  //need to wait until proxies arrive before awakening
397  }
398  } else if (box == 9) {
399  //do nothing
400  } else if (box == 10) {
401  //lcpoType Box closed: do nothing
402  } else {
403  //do nothing
404  }
405  // end gbis
406 
407  if ( ! --boxesOpen ) {
408  if ( replacementForces ) {
409  for ( int i = 0; i < numAtoms; ++i ) {
410  if ( replacementForces[i].replace ) {
411  for ( int j = 0; j < Results::maxNumForces; ++j ) { f[j][i] = 0; }
412  f[Results::normal][i] = replacementForces[i].force;
413  }
414  }
415  replacementForces = 0;
416  }
417  DebugM(1,patchID << ": " << CthSelf() << " awakening sequencer "
418  << sequencer->thread << "(" << patchID << ") @" << CmiTimer() << "\n");
419  // only awaken suspended threads. Then say it is suspended.
420 
421  phase3BoxClosedCalled = true;
422  if (flags.doGBIS) {
423  if (flags.doNonbonded) {
424  sequencer->awaken();
425  } else {
426  if (numGBISP1Arrived == proxy.size() &&
427  numGBISP2Arrived == proxy.size() &&
428  numGBISP3Arrived == proxy.size()) {
429  sequencer->awaken();//all boxes closed and all proxies arrived
430  }
431  }
432  } else {//non-gbis awaken
434  if(!simParams->CUDASOAintegrate) {
435  sequencer->awaken();
436  }
437  }
438  } else {
439  DebugM(1,patchID << ": " << boxesOpen << " boxes left to close.\n");
440  }
441 }
static Node * Object()
Definition: Node.h:86
int size(void) const
Definition: ResizeArray.h:131
SimParameters * simParameters
Definition: Node.h:181
#define DebugM(x, y)
Definition: Debug.h:75
Flags flags
Definition: Patch.h:128
void awaken(void)
Definition: Sequencer.h:55
int boxesOpen
Definition: Patch.h:250
int numAtoms
Definition: Patch.h:151
int doNonbonded
Definition: PatchTypes.h:22
Force force
Definition: NamdTypes.h:307
#define simParams
Definition: Output.C:131
const PatchID patchID
Definition: Patch.h:150
OwnerBox< Patch, GBReal > dEdaSumBox
Definition: Patch.h:236
int doGBIS
Definition: PatchTypes.h:30
ForceList f[Results::maxNumForces]
Definition: Patch.h:214
int isOpen()
Definition: OwnerBox.h:51
OwnerBox< Patch, GBReal > psiSumBox
Definition: Patch.h:232

◆ buildRattleList()

void HomePatch::buildRattleList ( )

Definition at line 3616 of file HomePatch.C.

References RattleParam::dsq, Patch::flags, getWaterModelGroupSize(), RattleParam::ia, RattleParam::ib, HomePatch::RattleList::icnt, HomePatch::RattleList::ig, NAMD_die(), noconstList, Patch::numAtoms, Node::Object(), Patch::patchID, posNew, rattleList, rattleParam, RattleParam::rma, RattleParam::rmb, settle1init(), settleList, Node::simParameters, simParams, Flags::step, SWM4, and velNew.

Referenced by rattle1().

3616  {
3617 #ifdef DEBUG_MINIMIZE
3618  if (patchID == 0) {
3619  printf("Step %d, patch %d: buildRattleList()\n",
3620  flags.step, (int)patchID);
3621  }
3622 #endif
3624  const int fixedAtomsOn = simParams->fixedAtomsOn;
3625  const int useSettle = simParams->useSettle;
3626 
3627  // Re-size to containt numAtoms elements
3628  velNew.resize(numAtoms);
3629  posNew.resize(numAtoms);
3630 
3631  // Size of a hydrogen group for water
3632  const WaterModel watmodel = simParams->watmodel;
3633  const int wathgsize = getWaterModelGroupSize(watmodel);
3634 
3635  // Initialize the settle algorithm with water parameters
3636  // settle1() assumes all waters are identical,
3637  // and will generate bad results if they are not.
3638  // XXX this will move to Molecule::build_atom_status when that
3639  // version is debugged
3640  if ( ! settle_initialized ) {
3641  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
3642  // find a water
3643  if (atom[ig].rigidBondLength > 0) {
3644  int oatm;
3645  if (watmodel == WaterModel::SWM4) {
3646  oatm = ig+3; // skip over Drude and Lonepair
3647  //printf("ig=%d mass_ig=%g oatm=%d mass_oatm=%g\n",
3648  // ig, atom[ig].mass, oatm, atom[oatm].mass);
3649  }
3650  else {
3651  oatm = ig+1;
3652  // Avoid using the Om site to set this by mistake
3653  if (atom[ig].mass < 0.5 || atom[ig+1].mass < 0.5) {
3654  oatm += 1;
3655  }
3656  }
3657 
3658  // initialize settle water parameters
3659  settle1init(atom[ig].mass, atom[oatm].mass,
3660  atom[ig].rigidBondLength,
3661  atom[oatm].rigidBondLength,
3662  settle_mO, settle_mH,
3663  settle_mOrmT, settle_mHrmT, settle_ra,
3664  settle_rb, settle_rc, settle_rra);
3665  settle_initialized = 1;
3666  break; // done with init
3667  }
3668  }
3669  }
3670 
3671  Vector ref[10];
3672  BigReal rmass[10];
3673  BigReal dsq[10];
3674  int fixed[10];
3675  int ial[10];
3676  int ibl[10];
3677 
3678  int numSettle = 0;
3679  int numRattle = 0;
3680  int posRattleParam = 0;
3681 
3682  settleList.clear();
3683  rattleList.clear();
3684  noconstList.clear();
3685  rattleParam.clear();
3686 
3687  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
3688  int hgs = atom[ig].hydrogenGroupSize;
3689  if ( hgs == 1 ) {
3690  // only one atom in group
3691  noconstList.push_back(ig);
3692  continue;
3693  }
3694  int anyfixed = 0;
3695  for (int i = 0; i < hgs; ++i ) {
3696  ref[i] = atom[ig+i].position;
3697  rmass[i] = (atom[ig+i].mass > 0. ? 1. / atom[ig+i].mass : 0.);
3698  fixed[i] = ( fixedAtomsOn && atom[ig+i].atomFixed );
3699  if ( fixed[i] ) {
3700  anyfixed = 1;
3701  rmass[i] = 0.;
3702  }
3703  }
3704  int icnt = 0;
3705  BigReal tmp = atom[ig].rigidBondLength;
3706  if (tmp > 0.0) { // for water
3707  if (hgs != wathgsize) {
3708  char errmsg[256];
3709  sprintf(errmsg, "Water molecule starting with atom %d contains %d atoms "
3710  "but the specified water model requires %d atoms.\n",
3711  atom[ig].id+1, hgs, wathgsize);
3712  NAMD_die(errmsg);
3713  }
3714  // Use SETTLE for water unless some of the water atoms are fixed,
3715  if (useSettle && !anyfixed) {
3716  // Store to Settle -list
3717  settleList.push_back(ig);
3718  continue;
3719  }
3720  if ( !(fixed[1] && fixed[2]) ) {
3721  dsq[icnt] = tmp * tmp;
3722  ial[icnt] = 1;
3723  ibl[icnt] = 2;
3724  ++icnt;
3725  }
3726  } // if (tmp > 0.0)
3727  for (int i = 1; i < hgs; ++i ) { // normal bonds to mother atom
3728  if ( ( tmp = atom[ig+i].rigidBondLength ) > 0 ) {
3729  if ( !(fixed[0] && fixed[i]) ) {
3730  dsq[icnt] = tmp * tmp;
3731  ial[icnt] = 0;
3732  ibl[icnt] = i;
3733  ++icnt;
3734  }
3735  }
3736  }
3737  if ( icnt == 0 ) {
3738  // no constraints
3739  noconstList.push_back(ig);
3740  continue;
3741  }
3742  // Store to Rattle -list
3743  RattleList rattleListElem;
3744  rattleListElem.ig = ig;
3745  rattleListElem.icnt = icnt;
3746  rattleList.push_back(rattleListElem);
3747  for (int i = 0; i < icnt; ++i ) {
3748  int a = ial[i];
3749  int b = ibl[i];
3750  RattleParam rattleParamElem;
3751  rattleParamElem.ia = a;
3752  rattleParamElem.ib = b;
3753  rattleParamElem.dsq = dsq[i];
3754  rattleParamElem.rma = rmass[a];
3755  rattleParamElem.rmb = rmass[b];
3756  rattleParam.push_back(rattleParamElem);
3757  }
3758  //adding dummy atom in the hydrogen group
3759  for (int i = icnt; i < 4; ++i ) {
3760  RattleParam rattleParamElem;
3761  rattleParamElem.ia = 0;
3762  rattleParamElem.ib = 0;
3763  rattleParamElem.dsq = 0;
3764  rattleParamElem.rma = 0;
3765  rattleParamElem.rmb = 0;
3766  rattleParam.push_back(rattleParamElem);
3767  }
3768 #if 0
3769  for(int i = 0; i < 4; ++i) {
3770  std::cout << rattleParam[i].ia << " " << rattleParam[i].ib << std::endl;
3771  }
3772  std::cout << std::endl;
3773 #endif
3774  }
3775 
3776 }
static Node * Object()
Definition: Node.h:86
int ib
Definition: Settle.h:58
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
BigReal dsq
Definition: Settle.h:59
std::vector< RattleList > rattleList
Definition: HomePatch.h:449
Flags flags
Definition: Patch.h:128
void settle1init(BigReal pmO, BigReal pmH, BigReal hhdist, BigReal ohdist, BigReal &mO, BigReal &mH, BigReal &mOrmT, BigReal &mHrmT, BigReal &ra, BigReal &rb, BigReal &rc, BigReal &rra)
initialize cached water properties
Definition: Settle.C:46
constexpr int getWaterModelGroupSize(const WaterModel &watmodel)
Definition: common.h:228
int numAtoms
Definition: Patch.h:151
std::vector< int > settleList
Definition: HomePatch.h:448
void NAMD_die(const char *err_msg)
Definition: common.C:147
std::vector< Vector > posNew
Definition: HomePatch.h:458
std::vector< RattleParam > rattleParam
Definition: HomePatch.h:450
#define simParams
Definition: Output.C:131
BigReal rmb
Definition: Settle.h:61
const PatchID patchID
Definition: Patch.h:150
BigReal rma
Definition: Settle.h:60
int ia
Definition: Settle.h:57
std::vector< Vector > velNew
Definition: HomePatch.h:457
std::vector< int > noconstList
Definition: HomePatch.h:451
WaterModel
Definition: common.h:221
double BigReal
Definition: common.h:123
int step
Definition: PatchTypes.h:16

◆ buildRattleList_SOA()

void HomePatch::buildRattleList_SOA ( )

Definition at line 4520 of file HomePatch.C.

References RattleParam::dsq, Patch::flags, getWaterModelGroupSize(), PatchDataSOA::hydrogenGroupSize, RattleParam::ia, RattleParam::ib, HomePatch::RattleList::icnt, HomePatch::RattleList::ig, PatchDataSOA::mass, NAMD_bug(), noconstList, Patch::numAtoms, Node::Object(), Patch::patchID, PatchDataSOA::pos_x, PatchDataSOA::pos_y, PatchDataSOA::pos_z, rattleList, rattleParam, PatchDataSOA::recipMass, PatchDataSOA::rigidBondLength, RattleParam::rma, RattleParam::rmb, settle1init(), Node::simParameters, simParams, Flags::step, and SWM4.

Referenced by depositMigration(), rattle1_SOA(), recvCheckpointLoad(), recvExchangeMsg(), and revert().

4520  {
4521 #ifdef DEBUG_MINIMIZE
4522  if (patchID == 0) {
4523  printf("Step %d, patch %d: buildRattleList_SOA()\n",
4524  flags.step, (int)patchID);
4525  }
4526 #endif
4527 
4528  // Called when rattleListValid_SOA is false.
4529  // List will stay valid until atom migration or some other event,
4530  // such as exchanging replicas, SCRIPT_REVERT from Tcl, reinit atoms.
4531 
4532  const double * __restrict pos_x = patchDataSOA.pos_x;
4533  const double * __restrict pos_y = patchDataSOA.pos_y;
4534  const double * __restrict pos_z = patchDataSOA.pos_z;
4535  const float * __restrict mass = patchDataSOA.mass;
4536  const double * __restrict recipMass = patchDataSOA.recipMass;
4537  const float * __restrict rigidBondLength = patchDataSOA.rigidBondLength;
4538  const int * __restrict hydrogenGroupSize = patchDataSOA.hydrogenGroupSize;
4539 
4541  const int fixedAtomsOn = simParams->fixedAtomsOn;
4542  const int useSettle = simParams->useSettle;
4543 
4544  // Size of a hydrogen group for water
4545  const WaterModel watmodel = simParams->watmodel;
4546  const int wathgsize = getWaterModelGroupSize(watmodel);
4547 
4548  // Initialize the settle algorithm with water parameters
4549  // settle1() assumes all waters are identical,
4550  // and will generate bad results if they are not.
4551  // XXX this will move to Molecule::build_atom_status when that
4552  // version is debugged
4553  if ( ! settle_initialized ) {
4554  for (int ig = numSoluteAtoms;
4555  ig < numAtoms;
4556  ig += hydrogenGroupSize[ig]) {
4557  // find a water
4558  if (rigidBondLength[ig] > 0) {
4559  int oatm;
4560  if (watmodel == WaterModel::SWM4) {
4561  oatm = ig+3; // skip over Drude and Lonepair
4562  //printf("ig=%d mass_ig=%g oatm=%d mass_oatm=%g\n",
4563  // ig, atom[ig].mass, oatm, atom[oatm].mass);
4564  }
4565  else {
4566  oatm = ig+1;
4567  // Avoid using the Om site to set this by mistake
4568  if (mass[ig] < 0.5 || mass[ig+1] < 0.5) {
4569  oatm += 1;
4570  }
4571  }
4572 
4573  // initialize settle water parameters
4574  settle1init(mass[ig], mass[oatm],
4575  rigidBondLength[ig],
4576  rigidBondLength[oatm],
4577  settle_mO, settle_mH,
4578  settle_mOrmT, settle_mHrmT, settle_ra,
4579  settle_rb, settle_rc, settle_rra);
4580  settle_initialized = 1;
4581  break; // done with init
4582  }
4583  }
4584  }
4585 
4586  BigReal dsq[10];
4587  int ial[10];
4588  int ibl[10];
4589 
4590  rattleList.clear();
4591  noconstList.clear();
4592  rattleParam.clear();
4593 
4594  for (int ig = 0; ig < numSoluteAtoms; ig += hydrogenGroupSize[ig]) {
4595  int hgs = hydrogenGroupSize[ig];
4596  if (hgs == 0) {
4597  NAMD_bug("Hydrogen group size 0. Exiting to avoid infinite loop\n.");
4598  } else if ( hgs == 1 ) {
4599  // only one atom in group
4600  noconstList.push_back(ig);
4601  continue;
4602  }
4603  int icnt = 0;
4604  // XXX convert rigid bond length to double to square it?
4605  BigReal tmp = rigidBondLength[ig];
4606  if (tmp > 0.0) { // for water
4607  dsq[icnt] = tmp * tmp;
4608  ial[icnt] = 1;
4609  ibl[icnt] = 2;
4610  ++icnt;
4611  }
4612  for (int i = 1; i < hgs; ++i ) { // normal bonds to mother atom
4613  if ( ( tmp = rigidBondLength[ig+i] ) > 0 ) {
4614  dsq[icnt] = tmp * tmp;
4615  ial[icnt] = 0;
4616  ibl[icnt] = i;
4617  ++icnt;
4618  }
4619  }
4620  if ( icnt == 0 ) {
4621  // no constraints
4622  noconstList.push_back(ig);
4623  continue;
4624  }
4625  // Store to Rattle -list
4626  RattleList rattleListElem;
4627  rattleListElem.ig = ig;
4628  rattleListElem.icnt = icnt;
4629  rattleList.push_back(rattleListElem);
4630  for (int i = 0; i < icnt; ++i ) {
4631  int a = ial[i];
4632  int b = ibl[i];
4633  RattleParam rattleParamElem;
4634  rattleParamElem.ia = a;
4635  rattleParamElem.ib = b;
4636  rattleParamElem.dsq = dsq[i];
4637  rattleParamElem.rma = recipMass[ig+a];
4638  rattleParamElem.rmb = recipMass[ig+b];
4639  rattleParam.push_back(rattleParamElem);
4640  }
4641  //adding dummy atom in the hydrogen group
4642  for (int i = icnt; i < 4; ++i )
4643  {
4644  RattleParam rattleParamElem;
4645  rattleParamElem.ia = 0;
4646  rattleParamElem.ib = 0;
4647  rattleParamElem.dsq = 0;
4648  rattleParamElem.rma = 0;
4649  rattleParamElem.rmb = 0;
4650  rattleParam.push_back(rattleParamElem);
4651  }
4652 
4653  }
4654 }
static Node * Object()
Definition: Node.h:86
int ib
Definition: Settle.h:58
SimParameters * simParameters
Definition: Node.h:181
BigReal dsq
Definition: Settle.h:59
double * pos_y
Definition: NamdTypes.h:378
std::vector< RattleList > rattleList
Definition: HomePatch.h:449
float * mass
Definition: NamdTypes.h:405
Flags flags
Definition: Patch.h:128
void settle1init(BigReal pmO, BigReal pmH, BigReal hhdist, BigReal ohdist, BigReal &mO, BigReal &mH, BigReal &mOrmT, BigReal &mHrmT, BigReal &ra, BigReal &rb, BigReal &rc, BigReal &rra)
initialize cached water properties
Definition: Settle.C:46
int32 * hydrogenGroupSize
Definition: NamdTypes.h:385
constexpr int getWaterModelGroupSize(const WaterModel &watmodel)
Definition: common.h:228
void NAMD_bug(const char *err_msg)
Definition: common.C:195
int numAtoms
Definition: Patch.h:151
float * rigidBondLength
Definition: NamdTypes.h:416
std::vector< RattleParam > rattleParam
Definition: HomePatch.h:450
double * recipMass
derived from mass
Definition: NamdTypes.h:404
#define simParams
Definition: Output.C:131
double * pos_z
Definition: NamdTypes.h:379
BigReal rmb
Definition: Settle.h:61
const PatchID patchID
Definition: Patch.h:150
double * pos_x
Definition: NamdTypes.h:377
BigReal rma
Definition: Settle.h:60
int ia
Definition: Settle.h:57
std::vector< int > noconstList
Definition: HomePatch.h:451
WaterModel
Definition: common.h:221
double BigReal
Definition: common.h:123
int step
Definition: PatchTypes.h:16

◆ buildSpanningTree()

void HomePatch::buildSpanningTree ( void  )

Definition at line 715 of file HomePatch.C.

References ResizeArray< Elem >::begin(), compDistance(), ResizeArray< Elem >::end(), ResizeArray< Elem >::find(), NAMD_bug(), PatchMap::numNodesWithPatches(), PatchMap::numPatchesOnNode(), PatchMap::Object(), Patch::patchID, proxySpanDim, ResizeArray< Elem >::resize(), sendSpanningTree(), ResizeArray< Elem >::setall(), ResizeArray< Elem >::size(), and ResizeArray< Elem >::swap().

Referenced by ProxyMgr::buildProxySpanningTree().

716 {
717  nChild = 0;
718  int psize = proxy.size();
719  if (psize == 0) return;
720  NodeIDList oldtree; oldtree.swap(tree);
721  int oldsize = oldtree.size();
722  tree.resize(psize + 1);
723  tree.setall(-1);
724  tree[0] = CkMyPe();
725  int s=1, e=psize+1;
727  int patchNodesLast =
728  ( PatchMap::Object()->numNodesWithPatches() < ( 0.7 * CkNumPes() ) );
729  int nNonPatch = 0;
730 #if 1
731  // try to put it to the same old tree
732  for ( pli = proxy.begin(); pli != proxy.end(); ++pli )
733  {
734  int oldindex = oldtree.find(*pli);
735  if (oldindex != -1 && oldindex < psize) {
736  tree[oldindex] = *pli;
737  }
738  }
739  s=1; e=psize;
740  for ( pli = proxy.begin(); pli != proxy.end(); ++pli )
741  {
742  if (tree.find(*pli) != -1) continue; // already assigned
743  if ( patchNodesLast && PatchMap::Object()->numPatchesOnNode(*pli) ) {
744  while (tree[e] != -1) { e--; if (e==-1) e = psize; }
745  tree[e] = *pli;
746  } else {
747  while (tree[s] != -1) { s++; if (s==psize+1) s = 1; }
748  tree[s] = *pli;
749  nNonPatch++;
750  }
751  }
752 #if 1
753  if (oldsize==0 && nNonPatch) {
754  // first time, sort by distance
755  qsort(&tree[1], nNonPatch, sizeof(int), compDistance);
756  }
757 #endif
758 
759  //CkPrintf("home: %d:(%d) %d %d %d %d %d\n", patchID, tree.size(),tree[0],tree[1],tree[2],tree[3],tree[4]);
760 
761 #if USE_TOPOMAP && USE_SPANNING_TREE
762 
763  //Right now only works for spanning trees with two levels
764  int *treecopy = new int [psize];
765  int subroots[proxySpanDim];
766  int subsizes[proxySpanDim];
767  int subtrees[proxySpanDim][proxySpanDim];
768  int idxes[proxySpanDim];
769  int i = 0;
770 
771  for(i=0;i<proxySpanDim;i++){
772  subsizes[i] = 0;
773  idxes[i] = i;
774  }
775 
776  for(i=0;i<psize;i++){
777  treecopy[i] = tree[i+1];
778  }
779 
780  TopoManager tmgr;
781  tmgr.sortRanksByHops(treecopy,nNonPatch);
782  tmgr.sortRanksByHops(treecopy+nNonPatch,
783  psize-nNonPatch);
784 
785  /* build tree and subtrees */
786  nChild = findSubroots(proxySpanDim,subroots,psize,treecopy);
787  delete [] treecopy;
788 
789  for(int i=1;i<psize+1;i++){
790  int isSubroot=0;
791  for(int j=0;j<nChild;j++)
792  if(tree[i]==subroots[j]){
793  isSubroot=1;
794  break;
795  }
796  if(isSubroot) continue;
797 
798  int bAdded = 0;
799  tmgr.sortIndexByHops(tree[i], subroots,
800  idxes, proxySpanDim);
801  for(int j=0;j<proxySpanDim;j++){
802  if(subsizes[idxes[j]]<proxySpanDim){
803  subtrees[idxes[j]][(subsizes[idxes[j]])++] = tree[i];
804  bAdded = 1;
805  break;
806  }
807  }
808  if( psize > proxySpanDim && ! bAdded ) {
809  NAMD_bug("HomePatch BGL Spanning Tree error: Couldn't find subtree for leaf\n");
810  }
811  }
812 
813 #else /* USE_TOPOMAP && USE_SPANNING_TREE */
814 
815  for (int i=1; i<=proxySpanDim; i++) {
816  if (tree.size() <= i) break;
817  child[i-1] = tree[i];
818  nChild++;
819  }
820 #endif
821 #endif
822 
823 #if 0
824  // for debugging
825  CkPrintf("[%d] Spanning tree for %d with %d children %d nNonPatch %d\n", CkMyPe(), patchID, psize, nNonPatch);
826  for (int i=0; i<psize+1; i++) {
827  CkPrintf("%d ", tree[i]);
828  }
829  CkPrintf("\n");
830 #endif
831  // send to children nodes
833 }
int numNodesWithPatches(void)
Definition: PatchMap.h:61
int size(void) const
Definition: ResizeArray.h:131
static PatchMap * Object()
Definition: PatchMap.h:27
void resize(int i)
Definition: ResizeArray.h:84
void setall(const Elem &elem)
Definition: ResizeArray.h:94
static int compDistance(const void *a, const void *b)
Definition: HomePatch.C:497
void NAMD_bug(const char *err_msg)
Definition: common.C:195
void sendSpanningTree()
Definition: HomePatch.C:700
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150
iterator end(void)
Definition: ResizeArray.h:37
int find(const Elem &e) const
Definition: ResizeArray.h:141
int numPatchesOnNode(int node)
Definition: PatchMap.h:60
void swap(ResizeArray< Elem > &ra)
Definition: ResizeArray.h:64
int proxySpanDim
Definition: ProxyMgr.C:47

◆ checkpoint()

void HomePatch::checkpoint ( void  )

Definition at line 5222 of file HomePatch.C.

References ResizeArray< Elem >::copy(), and Patch::lattice.

Referenced by Sequencer::algorithm().

5222  {
5223  checkpoint_atom.copy(atom);
5224  checkpoint_lattice = lattice;
5225 
5226  // DMK - Atom Separation (water vs. non-water)
5227  #if NAMD_SeparateWaters != 0
5228  checkpoint_numWaterAtoms = numWaterAtoms;
5229  #endif
5230 }
void copy(ResizeArray< Elem > &ra)
Definition: ResizeArray.h:59
Lattice & lattice
Definition: Patch.h:127

◆ depositMigration()

void HomePatch::depositMigration ( MigrateAtomsMsg msg)

Definition at line 5962 of file HomePatch.C.

References ResizeArray< Elem >::add(), Lattice::apply_transform(), Sequencer::awaken(), ResizeArray< Elem >::begin(), buildRattleList_SOA(), DebugM, ResizeArray< Elem >::end(), CompAtom::hydrogenGroupSize, CompAtomExt::id, inMigration, Patch::lattice, FullAtom::migrationGroupSize, MigrateAtomsMsg::migrationList, msgbuf, Lattice::nearest(), Patch::numAtoms, numMlBuf, Node::Object(), Patch::patchID, CompAtom::position, rattleListValid_SOA, Lattice::reverse_transform(), RIGID_NONE, Node::simParameters, simParams, ResizeArray< Elem >::size(), and FullAtom::transform.

Referenced by MigrateAtomsCombinedMsg::distribute(), and doAtomMigration().

5963 {
5964 
5965  if (!inMigration) { // We have to buffer changes due to migration
5966  // until our patch is in migration mode
5967  msgbuf[numMlBuf++] = msg;
5968  return;
5969  }
5970 
5971  // DMK - Atom Separation (water vs. non-water)
5972  #if NAMD_SeparateWaters != 0
5973 
5974 
5975  // Merge the incoming list of atoms with the current list of
5976  // atoms. Note that mergeSeparatedAtomList() will apply any
5977  // required transformations to the incoming atoms as it is
5978  // separating them.
5979  mergeAtomList(msg->migrationList);
5980 
5981 
5982  #else
5983 
5984  // Merge the incoming list of atoms with the current list of
5985  // atoms. Apply transformations to the incoming atoms as they are
5986  // added to this patch's list.
5987  {
5988  MigrationList &migrationList = msg->migrationList;
5990  Transform mother_transform;
5991  for (mi = migrationList.begin(); mi != migrationList.end(); mi++) {
5992  DebugM(1,"Migrating atom " << mi->id << " to patch "
5993  << patchID << " with position " << mi->position << "\n");
5994  if ( mi->migrationGroupSize ) {
5995  if ( mi->migrationGroupSize != mi->hydrogenGroupSize ) {
5996  Position pos = mi->position;
5997  int mgs = mi->migrationGroupSize;
5998  int c = 1;
5999  for ( int j=mi->hydrogenGroupSize; j<mgs;
6000  j+=(mi+j)->hydrogenGroupSize ) {
6001  pos += (mi+j)->position;
6002  ++c;
6003  }
6004  pos *= 1./c;
6005  // iout << "mgroup " << mi->id << " at " << pos << "\n" << endi;
6006  mother_transform = mi->transform;
6007  pos = lattice.nearest(pos,center,&mother_transform);
6009  mi->position = lattice.apply_transform(mi->position,mother_transform);
6010  mi->transform = mother_transform;
6011  } else {
6012  mi->position = lattice.nearest(mi->position,center,&(mi->transform));
6013  mother_transform = mi->transform;
6014  }
6015  } else {
6017  mi->position = lattice.apply_transform(mi->position,mother_transform);
6018  mi->transform = mother_transform;
6019  }
6020  atom.add(*mi);
6021  }
6022  }
6023 
6024 
6025  #endif // if (NAMD_SeparateWaters != 0)
6026 
6027 
6028  numAtoms = atom.size();
6029  delete msg;
6030 
6031  DebugM(3,"Counter on " << patchID << " = " << patchMigrationCounter << "\n");
6032  if (!--patchMigrationCounter) {
6033  // DH - All atoms are now incorporated from migration.
6034  // This is where we can separate waters from non-waters and
6035  // perhaps sort non-waters by hydrogen group size.
6037  if (simParams->SOAintegrateOn) {
6038  sort_solvent_atoms();
6039  copy_atoms_to_SOA();
6040 #if 0
6041  if (simParams->rigidBonds != RIGID_NONE) {
6043  rattleListValid_SOA = true;
6044  }
6045 #endif
6046  }
6047  DebugM(3,"All Migrations are in for patch "<<patchID<<"\n");
6048  allMigrationIn = true;
6049  patchMigrationCounter = numNeighbors;
6050  if (migrationSuspended) {
6051  DebugM(3,"patch "<<patchID<<" is being awakened\n");
6052  migrationSuspended = false;
6053  // fprintf(stderr, "Calling awaken() on patch %d: 8\n", this->patchID);
6054  sequencer->awaken();
6055  return;
6056  }
6057  else {
6058  DebugM(3,"patch "<<patchID<<" was not suspended\n");
6059  }
6060  }
6061 }
static Node * Object()
Definition: Node.h:86
int size(void) const
Definition: ResizeArray.h:131
NAMD_HOST_DEVICE Position reverse_transform(Position data, const Transform &t) const
Definition: Lattice.h:143
Lattice & lattice
Definition: Patch.h:127
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
MigrationList migrationList
#define DebugM(x, y)
Definition: Debug.h:75
Position position
Definition: NamdTypes.h:78
int inMigration
Definition: HomePatch.h:569
int add(const Elem &elem)
Definition: ResizeArray.h:101
uint32 id
Definition: NamdTypes.h:160
void awaken(void)
Definition: Sequencer.h:55
NAMD_HOST_DEVICE Position apply_transform(Position data, const Transform &t) const
Definition: Lattice.h:137
int32 migrationGroupSize
Definition: NamdTypes.h:230
int numAtoms
Definition: Patch.h:151
uint8 hydrogenGroupSize
Definition: NamdTypes.h:89
NAMD_HOST_DEVICE Position nearest(Position data, ScaledPosition ref) const
Definition: Lattice.h:95
MigrateAtomsMsg * msgbuf[PatchMap::MaxOneAway]
Definition: HomePatch.h:571
void buildRattleList_SOA()
Definition: HomePatch.C:4520
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150
iterator end(void)
Definition: ResizeArray.h:37
bool rattleListValid_SOA
Definition: HomePatch.h:454
#define RIGID_NONE
Definition: SimParameters.h:80
int numMlBuf
Definition: HomePatch.h:570
Transform transform
Definition: NamdTypes.h:229

◆ doAtomMigration()

void HomePatch::doAtomMigration ( )
protected

Definition at line 5798 of file HomePatch.C.

References ResizeArray< Elem >::add(), Patch::atomMapper, ResizeArray< Elem >::begin(), DebugM, ResizeArray< Elem >::del(), depositMigration(), ResizeArray< Elem >::end(), Patch::getPatchID(), CompAtom::hydrogenGroupSize, CompAtomExt::id, inMigration, Patch::lattice, marginViolations, FullAtom::migrationGroupSize, MigrationInfo::mList, msgbuf, NAMD_EVENT_START_EX, NAMD_EVENT_STOP, NamdProfileEventStr, Patch::numAtoms, numMlBuf, PatchMgr::Object(), Patch::patchID, CompAtom::position, ResizeArray< Elem >::resize(), Lattice::scale(), PatchMgr::sendMigrationMsgs(), ResizeArray< Elem >::size(), Sequencer::suspend(), AtomMapper::unregisterIDsFullAtom(), Vector::x, Vector::y, and Vector::z.

Referenced by positionsReady(), and positionsReady_SOA().

5799 {
5800 #if defined(NAMD_NVTX_ENABLED) || defined(NAMD_CMK_TRACE_ENABLED) || defined(NAMD_ROCTX_ENABLED)
5801  char ambuf[32];
5802  sprintf(ambuf, "%s: %d", NamdProfileEventStr[NamdProfileEvent::ATOM_MIGRATIONS], this->getPatchID());
5803  NAMD_EVENT_START_EX(1, NamdProfileEvent::ATOM_MIGRATIONS, ambuf);
5804 #endif
5805 
5806  // every patch needs to call this once per migration step
5807  // XXX TODO: check if the cpu version also calls it once per tstep
5808  int i;
5809  for (i=0; i<numNeighbors; i++) {
5810  realInfo[i].mList.resize(0);
5811  }
5812 
5813  // Purge the AtomMap
5814  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
5815 
5816  // Determine atoms that need to migrate
5817 
5818  BigReal minx = min.x;
5819  BigReal miny = min.y;
5820  BigReal minz = min.z;
5821  BigReal maxx = max.x;
5822  BigReal maxy = max.y;
5823  BigReal maxz = max.z;
5824 
5825  int xdev, ydev, zdev;
5826  int delnum = 0;
5827 
5828  FullAtomList::iterator atom_i = atom.begin();
5829  FullAtomList::iterator atom_e = atom.end();
5830 
5831  // DMK - Atom Separation (water vs. non-water)
5832  #if NAMD_SeparateWaters != 0
5833  FullAtomList::iterator atom_first = atom_i;
5834  int numLostWaterAtoms = 0;
5835  #endif
5836 
5837  while ( atom_i != atom_e ) {
5838  // Even though this code iterates through all atoms successively
5839  // it moves entire hydrogen/migration groups as follows:
5840  // Only the parent atom of the hydrogen/migration group has
5841  // nonzero migrationGroupSize. Values determined for xdev,ydev,zdev
5842  // will persist through the remaining group members so that each
5843  // following atom will again be added to the same mList.
5844  if ( atom_i->migrationGroupSize ) {
5845  Position pos = atom_i->position;
5846  if ( atom_i->migrationGroupSize != atom_i->hydrogenGroupSize ) {
5847  // If there are multiple hydrogen groups in a migration group
5848  // (e.g. for supporting lone pairs)
5849  // the following code takes the average position (midpoint)
5850  // of their parents.
5851  int mgs = atom_i->migrationGroupSize;
5852  int c = 1;
5853  for ( int j=atom_i->hydrogenGroupSize; j<mgs;
5854  j+=(atom_i+j)->hydrogenGroupSize ) {
5855  pos += (atom_i+j)->position;
5856  ++c;
5857  }
5858  pos *= 1./c;
5859  // iout << "mgroup " << atom_i->id << " at " << pos << "\n" << endi;
5860  }
5861 
5862  // Scaling the position below transforms space within patch from
5863  // what could have been a rotated parallelepiped into
5864  // orthogonal coordinates, where we can use minmax comparison
5865  // to detect which of our nearest neighbors this
5866  // parent atom might have entered.
5867  ScaledPosition s = lattice.scale(pos);
5868 
5869  // check if atom is within bounds
5870  if (s.x < minx) xdev = 0;
5871  else if (maxx <= s.x) xdev = 2;
5872  else xdev = 1;
5873 
5874  if (s.y < miny) ydev = 0;
5875  else if (maxy <= s.y) ydev = 2;
5876  else ydev = 1;
5877 
5878  if (s.z < minz) zdev = 0;
5879  else if (maxz <= s.z) zdev = 2;
5880  else zdev = 1;
5881 
5882  }
5883 
5884  if (mInfo[xdev][ydev][zdev]) { // process atom for migration
5885  // Don't migrate if destination is myself
5886 
5887  // See if we have a migration list already
5888  MigrationList &mCur = mInfo[xdev][ydev][zdev]->mList;
5889  DebugM(3,"Migrating atom " << atom_i->id << " from patch "
5890  << patchID << " with position " << atom_i->position << "\n");
5891  mCur.add(*atom_i);
5892  ++delnum;
5893 
5894 
5895  // DMK - Atom Separation (water vs. non-water)
5896  #if NAMD_SeparateWaters != 0
5897  // Check to see if this atom is part of a water molecule. If
5898  // so, numWaterAtoms needs to be adjusted to refect the lost of
5899  // this atom.
5900  // NOTE: The atom separation code assumes that if the oxygen
5901  // atom of the hydrogen group making up the water molecule is
5902  // migrated to another HomePatch, the hydrogens will also
5903  // move!!!
5904  int atomIndex = atom_i - atom_first;
5905  if (atomIndex < numWaterAtoms)
5906  numLostWaterAtoms++;
5907  #endif
5908 
5909 
5910  } else {
5911  // By keeping track of delnum total being deleted from FullAtomList
5912  // the else clause allows us to fill holes as we visit each atom.
5913 
5914  if ( delnum ) { *(atom_i-delnum) = *atom_i; }
5915 
5916  }
5917 
5918  ++atom_i;
5919  }
5920 
5921  // DMK - Atom Separation (water vs. non-water)
5922  #if NAMD_SeparateWaters != 0
5923  numWaterAtoms -= numLostWaterAtoms;
5924  #endif
5925 
5926 
5927  int delpos = numAtoms - delnum;
5928  DebugM(4,"numAtoms " << numAtoms << " deleted " << delnum << "\n");
5929  atom.del(delpos,delnum);
5930 
5931  numAtoms = atom.size();
5932  // Calls sendMigrationMsgs to the manager.
5933  // the manager only
5934  // wait, does this work??????
5935  PatchMgr::Object()->sendMigrationMsgs(patchID, realInfo, numNeighbors);
5936 
5937  // signal depositMigration() that we are inMigration mode
5938  inMigration = true;
5939 
5940  // Drain the migration message buffer
5941  for (i=0; i<numMlBuf; i++) {
5942  DebugM(1, "Draining migration buffer ("<<i<<","<<numMlBuf<<")\n");
5944  }
5945  numMlBuf = 0;
5946 
5947  NAMD_EVENT_STOP(1, NamdProfileEvent::ATOM_MIGRATIONS);
5948 
5949  if (!allMigrationIn) {
5950  DebugM(3,"All Migrations NOT in, we are suspending patch "<<patchID<<"\n");
5951  migrationSuspended = true;
5952  sequencer->suspend();
5953  migrationSuspended = false;
5954  }
5955  allMigrationIn = false;
5956 
5957  inMigration = false;
5958  marginViolations = 0;
5959 }
void depositMigration(MigrateAtomsMsg *)
Definition: HomePatch.C:5962
#define NAMD_EVENT_STOP(eon, id)
int size(void) const
Definition: ResizeArray.h:131
int marginViolations
Definition: HomePatch.h:401
Lattice & lattice
Definition: Patch.h:127
Definition: Vector.h:72
#define DebugM(x, y)
Definition: Debug.h:75
BigReal z
Definition: Vector.h:74
char const *const NamdProfileEventStr[]
Position position
Definition: NamdTypes.h:78
int inMigration
Definition: HomePatch.h:569
int add(const Elem &elem)
Definition: ResizeArray.h:101
AtomMapper * atomMapper
Definition: Patch.h:159
void resize(int i)
Definition: ResizeArray.h:84
uint32 id
Definition: NamdTypes.h:160
int32 migrationGroupSize
Definition: NamdTypes.h:230
NAMD_HOST_DEVICE ScaledPosition scale(Position p) const
Definition: Lattice.h:83
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
uint8 hydrogenGroupSize
Definition: NamdTypes.h:89
PatchID getPatchID() const
Definition: Patch.h:114
void sendMigrationMsgs(PatchID, MigrationInfo *, int)
Definition: PatchMgr.C:175
MigrateAtomsMsg * msgbuf[PatchMap::MaxOneAway]
Definition: HomePatch.h:571
void suspend(void)
Definition: Sequencer.C:279
#define NAMD_EVENT_START_EX(eon, id, str)
iterator begin(void)
Definition: ResizeArray.h:36
MigrationList mList
Definition: Migration.h:22
const PatchID patchID
Definition: Patch.h:150
iterator end(void)
Definition: ResizeArray.h:37
BigReal y
Definition: Vector.h:74
void del(int index, int num=1)
Definition: ResizeArray.h:108
void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:100
int numMlBuf
Definition: HomePatch.h:570
static PatchMgr * Object()
Definition: PatchMgr.h:152
double BigReal
Definition: common.h:123

◆ doGroupSizeCheck()

void HomePatch::doGroupSizeCheck ( )
protected

Definition at line 5590 of file HomePatch.C.

References ResizeArray< Elem >::begin(), Flags::doNonbonded, ResizeArray< Elem >::end(), Patch::flags, CompAtom::hydrogenGroupSize, Flags::maxGroupRadius, NAMD_bug(), CompAtom::nonbondedGroupSize, Node::Object(), CompAtom::position, Node::simParameters, simParams, Vector::x, Vector::y, and Vector::z.

Referenced by positionsReady().

5591 {
5592  if ( ! flags.doNonbonded ) return;
5593 
5595  BigReal hgcut = 0.5 * simParams->hgroupCutoff; hgcut *= hgcut;
5596  BigReal maxrad2 = 0.;
5597 
5598  FullAtomList::iterator p_i = atom.begin();
5599  FullAtomList::iterator p_e = atom.end();
5600 
5601  while ( p_i != p_e ) {
5602  const int hgs = p_i->hydrogenGroupSize;
5603  if ( ! hgs ) break; // avoid infinite loop on bug
5604  int ngs = hgs;
5605  if ( ngs > 5 ) ngs = 5; // XXX why? limit to at most 5 atoms per group
5606  BigReal x = p_i->position.x;
5607  BigReal y = p_i->position.y;
5608  BigReal z = p_i->position.z;
5609  int i;
5610  for ( i = 1; i < ngs; ++i ) { // limit spatial extent
5611  p_i[i].nonbondedGroupSize = 0;
5612  BigReal dx = p_i[i].position.x - x;
5613  BigReal dy = p_i[i].position.y - y;
5614  BigReal dz = p_i[i].position.z - z;
5615  BigReal r2 = dx * dx + dy * dy + dz * dz;
5616  if ( r2 > hgcut ) break;
5617  else if ( r2 > maxrad2 ) maxrad2 = r2;
5618  }
5619  p_i->nonbondedGroupSize = i;
5620  for ( ; i < hgs; ++i ) {
5621  p_i[i].nonbondedGroupSize = 1;
5622  }
5623  p_i += hgs;
5624  }
5625 
5626  if ( p_i != p_e ) {
5627  NAMD_bug("hydrogenGroupSize is zero in HomePatch::doGroupSizeCheck");
5628  }
5629 
5630  flags.maxGroupRadius = sqrt(maxrad2);
5631 
5632 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Position position
Definition: NamdTypes.h:78
Flags flags
Definition: Patch.h:128
void NAMD_bug(const char *err_msg)
Definition: common.C:195
BigReal x
Definition: Vector.h:74
uint8 hydrogenGroupSize
Definition: NamdTypes.h:89
int doNonbonded
Definition: PatchTypes.h:22
uint8 nonbondedGroupSize
Definition: NamdTypes.h:82
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
iterator end(void)
Definition: ResizeArray.h:37
BigReal y
Definition: Vector.h:74
BigReal maxGroupRadius
Definition: PatchTypes.h:44
double BigReal
Definition: common.h:123

◆ doGroupSizeCheck_SOA()

void HomePatch::doGroupSizeCheck_SOA ( )
protected

Definition at line 5537 of file HomePatch.C.

References Flags::doNonbonded, Patch::flags, PatchDataSOA::hydrogenGroupSize, Flags::maxGroupRadius, NAMD_bug(), PatchDataSOA::nonbondedGroupSize, Patch::numAtoms, Node::Object(), PatchDataSOA::pos_x, PatchDataSOA::pos_y, PatchDataSOA::pos_z, Node::simParameters, and simParams.

Referenced by positionsReady_SOA().

5538 {
5539  if ( ! flags.doNonbonded ) return;
5540 
5542  BigReal hgcut = 0.5 * simParams->hgroupCutoff; hgcut *= hgcut;
5543  BigReal maxrad2 = 0.;
5544 
5545  double * __restrict pos_x = patchDataSOA.pos_x;
5546  double * __restrict pos_y = patchDataSOA.pos_y;
5547  double * __restrict pos_z = patchDataSOA.pos_z;
5548  int * __restrict hydrogenGroupSize = patchDataSOA.hydrogenGroupSize;
5549  int * __restrict nonbondedGroupSize = patchDataSOA.nonbondedGroupSize;
5550 
5551  int j=0;
5552  while (j < numAtoms) {
5553  const int hgs = hydrogenGroupSize[j];
5554  if ( ! hgs ) break; // avoid infinite loop on bug
5555  int ngs = hgs;
5556  if ( ngs > 5 ) ngs = 5; // XXX why? limit to at most 5 atoms per group
5557  BigReal x = pos_x[j];
5558  BigReal y = pos_y[j];
5559  BigReal z = pos_z[j];
5560  int i;
5561  for ( i = 1; i < ngs; ++i ) { // limit spatial extent
5562  nonbondedGroupSize[j+i] = 0;
5563  BigReal dx = pos_x[j+i] - x;
5564  BigReal dy = pos_y[j+i] - y;
5565  BigReal dz = pos_z[j+i] - z;
5566  BigReal r2 = dx * dx + dy * dy + dz * dz;
5567  if ( r2 > hgcut ) break;
5568  else if ( r2 > maxrad2 ) maxrad2 = r2;
5569  }
5570  nonbondedGroupSize[j] = i;
5571  for ( ; i < hgs; ++i ) {
5572  nonbondedGroupSize[j+i] = 1;
5573  }
5574  j += hgs;
5575  }
5576 
5577  if (j != numAtoms) {
5578  NAMD_bug("hydrogenGroupSize is zero in HomePatch::doGroupSizeCheck");
5579  }
5580 
5581  flags.maxGroupRadius = sqrt(maxrad2);
5582 
5583 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
double * pos_y
Definition: NamdTypes.h:378
Flags flags
Definition: Patch.h:128
int32 * hydrogenGroupSize
Definition: NamdTypes.h:385
void NAMD_bug(const char *err_msg)
Definition: common.C:195
int numAtoms
Definition: Patch.h:151
int doNonbonded
Definition: PatchTypes.h:22
#define simParams
Definition: Output.C:131
double * pos_z
Definition: NamdTypes.h:379
double * pos_x
Definition: NamdTypes.h:377
int32 * nonbondedGroupSize
Definition: NamdTypes.h:384
BigReal maxGroupRadius
Definition: PatchTypes.h:44
double BigReal
Definition: common.h:123

◆ doMarginCheck()

void HomePatch::doMarginCheck ( )
protected

Definition at line 5721 of file HomePatch.C.

References Lattice::a(), Lattice::a_r(), Lattice::b(), Lattice::b_r(), ResizeArray< Elem >::begin(), Lattice::c(), Lattice::c_r(), ResizeArray< Elem >::end(), Patch::lattice, marginViolations, NAMD_die(), Node::Object(), CompAtom::position, Lattice::scale(), Node::simParameters, simParams, Vector::unit(), Vector::x, Vector::y, and Vector::z.

Referenced by positionsReady().

5722 {
5724 
5725  BigReal sysdima = lattice.a_r().unit() * lattice.a();
5726  BigReal sysdimb = lattice.b_r().unit() * lattice.b();
5727  BigReal sysdimc = lattice.c_r().unit() * lattice.c();
5728 
5729  BigReal minSize = simParams->patchDimension - simParams->margin;
5730 
5731  if ( ( aAwayDist*sysdima < minSize*0.9999 ) ||
5732  ( bAwayDist*sysdimb < minSize*0.9999 ) ||
5733  ( cAwayDist*sysdimc < minSize*0.9999 ) ) {
5734 
5735  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5736  "Possible solutions are to restart from a recent checkpoint,\n"
5737  "increase margin, or disable useFlexibleCell for liquid simulation.");
5738  }
5739 
5740  BigReal cutoff = simParams->cutoff;
5741 
5742  BigReal margina = 0.5 * ( aAwayDist - cutoff / sysdima );
5743  BigReal marginb = 0.5 * ( bAwayDist - cutoff / sysdimb );
5744  BigReal marginc = 0.5 * ( cAwayDist - cutoff / sysdimc );
5745 
5746  if ( (margina < -0.0001) || (marginb < -0.0001) || (marginc < -0.0001) ) {
5747  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5748  "There are probably many margin violations already reported.\n"
5749  "Possible solutions are to restart from a recent checkpoint,\n"
5750  "increase margin, or disable useFlexibleCell for liquid simulation.");
5751  }
5752 
5753  BigReal minx = min.x - margina;
5754  BigReal miny = min.y - marginb;
5755  BigReal minz = min.z - marginc;
5756  BigReal maxx = max.x + margina;
5757  BigReal maxy = max.y + marginb;
5758  BigReal maxz = max.z + marginc;
5759 
5760  int xdev, ydev, zdev;
5761  int problemCount = 0;
5762 
5763  FullAtomList::iterator p_i = atom.begin();
5764  FullAtomList::iterator p_e = atom.end();
5765  for ( ; p_i != p_e; ++p_i ) {
5766 
5768 
5769  // check if atom is within bounds
5770  if (s.x < minx) xdev = 0;
5771  else if (maxx <= s.x) xdev = 2;
5772  else xdev = 1;
5773 
5774  if (s.y < miny) ydev = 0;
5775  else if (maxy <= s.y) ydev = 2;
5776  else ydev = 1;
5777 
5778  if (s.z < minz) zdev = 0;
5779  else if (maxz <= s.z) zdev = 2;
5780  else zdev = 1;
5781 
5782  if (mInfo[xdev][ydev][zdev]) { // somewhere else to be
5783  ++problemCount;
5784  }
5785 
5786  }
5787 
5788  marginViolations = problemCount;
5789  // if ( problemCount ) {
5790  // iout << iERROR <<
5791  // "Found " << problemCount << " margin violations!\n" << endi;
5792  // }
5793 
5794 }
static Node * Object()
Definition: Node.h:86
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
int marginViolations
Definition: HomePatch.h:401
Lattice & lattice
Definition: Patch.h:127
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Position position
Definition: NamdTypes.h:78
NAMD_HOST_DEVICE ScaledPosition scale(Position p) const
Definition: Lattice.h:83
BigReal x
Definition: Vector.h:74
NAMD_HOST_DEVICE Vector a_r() const
Definition: Lattice.h:284
NAMD_HOST_DEVICE Vector b_r() const
Definition: Lattice.h:285
void NAMD_die(const char *err_msg)
Definition: common.C:147
NAMD_HOST_DEVICE Vector c_r() const
Definition: Lattice.h:286
NAMD_HOST_DEVICE Vector b() const
Definition: Lattice.h:269
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
iterator end(void)
Definition: ResizeArray.h:37
BigReal y
Definition: Vector.h:74
NAMD_HOST_DEVICE Vector a() const
Definition: Lattice.h:268
NAMD_HOST_DEVICE Vector unit(void) const
Definition: Vector.h:215
double BigReal
Definition: common.h:123

◆ doMarginCheck_SOA()

void HomePatch::doMarginCheck_SOA ( )
protected

Definition at line 5639 of file HomePatch.C.

References Lattice::a(), Lattice::a_r(), Lattice::b(), Lattice::b_r(), Lattice::c(), Lattice::c_r(), Patch::lattice, marginViolations, NAMD_die(), Patch::numAtoms, Node::Object(), PatchDataSOA::pos_x, PatchDataSOA::pos_y, PatchDataSOA::pos_z, Lattice::scale(), Node::simParameters, simParams, Vector::unit(), Vector::x, Vector::y, and Vector::z.

Referenced by positionsReady_SOA().

5640 {
5642 
5643  BigReal sysdima = lattice.a_r().unit() * lattice.a();
5644  BigReal sysdimb = lattice.b_r().unit() * lattice.b();
5645  BigReal sysdimc = lattice.c_r().unit() * lattice.c();
5646 
5647  BigReal minSize = simParams->patchDimension - simParams->margin;
5648 
5649  if ( ( aAwayDist*sysdima < minSize*0.9999 ) ||
5650  ( bAwayDist*sysdimb < minSize*0.9999 ) ||
5651  ( cAwayDist*sysdimc < minSize*0.9999 ) ) {
5652 
5653  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5654  "Possible solutions are to restart from a recent checkpoint,\n"
5655  "increase margin, or disable useFlexibleCell for liquid simulation.");
5656  }
5657 
5658  BigReal cutoff = simParams->cutoff;
5659 
5660  BigReal margina = 0.5 * ( aAwayDist - cutoff / sysdima );
5661  BigReal marginb = 0.5 * ( bAwayDist - cutoff / sysdimb );
5662  BigReal marginc = 0.5 * ( cAwayDist - cutoff / sysdimc );
5663 
5664  if ( (margina < -0.0001) || (marginb < -0.0001) || (marginc < -0.0001) ) {
5665  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5666  "There are probably many margin violations already reported.\n"
5667  "Possible solutions are to restart from a recent checkpoint,\n"
5668  "increase margin, or disable useFlexibleCell for liquid simulation.");
5669  }
5670 
5671  BigReal minx = min.x - margina;
5672  BigReal miny = min.y - marginb;
5673  BigReal minz = min.z - marginc;
5674  BigReal maxx = max.x + margina;
5675  BigReal maxy = max.y + marginb;
5676  BigReal maxz = max.z + marginc;
5677 
5678  int xdev, ydev, zdev;
5679  int problemCount = 0;
5680 
5681  double * __restrict pos_x = patchDataSOA.pos_x;
5682  double * __restrict pos_y = patchDataSOA.pos_y;
5683  double * __restrict pos_z = patchDataSOA.pos_z;
5684  for (int i=0; i < numAtoms; i++) {
5685  Vector pos(pos_x[i],pos_y[i],pos_z[i]);
5686 
5687  ScaledPosition s = lattice.scale(pos);
5688 
5689  // check if atom is within bounds
5690  if (s.x < minx) xdev = 0;
5691  else if (maxx <= s.x) xdev = 2;
5692  else xdev = 1;
5693 
5694  if (s.y < miny) ydev = 0;
5695  else if (maxy <= s.y) ydev = 2;
5696  else ydev = 1;
5697 
5698  if (s.z < minz) zdev = 0;
5699  else if (maxz <= s.z) zdev = 2;
5700  else zdev = 1;
5701 
5702  if (mInfo[xdev][ydev][zdev]) { // somewhere else to be
5703  ++problemCount;
5704  }
5705 
5706  }
5707 
5708  marginViolations = problemCount;
5709  // if ( problemCount ) {
5710  // iout << iERROR <<
5711  // "Found " << problemCount << " margin violations!\n" << endi;
5712  // }
5713 
5714 }
static Node * Object()
Definition: Node.h:86
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
int marginViolations
Definition: HomePatch.h:401
Lattice & lattice
Definition: Patch.h:127
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
double * pos_y
Definition: NamdTypes.h:378
NAMD_HOST_DEVICE ScaledPosition scale(Position p) const
Definition: Lattice.h:83
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
NAMD_HOST_DEVICE Vector a_r() const
Definition: Lattice.h:284
NAMD_HOST_DEVICE Vector b_r() const
Definition: Lattice.h:285
void NAMD_die(const char *err_msg)
Definition: common.C:147
NAMD_HOST_DEVICE Vector c_r() const
Definition: Lattice.h:286
NAMD_HOST_DEVICE Vector b() const
Definition: Lattice.h:269
#define simParams
Definition: Output.C:131
double * pos_z
Definition: NamdTypes.h:379
double * pos_x
Definition: NamdTypes.h:377
BigReal y
Definition: Vector.h:74
NAMD_HOST_DEVICE Vector a() const
Definition: Lattice.h:268
NAMD_HOST_DEVICE Vector unit(void) const
Definition: Vector.h:215
double BigReal
Definition: common.h:123

◆ doPairlistCheck()

void HomePatch::doPairlistCheck ( )
protected

Definition at line 5438 of file HomePatch.C.

References ResizeArray< Elem >::begin(), Patch::flags, Patch::getPatchID(), Patch::lattice, Vector::length2(), Flags::maxAtomMovement, NAMD_EVENT_START_EX, NAMD_EVENT_STOP, NamdProfileEventStr, Patch::numAtoms, Node::Object(), Patch::p, Flags::pairlistTolerance, CompAtom::position, ResizeArray< Elem >::resize(), Flags::savePairlists, Node::simParameters, simParams, Lattice::unscale(), Flags::usePairlists, Vector::x, Vector::y, and Vector::z.

Referenced by positionsReady(), and positionsReady_SOA().

5439 {
5440 #if 0
5441 #if defined(NAMD_NVTX_ENABLED) || defined(NAMD_CMK_TRACE_ENABLED) || defined(NAMD_ROCTX_ENABLED)
5442  char dpcbuf[32];
5443  sprintf(dpcbuf, "%s: %d", NamdProfileEventStr[NamdProfileEvent::DO_PAIRLIST_CHECK], this->getPatchID());
5444  NAMD_EVENT_START_EX(1, NamdProfileEvent::DO_PAIRLIST_CHECK, dpcbuf);
5445 #endif
5446 #endif
5447 
5449 
5450  if ( numAtoms == 0 || ! flags.usePairlists ) {
5451  flags.pairlistTolerance = 0.;
5452  flags.maxAtomMovement = 99999.;
5453 #if 0
5454  NAMD_EVENT_STOP(1, NamdProfileEvent::DO_PAIRLIST_CHECK);
5455 #endif
5456  return;
5457  }
5458 
5459  int i; int n = numAtoms;
5460  CompAtom *p_i = p.begin();
5461 
5462  if ( flags.savePairlists ) {
5463  flags.pairlistTolerance = doPairlistCheck_newTolerance;
5464  flags.maxAtomMovement = 0.;
5465  doPairlistCheck_newTolerance *= (1. - simParams->pairlistShrink);
5466  doPairlistCheck_lattice = lattice;
5467  doPairlistCheck_positions.resize(numAtoms);
5468  CompAtom *psave_i = doPairlistCheck_positions.begin();
5469  for ( i=0; i<n; ++i ) { psave_i[i] = p_i[i]; }
5470 #if 0
5471  NAMD_EVENT_STOP(1, NamdProfileEvent::DO_PAIRLIST_CHECK);
5472 #endif
5473  return;
5474  }
5475 
5476  Lattice &lattice_old = doPairlistCheck_lattice;
5477  Position center_cur = lattice.unscale(center);
5478  Position center_old = lattice_old.unscale(center);
5479  Vector center_delta = center_cur - center_old;
5480 
5481  // find max deviation to corner (any neighbor shares a corner)
5482  BigReal max_cd = 0.;
5483  for ( i=0; i<2; ++i ) {
5484  for ( int j=0; j<2; ++j ) {
5485  for ( int k=0; k<2; ++k ) {
5486  ScaledPosition corner( i ? min.x : max.x , j ? min.y : max.y , k ? min.z : max.z );
5487  Vector corner_delta = lattice.unscale(corner) - lattice_old.unscale(corner);
5488  corner_delta -= center_delta;
5489  BigReal cd = corner_delta.length2();
5490  if ( cd > max_cd ) max_cd = cd;
5491  }
5492  }
5493  }
5494  max_cd = sqrt(max_cd);
5495 
5496  // find max deviation of atoms relative to center
5497  BigReal max_pd = 0.;
5498  CompAtom *p_old_i = doPairlistCheck_positions.begin();
5499  for ( i=0; i<n; ++i ) {
5500  // JM: Calculating position difference and making it patch-centered
5501  Vector p_delta = p_i[i].position - p_old_i[i].position;
5502  p_delta -= center_delta;
5503  BigReal pd = p_delta.length2();
5504  if ( pd > max_pd ) max_pd = pd;
5505  }
5506  max_pd = sqrt(max_pd);
5507 
5508  BigReal max_tol = max_pd + max_cd;
5509 
5510  flags.maxAtomMovement = max_tol;
5511 
5512  // if ( max_tol > flags.pairlistTolerance ) iout << "tolerance " << max_tol << " > " << flags.pairlistTolerance << "\n" << endi;
5513 
5514  if ( max_tol > ( (1. - simParams->pairlistTrigger) *
5515  doPairlistCheck_newTolerance ) ) {
5516  //if(this->getPatchID() == 0) fprintf(stderr, "CPU: Increasing pairList tolerance(%lf %lf)\n",
5517  // max_tol, doPairlistCheck_newTolerance);
5518  doPairlistCheck_newTolerance *= (1. + simParams->pairlistGrow);
5519  }
5520 
5521  if ( max_tol > doPairlistCheck_newTolerance ) {
5522  //if(this->getPatchID() == 0) fprintf(stderr, "CPU: Decreasing pairList tolerance(%lf %lf)\n",
5523  // max_tol, doPairlistCheck_newTolerance);
5524  doPairlistCheck_newTolerance = max_tol / (1. - simParams->pairlistTrigger);
5525  }
5526 
5527  //if(this->getPatchID() == 0) fprintf(stderr, "CPU: New patchTolerance: %lf\n", doPairlistCheck_newTolerance);
5528 
5529 // NAMD_EVENT_STOP(1, NamdProfileEvent::DO_PAIRLIST_CHECK);
5530 }
static Node * Object()
Definition: Node.h:86
#define NAMD_EVENT_STOP(eon, id)
Lattice & lattice
Definition: Patch.h:127
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
int savePairlists
Definition: PatchTypes.h:41
NAMD_HOST_DEVICE Position unscale(ScaledPosition s) const
Definition: Lattice.h:77
BigReal z
Definition: Vector.h:74
char const *const NamdProfileEventStr[]
int usePairlists
Definition: PatchTypes.h:40
Position position
Definition: NamdTypes.h:78
Flags flags
Definition: Patch.h:128
void resize(int i)
Definition: ResizeArray.h:84
CompAtomList p
Definition: Patch.h:153
NAMD_HOST_DEVICE BigReal length2(void) const
Definition: Vector.h:206
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
PatchID getPatchID() const
Definition: Patch.h:114
BigReal maxAtomMovement
Definition: PatchTypes.h:43
#define simParams
Definition: Output.C:131
#define NAMD_EVENT_START_EX(eon, id, str)
iterator begin(void)
Definition: ResizeArray.h:36
BigReal y
Definition: Vector.h:74
BigReal pairlistTolerance
Definition: PatchTypes.h:42
double BigReal
Definition: common.h:123

◆ exchangeAtoms()

void HomePatch::exchangeAtoms ( int  scriptTask)

Definition at line 5370 of file HomePatch.C.

References ExchangeAtomsMsg::atoms, ResizeArray< Elem >::begin(), exchange_dst, exchange_msg, exchange_req, exchange_src, ExchangeAtomsMsg::lattice, Patch::lattice, ExchangeAtomsMsg::numAtoms, Patch::numAtoms, Node::Object(), PatchMgr::Object(), Patch::patchID, ExchangeAtomsMsg::pid, recvExchangeReq(), SCRIPT_ATOMRECV, SCRIPT_ATOMSEND, SCRIPT_ATOMSENDRECV, PatchMgr::sendExchangeReq(), Node::simParameters, and simParams.

Referenced by Sequencer::algorithm().

5370  {
5372  // CkPrintf("exchangeAtoms %d %d %d %d\n", CmiMyPartition(), scriptTask, (int)(simParams->scriptArg1), (int)(simParams->scriptArg2));
5373  if ( scriptTask == SCRIPT_ATOMSEND || scriptTask == SCRIPT_ATOMSENDRECV ) {
5374  exchange_dst = (int) simParams->scriptArg1;
5375  // create and save outgoing message
5380  memcpy(exchange_msg->atoms,atom.begin(),numAtoms*sizeof(FullAtom));
5381  if ( exchange_req >= 0 ) {
5383  }
5384  }
5385  if ( scriptTask == SCRIPT_ATOMRECV || scriptTask == SCRIPT_ATOMSENDRECV ) {
5386  exchange_src = (int) simParams->scriptArg2;
5388  }
5389 }
static Node * Object()
Definition: Node.h:86
Lattice & lattice
Definition: Patch.h:127
int exchange_dst
Definition: HomePatch.h:514
SimParameters * simParameters
Definition: Node.h:181
void sendExchangeReq(int pid, int src)
Definition: PatchMgr.C:388
ExchangeAtomsMsg * exchange_msg
Definition: HomePatch.h:517
Lattice lattice
Definition: PatchMgr.h:109
int numAtoms
Definition: Patch.h:151
int exchange_req
Definition: HomePatch.h:516
int exchange_src
Definition: HomePatch.h:515
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150
void recvExchangeReq(int req)
Definition: HomePatch.C:5391
FullAtom * atoms
Definition: PatchMgr.h:112
static PatchMgr * Object()
Definition: PatchMgr.h:152

◆ exchangeCheckpoint()

void HomePatch::exchangeCheckpoint ( int  scriptTask,
int &  bpc 
)

Definition at line 5263 of file HomePatch.C.

References checkpoint_task, Node::Object(), PatchMgr::Object(), Patch::patchID, PatchMgr::sendCheckpointReq(), Node::simParameters, and simParams.

Referenced by Sequencer::algorithm().

5263  { // initiating replica
5265  checkpoint_task = scriptTask;
5266  const int remote = simParams->scriptIntArg1;
5267  const char *key = simParams->scriptStringArg1;
5268  PatchMgr::Object()->sendCheckpointReq(patchID, remote, key, scriptTask);
5269 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
#define simParams
Definition: Output.C:131
const PatchID patchID
Definition: Patch.h:150
int checkpoint_task
Definition: HomePatch.h:501
void sendCheckpointReq(int pid, int remote, const char *key, int task)
Definition: PatchMgr.C:272
static PatchMgr * Object()
Definition: PatchMgr.h:152

◆ gbisComputeAfterP1()

void HomePatch::gbisComputeAfterP1 ( )

Definition at line 4915 of file HomePatch.C.

References Patch::bornRad, Patch::flags, gbisP2Ready(), Patch::intRad, Patch::numAtoms, Node::Object(), Patch::pExt, Patch::psiFin, Patch::psiSum, Flags::sequence, Node::simParameters, and simParams.

Referenced by Sequencer::runComputeObjects().

4915  {
4916 
4918  BigReal alphaMax = simParams->alpha_max;
4919  BigReal delta = simParams->gbis_delta;
4920  BigReal beta = simParams->gbis_beta;
4921  BigReal gamma = simParams->gbis_gamma;
4922  BigReal coulomb_radius_offset = simParams->coulomb_radius_offset;
4923 
4924  BigReal rhoi;
4925  BigReal rhoi0;
4926  //calculate bornRad from psiSum
4927  for (int i = 0; i < numAtoms; i++) {
4928  rhoi0 = intRad[2*i];
4929  rhoi = rhoi0+coulomb_radius_offset;
4930  psiFin[i] += psiSum[i];
4931  psiFin[i] *= rhoi0;
4932  bornRad[i]=1/(1/rhoi0-1/rhoi*tanh(psiFin[i]*(delta+psiFin[i]*(-beta+gamma*psiFin[i]))));
4933  bornRad[i] = (bornRad[i] > alphaMax) ? alphaMax : bornRad[i];
4934 #ifdef PRINT_COMP
4935  CkPrintf("BORNRAD(%04i)[%04i] = % .4e\n",flags.sequence,pExt[i].id,bornRad[i]);
4936 #endif
4937  }
4938 
4939  gbisP2Ready();
4940 }
static Node * Object()
Definition: Node.h:86
RealList intRad
Definition: Patch.h:162
SimParameters * simParameters
Definition: Node.h:181
GBRealList psiFin
Definition: Patch.h:164
Flags flags
Definition: Patch.h:128
GBRealList psiSum
Definition: Patch.h:163
int numAtoms
Definition: Patch.h:151
int sequence
Definition: PatchTypes.h:18
void gbisP2Ready()
Definition: HomePatch.C:4987
#define simParams
Definition: Output.C:131
RealList bornRad
Definition: Patch.h:165
CompAtomExtList pExt
Definition: Patch.h:181
double BigReal
Definition: common.h:123

◆ gbisComputeAfterP2()

void HomePatch::gbisComputeAfterP2 ( )

Definition at line 4943 of file HomePatch.C.

References Patch::bornRad, COULOMB, Patch::dEdaSum, Patch::dHdrPrefix, Patch::flags, gbisP3Ready(), Patch::intRad, Patch::numAtoms, Node::Object(), Patch::pExt, Patch::psiFin, Flags::sequence, Node::simParameters, and simParams.

Referenced by Sequencer::runComputeObjects().

4943  {
4944 
4946  BigReal delta = simParams->gbis_delta;
4947  BigReal beta = simParams->gbis_beta;
4948  BigReal gamma = simParams->gbis_gamma;
4949  BigReal epsilon_s = simParams->solvent_dielectric;
4950  BigReal epsilon_p = simParams->dielectric;
4951  BigReal epsilon_s_i = 1/simParams->solvent_dielectric;
4952  BigReal epsilon_p_i = 1/simParams->dielectric;
4953  BigReal coulomb_radius_offset = simParams->coulomb_radius_offset;
4954  BigReal kappa = simParams->kappa;
4955  BigReal fij, expkappa, Dij, dEdai, dedasum;
4956  BigReal rhoi, rhoi0, psii, nbetapsi;
4957  BigReal gammapsi2, tanhi, daidr;
4958  for (int i = 0; i < numAtoms; i++) {
4959  //add diagonal dEda term
4960  dHdrPrefix[i] += dEdaSum[i];//accumulated from proxies
4961  fij = bornRad[i];//inf
4962  expkappa = exp(-kappa*fij);//0
4963  Dij = epsilon_p_i - expkappa*epsilon_s_i;//dielectric term
4964  //calculate dHij prefix
4965  dEdai = -0.5*COULOMB*atom[i].charge*atom[i].charge
4966  *(kappa*epsilon_s_i*expkappa-Dij/fij)/bornRad[i];
4967  dHdrPrefix[i] += dEdai;
4968  dedasum = dHdrPrefix[i];
4969 
4970  rhoi0 = intRad[2*i];
4971  rhoi = rhoi0+coulomb_radius_offset;
4972  psii = psiFin[i];
4973  nbetapsi = -beta*psii;
4974  gammapsi2 = gamma*psii*psii;
4975  tanhi = tanh(psii*(delta+nbetapsi+gammapsi2));
4976  daidr = bornRad[i]*bornRad[i]*rhoi0/rhoi*(1-tanhi*tanhi)
4977  * (delta+nbetapsi+nbetapsi+gammapsi2+gammapsi2+gammapsi2);
4978  dHdrPrefix[i] *= daidr;//dHdrPrefix previously equaled dEda
4979 #ifdef PRINT_COMP
4980  CkPrintf("DHDR(%04i)[%04i] = % .4e\n",flags.sequence,pExt[i].id,dHdrPrefix[i]);
4981 #endif
4982  }
4983  gbisP3Ready();
4984 }
static Node * Object()
Definition: Node.h:86
RealList intRad
Definition: Patch.h:162
SimParameters * simParameters
Definition: Node.h:181
#define COULOMB
Definition: common.h:53
RealList dHdrPrefix
Definition: Patch.h:166
GBRealList psiFin
Definition: Patch.h:164
GBRealList dEdaSum
Definition: Patch.h:167
void gbisP3Ready()
Definition: HomePatch.C:5007
Flags flags
Definition: Patch.h:128
int numAtoms
Definition: Patch.h:151
int sequence
Definition: PatchTypes.h:18
#define simParams
Definition: Output.C:131
RealList bornRad
Definition: Patch.h:165
CompAtomExtList pExt
Definition: Patch.h:181
double BigReal
Definition: common.h:123

◆ gbisP2Ready()

void HomePatch::gbisP2Ready ( )

Definition at line 4987 of file HomePatch.C.

References ResizeArray< Elem >::begin(), ProxyGBISP2DataMsg::bornRad, Patch::bornRad, ProxyGBISP2DataMsg::destPe, Patch::flags, GB2_PROXY_DATA_PRIORITY, Patch::gbisP2Ready(), Patch::numAtoms, ProxyGBISP2DataMsg::origPe, ProxyGBISP2DataMsg::patch, PATCH_PRIORITY, Patch::patchID, PRIORITY_SIZE, Flags::sequence, SET_PRIORITY, and ResizeArray< Elem >::size().

Referenced by gbisComputeAfterP1().

4987  {
4988  if (proxy.size() > 0) {
4989  CProxy_ProxyMgr cp(CkpvAccess(BOCclass_group).proxyMgr);
4990  for (int i = 0; i < proxy.size(); i++) {
4991  int node = proxy[i];
4993  msg->patch = patchID;
4994  msg->origPe = CkMyPe();
4995  memcpy(msg->bornRad,bornRad.begin(),numAtoms*sizeof(Real));
4996  msg->destPe = node;
4997  int seq = flags.sequence;
4999  SET_PRIORITY(msg,seq,priority);
5000  cp[node].recvData(msg);
5001  }
5002  }
5004 }
int size(void) const
Definition: ResizeArray.h:131
float Real
Definition: common.h:118
Flags flags
Definition: Patch.h:128
#define PRIORITY_SIZE
Definition: Priorities.h:13
void gbisP2Ready()
Definition: Patch.C:598
int numAtoms
Definition: Patch.h:151
int sequence
Definition: PatchTypes.h:18
RealList bornRad
Definition: Patch.h:165
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150
#define SET_PRIORITY(MSG, SEQ, PRIO)
Definition: Priorities.h:18
#define GB2_PROXY_DATA_PRIORITY
Definition: Priorities.h:58
#define PATCH_PRIORITY(PID)
Definition: Priorities.h:25

◆ gbisP3Ready()

void HomePatch::gbisP3Ready ( )

Definition at line 5007 of file HomePatch.C.

References ResizeArray< Elem >::begin(), ProxyGBISP3DataMsg::destPe, ProxyGBISP3DataMsg::dHdrPrefix, Patch::dHdrPrefix, ProxyGBISP3DataMsg::dHdrPrefixLen, Flags::doFullElectrostatics, Patch::flags, GB3_PROXY_DATA_PRIORITY, Patch::gbisP3Ready(), Patch::numAtoms, ProxyGBISP3DataMsg::origPe, ProxyGBISP3DataMsg::patch, PATCH_PRIORITY, Patch::patchID, PRIORITY_SIZE, Flags::sequence, SET_PRIORITY, and ResizeArray< Elem >::size().

Referenced by gbisComputeAfterP2().

5007  {
5008  if (proxy.size() > 0) {
5009  CProxy_ProxyMgr cp(CkpvAccess(BOCclass_group).proxyMgr);
5010  //only nonzero message should be sent for doFullElec
5011  int msgAtoms = (flags.doFullElectrostatics) ? numAtoms : 0;
5012  for (int i = 0; i < proxy.size(); i++) {
5013  int node = proxy[i];
5015  msg->patch = patchID;
5016  msg->dHdrPrefixLen = msgAtoms;
5017  msg->origPe = CkMyPe();
5018  memcpy(msg->dHdrPrefix, dHdrPrefix.begin(), msgAtoms*sizeof(Real));
5019  msg->destPe = node;
5020  int seq = flags.sequence;
5022  SET_PRIORITY(msg,seq,priority);
5023  cp[node].recvData(msg);
5024  }
5025  }
5027 }
int size(void) const
Definition: ResizeArray.h:131
float Real
Definition: common.h:118
RealList dHdrPrefix
Definition: Patch.h:166
Flags flags
Definition: Patch.h:128
#define PRIORITY_SIZE
Definition: Priorities.h:13
int doFullElectrostatics
Definition: PatchTypes.h:23
int numAtoms
Definition: Patch.h:151
int sequence
Definition: PatchTypes.h:18
void gbisP3Ready()
Definition: Patch.C:614
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150
Real * dHdrPrefix
Definition: ProxyMgr.h:59
#define SET_PRIORITY(MSG, SEQ, PRIO)
Definition: Priorities.h:18
#define GB3_PROXY_DATA_PRIORITY
Definition: Priorities.h:66
#define PATCH_PRIORITY(PID)
Definition: Priorities.h:25

◆ getAtomList()

FullAtomList& HomePatch::getAtomList ( )
inline

◆ getMax()

ScaledPosition HomePatch::getMax ( )
inline

Definition at line 530 of file HomePatch.h.

530 {return max;}

◆ getMin()

ScaledPosition HomePatch::getMin ( )
inline

Definition at line 529 of file HomePatch.h.

529 {return min;}

◆ hardWallDrude()

int HomePatch::hardWallDrude ( const BigReal  timestep,
Tensor virial,
SubmitReduction ppreduction 
)

Definition at line 3410 of file HomePatch.C.

References BOLTZMANN, Lattice::c(), endi(), iERROR(), iout, SubmitReduction::item(), Patch::lattice, Node::molecule, Patch::numAtoms, Node::Object(), Lattice::origin(), outer(), partition(), Node::simParameters, simParams, TIMEFACTOR, Vector::x, Tensor::xx, Vector::y, Tensor::yy, Vector::z, and Tensor::zz.

Referenced by Sequencer::hardWallDrude().

3412 {
3413  Molecule *mol = Node::Object()->molecule;
3415  const BigReal kbt=BOLTZMANN*simParams->drudeTemp;
3416  const int fixedAtomsOn = simParams->fixedAtomsOn;
3417  const BigReal dt = timestep / TIMEFACTOR;
3418  const BigReal invdt = (dt == 0.) ? 0. : 1.0 / dt; // precalc 1/dt
3419  int i, ia, ib, j;
3420  int dieOnError = simParams->rigidDie;
3421  Tensor wc; // constraint virial
3422  BigReal idz, zmin, delta_T, maxtime=timestep,v_Bond;
3423  int nslabs;
3424 
3425  // start data for hard wall boundary between drude and its host atom
3426  // static int Count=0;
3427  int Idx;
3428  double r_wall, r_wall_SQ, rab, rab_SQ, dr, mass_a, mass_b, mass_sum;
3429  Vector v_ab, vb_1, vp_1, vb_2, vp_2, new_vel_a, new_vel_b, new_pos_a, new_pos_b, *new_pos, *new_vel;
3430  double dot_v_r_1, dot_v_r_2;
3431  double vb_cm, dr_a, dr_b;
3432  // end data for hard wall boundary between drude and its host atom
3433 
3434  // start calculation of hard wall boundary between drude and its host atom
3435  if (simParams->drudeHardWallOn) {
3436  if (ppreduction) {
3437  nslabs = simParams->pressureProfileSlabs;
3438  idz = nslabs/lattice.c().z;
3439  zmin = lattice.origin().z - 0.5*lattice.c().z;
3440  }
3441 
3442  r_wall = simParams->drudeBondLen;
3443  r_wall_SQ = r_wall*r_wall;
3444  // Count++;
3445  for (i=1; i<numAtoms; i++) {
3446  if ( (0.05 < atom[i].mass) && ((atom[i].mass < 1.0)) ) { // drude particle
3447  ia = i-1;
3448  ib = i;
3449 
3450  v_ab = atom[ib].position - atom[ia].position;
3451  rab_SQ = v_ab.x*v_ab.x + v_ab.y*v_ab.y + v_ab.z*v_ab.z;
3452 
3453  if (rab_SQ > r_wall_SQ) { // to impose the hard wall constraint
3454  rab = sqrt(rab_SQ);
3455  if ( (rab > (2.0*r_wall)) && dieOnError ) { // unexpected situation
3456  iout << iERROR << "HardWallDrude> "
3457  << "The drude is too far away from atom "
3458  << (atom[ia].id + 1) << " d = " << rab << "!\n" << endi;
3459  return -1; // triggers early exit
3460  }
3461 
3462  v_ab.x /= rab;
3463  v_ab.y /= rab;
3464  v_ab.z /= rab;
3465 
3466  if ( fixedAtomsOn && atom[ia].atomFixed ) { // the heavy atom is fixed
3467  if (atom[ib].atomFixed) { // the drude is fixed too
3468  continue;
3469  }
3470  else { // only the heavy atom is fixed
3471  dot_v_r_2 = atom[ib].velocity.x*v_ab.x
3472  + atom[ib].velocity.y*v_ab.y + atom[ib].velocity.z*v_ab.z;
3473  vb_2 = dot_v_r_2 * v_ab;
3474  vp_2 = atom[ib].velocity - vb_2;
3475 
3476  dr = rab - r_wall;
3477  if(dot_v_r_2 == 0.0) {
3478  delta_T = maxtime;
3479  }
3480  else {
3481  delta_T = dr/fabs(dot_v_r_2); // the time since the collision occurs
3482  if(delta_T > maxtime ) delta_T = maxtime; // make sure it is not crazy
3483  }
3484 
3485  dot_v_r_2 = -dot_v_r_2*sqrt(kbt/atom[ib].mass)/fabs(dot_v_r_2);
3486 
3487  vb_2 = dot_v_r_2 * v_ab;
3488 
3489  new_vel_a = atom[ia].velocity;
3490  new_vel_b = vp_2 + vb_2;
3491 
3492  dr_b = -dr + delta_T*dot_v_r_2; // L = L_0 + dT *v_new, v was flipped
3493 
3494  new_pos_a = atom[ia].position;
3495  new_pos_b = atom[ib].position + dr_b*v_ab; // correct the position
3496  }
3497  }
3498  else {
3499  mass_a = atom[ia].mass;
3500  mass_b = atom[ib].mass;
3501  mass_sum = mass_a+mass_b;
3502 
3503  dot_v_r_1 = atom[ia].velocity.x*v_ab.x
3504  + atom[ia].velocity.y*v_ab.y + atom[ia].velocity.z*v_ab.z;
3505  vb_1 = dot_v_r_1 * v_ab;
3506  vp_1 = atom[ia].velocity - vb_1;
3507 
3508  dot_v_r_2 = atom[ib].velocity.x*v_ab.x
3509  + atom[ib].velocity.y*v_ab.y + atom[ib].velocity.z*v_ab.z;
3510  vb_2 = dot_v_r_2 * v_ab;
3511  vp_2 = atom[ib].velocity - vb_2;
3512 
3513  vb_cm = (mass_a*dot_v_r_1 + mass_b*dot_v_r_2)/mass_sum;
3514 
3515  dot_v_r_1 -= vb_cm;
3516  dot_v_r_2 -= vb_cm;
3517 
3518  dr = rab - r_wall;
3519 
3520  if(dot_v_r_2 == dot_v_r_1) {
3521  delta_T = maxtime;
3522  }
3523  else {
3524  delta_T = dr/fabs(dot_v_r_2 - dot_v_r_1); // the time since the collision occurs
3525  if(delta_T > maxtime ) delta_T = maxtime; // make sure it is not crazy
3526  }
3527 
3528  // the relative velocity between ia and ib. Drawn according to T_Drude
3529  v_Bond = sqrt(kbt/mass_b);
3530 
3531  // reflect the velocity along bond vector and scale down
3532  dot_v_r_1 = -dot_v_r_1*v_Bond*mass_b/(fabs(dot_v_r_1)*mass_sum);
3533  dot_v_r_2 = -dot_v_r_2*v_Bond*mass_a/(fabs(dot_v_r_2)*mass_sum);
3534 
3535  dr_a = dr*mass_b/mass_sum + delta_T*dot_v_r_1;
3536  dr_b = -dr*mass_a/mass_sum + delta_T*dot_v_r_2;
3537 
3538  new_pos_a = atom[ia].position + dr_a*v_ab; // correct the position
3539  new_pos_b = atom[ib].position + dr_b*v_ab;
3540  // atom[ia].position += (dr_a*v_ab); // correct the position
3541  // atom[ib].position += (dr_b*v_ab);
3542 
3543  dot_v_r_1 += vb_cm;
3544  dot_v_r_2 += vb_cm;
3545 
3546  vb_1 = dot_v_r_1 * v_ab;
3547  vb_2 = dot_v_r_2 * v_ab;
3548 
3549  new_vel_a = vp_1 + vb_1;
3550  new_vel_b = vp_2 + vb_2;
3551  }
3552 
3553  int ppoffset, partition;
3554  if ( invdt == 0 ) {
3555  atom[ia].position = new_pos_a;
3556  atom[ib].position = new_pos_b;
3557  }
3558  else if ( virial == 0 ) {
3559  atom[ia].velocity = new_vel_a;
3560  atom[ib].velocity = new_vel_b;
3561  }
3562  else {
3563  for ( j = 0; j < 2; j++ ) {
3564  if (j==0) { // atom ia, heavy atom
3565  Idx = ia;
3566  new_pos = &new_pos_a;
3567  new_vel = &new_vel_a;
3568  }
3569  else if (j==1) { // atom ib, drude
3570  Idx = ib;
3571  new_pos = &new_pos_b;
3572  new_vel = &new_vel_b;
3573  }
3574  Force df = (*new_vel - atom[Idx].velocity) *
3575  ( atom[Idx].mass * invdt );
3576  Tensor vir = outer(df, atom[Idx].position);
3577  wc += vir;
3578  atom[Idx].velocity = *new_vel;
3579  atom[Idx].position = *new_pos;
3580 
3581  if (ppreduction) {
3582  if (!j) {
3583  BigReal z = new_pos->z;
3584  int partition = atom[Idx].partition;
3585  int slab = (int)floor((z-zmin)*idz);
3586  if (slab < 0) slab += nslabs;
3587  else if (slab >= nslabs) slab -= nslabs;
3588  ppoffset = 3*(slab + nslabs*partition);
3589  }
3590  ppreduction->item(ppoffset ) += vir.xx;
3591  ppreduction->item(ppoffset+1) += vir.yy;
3592  ppreduction->item(ppoffset+2) += vir.zz;
3593  }
3594 
3595  }
3596  }
3597  }
3598  }
3599  }
3600 
3601  // if ( (Count>10000) && (Count%10==0) ) {
3602  // v_ab = atom[1].position - atom[0].position;
3603  // rab_SQ = v_ab.x*v_ab.x + v_ab.y*v_ab.y + v_ab.z*v_ab.z;
3604  // iout << "DBG_R: " << Count << " " << sqrt(rab_SQ) << "\n" << endi;
3605  // }
3606 
3607  }
3608 
3609  // end calculation of hard wall boundary between drude and its host atom
3610 
3611  if ( dt && virial ) *virial += wc;
3612 
3613  return 0;
3614 }
static Node * Object()
Definition: Node.h:86
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
#define BOLTZMANN
Definition: common.h:54
Lattice & lattice
Definition: Patch.h:127
static void partition(int *order, const FullAtom *atoms, int begin, int end)
Definition: SortAtoms.C:45
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
BigReal & item(int i)
Definition: ReductionMgr.h:336
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:174
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
BigReal xx
Definition: Tensor.h:17
BigReal zz
Definition: Tensor.h:19
#define simParams
Definition: Output.C:131
Definition: Tensor.h:15
BigReal y
Definition: Vector.h:74
BigReal yy
Definition: Tensor.h:18
#define TIMEFACTOR
Definition: common.h:55
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
Molecule * molecule
Definition: Node.h:179
NAMD_HOST_DEVICE Vector origin() const
Definition: Lattice.h:278
double BigReal
Definition: common.h:123

◆ loweAndersenFinish()

void HomePatch::loweAndersenFinish ( )

Definition at line 4881 of file HomePatch.C.

References DebugM, ResizeArray< Elem >::resize(), and Patch::v.

Referenced by Sequencer::runComputeObjects().

4882 {
4883  DebugM(2, "loweAndersenFinish\n");
4884  v.resize(0);
4885 }
#define DebugM(x, y)
Definition: Debug.h:75
CompAtomList v
Definition: Patch.h:156
void resize(int i)
Definition: ResizeArray.h:84

◆ loweAndersenVelocities()

void HomePatch::loweAndersenVelocities ( )

Definition at line 4866 of file HomePatch.C.

References DebugM, Node::molecule, Patch::numAtoms, Node::Object(), ResizeArray< Elem >::resize(), Node::simParameters, simParams, and Patch::v.

Referenced by positionsReady(), and positionsReady_SOA().

4867 {
4868  DebugM(2, "loweAndersenVelocities\n");
4869  Molecule *mol = Node::Object()->molecule;
4871  v.resize(numAtoms);
4872  for (int i = 0; i < numAtoms; ++i) {
4873  //v[i] = p[i];
4874  // co-opt CompAtom structure to pass velocity and mass information
4875  v[i].position = atom[i].velocity;
4876  v[i].charge = atom[i].mass;
4877  }
4878  DebugM(2, "loweAndersenVelocities\n");
4879 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
#define DebugM(x, y)
Definition: Debug.h:75
CompAtomList v
Definition: Patch.h:156
Molecule stores the structural information for the system.
Definition: Molecule.h:174
void resize(int i)
Definition: ResizeArray.h:84
int numAtoms
Definition: Patch.h:151
#define simParams
Definition: Output.C:131
Molecule * molecule
Definition: Node.h:179

◆ minimize_rattle2()

void HomePatch::minimize_rattle2 ( const BigReal  timestep,
Tensor virial,
bool  forces = false 
)

Definition at line 4382 of file HomePatch.C.

References ResizeArray< Elem >::begin(), endi(), Patch::f, getWaterModelGroupSize(), iout, iWARN(), Node::molecule, NAMD_bug(), NAMD_die(), Results::normal, Patch::numAtoms, Node::Object(), outer(), settle2(), Node::simParameters, simParams, SWM4, TIMEFACTOR, TIP4, Vector::x, Vector::y, and Vector::z.

Referenced by Sequencer::newMinimizeDirection(), and Sequencer::submitMinimizeReductions().

4383 {
4384  Molecule *mol = Node::Object()->molecule;
4386  Force *f1 = f[Results::normal].begin();
4387  const int fixedAtomsOn = simParams->fixedAtomsOn;
4388  const int useSettle = simParams->useSettle;
4389  const BigReal dt = timestep / TIMEFACTOR;
4390  Tensor wc; // constraint virial
4391  BigReal tol = simParams->rigidTol;
4392  int maxiter = simParams->rigidIter;
4393  int dieOnError = simParams->rigidDie;
4394  int i, iter;
4395  BigReal dsqi[10], tmp;
4396  int ial[10], ibl[10];
4397  Vector ref[10]; // reference position
4398  Vector refab[10]; // reference vector
4399  Vector vel[10]; // new velocity
4400  BigReal rmass[10]; // 1 / mass
4401  BigReal redmass[10]; // reduced mass
4402  int fixed[10]; // is atom fixed?
4403 
4404  // Size of a hydrogen group for water
4405  const WaterModel watmodel = simParams->watmodel;
4406  const int wathgsize = getWaterModelGroupSize(watmodel);
4407 
4408  // CkPrintf("In rattle2!\n");
4409  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
4410  // CkPrintf("ig=%d\n",ig);
4411  int hgs = atom[ig].hydrogenGroupSize;
4412  if ( hgs == 1 ) continue; // only one atom in group
4413  // cache data in local arrays and integrate positions normally
4414  int anyfixed = 0;
4415  for ( i = 0; i < hgs; ++i ) {
4416  ref[i] = atom[ig+i].position;
4417  vel[i] = ( forces ? f1[ig+i] : atom[ig+i].velocity );
4418  rmass[i] = 1.0;
4419  fixed[i] = ( fixedAtomsOn && atom[ig+i].atomFixed );
4420  if ( fixed[i] ) { anyfixed = 1; rmass[i] = 0.; }
4421  }
4422  int icnt = 0;
4423  if ( ( tmp = atom[ig].rigidBondLength ) > 0 ) { // for water
4424  if (hgs != wathgsize) {
4425  NAMD_bug("Hydrogen group error caught in rattle2().");
4426  }
4427  // Use SETTLE for water unless some of the water atoms are fixed,
4428  if (useSettle && !anyfixed) {
4429  if (watmodel == WaterModel::SWM4) {
4430  // SWM4 ordering: O D LP H1 H2
4431  // do swap(O,LP) and call settle with subarray O H1 H2
4432  // swap back after we return
4433  Vector lp_ref = ref[2];
4434  // Vector lp_vel = vel[2];
4435  ref[2] = ref[0];
4436  vel[2] = vel[0];
4437  settle2(1.0, 1.0, ref+2, vel+2, dt, virial);
4438  ref[0] = ref[2];
4439  vel[0] = vel[2];
4440  ref[2] = lp_ref;
4441  // vel[2] = vel[0]; // set LP vel to O vel
4442  }
4443  else {
4444  settle2(1.0, 1.0, ref, vel, dt, virial);
4445  if (watmodel == WaterModel::TIP4) {
4446  vel[3] = vel[0];
4447  }
4448  }
4449  for (i=0; i<hgs; i++) {
4450  ( forces ? f1[ig+i] : atom[ig+i].velocity ) = vel[i];
4451  }
4452  continue;
4453  }
4454  if ( !(fixed[1] && fixed[2]) ) {
4455  redmass[icnt] = 1. / (rmass[1] + rmass[2]);
4456  dsqi[icnt] = 1. / (tmp * tmp); ial[icnt] = 1; ibl[icnt] = 2; ++icnt;
4457  }
4458  }
4459  // CkPrintf("Loop 2\n");
4460  for ( i = 1; i < hgs; ++i ) { // normal bonds to mother atom
4461  if ( ( tmp = atom[ig+i].rigidBondLength ) > 0 ) {
4462  if ( !(fixed[0] && fixed[i]) ) {
4463  redmass[icnt] = 1. / (rmass[0] + rmass[i]);
4464  dsqi[icnt] = 1. / (tmp * tmp); ial[icnt] = 0;
4465  ibl[icnt] = i; ++icnt;
4466  }
4467  }
4468  }
4469  if ( icnt == 0 ) continue; // no constraints
4470  // CkPrintf("Loop 3\n");
4471  for ( i = 0; i < icnt; ++i ) {
4472  refab[i] = ref[ial[i]] - ref[ibl[i]];
4473  }
4474  // CkPrintf("Loop 4\n");
4475  int done;
4476  for ( iter = 0; iter < maxiter; ++iter ) {
4477  done = 1;
4478  for ( i = 0; i < icnt; ++i ) {
4479  int a = ial[i]; int b = ibl[i];
4480  Vector vab = vel[a] - vel[b];
4481  Vector &rab = refab[i];
4482  BigReal rabsqi = dsqi[i];
4483  BigReal rvab = rab.x*vab.x + rab.y*vab.y + rab.z*vab.z;
4484  if ( (fabs(rvab) * dt * rabsqi) > tol ) {
4485  Vector dp = rab * (-rvab * redmass[i] * rabsqi);
4486  wc += outer(dp,rab);
4487  vel[a] += rmass[a] * dp;
4488  vel[b] -= rmass[b] * dp;
4489  done = 0;
4490  }
4491  }
4492  if ( done ) break;
4493  //if (done) { if (iter > 0) CkPrintf("iter=%d\n", iter); break; }
4494  }
4495  if ( ! done ) {
4496  if ( dieOnError ) {
4497  NAMD_die("Exceeded maximum number of iterations in rattle2().");
4498  } else {
4499  iout << iWARN <<
4500  "Exceeded maximum number of iterations in rattle2().\n" << endi;
4501  }
4502  }
4503  // store data back to patch
4504  for ( i = 0; i < hgs; ++i ) {
4505  ( forces ? f1[ig+i] : atom[ig+i].velocity ) = vel[i];
4506  }
4507  }
4508  // CkPrintf("Leaving rattle2!\n");
4509  // check that there isn't a constant needed here!
4510  *virial += wc / ( 0.5 * dt );
4511 
4512 }
static Node * Object()
Definition: Node.h:86
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:174
int settle2(BigReal mO, BigReal mH, const Vector *pos, Vector *vel, BigReal dt, Tensor *virial)
Definition: Settle.C:1473
constexpr int getWaterModelGroupSize(const WaterModel &watmodel)
Definition: common.h:228
void NAMD_bug(const char *err_msg)
Definition: common.C:195
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
void NAMD_die(const char *err_msg)
Definition: common.C:147
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
Definition: Tensor.h:15
BigReal y
Definition: Vector.h:74
#define TIMEFACTOR
Definition: common.h:55
ForceList f[Results::maxNumForces]
Definition: Patch.h:214
WaterModel
Definition: common.h:221
Molecule * molecule
Definition: Node.h:179
double BigReal
Definition: common.h:123

◆ mollyAverage()

void HomePatch::mollyAverage ( )

Definition at line 5085 of file HomePatch.C.

References average(), endi(), iout, iWARN(), Node::molecule, NAMD_die(), Patch::numAtoms, Node::Object(), Patch::p, Patch::p_avg, ResizeArray< Elem >::resize(), Node::simParameters, and simParams.

Referenced by positionsReady(), and positionsReady_SOA().

5086 {
5087  Molecule *mol = Node::Object()->molecule;
5089  BigReal tol = simParams->mollyTol;
5090  int maxiter = simParams->mollyIter;
5091  int i, iter;
5092  HGArrayBigReal dsq;
5093  BigReal tmp;
5094  HGArrayInt ial, ibl;
5095  HGArrayVector ref; // reference position
5096  HGArrayVector refab; // reference vector
5097  HGArrayBigReal rmass; // 1 / mass
5098  BigReal *lambda; // Lagrange multipliers
5099  CompAtom *avg; // averaged position
5100  int numLambdas = 0;
5101  HGArrayInt fixed; // is atom fixed?
5102 
5103  // iout<<iINFO << "mollyAverage: "<<std::endl<<endi;
5105  for ( i=0; i<numAtoms; ++i ) p_avg[i] = p[i];
5106 
5107  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
5108  int hgs = atom[ig].hydrogenGroupSize;
5109  if ( hgs == 1 ) continue; // only one atom in group
5110  for ( i = 0; i < hgs; ++i ) {
5111  ref[i] = atom[ig+i].position;
5112  rmass[i] = 1. / atom[ig+i].mass;
5113  fixed[i] = ( simParams->fixedAtomsOn && atom[ig+i].atomFixed );
5114  if ( fixed[i] ) rmass[i] = 0.;
5115  }
5116  avg = &(p_avg[ig]);
5117  int icnt = 0;
5118 
5119  if ( ( tmp = atom[ig].rigidBondLength ) > 0 ) { // for water
5120  if ( hgs != 3 ) {
5121  NAMD_die("Hydrogen group error caught in mollyAverage(). It's a bug!\n");
5122  }
5123  if ( !(fixed[1] && fixed[2]) ) {
5124  dsq[icnt] = tmp * tmp; ial[icnt] = 1; ibl[icnt] = 2; ++icnt;
5125  }
5126  }
5127  for ( i = 1; i < hgs; ++i ) { // normal bonds to mother atom
5128  if ( ( tmp = atom[ig+i].rigidBondLength ) > 0 ) {
5129  if ( !(fixed[0] && fixed[i]) ) {
5130  dsq[icnt] = tmp * tmp; ial[icnt] = 0; ibl[icnt] = i; ++icnt;
5131  }
5132  }
5133  }
5134  if ( icnt == 0 ) continue; // no constraints
5135  numLambdas += icnt;
5136  molly_lambda.resize(numLambdas);
5137  lambda = &(molly_lambda[numLambdas - icnt]);
5138  for ( i = 0; i < icnt; ++i ) {
5139  refab[i] = ref[ial[i]] - ref[ibl[i]];
5140  }
5141  // iout<<iINFO<<"hgs="<<hgs<<" m="<<icnt<<std::endl<<endi;
5142  iter=average(avg,ref,lambda,hgs,icnt,rmass,dsq,ial,ibl,refab,tol,maxiter);
5143  if ( iter == maxiter ) {
5144  iout << iWARN << "Exceeded maximum number of iterations in mollyAverage().\n"<<endi;
5145  }
5146  }
5147 
5148  // for ( i=0; i<numAtoms; ++i ) {
5149  // if ( ( p_avg[i].position - p[i].position ).length2() > 1.0 ) {
5150  // iout << iERROR << "MOLLY moved atom " << (p[i].id + 1) << " from "
5151  // << p[i].position << " to " << p_avg[i].position << "\n" << endi;
5152  // }
5153  // }
5154 
5155 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:174
void resize(int i)
Definition: ResizeArray.h:84
BigReal HGArrayBigReal[MAXHGS]
Definition: HomePatch.C:66
CompAtomList p_avg
Definition: Patch.h:154
CompAtomList p
Definition: Patch.h:153
int numAtoms
Definition: Patch.h:151
void NAMD_die(const char *err_msg)
Definition: common.C:147
int HGArrayInt[MAXHGS]
Definition: HomePatch.C:65
#define simParams
Definition: Output.C:131
zVector HGArrayVector[MAXHGS]
Definition: HomePatch.C:67
Molecule * molecule
Definition: Node.h:179
double BigReal
Definition: common.h:123
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: HomePatch.C:6470

◆ mollyMollify()

void HomePatch::mollyMollify ( Tensor virial)

Definition at line 5159 of file HomePatch.C.

References Patch::f, Node::molecule, mollify(), NAMD_die(), Patch::numAtoms, Node::Object(), outer(), Patch::p_avg, ResizeArray< Elem >::resize(), Node::simParameters, simParams, and Results::slow.

Referenced by Sequencer::runComputeObjects().

5160 {
5161  Molecule *mol = Node::Object()->molecule;
5163  Tensor wc; // constraint virial
5164  int i;
5165  HGArrayInt ial, ibl;
5166  HGArrayVector ref; // reference position
5167  CompAtom *avg; // averaged position
5168  HGArrayVector refab; // reference vector
5169  HGArrayVector force; // new force
5170  HGArrayBigReal rmass; // 1 / mass
5171  BigReal *lambda; // Lagrange multipliers
5172  int numLambdas = 0;
5173  HGArrayInt fixed; // is atom fixed?
5174 
5175  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
5176  int hgs = atom[ig].hydrogenGroupSize;
5177  if (hgs == 1 ) continue; // only one atom in group
5178  for ( i = 0; i < hgs; ++i ) {
5179  ref[i] = atom[ig+i].position;
5180  force[i] = f[Results::slow][ig+i];
5181  rmass[i] = 1. / atom[ig+i].mass;
5182  fixed[i] = ( simParams->fixedAtomsOn && atom[ig+i].atomFixed );
5183  if ( fixed[i] ) rmass[i] = 0.;
5184  }
5185  int icnt = 0;
5186  // c-ji I'm only going to mollify water for now
5187  if ( atom[ig].rigidBondLength > 0 ) { // for water
5188  if ( hgs != 3 ) {
5189  NAMD_die("Hydrogen group error caught in mollyMollify(). It's a bug!\n");
5190  }
5191  if ( !(fixed[1] && fixed[2]) ) {
5192  ial[icnt] = 1; ibl[icnt] = 2; ++icnt;
5193  }
5194  }
5195  for ( i = 1; i < hgs; ++i ) { // normal bonds to mother atom
5196  if ( atom[ig+i].rigidBondLength > 0 ) {
5197  if ( !(fixed[0] && fixed[i]) ) {
5198  ial[icnt] = 0; ibl[icnt] = i; ++icnt;
5199  }
5200  }
5201  }
5202 
5203  if ( icnt == 0 ) continue; // no constraints
5204  lambda = &(molly_lambda[numLambdas]);
5205  numLambdas += icnt;
5206  for ( i = 0; i < icnt; ++i ) {
5207  refab[i] = ref[ial[i]] - ref[ibl[i]];
5208  }
5209  avg = &(p_avg[ig]);
5210  mollify(avg,ref,lambda,force,hgs,icnt,rmass,ial,ibl,refab);
5211  // store data back to patch
5212  for ( i = 0; i < hgs; ++i ) {
5213  wc += outer(force[i]-f[Results::slow][ig+i],ref[i]);
5214  f[Results::slow][ig+i] = force[i];
5215  }
5216  }
5217  // check that there isn't a constant needed here!
5218  *virial += wc;
5219  p_avg.resize(0);
5220 }
static Node * Object()
Definition: Node.h:86
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
SimParameters * simParameters
Definition: Node.h:181
Molecule stores the structural information for the system.
Definition: Molecule.h:174
void resize(int i)
Definition: ResizeArray.h:84
BigReal HGArrayBigReal[MAXHGS]
Definition: HomePatch.C:66
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: HomePatch.C:6652
CompAtomList p_avg
Definition: Patch.h:154
int numAtoms
Definition: Patch.h:151
void NAMD_die(const char *err_msg)
Definition: common.C:147
int HGArrayInt[MAXHGS]
Definition: HomePatch.C:65
#define simParams
Definition: Output.C:131
Definition: Tensor.h:15
zVector HGArrayVector[MAXHGS]
Definition: HomePatch.C:67
ForceList f[Results::maxNumForces]
Definition: Patch.h:214
Molecule * molecule
Definition: Node.h:179
double BigReal
Definition: common.h:123

◆ positionsReady()

void HomePatch::positionsReady ( int  doMigration = 0)

Definition at line 1895 of file HomePatch.C.

References ProxyDataMsg::avgPlLen, ProxyDataMsg::avgPositionList, Patch::avgPositionPtrBegin, Patch::avgPositionPtrEnd, ResizeArray< Elem >::begin(), CompAtom::charge, COULOMB, ProxyDataMsg::cudaAtomList, Patch::cudaAtomPtr, DebugM, ComputeNonbondedUtil::dielectric_1, doAtomMigration(), Flags::doGBIS, doGroupSizeCheck(), Flags::doLCPO, Flags::doLoweAndersen, doMarginCheck(), Flags::doMolly, doPairlistCheck(), ResizeArray< Elem >::end(), ProxyDataMsg::flags, Patch::flags, Patch::getPatchID(), gridForceIdxChecked, Patch::intRad, ProxyDataMsg::intRadList, Patch::lattice, Patch::lcpoType, ProxyDataMsg::lcpoTypeList, loweAndersenVelocities(), mollyAverage(), NAMD_EVENT_START, NAMD_EVENT_START_EX, NAMD_EVENT_STOP, NamdProfileEventStr, Patch::numAtoms, PatchMap::numNodesWithPatches(), PatchMap::numPatchesOnNode(), PatchMap::Object(), Sync::Object(), Node::Object(), ProxyMgr::Object(), Patch::p, Patch::p_avg, ProxyDataMsg::patch, PATCH_PRIORITY, Patch::patchID, Sync::PatchReady(), Patch::pExt, ProxyDataMsg::plExtLen, ProxyDataMsg::plLen, CompAtom::position, ProxyDataMsg::positionExtList, ProxyDataMsg::positionList, Patch::positionsReady(), PRIORITY_SIZE, PROXY_DATA_PRIORITY, proxySendSpanning, proxySpanDim, qmSwapAtoms(), rattleListValid, ResizeArray< Elem >::resize(), ComputeNonbondedUtil::scaling, ProxyMgr::sendProxyAll(), ProxyMgr::sendProxyData(), Flags::sequence, SET_PRIORITY, setGBISIntrinsicRadii(), setLcpoType(), Node::simParameters, simParams, ResizeArray< Elem >::size(), sortAtomsForCUDA(), CompAtomExt::sortOrder, Lattice::unscale(), Patch::v, ProxyDataMsg::velocityList, Patch::velocityPtrBegin, Patch::velocityPtrEnd, ProxyDataMsg::vlLen, Vector::x, Vector::y, and Vector::z.

Referenced by Sequencer::runComputeObjects().

1896 {
1898 
1899  flags.sequence++;
1900  if (doMigration)
1901  gridForceIdxChecked=false;
1902  if (!patchMapRead) { readPatchMap(); }
1903 
1904  if (numNeighbors && ! simParams->staticAtomAssignment) {
1905  if (doMigration) {
1906  rattleListValid = false;
1907  doAtomMigration();
1908  } else {
1909  doMarginCheck();
1910  }
1911  }
1912 
1913 #if defined(NAMD_NVTX_ENABLED) || defined(NAMD_CMK_TRACE_ENABLED) || defined(NAMD_ROCTX_ENABLED)
1914  char prbuf[32];
1915  sprintf(prbuf, "%s: %d", NamdProfileEventStr[NamdProfileEvent::POSITIONS_READY], this->getPatchID());
1916  NAMD_EVENT_START_EX(1, NamdProfileEvent::POSITIONS_READY, prbuf);
1917 #endif
1918 
1919  if (doMigration && simParams->qmLSSOn)
1920  qmSwapAtoms();
1921 
1922 #if defined(NAMD_CUDA) || defined(NAMD_MIC) || defined(NAMD_AVXTILES) || defined(NAMD_HIP)
1923  #ifdef NAMD_AVXTILES
1924  if ( simParams->useAVXTiles ) {
1925  #endif
1926  if ( doMigration ) {
1927  int n = numAtoms;
1928  FullAtom *a_i = atom.begin();
1929  #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_AVXTILES) || \
1930  (defined(NAMD_MIC) && MIC_SORT_ATOMS != 0)
1931  int *ao = new int[n];
1932  int nfree;
1933  if ( simParams->fixedAtomsOn && ! simParams->fixedAtomsForces ) {
1934  int k = 0;
1935  int k2 = n;
1936  for ( int j=0; j<n; ++j ) {
1937  // put fixed atoms at end
1938  if ( a_i[j].atomFixed ) ao[--k2] = j;
1939  else ao[k++] = j;
1940  }
1941  nfree = k;
1942  } else {
1943  nfree = n;
1944  for ( int j=0; j<n; ++j ) {
1945  ao[j] = j;
1946  }
1947  }
1948  sortAtomsForCUDA(ao,a_i,nfree,n);
1949  for ( int i=0; i<n; ++i ) {
1950  a_i[i].sortOrder = ao[i];
1951  }
1952  delete [] ao;
1953  #else
1954  for (int i = 0; i < n; ++i) {
1955  a_i[i].sortOrder = i;
1956  }
1957  #endif
1958  }
1959 
1960  {
1961  const double charge_scaling = sqrt(COULOMB * ComputeNonbondedUtil::scaling * ComputeNonbondedUtil::dielectric_1);
1962  const Vector ucenter = lattice.unscale(center);
1963  const BigReal ucenter_x = ucenter.x;
1964  const BigReal ucenter_y = ucenter.y;
1965  const BigReal ucenter_z = ucenter.z;
1966  const int n = numAtoms;
1967  #if defined(NAMD_MIC) && (MIC_HANDCODE_FORCE_SOA_VS_AOS == 0)
1968  int n_16 = n;
1969  n_16 = (n + 15) & (~15);
1970  cudaAtomList.resize(n_16);
1971  CudaAtom *ac = cudaAtomPtr = cudaAtomList.begin();
1972  mic_position_t *atom_x = ((mic_position_t*)ac) + (0 * n_16);
1973  mic_position_t *atom_y = ((mic_position_t*)ac) + (1 * n_16);
1974  mic_position_t *atom_z = ((mic_position_t*)ac) + (2 * n_16);
1975  mic_position_t *atom_q = ((mic_position_t*)ac) + (3 * n_16);
1976  #elif defined(NAMD_AVXTILES)
1977  int n_avx = (n + 15) & (~15);
1978  cudaAtomList.resize(n_avx);
1979  CudaAtom *ac = cudaAtomPtr = cudaAtomList.begin();
1980  tiles.realloc(n, ac);
1981  #else
1982  #if 1
1983  cudaAtomList.resize(n);
1984  CudaAtom *ac = cudaAtomPtr = cudaAtomList.begin();
1985  #else
1986  reallocate_host<CudaAtom>(&cudaAtomList, &sizeCudaAtomList, n);
1987  CudaAtom *ac = cudaAtomPtr = &cudaAtomList[0];
1988  #endif
1989  #endif
1990  const FullAtom *a = atom.begin();
1991  for ( int k=0; k<n; ++k ) {
1992  #if defined(NAMD_MIC) && (MIC_HANDCODE_FORCE_SOA_VS_AOS == 0)
1993  int j = a[k].sortOrder;
1994  atom_x[k] = a[j].position.x - ucenter_x;
1995  atom_y[k] = a[j].position.y - ucenter_y;
1996  atom_z[k] = a[j].position.z - ucenter_z;
1997  atom_q[k] = charge_scaling * a[j].charge;
1998  #else
1999  int j = a[k].sortOrder;
2000  ac[k].x = a[j].position.x - ucenter_x;
2001  ac[k].y = a[j].position.y - ucenter_y;
2002  ac[k].z = a[j].position.z - ucenter_z;
2003  ac[k].q = charge_scaling * a[j].charge;
2004  #endif
2005  }
2006  #ifdef NAMD_AVXTILES
2007  {
2008  if (n > 0) {
2009  int j = a[n-1].sortOrder;
2010  for ( int k=n; k<n_avx; ++k ) {
2011  ac[k].x = a[j].position.x - ucenter_x;
2012  ac[k].y = a[j].position.y - ucenter_y;
2013  ac[k].z = a[j].position.z - ucenter_z;
2014  }
2015  }
2016  }
2017  #endif
2018  }
2019  #ifdef NAMD_AVXTILES
2020  // If "Tiles" mode disabled, no use of the CUDA data structures
2021  } else doMigration = doMigration && numNeighbors;
2022  #endif
2023 #else
2024  doMigration = doMigration && numNeighbors;
2025 #endif
2026  doMigration = doMigration || ! patchMapRead;
2027 
2028  doMigration = doMigration || doAtomUpdate;
2029  doAtomUpdate = false;
2030 
2031  // Workaround for oversize groups:
2032  // reset nonbondedGroupSize (ngs) before force calculation,
2033  // making sure that subset of hydrogen group starting with
2034  // parent atom are all within 0.5 * hgroupCutoff.
2035  // XXX hydrogentGroupSize remains constant but is checked for nonzero
2036  // XXX should be skipped for CUDA, ngs not used by CUDA kernels
2037  // XXX should this also be skipped for KNL kernels?
2038  // ngs used by ComputeNonbondedBase.h - CPU nonbonded kernels
2039  // ngs used by ComputeGBIS.C - CPU GB nonbonded kernels
2040 #if ! (defined(NAMD_CUDA) || defined(NAMD_HIP))
2041 #if defined(NAMD_AVXTILES)
2042  if (!simParams->useAVXTiles)
2043 #endif
2044  doGroupSizeCheck();
2045 #endif
2046 
2047  // Copy information needed by computes and proxys to Patch::p.
2048  // Resize only if atoms were migrated
2049  if (doMigration) {
2050  p.resize(numAtoms);
2051  pExt.resize(numAtoms);
2052  }
2053  CompAtom *p_i = p.begin();
2054  CompAtomExt *pExt_i = pExt.begin();
2055  FullAtom *a_i = atom.begin();
2056  int i; int n = numAtoms;
2057  for ( i=0; i<n; ++i ) {
2058  p_i[i] = a_i[i];
2059  pExt_i[i] = a_i[i];
2060  }
2061 
2062  // Measure atom movement to test pairlist validity
2063  doPairlistCheck();
2064 
2065  if (flags.doMolly) mollyAverage();
2066  // BEGIN LA
2068  // END LA
2069 
2070  if (flags.doGBIS) {
2071  //reset for next time step
2072  numGBISP1Arrived = 0;
2073  phase1BoxClosedCalled = false;
2074  numGBISP2Arrived = 0;
2075  phase2BoxClosedCalled = false;
2076  numGBISP3Arrived = 0;
2077  phase3BoxClosedCalled = false;
2078  if (doMigration || isNewProxyAdded)
2080  }
2081 
2082  if (flags.doLCPO) {
2083  if (doMigration || isNewProxyAdded) {
2084  setLcpoType();
2085  }
2086  }
2087 
2088  // Must Add Proxy Changes when migration completed!
2090  int *pids = NULL;
2091  int pidsPreAllocated = 1;
2092  int npid;
2093  if (proxySendSpanning == 0) {
2094  npid = proxy.size();
2095  pids = new int[npid];
2096  pidsPreAllocated = 0;
2097  int *pidi = pids;
2098  int *pide = pids + proxy.size();
2099  int patchNodesLast =
2100  ( PatchMap::Object()->numNodesWithPatches() < ( 0.7 * CkNumPes() ) );
2101  for ( pli = proxy.begin(); pli != proxy.end(); ++pli )
2102  {
2103  if ( patchNodesLast && PatchMap::Object()->numPatchesOnNode(*pli) ) {
2104  *(--pide) = *pli;
2105  } else {
2106  *(pidi++) = *pli;
2107  }
2108  }
2109  }
2110  else {
2111 #ifdef NODEAWARE_PROXY_SPANNINGTREE
2112  #ifdef USE_NODEPATCHMGR
2113  npid = numNodeChild;
2114  pids = nodeChildren;
2115  #else
2116  npid = nChild;
2117  pids = child;
2118  #endif
2119 #else
2120  npid = nChild;
2121  pidsPreAllocated = 0;
2122  pids = new int[proxySpanDim];
2123  for (int i=0; i<nChild; i++) pids[i] = child[i];
2124 #endif
2125  }
2126  if (npid) { //have proxies
2127  int seq = flags.sequence;
2128  int priority = PROXY_DATA_PRIORITY + PATCH_PRIORITY(patchID);
2129  //begin to prepare proxy msg and send it
2130  int pdMsgPLLen = p.size();
2131  int pdMsgAvgPLLen = 0;
2132  if(flags.doMolly) {
2133  pdMsgAvgPLLen = p_avg.size();
2134  }
2135  // BEGIN LA
2136  int pdMsgVLLen = 0;
2137  if (flags.doLoweAndersen) {
2138  pdMsgVLLen = v.size();
2139  }
2140  // END LA
2141 
2142  int intRadLen = 0;
2143  if (flags.doGBIS && (doMigration || isNewProxyAdded)) {
2144  intRadLen = numAtoms * 2;
2145  }
2146 
2147  //LCPO
2148  int lcpoTypeLen = 0;
2149  if (flags.doLCPO && (doMigration || isNewProxyAdded)) {
2150  lcpoTypeLen = numAtoms;
2151  }
2152 
2153  int pdMsgPLExtLen = 0;
2154  if(doMigration || isNewProxyAdded) {
2155  pdMsgPLExtLen = pExt.size();
2156  }
2157 
2158  int cudaAtomLen = 0;
2159 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
2160  cudaAtomLen = numAtoms;
2161 #elif defined(NAMD_AVXTILES)
2162  if (simParams->useAVXTiles)
2163  cudaAtomLen = (numAtoms + 15) & (~15);
2164 #elif defined(NAMD_MIC)
2165  #if MIC_HANDCODE_FORCE_SOA_VS_AOS != 0
2166  cudaAtomLen = numAtoms;
2167  #else
2168  cudaAtomLen = (numAtoms + 15) & (~15);
2169  #endif
2170 #endif
2171 
2172  ProxyDataMsg *nmsg = new (pdMsgPLLen, pdMsgAvgPLLen, pdMsgVLLen, intRadLen,
2173  lcpoTypeLen, pdMsgPLExtLen, cudaAtomLen, PRIORITY_SIZE) ProxyDataMsg; // BEGIN LA, END LA
2174 
2175  SET_PRIORITY(nmsg,seq,priority);
2176  nmsg->patch = patchID;
2177  nmsg->flags = flags;
2178  nmsg->plLen = pdMsgPLLen;
2179  //copying data to the newly created msg
2180  NAMD_EVENT_START(1, NamdProfileEvent::MEMCPY);
2181  memcpy(nmsg->positionList, p.begin(), sizeof(CompAtom)*pdMsgPLLen);
2182  NAMD_EVENT_STOP(1, NamdProfileEvent::MEMCPY);
2183  nmsg->avgPlLen = pdMsgAvgPLLen;
2184  if(flags.doMolly) {
2185  memcpy(nmsg->avgPositionList, p_avg.begin(), sizeof(CompAtom)*pdMsgAvgPLLen);
2186  }
2187  // BEGIN LA
2188  nmsg->vlLen = pdMsgVLLen;
2189  if (flags.doLoweAndersen) {
2190  memcpy(nmsg->velocityList, v.begin(), sizeof(CompAtom)*pdMsgVLLen);
2191  }
2192  // END LA
2193 
2194  if (flags.doGBIS && (doMigration || isNewProxyAdded)) {
2195  for (int i = 0; i < numAtoms * 2; i++) {
2196  nmsg->intRadList[i] = intRad[i];
2197  }
2198  }
2199 
2200  if (flags.doLCPO && (doMigration || isNewProxyAdded)) {
2201  for (int i = 0; i < numAtoms; i++) {
2202  nmsg->lcpoTypeList[i] = lcpoType[i];
2203  }
2204  }
2205 
2206  nmsg->plExtLen = pdMsgPLExtLen;
2207  if(doMigration || isNewProxyAdded){
2208  memcpy(nmsg->positionExtList, pExt.begin(), sizeof(CompAtomExt)*pdMsgPLExtLen);
2209  }
2210 
2211 // DMK
2212 #if defined(NAMD_CUDA) || defined(NAMD_MIC) || defined(NAMD_AVXTILES) || defined(NAMD_HIP)
2213  #ifdef NAMD_AVXTILES
2214  if (simParams->useAVXTiles)
2215  #endif
2216  {
2217  NAMD_EVENT_START(1, NamdProfileEvent::MEMCPY);
2218  memcpy(nmsg->cudaAtomList, cudaAtomPtr, sizeof(CudaAtom)*cudaAtomLen);
2219  NAMD_EVENT_STOP(1, NamdProfileEvent::MEMCPY);
2220  }
2221 #endif
2222 
2223 #if NAMD_SeparateWaters != 0
2224  //DMK - Atom Separation (water vs. non-water)
2225  nmsg->numWaterAtoms = numWaterAtoms;
2226 #endif
2227 
2228 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR) && (CMK_SMP) && defined(NAMDSRC_IMMQD_HACK)
2229  nmsg->isFromImmMsgCall = 0;
2230 #endif
2231 
2232  #if defined(PROCTRACE_DEBUG) && defined(NAST_DEBUG)
2233  DebugFileTrace *dft = DebugFileTrace::Object();
2234  dft->openTrace();
2235  dft->writeTrace("HP::posReady: for HomePatch[%d], sending proxy msg to: ", patchID);
2236  for(int i=0; i<npid; i++) {
2237  dft->writeTrace("%d ", pids[i]);
2238  }
2239  dft->writeTrace("\n");
2240  dft->closeTrace();
2241  #endif
2242 
2243 #if CMK_PERSISTENT_COMM && USE_PERSISTENT_TREE
2244  if (isProxyChanged || localphs == NULL)
2245  {
2246 //CmiPrintf("[%d] Build persistent: isProxyChanged: %d %p\n", CkMyPe(), isProxyChanged, localphs);
2247  //CmiAssert(isProxyChanged);
2248  if (nphs) {
2249  for (int i=0; i<nphs; i++) {
2250  CmiDestoryPersistent(localphs[i]);
2251  }
2252  delete [] localphs;
2253  }
2254  localphs = new PersistentHandle[npid];
2255  int persist_size = sizeof(envelope) + sizeof(ProxyDataMsg) + sizeof(CompAtom)*(pdMsgPLLen+pdMsgAvgPLLen+pdMsgVLLen) + intRadLen*sizeof(Real) + lcpoTypeLen*sizeof(int) + sizeof(CompAtomExt)*pdMsgPLExtLen + sizeof(CudaAtom)*cudaAtomLen + PRIORITY_SIZE/8 + 2048;
2256  for (int i=0; i<npid; i++) {
2257 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR)
2258  if (proxySendSpanning)
2259  localphs[i] = CmiCreateNodePersistent(pids[i], persist_size, sizeof(envelope)+sizeof(ProxyDataMsg));
2260  else
2261 #endif
2262  localphs[i] = CmiCreatePersistent(pids[i], persist_size, sizeof(envelope)+sizeof(ProxyDataMsg));
2263  }
2264  nphs = npid;
2265  }
2266  CmiAssert(nphs == npid && localphs != NULL);
2267  CmiUsePersistentHandle(localphs, nphs);
2268 #endif
2269  if(doMigration || isNewProxyAdded) {
2270  ProxyMgr::Object()->sendProxyAll(nmsg,npid,pids);
2271  }else{
2272  ProxyMgr::Object()->sendProxyData(nmsg,npid,pids);
2273  }
2274 #if CMK_PERSISTENT_COMM && USE_PERSISTENT_TREE
2275  CmiUsePersistentHandle(NULL, 0);
2276 #endif
2277  isNewProxyAdded = 0;
2278  }
2279  isProxyChanged = 0;
2280  if(!pidsPreAllocated) delete [] pids;
2281  DebugM(4, "patchID("<<patchID<<") doing positions Ready\n");
2282 
2283 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
2284  positionPtrBegin = p.begin();
2285  positionPtrEnd = p.end();
2286 #endif
2287 
2288  if(flags.doMolly) {
2291  }
2292  // BEGIN LA
2293  if (flags.doLoweAndersen) {
2294  velocityPtrBegin = v.begin();
2295  velocityPtrEnd = v.end();
2296  }
2297  // END LA
2298 
2299  Patch::positionsReady(doMigration);
2300 
2301  patchMapRead = 1;
2302 
2303  // gzheng
2304  Sync::Object()->PatchReady();
2305 
2306  NAMD_EVENT_STOP(1, NamdProfileEvent::POSITIONS_READY);
2307 
2308 }
static Node * Object()
Definition: Node.h:86
#define NAMD_EVENT_STOP(eon, id)
int * lcpoTypeList
Definition: ProxyMgr.h:112
int numNodesWithPatches(void)
Definition: PatchMap.h:61
int size(void) const
Definition: ResizeArray.h:131
RealList intRad
Definition: Patch.h:162
static ProxyMgr * Object()
Definition: ProxyMgr.h:394
Lattice & lattice
Definition: Patch.h:127
static PatchMap * Object()
Definition: PatchMap.h:27
CompAtom * velocityPtrEnd
Definition: Patch.h:209
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
NAMD_HOST_DEVICE Position unscale(ScaledPosition s) const
Definition: Lattice.h:77
float Real
Definition: common.h:118
#define COULOMB
Definition: common.h:53
#define DebugM(x, y)
Definition: Debug.h:75
BigReal z
Definition: Vector.h:74
CompAtom * avgPositionPtrEnd
Definition: Patch.h:205
char const *const NamdProfileEventStr[]
Position position
Definition: NamdTypes.h:78
#define PROXY_DATA_PRIORITY
Definition: Priorities.h:40
CompAtomList v
Definition: Patch.h:156
void doGroupSizeCheck()
Definition: HomePatch.C:5590
CompAtom * avgPositionList
Definition: ProxyMgr.h:104
void loweAndersenVelocities()
Definition: HomePatch.C:4866
int doLoweAndersen
Definition: PatchTypes.h:28
CompAtom * velocityList
Definition: ProxyMgr.h:107
void sortAtomsForCUDA(int *order, const FullAtom *atoms, int nfree, int n)
Definition: SortAtoms.C:123
CudaAtom * cudaAtomPtr
Definition: Patch.h:212
bool rattleListValid
Definition: HomePatch.h:453
bool gridForceIdxChecked
Definition: HomePatch.h:402
Flags flags
Definition: Patch.h:128
void resize(int i)
Definition: ResizeArray.h:84
Charge charge
Definition: NamdTypes.h:79
#define PRIORITY_SIZE
Definition: Priorities.h:13
void qmSwapAtoms()
Definition: HomePatch.C:907
#define NAMD_EVENT_START(eon, id)
IntList lcpoType
Definition: Patch.h:171
CudaAtom * cudaAtomList
Definition: ProxyMgr.h:123
CompAtomList p_avg
Definition: Patch.h:154
int plExtLen
Definition: ProxyMgr.h:121
CompAtomList p
Definition: Patch.h:153
static Sync * Object()
Definition: Sync.h:52
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
PatchID getPatchID() const
Definition: Patch.h:114
int sequence
Definition: PatchTypes.h:18
void setLcpoType()
Definition: HomePatch.C:4889
CompAtom * avgPositionPtrBegin
Definition: Patch.h:204
void doPairlistCheck()
Definition: HomePatch.C:5438
void doAtomMigration()
Definition: HomePatch.C:5798
void PatchReady(void)
Definition: Sync.C:150
void setGBISIntrinsicRadii()
Definition: HomePatch.C:4900
PatchID patch
Definition: ProxyMgr.h:97
Flags flags
Definition: ProxyMgr.h:98
void sendProxyData(ProxyDataMsg *, int, int *)
Definition: ProxyMgr.C:1562
Real * intRadList
Definition: ProxyMgr.h:110
CompAtom * positionList
Definition: ProxyMgr.h:102
#define simParams
Definition: Output.C:131
int32 sortOrder
Definition: NamdTypes.h:153
#define NAMD_EVENT_START_EX(eon, id, str)
iterator begin(void)
Definition: ResizeArray.h:36
void sendProxyAll(ProxyDataMsg *, int, int *)
Definition: ProxyMgr.C:1676
const PatchID patchID
Definition: Patch.h:150
void mollyAverage()
Definition: HomePatch.C:5085
iterator end(void)
Definition: ResizeArray.h:37
BigReal y
Definition: Vector.h:74
int doLCPO
Definition: PatchTypes.h:31
CompAtomExt * positionExtList
Definition: ProxyMgr.h:122
int numPatchesOnNode(int node)
Definition: PatchMap.h:60
int doGBIS
Definition: PatchTypes.h:30
#define SET_PRIORITY(MSG, SEQ, PRIO)
Definition: Priorities.h:18
int avgPlLen
Definition: ProxyMgr.h:103
int proxySpanDim
Definition: ProxyMgr.C:47
CompAtomExtList pExt
Definition: Patch.h:181
void positionsReady(int n=0, int startup=1)
Definition: Patch.C:403
void doMarginCheck()
Definition: HomePatch.C:5721
int doMolly
Definition: PatchTypes.h:25
double BigReal
Definition: common.h:123
#define PATCH_PRIORITY(PID)
Definition: Priorities.h:25
CompAtom * velocityPtrBegin
Definition: Patch.h:208
int proxySendSpanning
Definition: ProxyMgr.C:44

◆ positionsReady_GPU()

void HomePatch::positionsReady_GPU ( int  doMigration = 0,
int  startup = 0 
)

◆ positionsReady_SOA()

void HomePatch::positionsReady_SOA ( int  doMigration = 0)

Definition at line 971 of file HomePatch.C.

References ASSERT, PatchDataSOA::atomFixed, ProxyDataMsg::avgPlLen, ProxyDataMsg::avgPositionList, Patch::avgPositionPtrBegin, Patch::avgPositionPtrEnd, ResizeArray< Elem >::begin(), PatchDataSOA::charge, COULOMB, ProxyDataMsg::cudaAtomList, Patch::cudaAtomPtr, DebugM, ComputeNonbondedUtil::dielectric_1, doAtomMigration(), Flags::doGBIS, doGroupSizeCheck_SOA(), Flags::doLCPO, Flags::doLoweAndersen, doMarginCheck_SOA(), Flags::doMolly, doPairlistCheck(), ResizeArray< Elem >::end(), PatchDataSOA::exclId, ProxyDataMsg::flags, Patch::flags, Patch::getPatchID(), PatchDataSOA::groupFixed, PatchDataSOA::hydrogenGroupSize, CompAtomExtCopy::id, PatchDataSOA::id, LocalID::index, Patch::intRad, ProxyDataMsg::intRadList, PatchDataSOA::isWater, Patch::lattice, Patch::lcpoType, ProxyDataMsg::lcpoTypeList, AtomMap::localID(), loweAndersenVelocities(), mollyAverage(), NAMD_ATOM_FIXED_MASK, NAMD_EVENT_START, NAMD_EVENT_START_EX, NAMD_EVENT_STOP, NAMD_GROUP_FIXED_MASK, NamdProfileEventStr, PatchDataSOA::nonbondedGroupSize, Patch::numAtoms, PatchMap::numNodesWithPatches(), PatchMap::numPatchesOnNode(), PatchMap::Object(), AtomMap::Object(), Sync::Object(), Node::Object(), ProxyMgr::Object(), Patch::p, Patch::p_avg, partition(), PatchDataSOA::partition, ProxyDataMsg::patch, PATCH_PRIORITY, Patch::patchID, Sync::PatchReady(), Patch::pExt, LocalID::pid, ProxyDataMsg::plExtLen, ProxyDataMsg::plLen, PatchDataSOA::pos_x, PatchDataSOA::pos_y, PatchDataSOA::pos_z, ProxyDataMsg::positionExtList, ProxyDataMsg::positionList, Patch::positionsReady(), PRIORITY_SIZE, PROXY_DATA_PRIORITY, proxySendSpanning, proxySpanDim, CudaAtom::q, qmSwapAtoms(), rattleListValid, rattleListValid_SOA, ResizeArray< Elem >::resize(), ComputeNonbondedUtil::scaling, ProxyMgr::sendProxyAll(), ProxyMgr::sendProxyData(), Flags::sequence, SET_PRIORITY, setGBISIntrinsicRadii(), setLcpoType(), PatchDataSOA::sigId, Node::simParameters, simParams, ResizeArray< Elem >::size(), sortAtomsForCUDA_SOA(), CompAtomExtCopy::sortOrder, PatchDataSOA::sortOrder, Lattice::unscale(), PatchDataSOA::unsortOrder, Patch::v, PatchDataSOA::vdwType, ProxyDataMsg::velocityList, Patch::velocityPtrBegin, Patch::velocityPtrEnd, ProxyDataMsg::vlLen, CudaAtom::x, Vector::x, CudaAtom::y, Vector::y, CudaAtom::z, and Vector::z.

Referenced by Sequencer::runComputeObjects_SOA().

972 {
974  // char prbuf[32];
975  // sprintf(prbuf, "%s: %d", NamdProfileEventStr[NamdProfileEvent::POSITIONS_READY_SOA], this->getPatchID());
976  // NAMD_EVENT_START_EX(1, NamdProfileEvent::POSITIONS_READY_SOA, prbuf);
977  if(!simParams->CUDASOAintegrate) flags.sequence++;
978  // flags.sequence++;
979  if (!patchMapRead) { readPatchMap(); }
980  if (numNeighbors && ! simParams->staticAtomAssignment) {
981  if (doMigration) {
982  // copy SOA updates to AOS
983  // XXX TODO:
984  copy_updates_to_AOS();
985  // make sure to invalidate RATTLE lists when atoms move
986  rattleListValid_SOA = false;
987  rattleListValid = false;
988  // this has a suspend
989  doAtomMigration();
990  } else {
991  // XXX TODO: Get rid of this marginCheck for every tstep
992  // move this to the GPU afterwards
993  if(!simParams->CUDASOAintegrate) doMarginCheck_SOA();
994  }
995  }
996 
997 #if defined(NAMD_NVTX_ENABLED) || defined(NAMD_CMK_TRACE_ENABLED) || defined(NAMD_ROCTX_ENABLED)
998  char prbuf[32];
999  sprintf(prbuf, "%s: %d", NamdProfileEventStr[NamdProfileEvent::POSITIONS_READY], this->getPatchID());
1000  NAMD_EVENT_START_EX(1, NamdProfileEvent::POSITIONS_READY, prbuf);
1001 #endif
1002 
1003 #if 0
1004  if (doMigration && simParams->qmLSSOn)
1005  qmSwapAtoms();
1006 #endif
1007 
1008 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
1009  if ( doMigration ) {
1010  // XXX Since we just migrated FullAtom array is up-to-date
1011  int n = numAtoms;
1012  int * __restrict ao_SOA = patchDataSOA.sortOrder;
1013  int * __restrict unsort_SOA = patchDataSOA.unsortOrder;
1014  #if defined(NAMD_CUDA) || defined(NAMD_HIP) || (defined(NAMD_MIC) && MIC_SORT_ATOMS != 0)
1015  //#if 0
1016  int nfree_SOA;
1017  if ( simParams->fixedAtomsOn && ! simParams->fixedAtomsForces ) {
1018  int k = 0;
1019  int k2 = n;
1020  int * __restrict atomFixed = patchDataSOA.atomFixed;
1021  for ( int j=0; j<n; ++j ) {
1022  // put fixed atoms at end
1023  if ( atomFixed[j] ) ao_SOA[--k2] = j;
1024  else ao_SOA[k++] = j;
1025  }
1026  nfree_SOA = k;
1027  } else {
1028  nfree_SOA = n;
1029  for ( int j=0; j<n; ++j ) {
1030  ao_SOA[j] = j;
1031  }
1032  }
1033 #if 1
1034  sortAtomsForCUDA_SOA(ao_SOA, unsort_SOA,
1035  patchDataSOA.pos_x, patchDataSOA.pos_y, patchDataSOA.pos_z,
1036  nfree_SOA, n);
1037 #endif
1038 #if 0
1039  for (int i = 0; i < n; ++i) {
1040  ao_SOA[i] = i;
1041  printf("ao_SOA[%d] = %d\n", i, ao_SOA[i]);
1042  }
1043 #endif
1044 
1045 #else
1046  for (int i = 0; i < n; ++i) {
1047  ao_SOA[i] = i;
1048  }
1049 #endif
1050  }
1051  {
1052  const double charge_scaling = sqrt(COULOMB * ComputeNonbondedUtil::scaling * ComputeNonbondedUtil::dielectric_1);
1053  const Vector ucenter = lattice.unscale(center);
1054  const BigReal ucenter_x = ucenter.x;
1055  const BigReal ucenter_y = ucenter.y;
1056  const BigReal ucenter_z = ucenter.z;
1057  const int n = numAtoms;
1058  #if defined(NAMD_MIC) && (MIC_HANDCODE_FORCE_SOA_VS_AOS == 0)
1059  int n_16 = n;
1060  n_16 = (n + 15) & (~15);
1061  cudaAtomList.resize(n_16);
1062  CudaAtom *ac = cudaAtomPtr = cudaAtomList.begin();
1063  mic_position_t *atom_x = ((mic_position_t*)ac) + (0 * n_16);
1064  mic_position_t *atom_y = ((mic_position_t*)ac) + (1 * n_16);
1065  mic_position_t *atom_z = ((mic_position_t*)ac) + (2 * n_16);
1066  mic_position_t *atom_q = ((mic_position_t*)ac) + (3 * n_16);
1067  #elif defined(NAMD_AVXTILES)
1068  int n_avx = (n + 15) & (~15);
1069  cudaAtomList.resize(n_avx);
1070  CudaAtom *ac = cudaAtomPtr = cudaAtomList.begin();
1071  tiles.realloc(n, ac);
1072  #else
1073  if(doMigration) cudaAtomList.resize(n);
1074  CudaAtom *ac = cudaAtomPtr = cudaAtomList.begin();
1075  #endif
1076  double * __restrict pos_x = patchDataSOA.pos_x;
1077  double * __restrict pos_y = patchDataSOA.pos_y;
1078  double * __restrict pos_z = patchDataSOA.pos_z;
1079  float * __restrict charge = patchDataSOA.charge;
1080  int * __restrict ao_SOA = patchDataSOA.sortOrder;
1081 #ifndef NODEGROUP_FORCE_REGISTER
1082 //#if 1
1083  for ( int k=0; k<n; ++k ) {
1084  #if defined(NAMD_MIC) && (MIC_HANDCODE_FORCE_SOA_VS_AOS == 0)
1085  int j = ao_SOA[k];
1086  atom_x[k] = pos_x[j] - ucenter_x;
1087  atom_y[k] = pos_y[j] - ucenter_y;
1088  atom_z[k] = pos_z[j] - ucenter_z;
1089  atom_q[k] = charge_scaling * charge[j];
1090  #else
1091  // XXX TODO: This has to go
1092  int j = ao_SOA[k];
1093  // JM: Calculating single-precision patch-centered atomic coordinates as
1094  // offsets. By adding single-precision offsets to double-precision
1095  // patch-patch center distances, we maintain full precision
1096  // XXX NOTE: check where I can use this to use float instead of double in NAMD
1097  ac[k].x = pos_x[j] - ucenter_x;
1098  ac[k].y = pos_y[j] - ucenter_y;
1099  ac[k].z = pos_z[j] - ucenter_z;
1100  // XXX TODO: Compute charge scaling on GPUs and not here to avoid a copy
1101  // for every timestep
1102  // XXX TODO: Check when do we have to update this value and do it
1103  // on the gpu
1104  ac[k].q = charge_scaling * charge[j];
1105  #endif
1106  }
1107 #else
1108  if(!simParams->CUDASOAintegrate || doMigration){
1109  for ( int k=0; k<n; ++k ) {
1110  #if defined(NAMD_MIC) && (MIC_HANDCODE_FORCE_SOA_VS_AOS == 0)
1111  int j = ao_SOA[k];
1112  atom_x[k] = pos_x[j] - ucenter_x;
1113  atom_y[k] = pos_y[j] - ucenter_y;
1114  atom_z[k] = pos_z[j] - ucenter_z;
1115  atom_q[k] = charge_scaling * charge[j];
1116  #else
1117  // XXX TODO: This has to go
1118  int j = ao_SOA[k];
1119  // JM: Calculating single-precision patch-centered atomic coordinates as
1120  // offsets. By adding single-precision offsets to double-precision
1121  // patch-patch center distances, we maintain full precision
1122  ac[k].x = pos_x[j] - ucenter_x;
1123  ac[k].y = pos_y[j] - ucenter_y;
1124  ac[k].z = pos_z[j] - ucenter_z;
1125  // XXX TODO: Compute charge scaling on GPUs and not here to avoid a copy
1126  // for every timestep
1127  // XXX TODO: Check when do we have to update this value and do it
1128  // on the gpu
1129  ac[k].q = charge_scaling * charge[j];
1130  #endif
1131  }
1132  }
1133 #endif
1134  }
1135 #else
1136  doMigration = doMigration && numNeighbors;
1137 #endif
1138  doMigration = doMigration || ! patchMapRead;
1139 
1140  doMigration = doMigration || doAtomUpdate;
1141  doAtomUpdate = false;
1142 
1143  // Workaround for oversize groups:
1144  // reset nonbondedGroupSize (ngs) before force calculation,
1145  // making sure that subset of hydrogen group starting with
1146  // parent atom are all within 0.5 * hgroupCutoff.
1147  // XXX hydrogentGroupSize remains constant but is checked for nonzero
1148  // XXX should be skipped for CUDA, ngs not used by CUDA kernels
1149  // XXX should this also be skipped for KNL kernels?
1150  // ngs used by ComputeNonbondedBase.h - CPU nonbonded kernels
1151  // ngs used by ComputeGBIS.C - CPU GB nonbonded kernels
1152 #if !defined(NAMD_CUDA) && !defined(NAMD_HIP)
1154 #endif
1155 
1156  // Copy information needed by computes and proxys to Patch::p.
1157  if (doMigration) {
1158  // Atom data changes after migration, so must copy all of it.
1159  // Must resize CompAtom and CompAtomExt arrays to new atom count.
1160  p.resize(numAtoms);
1161  pExt.resize(numAtoms);
1162  CompAtom * __restrict p_i = p.begin();
1163  CompAtomExt * __restrict pExt_i = pExt.begin();
1164  const double * __restrict pos_x = patchDataSOA.pos_x;
1165  const double * __restrict pos_y = patchDataSOA.pos_y;
1166  const double * __restrict pos_z = patchDataSOA.pos_z;
1167  const float * __restrict charge = patchDataSOA.charge;
1168  const int * __restrict vdwType = patchDataSOA.vdwType;
1169  const int * __restrict partition = patchDataSOA.partition;
1170 #if !defined(NAMD_CUDA) && !defined(NAMD_HIP)
1171  const int * __restrict nonbondedGroupSize = patchDataSOA.nonbondedGroupSize;
1172 #endif
1173  const int * __restrict hydrogenGroupSize = patchDataSOA.hydrogenGroupSize;
1174  const int * __restrict isWater = patchDataSOA.isWater;
1175  int n = numAtoms;
1176  for (int i=0; i < n; i++) {
1177  p_i[i].position.x = pos_x[i];
1178  p_i[i].position.y = pos_y[i];
1179  p_i[i].position.z = pos_z[i];
1180  p_i[i].charge = charge[i];
1181  p_i[i].vdwType = vdwType[i];
1182  p_i[i].partition = partition[i];
1183 #if !defined(NAMD_CUDA) && !defined(NAMD_HIP)
1184  p_i[i].nonbondedGroupSize = nonbondedGroupSize[i];
1185 #endif
1186  p_i[i].hydrogenGroupSize = hydrogenGroupSize[i];
1187  p_i[i].isWater = isWater[i];
1188  }
1189 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
1190  const int * __restrict sortOrder = patchDataSOA.sortOrder;
1191 #endif
1192  const int * __restrict id = patchDataSOA.id;
1193 #if defined(MEM_OPT_VERSION)
1194  const int * __restrict exclId = patchDataSOA.exclId;
1195  const int * __restrict sigId = patchDataSOA.sigId;
1196 #endif
1197  const int * __restrict atomFixed = patchDataSOA.atomFixed;
1198  const int * __restrict groupFixed = patchDataSOA.groupFixed;
1199  // Copy into CompAtomExt using typecast to temporary CompAtomExtCopy
1200  // to avoid loop vectorization bug in Intel 2018 compiler.
1201 #ifndef USE_NO_BITFIELDS
1202  CompAtomExtCopy *pExtCopy_i = (CompAtomExtCopy *) pExt_i;
1203 #endif // USE_NO_BITFIELDS
1204  for (int i=0; i < n; i++) {
1205 #ifndef USE_NO_BITFIELDS
1206 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
1207  pExtCopy_i[i].sortOrder = sortOrder[i];
1208 #endif
1209 #if defined(MEM_OPT_VERSION)
1210  pExtCopy_i[i].id = id[i];
1211  pExtCopy_i[i].exclId = exclId[i];
1212  ASSERT(atomFixed[i] == 0 || atomFixed[i] == 1);
1213  ASSERT(groupFixed[i] == 0 || groupFixed[i] == 1);
1214  uint32 atomFixedBit = NAMD_ATOM_FIXED_MASK * atomFixed[i];
1215  uint32 groupFixedBit = NAMD_GROUP_FIXED_MASK * groupFixed[i];
1216  pExtCopy_i[i].sigId = (sigId[i] | atomFixedBit | groupFixedBit);
1217 #else
1218  ASSERT(atomFixed[i] == 0 || atomFixed[i] == 1);
1219  ASSERT(groupFixed[i] == 0 || groupFixed[i] == 1);
1220  uint32 atomFixedBit = NAMD_ATOM_FIXED_MASK * atomFixed[i];
1221  uint32 groupFixedBit = NAMD_GROUP_FIXED_MASK * groupFixed[i];
1222  pExtCopy_i[i].id = (id[i] | atomFixedBit | groupFixedBit);
1223 #endif // if defined(MEM_OPT_VERSION)
1224 #else
1225 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
1226  pExt_i[i].sortOrder = sortOrder[i];
1227 #endif
1228  pExt_i[i].id = id[i];
1229 #if defined(MEM_OPT_VERSION)
1230  pExt_i[i].exclId = exclId[i];
1231  pExt_i[i].sigId = sigId[i];
1232 #endif
1233  pExt_i[i].atomFixed = atomFixed[i];
1234  pExt_i[i].groupFixed = groupFixed[i];
1235 #endif // USE_NO_BITFIELDS
1236  }
1237  }
1238  else {
1239  // JM: This is done for every timestep
1240  // Only need to copy positions, nonbondedGroupSize, and sortOrder.
1241  // Other data remains unchanged.
1242  CompAtom * __restrict p_i = p.begin();
1243  CompAtomExt * __restrict pExt_i = pExt.begin();
1244  const double * __restrict pos_x = patchDataSOA.pos_x;
1245  const double * __restrict pos_y = patchDataSOA.pos_y;
1246  const double * __restrict pos_z = patchDataSOA.pos_z;
1247 #if !defined(NAMD_CUDA) && !defined(NAMD_HIP)
1248  const int * __restrict nonbondedGroupSize = patchDataSOA.nonbondedGroupSize;
1249 #endif
1250  int n = numAtoms;
1251 #ifndef NODEGROUP_FORCE_REGISTER
1252 //#if 1
1253  for (int i=0; i < n; i++) {
1254  p_i[i].position.x = pos_x[i];
1255  p_i[i].position.y = pos_y[i];
1256  p_i[i].position.z = pos_z[i];
1257 #if !defined(NAMD_CUDA) && !defined(NAMD_HIP)
1258  p_i[i].nonbondedGroupSize = nonbondedGroupSize[i];
1259 #endif
1260  }
1261 #else
1262  if(!simParams->CUDASOAintegrate || doMigration){
1263  for (int i=0; i < n; i++) {
1264  p_i[i].position.x = pos_x[i];
1265  p_i[i].position.y = pos_y[i];
1266  p_i[i].position.z = pos_z[i];
1267 #if !defined(NAMD_CUDA) && !defined(NAMD_HIP)
1268  p_i[i].nonbondedGroupSize = nonbondedGroupSize[i];
1269 #endif
1270  }
1271  }
1272 #endif
1273 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
1274  const int * __restrict sortOrder = patchDataSOA.sortOrder;
1275 #ifdef NODEGROUP_FORCE_REGISTER
1276 //#if 0
1277  if(!simParams->CUDASOAintegrate || doMigration){
1278  for (int i=0; i < n; i++) {
1279  pExt_i[i].sortOrder = sortOrder[i];
1280  }
1281  }
1282 #else
1283  //if(!simParams->CUDASOAintegrate || doMigration){
1284  for (int i=0; i < n; i++) {
1285  pExt_i[i].sortOrder = sortOrder[i];
1286  }
1287 #endif
1288 #endif
1289  } // end Copy information to Patch::p
1290 
1291  // Measure atom movement to test pairlist validity
1292  // XXX TODO: Check if this ever needs to be done if CUDASOAintegrate
1293 #ifdef NODEGROUP_FORCE_REGISTER
1294  if(!simParams->CUDASOAintegrate || flags.sequence == 0){
1295  doPairlistCheck();
1296  }
1297 #else
1298  doPairlistCheck();
1299 #endif
1300 
1301 #if 0
1302  if (flags.doMolly) mollyAverage();
1303  // BEGIN LA
1305  // END LA
1306 
1307  if (flags.doGBIS) {
1308  //reset for next time step
1309  numGBISP1Arrived = 0;
1310  phase1BoxClosedCalled = false;
1311  numGBISP2Arrived = 0;
1312  phase2BoxClosedCalled = false;
1313  numGBISP3Arrived = 0;
1314  phase3BoxClosedCalled = false;
1315  if (doMigration || isNewProxyAdded)
1317  }
1318 
1319  if (flags.doLCPO) {
1320  if (doMigration || isNewProxyAdded) {
1321  setLcpoType();
1322  }
1323  }
1324 #endif
1325 
1326  // Must Add Proxy Changes when migration completed!
1328  int *pids = NULL;
1329  int pidsPreAllocated = 1;
1330  int npid;
1331  if (proxySendSpanning == 0) {
1332  npid = proxy.size();
1333  pids = new int[npid];
1334  pidsPreAllocated = 0;
1335  int *pidi = pids;
1336  int *pide = pids + proxy.size();
1337  int patchNodesLast =
1338  ( PatchMap::Object()->numNodesWithPatches() < ( 0.7 * CkNumPes() ) );
1339  for ( pli = proxy.begin(); pli != proxy.end(); ++pli )
1340  {
1341  if ( patchNodesLast && PatchMap::Object()->numPatchesOnNode(*pli) ) {
1342  *(--pide) = *pli;
1343  } else {
1344  *(pidi++) = *pli;
1345  }
1346  }
1347  }
1348  else {
1349 #ifdef NODEAWARE_PROXY_SPANNINGTREE
1350  #ifdef USE_NODEPATCHMGR
1351  npid = numNodeChild;
1352  pids = nodeChildren;
1353  #else
1354  npid = nChild;
1355  pids = child;
1356  #endif
1357 #else
1358  npid = nChild;
1359  pidsPreAllocated = 0;
1360  pids = new int[proxySpanDim];
1361  for (int i=0; i<nChild; i++) pids[i] = child[i];
1362 #endif
1363  }
1364  if (npid) { //have proxies
1365  int seq = flags.sequence;
1366  int priority = PROXY_DATA_PRIORITY + PATCH_PRIORITY(patchID);
1367  //begin to prepare proxy msg and send it
1368  int pdMsgPLLen = p.size();
1369  int pdMsgAvgPLLen = 0;
1370 #if 0
1371  if(flags.doMolly) {
1372  pdMsgAvgPLLen = p_avg.size();
1373  }
1374 #endif
1375  // BEGIN LA
1376  int pdMsgVLLen = 0;
1377 #if 0
1378  if (flags.doLoweAndersen) {
1379  pdMsgVLLen = v.size();
1380  }
1381 #endif
1382  // END LA
1383 
1384  int intRadLen = 0;
1385 #if 0
1386  if (flags.doGBIS && (doMigration || isNewProxyAdded)) {
1387  intRadLen = numAtoms * 2;
1388  }
1389 #endif
1390 
1391  //LCPO
1392  int lcpoTypeLen = 0;
1393 #if 0
1394  if (flags.doLCPO && (doMigration || isNewProxyAdded)) {
1395  lcpoTypeLen = numAtoms;
1396  }
1397 #endif
1398 
1399  int pdMsgPLExtLen = 0;
1400  if(doMigration || isNewProxyAdded) {
1401  pdMsgPLExtLen = pExt.size();
1402  }
1403 
1404  int cudaAtomLen = 0;
1405 #if defined(NAMD_CUDA) || defined(NAMD_HIP)
1406  cudaAtomLen = numAtoms;
1407 #endif
1408 
1409  #ifdef NAMD_MIC
1410  #if MIC_HANDCODE_FORCE_SOA_VS_AOS != 0
1411  cudaAtomLen = numAtoms;
1412  #else
1413  cudaAtomLen = (numAtoms + 15) & (~15);
1414  #endif
1415  #endif
1416  ProxyDataMsg *nmsg = new (pdMsgPLLen, pdMsgAvgPLLen, pdMsgVLLen, intRadLen,
1417  lcpoTypeLen, pdMsgPLExtLen, cudaAtomLen, PRIORITY_SIZE) ProxyDataMsg; // BEGIN LA, END LA
1418 
1419  SET_PRIORITY(nmsg,seq,priority);
1420  nmsg->patch = patchID;
1421  nmsg->flags = flags;
1422  nmsg->plLen = pdMsgPLLen;
1423  //copying data to the newly created msg
1424  NAMD_EVENT_START(1, NamdProfileEvent::MEMCPY);
1425  memcpy(nmsg->positionList, p.begin(), sizeof(CompAtom)*pdMsgPLLen);
1426  NAMD_EVENT_STOP(1, NamdProfileEvent::MEMCPY);
1427  nmsg->avgPlLen = pdMsgAvgPLLen;
1428 #if 0
1429  if(flags.doMolly) {
1430  memcpy(nmsg->avgPositionList, p_avg.begin(), sizeof(CompAtom)*pdMsgAvgPLLen);
1431  }
1432 #endif
1433  // BEGIN LA
1434  nmsg->vlLen = pdMsgVLLen;
1435 #if 0
1436  if (flags.doLoweAndersen) {
1437  memcpy(nmsg->velocityList, v.begin(), sizeof(CompAtom)*pdMsgVLLen);
1438  }
1439 #endif
1440  // END LA
1441 
1442 #if 0
1443  if (flags.doGBIS && (doMigration || isNewProxyAdded)) {
1444  for (int i = 0; i < numAtoms * 2; i++) {
1445  nmsg->intRadList[i] = intRad[i];
1446  }
1447  }
1448 #endif
1449 
1450 #if 0
1451  if (flags.doLCPO && (doMigration || isNewProxyAdded)) {
1452  for (int i = 0; i < numAtoms; i++) {
1453  nmsg->lcpoTypeList[i] = lcpoType[i];
1454  }
1455  }
1456 #endif
1457  nmsg->plExtLen = pdMsgPLExtLen;
1458  if(doMigration || isNewProxyAdded){
1459  memcpy(nmsg->positionExtList, pExt.begin(), sizeof(CompAtomExt)*pdMsgPLExtLen);
1460  }
1461 
1462 // DMK
1463 #if defined(NAMD_CUDA) || defined(NAMD_HIP) || defined(NAMD_MIC)
1464  NAMD_EVENT_START(1, NamdProfileEvent::MEMCPY);
1465  memcpy(nmsg->cudaAtomList, cudaAtomPtr, sizeof(CudaAtom)*cudaAtomLen);
1466  NAMD_EVENT_STOP(1, NamdProfileEvent::MEMCPY);
1467 #endif
1468 
1469 #if NAMD_SeparateWaters != 0
1470  //DMK - Atom Separation (water vs. non-water)
1471  nmsg->numWaterAtoms = numWaterAtoms;
1472 #endif
1473 
1474 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR) && (CMK_SMP) && defined(NAMDSRC_IMMQD_HACK)
1475  nmsg->isFromImmMsgCall = 0;
1476 #endif
1477 
1478  #if defined(PROCTRACE_DEBUG) && defined(NAST_DEBUG)
1479  DebugFileTrace *dft = DebugFileTrace::Object();
1480  dft->openTrace();
1481  dft->writeTrace("HP::posReady: for HomePatch[%d], sending proxy msg to: ", patchID);
1482  for(int i=0; i<npid; i++) {
1483  dft->writeTrace("%d ", pids[i]);
1484  }
1485  dft->writeTrace("\n");
1486  dft->closeTrace();
1487  #endif
1488 
1489 #if CMK_PERSISTENT_COMM && USE_PERSISTENT_TREE
1490  if (isProxyChanged || localphs == NULL)
1491  {
1492 //CmiPrintf("[%d] Build persistent: isProxyChanged: %d %p\n", CkMyPe(), isProxyChanged, localphs);
1493  //CmiAssert(isProxyChanged);
1494  if (nphs) {
1495  for (int i=0; i<nphs; i++) {
1496  CmiDestoryPersistent(localphs[i]);
1497  }
1498  delete [] localphs;
1499  }
1500  localphs = new PersistentHandle[npid];
1501  int persist_size = sizeof(envelope) + sizeof(ProxyDataMsg) + sizeof(CompAtom)*(pdMsgPLLen+pdMsgAvgPLLen+pdMsgVLLen) + intRadLen*sizeof(Real) + lcpoTypeLen*sizeof(int) + sizeof(CompAtomExt)*pdMsgPLExtLen + sizeof(CudaAtom)*cudaAtomLen + PRIORITY_SIZE/8 + 2048;
1502  for (int i=0; i<npid; i++) {
1503 #if defined(NODEAWARE_PROXY_SPANNINGTREE) && defined(USE_NODEPATCHMGR)
1504  if (proxySendSpanning)
1505  localphs[i] = CmiCreateNodePersistent(pids[i], persist_size, sizeof(envelope)+sizeof(ProxyDataMsg));
1506  else
1507 #endif
1508  localphs[i] = CmiCreatePersistent(pids[i], persist_size, sizeof(envelope)+sizeof(ProxyDataMsg));
1509  }
1510  nphs = npid;
1511  }
1512  CmiAssert(nphs == npid && localphs != NULL);
1513  CmiUsePersistentHandle(localphs, nphs);
1514 #endif
1515  if(doMigration || isNewProxyAdded) {
1516  ProxyMgr::Object()->sendProxyAll(nmsg,npid,pids);
1517  }else{
1518  ProxyMgr::Object()->sendProxyData(nmsg,npid,pids);
1519  }
1520 #if CMK_PERSISTENT_COMM && USE_PERSISTENT_TREE
1521  CmiUsePersistentHandle(NULL, 0);
1522 #endif
1523  isNewProxyAdded = 0;
1524  }
1525  isProxyChanged = 0;
1526  if(!pidsPreAllocated) delete [] pids;
1527  DebugM(4, "patchID("<<patchID<<") doing positions Ready\n");
1528 
1529 #ifdef REMOVE_PROXYDATAMSG_EXTRACOPY
1530  positionPtrBegin = p.begin();
1531  positionPtrEnd = p.end();
1532 #endif
1533 
1534 #if 0
1535  if(flags.doMolly) {
1538  }
1539  // BEGIN LA
1540  if (flags.doLoweAndersen) {
1541  velocityPtrBegin = v.begin();
1542  velocityPtrEnd = v.end();
1543  }
1544  // END LA
1545 #endif
1546  // fprintf(stderr, "(Pe[%d] tstep %d)calling positionsReady on patch %d\n",
1547  // CkMyPe(), this->flags.step, this->patchID);
1548  Patch::positionsReady(doMigration);
1549 
1550  patchMapRead = 1;
1551 
1552  // gzheng
1553  NAMD_EVENT_STOP(1, NamdProfileEvent::POSITIONS_READY_SOA);
1554 
1555  Sync::Object()->PatchReady();
1556 
1557 #if 0
1558  fprintf(stderr, "Patch %d atom IDS\n", this->patchID);
1559  AtomMap* mapper = AtomMap::Object();
1560  for(int i = 0 ; i < numAtoms; i++){
1561  fprintf(stderr, "atom[%d] = %d %d %d\n", i, atom[i].id,
1562  mapper->localID(atom[i].id).pid, mapper->localID(atom[i].id).index);
1563  }
1564 #endif
1565 
1566 }
static Node * Object()
Definition: Node.h:86
void doMarginCheck_SOA()
Definition: HomePatch.C:5639
#define NAMD_EVENT_STOP(eon, id)
int * lcpoTypeList
Definition: ProxyMgr.h:112
float q
Definition: CudaRecord.h:59
int numNodesWithPatches(void)
Definition: PatchMap.h:61
int size(void) const
Definition: ResizeArray.h:131
RealList intRad
Definition: Patch.h:162
int32 * isWater
Definition: NamdTypes.h:386
static ProxyMgr * Object()
Definition: ProxyMgr.h:394
int32 * groupFixed
Definition: NamdTypes.h:394
Lattice & lattice
Definition: Patch.h:127
static void partition(int *order, const FullAtom *atoms, int begin, int end)
Definition: SortAtoms.C:45
static PatchMap * Object()
Definition: PatchMap.h:27
int32 * exclId
Definition: NamdTypes.h:391
int32 * unsortOrder
Definition: NamdTypes.h:389
CompAtom * velocityPtrEnd
Definition: Patch.h:209
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
float z
Definition: CudaRecord.h:59
NAMD_HOST_DEVICE Position unscale(ScaledPosition s) const
Definition: Lattice.h:77
float Real
Definition: common.h:118
#define COULOMB
Definition: common.h:53
#define DebugM(x, y)
Definition: Debug.h:75
BigReal z
Definition: Vector.h:74
float x
Definition: CudaRecord.h:59
CompAtom * avgPositionPtrEnd
Definition: Patch.h:205
char const *const NamdProfileEventStr[]
#define PROXY_DATA_PRIORITY
Definition: Priorities.h:40
CompAtomList v
Definition: Patch.h:156
CompAtom * avgPositionList
Definition: ProxyMgr.h:104
void loweAndersenVelocities()
Definition: HomePatch.C:4866
int doLoweAndersen
Definition: PatchTypes.h:28
CompAtom * velocityList
Definition: ProxyMgr.h:107
CudaAtom * cudaAtomPtr
Definition: Patch.h:212
double * pos_y
Definition: NamdTypes.h:378
bool rattleListValid
Definition: HomePatch.h:453
Flags flags
Definition: Patch.h:128
void resize(int i)
Definition: ResizeArray.h:84
int32 index
Definition: NamdTypes.h:300
void doGroupSizeCheck_SOA()
Definition: HomePatch.C:5537
#define PRIORITY_SIZE
Definition: Priorities.h:13
int32 * hydrogenGroupSize
Definition: NamdTypes.h:385
void qmSwapAtoms()
Definition: HomePatch.C:907
#define NAMD_EVENT_START(eon, id)
uint32_t uint32
Definition: common.h:42
int32 * vdwType
Definition: NamdTypes.h:382
#define NAMD_GROUP_FIXED_MASK
Definition: NamdTypes.h:146
IntList lcpoType
Definition: Patch.h:171
int32 * sortOrder
Definition: NamdTypes.h:388
CudaAtom * cudaAtomList
Definition: ProxyMgr.h:123
int32 * id
Definition: NamdTypes.h:390
CompAtomList p_avg
Definition: Patch.h:154
float * charge
Definition: NamdTypes.h:381
int plExtLen
Definition: ProxyMgr.h:121
CompAtomList p
Definition: Patch.h:153
LocalID localID(AtomID id)
Definition: AtomMap.h:78
static Sync * Object()
Definition: Sync.h:52
int numAtoms
Definition: Patch.h:151
#define NAMD_ATOM_FIXED_MASK
Definition: NamdTypes.h:145
BigReal x
Definition: Vector.h:74
PatchID getPatchID() const
Definition: Patch.h:114
int sequence
Definition: PatchTypes.h:18
int32 * partition
Definition: NamdTypes.h:383
void setLcpoType()
Definition: HomePatch.C:4889
CompAtom * avgPositionPtrBegin
Definition: Patch.h:204
PatchID pid
Definition: NamdTypes.h:299
void doPairlistCheck()
Definition: HomePatch.C:5438
static AtomMap * Object()
Definition: AtomMap.h:37
void sortAtomsForCUDA_SOA(int *__restrict order, int *__restrict unorder, const double *__restrict ax, const double *__restrict ay, const double *__restrict az, int nfree, int n)
Definition: SortAtoms.C:317
void doAtomMigration()
Definition: HomePatch.C:5798
void PatchReady(void)
Definition: Sync.C:150
void setGBISIntrinsicRadii()
Definition: HomePatch.C:4900
PatchID patch
Definition: ProxyMgr.h:97
Flags flags
Definition: ProxyMgr.h:98
void sendProxyData(ProxyDataMsg *, int, int *)
Definition: ProxyMgr.C:1562
Real * intRadList
Definition: ProxyMgr.h:110
float y
Definition: CudaRecord.h:59
#define ASSERT(expr)
Definition: Debug.h:23
CompAtom * positionList
Definition: ProxyMgr.h:102
#define simParams
Definition: Output.C:131
#define NAMD_EVENT_START_EX(eon, id, str)
iterator begin(void)
Definition: ResizeArray.h:36
double * pos_z
Definition: NamdTypes.h:379
void sendProxyAll(ProxyDataMsg *, int, int *)
Definition: ProxyMgr.C:1676
const PatchID patchID
Definition: Patch.h:150
void mollyAverage()
Definition: HomePatch.C:5085
iterator end(void)
Definition: ResizeArray.h:37
bool rattleListValid_SOA
Definition: HomePatch.h:454
double * pos_x
Definition: NamdTypes.h:377
BigReal y
Definition: Vector.h:74
int doLCPO
Definition: PatchTypes.h:31
CompAtomExt * positionExtList
Definition: ProxyMgr.h:122
int32 * sigId
Definition: NamdTypes.h:392
int numPatchesOnNode(int node)
Definition: PatchMap.h:60
int doGBIS
Definition: PatchTypes.h:30
#define SET_PRIORITY(MSG, SEQ, PRIO)
Definition: Priorities.h:18
int avgPlLen
Definition: ProxyMgr.h:103
int proxySpanDim
Definition: ProxyMgr.C:47
int32 * atomFixed
Definition: NamdTypes.h:393
int32 * nonbondedGroupSize
Definition: NamdTypes.h:384
CompAtomExtList pExt
Definition: Patch.h:181
void positionsReady(int n=0, int startup=1)
Definition: Patch.C:403
int doMolly
Definition: PatchTypes.h:25
double BigReal
Definition: common.h:123
#define PATCH_PRIORITY(PID)
Definition: Priorities.h:25
CompAtom * velocityPtrBegin
Definition: Patch.h:208
int proxySendSpanning
Definition: ProxyMgr.C:44

◆ qmSwapAtoms()

void HomePatch::qmSwapAtoms ( )

Definition at line 907 of file HomePatch.C.

References ResizeArray< Elem >::begin(), CompAtom::charge, SortedArray< Elem >::find(), Molecule::get_numQMAtoms(), Molecule::get_qmAtmChrg(), Molecule::get_qmAtmIndx(), Molecule::get_qmAtomGroup(), CompAtomExt::id, lssSubs(), Node::molecule, LSSSubsDat::newCharge, LSSSubsDat::newID, LSSSubsDat::newVdWType, Patch::numAtoms, Node::Object(), Node::simParameters, simParams, and CompAtom::vdwType.

Referenced by positionsReady(), and positionsReady_SOA().

908 {
909  // This is used for LSS in QM/MM simulations.
910  // Changes atom labels so that we effectively exchange solvent
911  // molecules between classical and quantum modes.
912 
914  int numQMAtms = Node::Object()->molecule->get_numQMAtoms();
915  const Real * const qmAtomGroup = Node::Object()->molecule->get_qmAtomGroup() ;
916  const int *qmAtmIndx = Node::Object()->molecule->get_qmAtmIndx() ;
917  Real *qmAtmChrg = Node::Object()->molecule->get_qmAtmChrg() ;
918 
919  ComputeQMMgr *mgrP = CProxy_ComputeQMMgr::ckLocalBranch(
920  CkpvAccess(BOCclass_group).computeQMMgr) ;
921 
922  FullAtom *a_i = atom.begin();
923 
924  for (int i=0; i<numAtoms; ++i ) {
925 
926  LSSSubsDat *subP = lssSubs(mgrP).find( LSSSubsDat(a_i[i].id) ) ;
927 
928  if ( subP != NULL ) {
929  a_i[i].id = subP->newID ;
930  a_i[i].vdwType = subP->newVdWType ;
931 
932  // If we are swappign a classical atom with a QM one, the charge
933  // will need extra handling.
934  if (qmAtomGroup[subP->newID] > 0 && simParams->PMEOn) {
935  // We make sure that the last atom charge calculated for the
936  // QM atom being transfered here is available for PME
937  // in the next step.
938 
939  // Loops over all QM atoms (in all QM groups) comparing their
940  // global indices (the sequential atom ID from NAMD).
941  for (int qmIter=0; qmIter<numQMAtms; qmIter++) {
942 
943  if (qmAtmIndx[qmIter] == subP->newID) {
944  qmAtmChrg[qmIter] = subP->newCharge;
945  break;
946  }
947 
948  }
949 
950  // For QM atoms, the charge in the full atom structure is zero.
951  // Electrostatic interactions between QM atoms and their
952  // environment is handled in ComputeQM.
953  a_i[i].charge = 0;
954  }
955  else {
956  // If we are swappign a QM atom with a Classical one, only the charge
957  // in the full atomstructure needs updating, since it used to be zero.
958  a_i[i].charge = subP->newCharge ;
959  }
960  }
961  }
962 
963  return;
964 }
static Node * Object()
Definition: Node.h:86
SortedArray< LSSSubsDat > & lssSubs(ComputeQMMgr *mgr)
Definition: ComputeQM.C:596
const int * get_qmAtmIndx()
Definition: Molecule.h:863
SimParameters * simParameters
Definition: Node.h:181
int get_numQMAtoms()
Definition: Molecule.h:865
float Real
Definition: common.h:118
uint32 id
Definition: NamdTypes.h:160
Charge charge
Definition: NamdTypes.h:79
int newVdWType
Definition: ComputeQM.h:33
int16 vdwType
Definition: NamdTypes.h:80
Real * get_qmAtmChrg()
Definition: Molecule.h:862
int numAtoms
Definition: Patch.h:151
const Real * get_qmAtomGroup() const
Definition: Molecule.h:859
Real newCharge
Definition: ComputeQM.h:34
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
Elem * find(const Elem &elem)
Definition: SortedArray.h:94
int newID
Definition: ComputeQM.h:32
Molecule * molecule
Definition: Node.h:179

◆ rattle1()

int HomePatch::rattle1 ( const BigReal  timestep,
Tensor virial,
SubmitReduction ppreduction 
)

Definition at line 3788 of file HomePatch.C.

References addRattleForce(), buildRattleList(), endi(), iERROR(), iout, iWARN(), LINCS(), MSHAKEIterate(), noconstList, Patch::numAtoms, Node::Object(), posNew, rattle1old(), rattleList, rattleListValid, rattleN(), rattlePair< 1 >(), rattleParam, settle1_SIMD< 1 >(), settle1_SIMD< 2 >(), settleList, Node::simParameters, simParams, TIMEFACTOR, TIP3, velNew, Vector::x, Vector::y, and Vector::z.

Referenced by Sequencer::minimize(), Sequencer::minimizeMoveDownhill(), Sequencer::newMinimizePosition(), and Sequencer::rattle1().

3789  {
3790 
3792  if (simParams->watmodel != WaterModel::TIP3 || ppreduction) {
3793  // Call old rattle1 -method instead
3794  return rattle1old(timestep, virial, ppreduction);
3795  }
3796 
3797  if (!rattleListValid) {
3798  buildRattleList();
3799  rattleListValid = true;
3800  }
3801 
3802  const int fixedAtomsOn = simParams->fixedAtomsOn;
3803  const int useSettle = simParams->useSettle;
3804  const BigReal dt = timestep / TIMEFACTOR;
3805  const BigReal invdt = (dt == 0.) ? 0. : 1.0 / dt; // precalc 1/dt
3806  const BigReal tol2 = 2.0 * simParams->rigidTol;
3807  int maxiter = simParams->rigidIter;
3808  int dieOnError = simParams->rigidDie;
3809 
3810  Vector ref[10]; // reference position
3811  Vector pos[10]; // new position
3812  Vector vel[10]; // new velocity
3813 
3814  // Manual un-roll
3815  int n = (settleList.size()/2)*2;
3816  for (int j=0;j < n;j+=2) {
3817  int ig;
3818  ig = settleList[j];
3819  for (int i = 0; i < 3; ++i ) {
3820  ref[i] = atom[ig+i].position;
3821  pos[i] = atom[ig+i].position + atom[ig+i].velocity * dt;
3822  }
3823  ig = settleList[j+1];
3824  for (int i = 0; i < 3; ++i ) {
3825  ref[i+3] = atom[ig+i].position;
3826  pos[i+3] = atom[ig+i].position + atom[ig+i].velocity * dt;
3827  }
3828  settle1_SIMD<2>(ref, pos,
3829  settle_mOrmT, settle_mHrmT, settle_ra,
3830  settle_rb, settle_rc, settle_rra);
3831 
3832  ig = settleList[j];
3833  for (int i = 0; i < 3; ++i ) {
3834  velNew[ig+i] = (pos[i] - ref[i])*invdt;
3835  posNew[ig+i] = pos[i];
3836  }
3837  ig = settleList[j+1];
3838  for (int i = 0; i < 3; ++i ) {
3839  velNew[ig+i] = (pos[i+3] - ref[i+3])*invdt;
3840  posNew[ig+i] = pos[i+3];
3841  }
3842 
3843  }
3844 
3845  if (settleList.size() % 2) {
3846  int ig = settleList[settleList.size()-1];
3847  for (int i = 0; i < 3; ++i ) {
3848  ref[i] = atom[ig+i].position;
3849  pos[i] = atom[ig+i].position + atom[ig+i].velocity * dt;
3850  }
3851  settle1_SIMD<1>(ref, pos,
3852  settle_mOrmT, settle_mHrmT, settle_ra,
3853  settle_rb, settle_rc, settle_rra);
3854  for (int i = 0; i < 3; ++i ) {
3855  velNew[ig+i] = (pos[i] - ref[i])*invdt;
3856  posNew[ig+i] = pos[i];
3857  }
3858  }
3859 
3860  int posParam = 0;
3861  for (int j=0;j < rattleList.size();++j) {
3862 
3863  BigReal refx[10];
3864  BigReal refy[10];
3865  BigReal refz[10];
3866 
3867  BigReal posx[10];
3868  BigReal posy[10];
3869  BigReal posz[10];
3870 
3871  int ig = rattleList[j].ig;
3872  int icnt = rattleList[j].icnt;
3873  int hgs = atom[ig].hydrogenGroupSize;
3874  for (int i = 0; i < hgs; ++i ) {
3875  ref[i] = atom[ig+i].position;
3876  pos[i] = atom[ig+i].position;
3877  if (!(fixedAtomsOn && atom[ig+i].atomFixed)) {
3878  pos[i] += atom[ig+i].velocity * dt;
3879  }
3880  refx[i] = ref[i].x;
3881  refy[i] = ref[i].y;
3882  refz[i] = ref[i].z;
3883  posx[i] = pos[i].x;
3884  posy[i] = pos[i].y;
3885  posz[i] = pos[i].z;
3886  }
3887 
3888  bool done;
3889  bool consFailure;
3890  if (icnt == 1) {
3891  rattlePair<1>(&rattleParam[posParam],
3892  refx, refy, refz,
3893  posx, posy, posz,
3894  consFailure);
3895  done = true;
3896  } else {
3897  if (simParams->mshakeOn) {
3898  MSHAKEIterate(icnt, &rattleParam[posParam],
3899  refx, refy, refz,
3900  posx, posy, posz,
3901  tol2, maxiter,
3902  done, consFailure);
3903  }
3904  else if(simParams->lincsOn) {
3905  LINCS(icnt, &rattleParam[posParam],
3906  refx, refy, refz,
3907  posx, posy, posz,
3908  tol2, maxiter, done, consFailure);
3909  }
3910  else
3911  rattleN(icnt, &rattleParam[posParam],
3912  refx, refy, refz,
3913  posx, posy, posz,
3914  tol2, maxiter,
3915  done, consFailure);
3916  }
3917 
3918  // Advance position in rattleParam
3919  //posParam += icnt;
3920  posParam += 4;
3921  for (int i = 0; i < hgs; ++i ) {
3922  pos[i].x = posx[i];
3923  pos[i].y = posy[i];
3924  pos[i].z = posz[i];
3925  }
3926 
3927  for (int i = 0; i < hgs; ++i ) {
3928  velNew[ig+i] = (pos[i] - ref[i])*invdt;
3929  posNew[ig+i] = pos[i];
3930  }
3931 
3932  if ( consFailure ) {
3933  if ( dieOnError ) {
3934  iout << iERROR << "Constraint failure in RATTLE algorithm for atom "
3935  << (atom[ig].id + 1) << "!\n" << endi;
3936  return -1; // triggers early exit
3937  } else {
3938  iout << iWARN << "Constraint failure in RATTLE algorithm for atom "
3939  << (atom[ig].id + 1) << "!\n" << endi;
3940  }
3941  } else if ( ! done ) {
3942  if ( dieOnError ) {
3943  iout << iERROR << "Exceeded RATTLE iteration limit for atom "
3944  << (atom[ig].id + 1) << "!\n" << endi;
3945  return -1; // triggers early exit
3946  } else {
3947  iout << iWARN << "Exceeded RATTLE iteration limit for atom "
3948  << (atom[ig].id + 1) << "!\n" << endi;
3949  }
3950  }
3951  }
3952  // Finally, we have to go through atoms that are not involved in rattle just so that we have
3953  // their positions and velocities up-to-date in posNew and velNew
3954  for (int j=0;j < noconstList.size();++j) {
3955  int ig = noconstList[j];
3956  int hgs = atom[ig].hydrogenGroupSize;
3957  for (int i = 0; i < hgs; ++i ) {
3958  velNew[ig+i] = atom[ig+i].velocity;
3959  posNew[ig+i] = atom[ig+i].position;
3960  }
3961  }
3962 
3963  if ( invdt == 0 ) {
3964  for (int ig = 0; ig < numAtoms; ++ig )
3965  atom[ig].position = posNew[ig];
3966  } else if ( virial == 0 ) {
3967  for (int ig = 0; ig < numAtoms; ++ig )
3968  atom[ig].velocity = velNew[ig];
3969  } else {
3970  Tensor wc; // constraint virial
3971  addRattleForce(invdt, wc);
3972  *virial += wc;
3973  }
3974 
3975  return 0;
3976 }
static Node * Object()
Definition: Node.h:86
template void settle1_SIMD< 1 >(const Vector *ref, Vector *pos, BigReal mOrmT, BigReal mHrmT, BigReal ra, BigReal rb, BigReal rc, BigReal rra)
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
void MSHAKEIterate(const int icnt, const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, const BigReal tol2, const int maxiter, bool &done, bool &consFailure)
Definition: Settle.C:830
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
template void settle1_SIMD< 2 >(const Vector *ref, Vector *pos, BigReal mOrmT, BigReal mHrmT, BigReal ra, BigReal rb, BigReal rc, BigReal rra)
bool rattleListValid
Definition: HomePatch.h:453
std::vector< RattleList > rattleList
Definition: HomePatch.h:449
void LINCS(const int icnt, const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, const BigReal tol2, const int maxiter, bool &done, bool &consFailure)
Definition: Settle.C:936
template void rattlePair< 1 >(const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, bool &consFailure)
int rattle1old(const BigReal, Tensor *virial, SubmitReduction *)
Definition: HomePatch.C:3979
void buildRattleList()
Definition: HomePatch.C:3616
int numAtoms
Definition: Patch.h:151
std::vector< int > settleList
Definition: HomePatch.h:448
std::vector< Vector > posNew
Definition: HomePatch.h:458
std::vector< RattleParam > rattleParam
Definition: HomePatch.h:450
#define simParams
Definition: Output.C:131
Definition: Tensor.h:15
#define TIMEFACTOR
Definition: common.h:55
std::vector< Vector > velNew
Definition: HomePatch.h:457
void rattleN(const int icnt, const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, const BigReal tol2, const int maxiter, bool &done, bool &consFailure)
Definition: Settle.C:1359
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
std::vector< int > noconstList
Definition: HomePatch.h:451
void addRattleForce(const BigReal invdt, Tensor &wc)
Definition: HomePatch.C:3778
double BigReal
Definition: common.h:123

◆ rattle1_SOA()

int HomePatch::rattle1_SOA ( const BigReal  dt,
Tensor virial,
SubmitReduction ppreduction 
)

Definition at line 4659 of file HomePatch.C.

References buildRattleList_SOA(), endi(), PatchDataSOA::f_normal_x, PatchDataSOA::f_normal_y, PatchDataSOA::f_normal_z, PatchDataSOA::hydrogenGroupSize, iERROR(), iout, iWARN(), LINCS(), PatchDataSOA::mass, MSHAKEIterate(), noconstList, Patch::numAtoms, Node::Object(), PatchDataSOA::pos_x, PatchDataSOA::pos_y, PatchDataSOA::pos_z, PatchDataSOA::posNew_x, PatchDataSOA::posNew_y, PatchDataSOA::posNew_z, rattleList, rattleListValid_SOA, rattleN(), rattlePair< 1 >(), rattleParam, settle1_SOA(), Node::simParameters, simParams, PatchDataSOA::vel_x, PatchDataSOA::vel_y, PatchDataSOA::vel_z, PatchDataSOA::velNew_x, PatchDataSOA::velNew_y, PatchDataSOA::velNew_z, Tensor::xx, Tensor::xy, Tensor::xz, Tensor::yx, Tensor::yy, Tensor::yz, Tensor::zx, Tensor::zy, and Tensor::zz.

Referenced by Sequencer::rattle1_SOA().

4660  {
4661 
4663 
4664 #if 1
4665  if (!rattleListValid_SOA) {
4667  rattleListValid_SOA = true;
4668  }
4669 #endif
4670 
4671  double * __restrict pos_x = patchDataSOA.pos_x;
4672  double * __restrict pos_y = patchDataSOA.pos_y;
4673  double * __restrict pos_z = patchDataSOA.pos_z;
4674  double * __restrict vel_x = patchDataSOA.vel_x;
4675  double * __restrict vel_y = patchDataSOA.vel_y;
4676  double * __restrict vel_z = patchDataSOA.vel_z;
4677  double * __restrict posNew_x = patchDataSOA.posNew_x;
4678  double * __restrict posNew_y = patchDataSOA.posNew_y;
4679  double * __restrict posNew_z = patchDataSOA.posNew_z;
4680  double * __restrict velNew_x = patchDataSOA.velNew_x;
4681  double * __restrict velNew_y = patchDataSOA.velNew_y;
4682  double * __restrict velNew_z = patchDataSOA.velNew_z;
4683  const int * __restrict hydrogenGroupSize = patchDataSOA.hydrogenGroupSize;
4684 #ifdef __INTEL_COMPILER
4685  __assume_aligned(pos_x,64);
4686  __assume_aligned(pos_y,64);
4687  __assume_aligned(pos_z,64);
4688  __assume_aligned(vel_x,64);
4689  __assume_aligned(vel_y,64);
4690  __assume_aligned(vel_z,64);
4691  __assume_aligned(posNew_x,64);
4692  __assume_aligned(posNew_y,64);
4693  __assume_aligned(posNew_z,64);
4694  __assume_aligned(velNew_x,64);
4695  __assume_aligned(velNew_y,64);
4696  __assume_aligned(velNew_z,64);
4697  __assume_aligned(hydrogenGroupSize,64);
4698 #endif
4699 
4700  const BigReal invdt = (dt == 0.) ? 0. : 1.0 / dt; // precalc 1/dt
4701  const BigReal tol2 = 2.0 * simParams->rigidTol;
4702  int maxiter = simParams->rigidIter;
4703  int dieOnError = simParams->rigidDie;
4704 
4705  // calculate full step update to all positions
4706  for (int i=0; i < numAtoms; i++) {
4707  posNew_x[i] = pos_x[i] + vel_x[i] * dt;
4708  posNew_y[i] = pos_y[i] + vel_y[i] * dt;
4709  posNew_z[i] = pos_z[i] + vel_z[i] * dt;
4710  }
4711 
4712  // call settle to process all waters at once
4713  // XXX this assumes sorting waters into consecutive part of list
4714  //int numWaters = settleList.size();
4715  if (numSolventAtoms > 0) {
4716  int n = numSoluteAtoms; // index of first water in list is past solute
4717  settle1_SOA(&pos_x[n], &pos_y[n], &pos_z[n],
4718  &posNew_x[n], &posNew_y[n], &posNew_z[n],
4719  numWaters,
4720  settle_mOrmT, settle_mHrmT, settle_ra,
4721  settle_rb, settle_rc, settle_rra);
4722  }
4723  int posParam = 0;
4724  for (int j=0;j < rattleList.size();++j) {
4725  int ig = rattleList[j].ig;
4726  int icnt = rattleList[j].icnt;
4727  bool done;
4728  bool consFailure;
4729  if (icnt == 1) {
4730  rattlePair<1>(&rattleParam[posParam],
4731  &pos_x[ig], &pos_y[ig], &pos_z[ig],
4732  &posNew_x[ig], &posNew_y[ig], &posNew_z[ig],
4733  consFailure
4734  );
4735  done = true;
4736  } else {
4737  if (simParams->mshakeOn) {
4738  //buildConstantMatrix();
4739  MSHAKEIterate(icnt, &rattleParam[posParam],
4740  &pos_x[ig], &pos_y[ig], &pos_z[ig],
4741  &posNew_x[ig], &posNew_y[ig], &posNew_z[ig],
4742  tol2, maxiter,
4743  done, consFailure);
4744  }
4745  else if(simParams->lincsOn) {
4746  LINCS(icnt, &rattleParam[posParam],
4747  &pos_x[ig], &pos_y[ig], &pos_z[ig],
4748  &posNew_x[ig], &posNew_y[ig], &posNew_z[ig],
4749  tol2, maxiter, done, consFailure);
4750  }
4751 
4752  else
4753  rattleN(icnt, &rattleParam[posParam],
4754  &pos_x[ig], &pos_y[ig], &pos_z[ig],
4755  &posNew_x[ig], &posNew_y[ig], &posNew_z[ig],
4756  tol2, maxiter,
4757  done, consFailure);
4758  }
4759 
4760  // Advance position in rattleParam
4761 // posParam += icnt;
4762  posParam += 4;
4763  if ( consFailure ) {
4764  if ( dieOnError ) {
4765  iout << iERROR << "Constraint failure in RATTLE algorithm for atom "
4766  << (atom[ig].id + 1) << "!\n" << endi;
4767  return -1; // triggers early exit
4768  } else {
4769  iout << iWARN << "Constraint failure in RATTLE algorithm for atom "
4770  << (atom[ig].id + 1) << "!\n" << endi;
4771  }
4772  } else if ( ! done ) {
4773  if ( dieOnError ) {
4774  iout << iERROR << "Exceeded RATTLE iteration limit for atom "
4775  << (atom[ig].id + 1) << "!\n" << endi;
4776  return -1; // triggers early exit
4777  } else {
4778  iout << iWARN << "Exceeded RATTLE iteration limit for atom "
4779  << (atom[ig].id + 1) << "!\n" << endi;
4780  }
4781  }
4782 
4783  } // end rattle
4784  // Now that all new positions are known, determine new velocities
4785  // needed to reach new position.
4786  for (int i=0; i < numAtoms; i++) {
4787  velNew_x[i] = (posNew_x[i] - pos_x[i]) * invdt;
4788  velNew_y[i] = (posNew_y[i] - pos_y[i]) * invdt;
4789  velNew_z[i] = (posNew_z[i] - pos_z[i]) * invdt;
4790  }
4791 
4792  // Bring new positions and velocities back to reference for noconstList.
4793  // No need to check hydrogen group size, since no fixed atoms.
4794  int numNoconst = noconstList.size();
4795  for (int j=0; j < numNoconst; j++) {
4796  int ig = noconstList[j];
4797  posNew_x[ig] = pos_x[ig];
4798  posNew_y[ig] = pos_y[ig];
4799  posNew_z[ig] = pos_z[ig];
4800  velNew_x[ig] = vel_x[ig];
4801  velNew_y[ig] = vel_y[ig];
4802  velNew_z[ig] = vel_z[ig];
4803  }
4804 
4805  if ( invdt == 0 ) {
4806  for (int ig = 0; ig < numAtoms; ++ig ) {
4807  pos_x[ig] = posNew_x[ig];
4808  pos_y[ig] = posNew_y[ig];
4809  pos_z[ig] = posNew_z[ig];
4810  }
4811  }
4812  else if ( virial == 0 ) {
4813  for (int ig = 0; ig < numAtoms; ++ig ) {
4814  vel_x[ig] = velNew_x[ig];
4815  vel_y[ig] = velNew_y[ig];
4816  vel_z[ig] = velNew_z[ig];
4817  }
4818  }
4819  else {
4820  const float * __restrict mass = patchDataSOA.mass;
4821  double * __restrict f_normal_x = patchDataSOA.f_normal_x;
4822  double * __restrict f_normal_y = patchDataSOA.f_normal_y;
4823  double * __restrict f_normal_z = patchDataSOA.f_normal_z;
4824 #ifdef __INTEL_COMPILER
4825  __assume_aligned(mass,64);
4826  __assume_aligned(f_normal_x,64);
4827  __assume_aligned(f_normal_y,64);
4828  __assume_aligned(f_normal_z,64);
4829 #endif
4830  Tensor vir; // = 0
4831  for (int ig = 0; ig < numAtoms; ig++) {
4832  BigReal df_x = (velNew_x[ig] - vel_x[ig]) * ( mass[ig] * invdt );
4833  BigReal df_y = (velNew_y[ig] - vel_y[ig]) * ( mass[ig] * invdt );
4834  BigReal df_z = (velNew_z[ig] - vel_z[ig]) * ( mass[ig] * invdt );
4835  f_normal_x[ig] += df_x;
4836  f_normal_y[ig] += df_y;
4837  f_normal_z[ig] += df_z;
4838  vir.xx += df_x * pos_x[ig];
4839  vir.xy += df_x * pos_y[ig];
4840  vir.xz += df_x * pos_z[ig];
4841  vir.yx += df_y * pos_x[ig];
4842  vir.yy += df_y * pos_y[ig];
4843  vir.yz += df_y * pos_z[ig];
4844  vir.zx += df_z * pos_x[ig];
4845  vir.zy += df_z * pos_y[ig];
4846  vir.zz += df_z * pos_z[ig];
4847  }
4848  *virial += vir;
4849  for (int ig = 0; ig < numAtoms; ig++) {
4850  vel_x[ig] = velNew_x[ig];
4851  vel_y[ig] = velNew_y[ig];
4852  vel_z[ig] = velNew_z[ig];
4853  }
4854  }
4855 
4856  return 0;
4857 }
static Node * Object()
Definition: Node.h:86
double * vel_y
Definition: NamdTypes.h:397
BigReal zy
Definition: Tensor.h:19
void settle1_SOA(const double *__restrict ref_x, const double *__restrict ref_y, const double *__restrict ref_z, double *__restrict pos_x, double *__restrict pos_y, double *__restrict pos_z, int numWaters, BigReal mOrmT, BigReal mHrmT, BigReal ra, BigReal rb, BigReal rc, BigReal rra)
Definition: Settle.C:1487
BigReal xz
Definition: Tensor.h:17
double * f_normal_z
Definition: NamdTypes.h:430
double * f_normal_y
Definition: NamdTypes.h:429
double * posNew_z
Definition: NamdTypes.h:453
SimParameters * simParameters
Definition: Node.h:181
void MSHAKEIterate(const int icnt, const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, const BigReal tol2, const int maxiter, bool &done, bool &consFailure)
Definition: Settle.C:830
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal yz
Definition: Tensor.h:18
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
double * pos_y
Definition: NamdTypes.h:378
double * velNew_z
Definition: NamdTypes.h:450
std::vector< RattleList > rattleList
Definition: HomePatch.h:449
float * mass
Definition: NamdTypes.h:405
int32 * hydrogenGroupSize
Definition: NamdTypes.h:385
double * f_normal_x
Definition: NamdTypes.h:428
void LINCS(const int icnt, const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, const BigReal tol2, const int maxiter, bool &done, bool &consFailure)
Definition: Settle.C:936
template void rattlePair< 1 >(const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, bool &consFailure)
BigReal yx
Definition: Tensor.h:18
double * vel_x
Jim recommends double precision velocity.
Definition: NamdTypes.h:396
int numAtoms
Definition: Patch.h:151
double * posNew_y
Definition: NamdTypes.h:452
BigReal xx
Definition: Tensor.h:17
void buildRattleList_SOA()
Definition: HomePatch.C:4520
BigReal zz
Definition: Tensor.h:19
std::vector< RattleParam > rattleParam
Definition: HomePatch.h:450
#define simParams
Definition: Output.C:131
double * velNew_y
Definition: NamdTypes.h:449
double * pos_z
Definition: NamdTypes.h:379
Definition: Tensor.h:15
BigReal xy
Definition: Tensor.h:17
bool rattleListValid_SOA
Definition: HomePatch.h:454
double * pos_x
Definition: NamdTypes.h:377
double * vel_z
Definition: NamdTypes.h:398
BigReal yy
Definition: Tensor.h:18
void rattleN(const int icnt, const RattleParam *rattleParam, const BigReal *refx, const BigReal *refy, const BigReal *refz, BigReal *posx, BigReal *posy, BigReal *posz, const BigReal tol2, const int maxiter, bool &done, bool &consFailure)
Definition: Settle.C:1359
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
std::vector< int > noconstList
Definition: HomePatch.h:451
double * posNew_x
Definition: NamdTypes.h:451
BigReal zx
Definition: Tensor.h:19
double * velNew_x
temp storage for rigid bond constraints
Definition: NamdTypes.h:448
double BigReal
Definition: common.h:123

◆ rattle1old()

int HomePatch::rattle1old ( const BigReal  timestep,
Tensor virial,
SubmitReduction ppreduction 
)

Definition at line 3979 of file HomePatch.C.

References Lattice::c(), endi(), Patch::f, getWaterModelGroupSize(), iERROR(), iout, SubmitReduction::item(), iWARN(), Patch::lattice, Node::molecule, NAMD_die(), Results::normal, Patch::numAtoms, Node::Object(), Lattice::origin(), outer(), partition(), settle1(), settle1init(), Node::simParameters, simParams, SWM4, TIMEFACTOR, TIP4, Vector::x, Tensor::xx, Vector::y, Tensor::yy, Vector::z, and Tensor::zz.

Referenced by rattle1().

3981 {
3982  // CkPrintf("Call HomePatch::rattle1old\n");
3983  Molecule *mol = Node::Object()->molecule;
3985  const int fixedAtomsOn = simParams->fixedAtomsOn;
3986  const int useSettle = simParams->useSettle;
3987  const BigReal dt = timestep / TIMEFACTOR;
3988  const BigReal invdt = (dt == 0.) ? 0. : 1.0 / dt; // precalc 1/dt
3989  BigReal tol2 = 2.0 * simParams->rigidTol;
3990  int maxiter = simParams->rigidIter;
3991  int dieOnError = simParams->rigidDie;
3992  int i, iter;
3993  BigReal dsq[10], tmp;
3994  int ial[10], ibl[10];
3995  Vector ref[10]; // reference position
3996  Vector refab[10]; // reference vector
3997  Vector pos[10]; // new position
3998  Vector vel[10]; // new velocity
3999  Vector netdp[10]; // total momentum change from constraint
4000  BigReal rmass[10]; // 1 / mass
4001  int fixed[10]; // is atom fixed?
4002  Tensor wc; // constraint virial
4003  BigReal idz, zmin;
4004  int nslabs;
4005 
4006  // Size of a hydrogen group for water
4007  const WaterModel watmodel = simParams->watmodel;
4008  const int wathgsize = getWaterModelGroupSize(watmodel);
4009 
4010  // Initialize the settle algorithm with water parameters
4011  // settle1() assumes all waters are identical,
4012  // and will generate bad results if they are not.
4013  // XXX this will move to Molecule::build_atom_status when that
4014  // version is debugged
4015  if ( ! settle_initialized ) {
4016  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
4017  // find a water
4018  if (atom[ig].rigidBondLength > 0) {
4019  int oatm;
4020  if (watmodel == WaterModel::SWM4) {
4021  oatm = ig+3; // skip over Drude and Lonepair
4022  //printf("ig=%d mass_ig=%g oatm=%d mass_oatm=%g\n",
4023  // ig, atom[ig].mass, oatm, atom[oatm].mass);
4024  }
4025  else {
4026  oatm = ig+1;
4027  // Avoid using the Om site to set this by mistake
4028  if (atom[ig].mass < 0.5 || atom[ig+1].mass < 0.5) {
4029  oatm += 1;
4030  }
4031  }
4032 
4033  // initialize settle water parameters
4034  settle1init(atom[ig].mass, atom[oatm].mass,
4035  atom[ig].rigidBondLength,
4036  atom[oatm].rigidBondLength,
4037  settle_mO, settle_mH,
4038  settle_mOrmT, settle_mHrmT, settle_ra,
4039  settle_rb, settle_rc, settle_rra);
4040  settle_initialized = 1;
4041  break; // done with init
4042  }
4043  }
4044  }
4045 
4046  if (ppreduction) {
4047  nslabs = simParams->pressureProfileSlabs;
4048  idz = nslabs/lattice.c().z;
4049  zmin = lattice.origin().z - 0.5*lattice.c().z;
4050  }
4051 
4052  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
4053  int hgs = atom[ig].hydrogenGroupSize;
4054  if ( hgs == 1 ) continue; // only one atom in group
4055  // cache data in local arrays and integrate positions normally
4056  int anyfixed = 0;
4057  for ( i = 0; i < hgs; ++i ) {
4058  ref[i] = atom[ig+i].position;
4059  pos[i] = atom[ig+i].position;
4060  vel[i] = atom[ig+i].velocity;
4061  rmass[i] = (atom[ig+i].mass > 0. ? 1. / atom[ig+i].mass : 0.);
4062  //printf("rmass of %i is %f\n", ig+i, rmass[i]);
4063  fixed[i] = ( fixedAtomsOn && atom[ig+i].atomFixed );
4064  //printf("fixed status of %i is %i\n", i, fixed[i]);
4065  // undo addVelocityToPosition to get proper reference coordinates
4066  if ( fixed[i] ) { anyfixed = 1; rmass[i] = 0.; } else pos[i] += vel[i] * dt;
4067  }
4068  int icnt = 0;
4069  if ( ( tmp = atom[ig].rigidBondLength ) > 0 ) { // for water
4070  if (hgs != wathgsize) {
4071  char errmsg[256];
4072  sprintf(errmsg, "Water molecule starting with atom %d contains %d atoms "
4073  "but the specified water model requires %d atoms.\n",
4074  atom[ig].id+1, hgs, wathgsize);
4075  NAMD_die(errmsg);
4076  }
4077  // Use SETTLE for water unless some of the water atoms are fixed,
4078  if (useSettle && !anyfixed) {
4079  if (watmodel == WaterModel::SWM4) {
4080  // SWM4 ordering: O D LP H1 H2
4081  // do swap(O,LP) and call settle with subarray O H1 H2
4082  // swap back after we return
4083  Vector lp_ref = ref[2];
4084  Vector lp_pos = pos[2];
4085  Vector lp_vel = vel[2];
4086  ref[2] = ref[0];
4087  pos[2] = pos[0];
4088  vel[2] = vel[0];
4089  settle1(ref+2, pos+2, vel+2, invdt,
4090  settle_mOrmT, settle_mHrmT, settle_ra,
4091  settle_rb, settle_rc, settle_rra);
4092  ref[0] = ref[2];
4093  pos[0] = pos[2];
4094  vel[0] = vel[2];
4095  ref[2] = lp_ref;
4096  pos[2] = lp_pos;
4097  vel[2] = lp_vel;
4098  // determine for LP updated pos and vel
4099  swm4_omrepos(ref, pos, vel, invdt);
4100  }
4101  else {
4102  settle1(ref, pos, vel, invdt,
4103  settle_mOrmT, settle_mHrmT, settle_ra,
4104  settle_rb, settle_rc, settle_rra);
4105  if (watmodel == WaterModel::TIP4) {
4106  tip4_omrepos(ref, pos, vel, invdt);
4107  }
4108  }
4109 
4110  // which slab the hydrogen group will belong to
4111  // for pprofile calculations.
4112  int ppoffset, partition;
4113  if ( invdt == 0 ) for ( i = 0; i < wathgsize; ++i ) {
4114  atom[ig+i].position = pos[i];
4115  } else if ( virial == 0 ) for ( i = 0; i < wathgsize; ++i ) {
4116  atom[ig+i].velocity = vel[i];
4117  } else for ( i = 0; i < wathgsize; ++i ) {
4118  Force df = (vel[i] - atom[ig+i].velocity) * ( atom[ig+i].mass * invdt );
4119  Tensor vir = outer(df, ref[i]);
4120  wc += vir;
4121  f[Results::normal][ig+i] += df;
4122  atom[ig+i].velocity = vel[i];
4123  if (ppreduction) {
4124  // put all the atoms from a water in the same slab. Atom 0
4125  // should be the parent atom.
4126  if (!i) {
4127  BigReal z = pos[i].z;
4128  partition = atom[ig].partition;
4129  int slab = (int)floor((z-zmin)*idz);
4130  if (slab < 0) slab += nslabs;
4131  else if (slab >= nslabs) slab -= nslabs;
4132  ppoffset = 3*(slab + nslabs*partition);
4133  }
4134  ppreduction->item(ppoffset ) += vir.xx;
4135  ppreduction->item(ppoffset+1) += vir.yy;
4136  ppreduction->item(ppoffset+2) += vir.zz;
4137  }
4138  }
4139  continue;
4140  }
4141  if ( !(fixed[1] && fixed[2]) ) {
4142  dsq[icnt] = tmp * tmp; ial[icnt] = 1; ibl[icnt] = 2; ++icnt;
4143  }
4144  }
4145  for ( i = 1; i < hgs; ++i ) { // normal bonds to mother atom
4146  if ( ( tmp = atom[ig+i].rigidBondLength ) > 0 ) {
4147  if ( !(fixed[0] && fixed[i]) ) {
4148  dsq[icnt] = tmp * tmp; ial[icnt] = 0; ibl[icnt] = i; ++icnt;
4149  }
4150  }
4151  }
4152  if ( icnt == 0 ) continue; // no constraints
4153  for ( i = 0; i < icnt; ++i ) {
4154  refab[i] = ref[ial[i]] - ref[ibl[i]];
4155  }
4156  for ( i = 0; i < hgs; ++i ) {
4157  netdp[i] = 0.;
4158  }
4159  int done;
4160  int consFailure;
4161  for ( iter = 0; iter < maxiter; ++iter ) {
4162 //if (iter > 0) CkPrintf("iteration %d\n", iter);
4163  done = 1;
4164  consFailure = 0;
4165  for ( i = 0; i < icnt; ++i ) {
4166  int a = ial[i]; int b = ibl[i];
4167  Vector pab = pos[a] - pos[b];
4168  BigReal pabsq = pab.x*pab.x + pab.y*pab.y + pab.z*pab.z;
4169  BigReal rabsq = dsq[i];
4170  BigReal diffsq = rabsq - pabsq;
4171  if ( fabs(diffsq) > (rabsq * tol2) ) {
4172  Vector &rab = refab[i];
4173  BigReal rpab = rab.x*pab.x + rab.y*pab.y + rab.z*pab.z;
4174  if ( rpab < ( rabsq * 1.0e-6 ) ) {
4175  done = 0;
4176  consFailure = 1;
4177  continue;
4178  }
4179  BigReal rma = rmass[a];
4180  BigReal rmb = rmass[b];
4181  BigReal gab = diffsq / ( 2.0 * ( rma + rmb ) * rpab );
4182  Vector dp = rab * gab;
4183  pos[a] += rma * dp;
4184  pos[b] -= rmb * dp;
4185  if ( invdt != 0. ) {
4186  dp *= invdt;
4187  netdp[a] += dp;
4188  netdp[b] -= dp;
4189  }
4190  done = 0;
4191  }
4192  }
4193  if ( done ) break;
4194  }
4195 
4196  if ( consFailure ) {
4197  if ( dieOnError ) {
4198  iout << iERROR << "Constraint failure in RATTLE algorithm for atom "
4199  << (atom[ig].id + 1) << "!\n" << endi;
4200  return -1; // triggers early exit
4201  } else {
4202  iout << iWARN << "Constraint failure in RATTLE algorithm for atom "
4203  << (atom[ig].id + 1) << "!\n" << endi;
4204  }
4205  } else if ( ! done ) {
4206  if ( dieOnError ) {
4207  iout << iERROR << "Exceeded RATTLE iteration limit for atom "
4208  << (atom[ig].id + 1) << "!\n" << endi;
4209  return -1; // triggers early exit
4210  } else {
4211  iout << iWARN << "Exceeded RATTLE iteration limit for atom "
4212  << (atom[ig].id + 1) << "!\n" << endi;
4213  }
4214  }
4215 
4216  // store data back to patch
4217  int ppoffset, partition;
4218  if ( invdt == 0 ) for ( i = 0; i < hgs; ++i ) {
4219  atom[ig+i].position = pos[i];
4220  } else if ( virial == 0 ) for ( i = 0; i < hgs; ++i ) {
4221  atom[ig+i].velocity = vel[i] + rmass[i] * netdp[i];
4222  } else for ( i = 0; i < hgs; ++i ) {
4223  Force df = netdp[i] * invdt;
4224  Tensor vir = outer(df, ref[i]);
4225  wc += vir;
4226  f[Results::normal][ig+i] += df;
4227  atom[ig+i].velocity = vel[i] + rmass[i] * netdp[i];
4228  if (ppreduction) {
4229  if (!i) {
4230  BigReal z = pos[i].z;
4231  int partition = atom[ig].partition;
4232  int slab = (int)floor((z-zmin)*idz);
4233  if (slab < 0) slab += nslabs;
4234  else if (slab >= nslabs) slab -= nslabs;
4235  ppoffset = 3*(slab + nslabs*partition);
4236  }
4237  ppreduction->item(ppoffset ) += vir.xx;
4238  ppreduction->item(ppoffset+1) += vir.yy;
4239  ppreduction->item(ppoffset+2) += vir.zz;
4240  }
4241  }
4242  }
4243  if ( dt && virial ) *virial += wc;
4244 
4245  return 0;
4246 }
static Node * Object()
Definition: Node.h:86
NAMD_HOST_DEVICE Vector c() const
Definition: Lattice.h:270
Lattice & lattice
Definition: Patch.h:127
static void partition(int *order, const FullAtom *atoms, int begin, int end)
Definition: SortAtoms.C:45
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
BigReal & item(int i)
Definition: ReductionMgr.h:336
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:174
void settle1init(BigReal pmO, BigReal pmH, BigReal hhdist, BigReal ohdist, BigReal &mO, BigReal &mH, BigReal &mOrmT, BigReal &mHrmT, BigReal &ra, BigReal &rb, BigReal &rc, BigReal &rra)
initialize cached water properties
Definition: Settle.C:46
constexpr int getWaterModelGroupSize(const WaterModel &watmodel)
Definition: common.h:228
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
void NAMD_die(const char *err_msg)
Definition: common.C:147
BigReal xx
Definition: Tensor.h:17
BigReal zz
Definition: Tensor.h:19
#define simParams
Definition: Output.C:131
int settle1(const Vector *ref, Vector *pos, Vector *vel, BigReal invdt, BigReal mOrmT, BigReal mHrmT, BigReal ra, BigReal rb, BigReal rc, BigReal rra)
optimized settle1 algorithm, reuses water properties as much as possible
Definition: Settle.C:63
Definition: Tensor.h:15
BigReal y
Definition: Vector.h:74
BigReal yy
Definition: Tensor.h:18
#define TIMEFACTOR
Definition: common.h:55
std::ostream & iERROR(std::ostream &s)
Definition: InfoStream.C:83
ForceList f[Results::maxNumForces]
Definition: Patch.h:214
WaterModel
Definition: common.h:221
Molecule * molecule
Definition: Node.h:179
NAMD_HOST_DEVICE Vector origin() const
Definition: Lattice.h:278
double BigReal
Definition: common.h:123

◆ rattle2()

void HomePatch::rattle2 ( const BigReal  timestep,
Tensor virial 
)

Definition at line 4249 of file HomePatch.C.

References endi(), getWaterModelGroupSize(), iout, iWARN(), Node::molecule, NAMD_bug(), NAMD_die(), Patch::numAtoms, Node::Object(), outer(), settle2(), Node::simParameters, simParams, SWM4, TIMEFACTOR, TIP4, Vector::x, Vector::y, and Vector::z.

4250 {
4251  Molecule *mol = Node::Object()->molecule;
4253  const int fixedAtomsOn = simParams->fixedAtomsOn;
4254  const int useSettle = simParams->useSettle;
4255  const BigReal dt = timestep / TIMEFACTOR;
4256  Tensor wc; // constraint virial
4257  BigReal tol = simParams->rigidTol;
4258  int maxiter = simParams->rigidIter;
4259  int dieOnError = simParams->rigidDie;
4260  int i, iter;
4261  BigReal dsqi[10], tmp;
4262  int ial[10], ibl[10];
4263  Vector ref[10]; // reference position
4264  Vector refab[10]; // reference vector
4265  Vector vel[10]; // new velocity
4266  BigReal rmass[10]; // 1 / mass
4267  BigReal redmass[10]; // reduced mass
4268  int fixed[10]; // is atom fixed?
4269 
4270  // Size of a hydrogen group for water
4271  const WaterModel watmodel = simParams->watmodel;
4272  const int wathgsize = getWaterModelGroupSize(watmodel);
4273 
4274  // CkPrintf("In rattle2!\n");
4275  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
4276  // CkPrintf("ig=%d\n",ig);
4277  int hgs = atom[ig].hydrogenGroupSize;
4278  if ( hgs == 1 ) continue; // only one atom in group
4279  // cache data in local arrays and integrate positions normally
4280  int anyfixed = 0;
4281  for ( i = 0; i < hgs; ++i ) {
4282  ref[i] = atom[ig+i].position;
4283  vel[i] = atom[ig+i].velocity;
4284  rmass[i] = atom[ig+i].mass > 0. ? 1. / atom[ig+i].mass : 0.;
4285  fixed[i] = ( fixedAtomsOn && atom[ig+i].atomFixed );
4286  if ( fixed[i] ) { anyfixed = 1; rmass[i] = 0.; }
4287  }
4288  int icnt = 0;
4289  if ( ( tmp = atom[ig].rigidBondLength ) > 0 ) { // for water
4290  if (hgs != wathgsize) {
4291  NAMD_bug("Hydrogen group error caught in rattle2().");
4292  }
4293  // Use SETTLE for water unless some of the water atoms are fixed,
4294  if (useSettle && !anyfixed) {
4295  if (watmodel == WaterModel::SWM4) {
4296  // SWM4 ordering: O D LP H1 H2
4297  // do swap(O,LP) and call settle with subarray O H1 H2
4298  // swap back after we return
4299  Vector lp_ref = ref[2];
4300  // Vector lp_vel = vel[2];
4301  ref[2] = ref[0];
4302  vel[2] = vel[0];
4303  settle2(atom[ig].mass, atom[ig+3].mass, ref+2, vel+2, dt, virial);
4304  ref[0] = ref[2];
4305  vel[0] = vel[2];
4306  ref[2] = lp_ref;
4307  // vel[2] = vel[0]; // set LP vel to O vel
4308  }
4309  else {
4310  settle2(atom[ig].mass, atom[ig+1].mass, ref, vel, dt, virial);
4311  if (watmodel == WaterModel::TIP4) {
4312  vel[3] = vel[0];
4313  }
4314  }
4315  for (i=0; i<hgs; i++) {
4316  atom[ig+i].velocity = vel[i];
4317  }
4318  continue;
4319  }
4320  if ( !(fixed[1] && fixed[2]) ) {
4321  redmass[icnt] = 1. / (rmass[1] + rmass[2]);
4322  dsqi[icnt] = 1. / (tmp * tmp); ial[icnt] = 1; ibl[icnt] = 2; ++icnt;
4323  }
4324  }
4325  // CkPrintf("Loop 2\n");
4326  for ( i = 1; i < hgs; ++i ) { // normal bonds to mother atom
4327  if ( ( tmp = atom[ig+i].rigidBondLength ) > 0 ) {
4328  if ( !(fixed[0] && fixed[i]) ) {
4329  redmass[icnt] = 1. / (rmass[0] + rmass[i]);
4330  dsqi[icnt] = 1. / (tmp * tmp); ial[icnt] = 0;
4331  ibl[icnt] = i; ++icnt;
4332  }
4333  }
4334  }
4335  if ( icnt == 0 ) continue; // no constraints
4336  // CkPrintf("Loop 3\n");
4337  for ( i = 0; i < icnt; ++i ) {
4338  refab[i] = ref[ial[i]] - ref[ibl[i]];
4339  }
4340  // CkPrintf("Loop 4\n");
4341  int done;
4342  for ( iter = 0; iter < maxiter; ++iter ) {
4343  done = 1;
4344  for ( i = 0; i < icnt; ++i ) {
4345  int a = ial[i]; int b = ibl[i];
4346  Vector vab = vel[a] - vel[b];
4347  Vector &rab = refab[i];
4348  BigReal rabsqi = dsqi[i];
4349  BigReal rvab = rab.x*vab.x + rab.y*vab.y + rab.z*vab.z;
4350  if ( (fabs(rvab) * dt * rabsqi) > tol ) {
4351  Vector dp = rab * (-rvab * redmass[i] * rabsqi);
4352  wc += outer(dp,rab);
4353  vel[a] += rmass[a] * dp;
4354  vel[b] -= rmass[b] * dp;
4355  done = 0;
4356  }
4357  }
4358  if ( done ) break;
4359  //if (done) { if (iter > 0) CkPrintf("iter=%d\n", iter); break; }
4360  }
4361  if ( ! done ) {
4362  if ( dieOnError ) {
4363  NAMD_die("Exceeded maximum number of iterations in rattle2().");
4364  } else {
4365  iout << iWARN <<
4366  "Exceeded maximum number of iterations in rattle2().\n" << endi;
4367  }
4368  }
4369  // store data back to patch
4370  for ( i = 0; i < hgs; ++i ) {
4371  atom[ig+i].velocity = vel[i];
4372  }
4373  }
4374  // CkPrintf("Leaving rattle2!\n");
4375  // check that there isn't a constant needed here!
4376  *virial += wc / ( 0.5 * dt );
4377 
4378 }
static Node * Object()
Definition: Node.h:86
NAMD_HOST_DEVICE Tensor outer(const Vector &v1, const Vector &v2)
Definition: Tensor.h:241
Definition: Vector.h:72
SimParameters * simParameters
Definition: Node.h:181
std::ostream & endi(std::ostream &s)
Definition: InfoStream.C:54
BigReal z
Definition: Vector.h:74
std::ostream & iWARN(std::ostream &s)
Definition: InfoStream.C:82
#define iout
Definition: InfoStream.h:51
Molecule stores the structural information for the system.
Definition: Molecule.h:174
int settle2(BigReal mO, BigReal mH, const Vector *pos, Vector *vel, BigReal dt, Tensor *virial)
Definition: Settle.C:1473
constexpr int getWaterModelGroupSize(const WaterModel &watmodel)
Definition: common.h:228
void NAMD_bug(const char *err_msg)
Definition: common.C:195
int numAtoms
Definition: Patch.h:151
BigReal x
Definition: Vector.h:74
void NAMD_die(const char *err_msg)
Definition: common.C:147
#define simParams
Definition: Output.C:131
Definition: Tensor.h:15
BigReal y
Definition: Vector.h:74
#define TIMEFACTOR
Definition: common.h:55
WaterModel
Definition: common.h:221
Molecule * molecule
Definition: Node.h:179
double BigReal
Definition: common.h:123

◆ receiveResult() [1/2]

void HomePatch::receiveResult ( ProxyGBISP1ResultMsg msg)

Definition at line 5030 of file HomePatch.C.

References Sequencer::awaken(), Patch::boxesOpen, Flags::doNonbonded, Patch::flags, Patch::psiFin, ProxyGBISP1ResultMsg::psiSum, ProxyGBISP1ResultMsg::psiSumLen, and ResizeArray< Elem >::size().

Referenced by ProxyMgr::recvResult().

5030  {
5031  ++numGBISP1Arrived;
5032  for ( int i = 0; i < msg->psiSumLen; ++i ) {
5033  psiFin[i] += msg->psiSum[i];
5034  }
5035  delete msg;
5036 
5037  if (flags.doNonbonded) {
5038  //awaken if phase 1 done
5039  if (phase1BoxClosedCalled == true &&
5040  numGBISP1Arrived==proxy.size() ) {
5041  // fprintf(stderr, "Calling awaken() on patch %d: 4\n", this->patchID);
5042  sequencer->awaken();
5043  }
5044  } else {
5045  //awaken if all phases done on noWork step
5046  if (boxesOpen == 0 &&
5047  numGBISP1Arrived == proxy.size() &&
5048  numGBISP2Arrived == proxy.size() &&
5049  numGBISP3Arrived == proxy.size()) {
5050  // fprintf(stderr, "Calling awaken() on patch %d: 5\n", this->patchID);
5051  sequencer->awaken();
5052  }
5053  }
5054 }
int size(void) const
Definition: ResizeArray.h:131
GBRealList psiFin
Definition: Patch.h:164
Flags flags
Definition: Patch.h:128
void awaken(void)
Definition: Sequencer.h:55
int boxesOpen
Definition: Patch.h:250
int doNonbonded
Definition: PatchTypes.h:22

◆ receiveResult() [2/2]

void HomePatch::receiveResult ( ProxyGBISP2ResultMsg msg)

Definition at line 5057 of file HomePatch.C.

References Sequencer::awaken(), Patch::boxesOpen, ProxyGBISP2ResultMsg::dEdaSum, ProxyGBISP2ResultMsg::dEdaSumLen, Patch::dHdrPrefix, Flags::doNonbonded, Patch::flags, and ResizeArray< Elem >::size().

5057  {
5058  ++numGBISP2Arrived;
5059  //accumulate dEda
5060  for ( int i = 0; i < msg->dEdaSumLen; ++i ) {
5061  dHdrPrefix[i] += msg->dEdaSum[i];
5062  }
5063  delete msg;
5064 
5065  if (flags.doNonbonded) {
5066  //awaken if phase 2 done
5067  if (phase2BoxClosedCalled == true &&
5068  numGBISP2Arrived==proxy.size() ) {
5069  // fprintf(stderr, "Calling awaken() on patch %d: 6\n", this->patchID);
5070  sequencer->awaken();
5071  }
5072  } else {
5073  //awaken if all phases done on noWork step
5074  if (boxesOpen == 0 &&
5075  numGBISP1Arrived == proxy.size() &&
5076  numGBISP2Arrived == proxy.size() &&
5077  numGBISP3Arrived == proxy.size()) {
5078  // fprintf(stderr, "Calling awaken() on patch %d: 7\n", this->patchID);
5079  sequencer->awaken();
5080  }
5081  }
5082 }
int size(void) const
Definition: ResizeArray.h:131
RealList dHdrPrefix
Definition: Patch.h:166
Flags flags
Definition: Patch.h:128
void awaken(void)
Definition: Sequencer.h:55
int boxesOpen
Definition: Patch.h:250
GBReal * dEdaSum
Definition: ProxyMgr.h:51
int doNonbonded
Definition: PatchTypes.h:22

◆ receiveResults() [1/3]

void HomePatch::receiveResults ( ProxyResultVarsizeMsg msg)

Definition at line 837 of file HomePatch.C.

References OwnerBox< Owner, Data >::clientClose(), OwnerBox< Owner, Data >::clientOpen(), DebugM, Results::f, ProxyResultVarsizeMsg::flLen, ProxyResultVarsizeMsg::forceArr, Patch::forceBox, ProxyResultVarsizeMsg::isZero, Results::maxNumForces, ProxyResultVarsizeMsg::node, and Patch::patchID.

Referenced by ProxyMgr::recvResults().

837  {
838 
839  numGBISP3Arrived++;
840  DebugM(4, "patchID("<<patchID<<") receiveRes() nodeID("<<msg->node<<")\n");
841  int n = msg->node;
842  Results *r = forceBox.clientOpen();
843 
844  char *iszeroPtr = msg->isZero;
845  Force *msgFPtr = msg->forceArr;
846 
847  for ( int k = 0; k < Results::maxNumForces; ++k )
848  {
849  Force *rfPtr = r->f[k];
850  for(int i=0; i<msg->flLen[k]; i++, rfPtr++, iszeroPtr++) {
851  if((*iszeroPtr)!=1) {
852  *rfPtr += *msgFPtr;
853  msgFPtr++;
854  }
855  }
856  }
858  delete msg;
859 }
Data * clientOpen(int count=1)
Definition: OwnerBox.h:58
OwnerBox< Patch, Results > forceBox
Definition: Patch.h:246
int flLen[Results::maxNumForces]
Definition: ProxyMgr.h:179
Definition: Vector.h:72
#define DebugM(x, y)
Definition: Debug.h:75
Force * f[maxNumForces]
Definition: PatchTypes.h:150
void clientClose(int count=1)
Definition: OwnerBox.h:62
const PatchID patchID
Definition: Patch.h:150

◆ receiveResults() [2/3]

void HomePatch::receiveResults ( ProxyResultMsg msg)

Definition at line 861 of file HomePatch.C.

References ResizeArray< Elem >::begin(), OwnerBox< Owner, Data >::clientClose(), OwnerBox< Owner, Data >::clientOpen(), DebugM, ResizeArray< Elem >::end(), Results::f, Patch::f, Patch::forceBox, ProxyResultMsg::forceList, Results::maxNumForces, ProxyResultMsg::node, and Patch::patchID.

861  {
862  numGBISP3Arrived++;
863  DebugM(4, "patchID("<<patchID<<") receiveRes() nodeID("<<msg->node<<")\n");
864  int n = msg->node;
865  Results *r = forceBox.clientOpen();
866  for ( int k = 0; k < Results::maxNumForces; ++k )
867  {
868  Force *f = r->f[k];
869  register ForceList::iterator f_i, f_e;
870  f_i = msg->forceList[k]->begin();
871  f_e = msg->forceList[k]->end();
872  for ( ; f_i != f_e; ++f_i, ++f ) *f += *f_i;
873  }
875  delete msg;
876 }
Data * clientOpen(int count=1)
Definition: OwnerBox.h:58
OwnerBox< Patch, Results > forceBox
Definition: Patch.h:246
Definition: Vector.h:72
#define DebugM(x, y)
Definition: Debug.h:75
Force * f[maxNumForces]
Definition: PatchTypes.h:150
void clientClose(int count=1)
Definition: OwnerBox.h:62
iterator begin(void)
Definition: ResizeArray.h:36
ForceList * forceList[Results::maxNumForces]
Definition: ProxyMgr.h:168
NodeID node
Definition: ProxyMgr.h:166
const PatchID patchID
Definition: Patch.h:150
iterator end(void)
Definition: ResizeArray.h:37
ForceList f[Results::maxNumForces]
Definition: Patch.h:214

◆ receiveResults() [3/3]

void HomePatch::receiveResults ( ProxyCombinedResultRawMsg msg)

Definition at line 878 of file HomePatch.C.

References OwnerBox< Owner, Data >::clientClose(), OwnerBox< Owner, Data >::clientOpen(), DebugM, Results::f, Patch::f, ProxyCombinedResultRawMsg::flLen, ProxyCombinedResultRawMsg::forceArr, Patch::forceBox, ProxyCombinedResultRawMsg::isForceNonZero, Results::maxNumForces, ProxyCombinedResultRawMsg::nodeSize, Patch::patchID, Vector::x, Vector::y, and Vector::z.

879 {
880  numGBISP3Arrived++;
881  DebugM(4, "patchID("<<patchID<<") receiveRes() #nodes("<<msg->nodeSize<<")\n");
882  Results *r = forceBox.clientOpen(msg->nodeSize);
883  register char* isNonZero = msg->isForceNonZero;
884  register Force* f_i = msg->forceArr;
885  for ( int k = 0; k < Results::maxNumForces; ++k )
886  {
887  Force *f = r->f[k];
888  int nf = msg->flLen[k];
889 #ifdef ARCH_POWERPC
890 #pragma disjoint (*f_i, *f)
891 #endif
892  for (int count = 0; count < nf; count++) {
893  if(*isNonZero){
894  f[count].x += f_i->x;
895  f[count].y += f_i->y;
896  f[count].z += f_i->z;
897  f_i++;
898  }
899  isNonZero++;
900  }
901  }
903 
904  delete msg;
905 }
Data * clientOpen(int count=1)
Definition: OwnerBox.h:58
OwnerBox< Patch, Results > forceBox
Definition: Patch.h:246
Definition: Vector.h:72
#define DebugM(x, y)
Definition: Debug.h:75
BigReal z
Definition: Vector.h:74
Force * f[maxNumForces]
Definition: PatchTypes.h:150
void clientClose(int count=1)
Definition: OwnerBox.h:62
BigReal x
Definition: Vector.h:74
const PatchID patchID
Definition: Patch.h:150
BigReal y
Definition: Vector.h:74
int flLen[Results::maxNumForces]
Definition: ProxyMgr.h:233
ForceList f[Results::maxNumForces]
Definition: Patch.h:214

◆ recvCheckpointAck()

void HomePatch::recvCheckpointAck ( )

Definition at line 5365 of file HomePatch.C.

Referenced by PatchMgr::recvCheckpointAck(), and recvCheckpointLoad().

5365  { // initiating replica
5366  CkpvAccess(_qd)->process();
5367 }

◆ recvCheckpointLoad()

void HomePatch::recvCheckpointLoad ( CheckpointAtomsMsg msg)

Definition at line 5301 of file HomePatch.C.

References Patch::atomMapper, CheckpointAtomsMsg::atoms, ResizeArray< Elem >::begin(), CheckpointAtomsMsg::berendsenPressure_count, Sequencer::berendsenPressure_count, buildRattleList_SOA(), checkpoint_task, ResizeArray< Elem >::end(), CheckpointAtomsMsg::key, CheckpointAtomsMsg::lattice, Patch::lattice, NAMD_bug(), CheckpointAtomsMsg::numAtoms, Patch::numAtoms, Node::Object(), PatchMgr::Object(), Patch::patchID, CheckpointAtomsMsg::pe, CheckpointAtomsMsg::pid, rattleListValid, rattleListValid_SOA, recvCheckpointAck(), AtomMapper::registerIDsFullAtom(), CheckpointAtomsMsg::replica, ResizeArray< Elem >::resize(), RIGID_NONE, SCRIPT_CHECKPOINT_FREE, SCRIPT_CHECKPOINT_LOAD, SCRIPT_CHECKPOINT_STORE, SCRIPT_CHECKPOINT_SWAP, PatchMgr::sendCheckpointStore(), Node::simParameters, simParams, and AtomMapper::unregisterIDsFullAtom().

Referenced by PatchMgr::recvCheckpointLoad().

5301  { // initiating replica
5303  const int remote = simParams->scriptIntArg1;
5304  const char *key = simParams->scriptStringArg1;
5306  NAMD_bug("HomePatch::recvCheckpointLoad called during checkpointFree.");
5307  }
5308  if ( msg->replica != remote ) {
5309  NAMD_bug("HomePatch::recvCheckpointLoad message from wrong replica.");
5310  }
5312  CheckpointAtomsMsg *newmsg = new (numAtoms,1+strlen(key),0) CheckpointAtomsMsg;
5313  strcpy(newmsg->key,key);
5314  newmsg->lattice = lattice;
5315  newmsg->berendsenPressure_count = sequencer->berendsenPressure_count;
5316  newmsg->pid = patchID;
5317  newmsg->pe = CkMyPe();
5318  newmsg->replica = CmiMyPartition();
5319  newmsg->numAtoms = numAtoms;
5320  memcpy(newmsg->atoms,atom.begin(),numAtoms*sizeof(FullAtom));
5321  PatchMgr::Object()->sendCheckpointStore(newmsg, remote, msg->pe);
5322  }
5324  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
5325  lattice = msg->lattice;
5327  numAtoms = msg->numAtoms;
5328  atom.resize(numAtoms);
5329  memcpy(atom.begin(),msg->atoms,numAtoms*sizeof(FullAtom));
5330  doAtomUpdate = true;
5331  rattleListValid = false;
5332  rattleListValid_SOA = false;
5333  if ( ! numNeighbors ) atomMapper->registerIDsFullAtom(atom.begin(),atom.end());
5334  if (simParams->SOAintegrateOn) {
5335  sort_solvent_atoms();
5336  copy_atoms_to_SOA();
5337 #if 0
5338  if (simParams->rigidBonds != RIGID_NONE) {
5340  rattleListValid_SOA = true;
5341  }
5342 #endif
5343  }
5344  }
5347  }
5348  delete msg;
5349 }
static Node * Object()
Definition: Node.h:86
Lattice & lattice
Definition: Patch.h:127
void registerIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:50
SimParameters * simParameters
Definition: Node.h:181
AtomMapper * atomMapper
Definition: Patch.h:159
FullAtom * atoms
Definition: PatchMgr.h:89
bool rattleListValid
Definition: HomePatch.h:453
void recvCheckpointAck()
Definition: HomePatch.C:5365
void resize(int i)
Definition: ResizeArray.h:84
void NAMD_bug(const char *err_msg)
Definition: common.C:195
int numAtoms
Definition: Patch.h:151
int berendsenPressure_count
Definition: Sequencer.h:294
void buildRattleList_SOA()
Definition: HomePatch.C:4520
int berendsenPressure_count
Definition: PatchMgr.h:87
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150
iterator end(void)
Definition: ResizeArray.h:37
bool rattleListValid_SOA
Definition: HomePatch.h:454
int checkpoint_task
Definition: HomePatch.h:501
Lattice lattice
Definition: PatchMgr.h:82
void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:100
#define RIGID_NONE
Definition: SimParameters.h:80
void sendCheckpointStore(CheckpointAtomsMsg *msg, int dst, int dstpe)
Definition: PatchMgr.C:335
static PatchMgr * Object()
Definition: PatchMgr.h:152

◆ recvCheckpointReq()

void HomePatch::recvCheckpointReq ( int  task,
const char *  key,
int  replica,
int  pe 
)

Definition at line 5271 of file HomePatch.C.

References CheckpointAtomsMsg::atoms, HomePatch::checkpoint_t::atoms, ResizeArray< Elem >::begin(), CheckpointAtomsMsg::berendsenPressure_count, HomePatch::checkpoint_t::berendsenPressure_count, checkpoints, CheckpointAtomsMsg::lattice, HomePatch::checkpoint_t::lattice, NAMD_die(), CheckpointAtomsMsg::numAtoms, HomePatch::checkpoint_t::numAtoms, PatchMgr::Object(), Patch::patchID, CheckpointAtomsMsg::pe, CheckpointAtomsMsg::pid, CheckpointAtomsMsg::replica, SCRIPT_CHECKPOINT_FREE, SCRIPT_CHECKPOINT_LOAD, SCRIPT_CHECKPOINT_SWAP, PatchMgr::sendCheckpointAck(), and PatchMgr::sendCheckpointLoad().

Referenced by PatchMgr::recvCheckpointReq().

5271  { // responding replica
5272  if ( task == SCRIPT_CHECKPOINT_FREE ) {
5273  if ( ! checkpoints.count(key) ) {
5274  NAMD_die("Unable to free checkpoint, requested key was never stored.");
5275  }
5276  delete checkpoints[key];
5277  checkpoints.erase(key);
5278  PatchMgr::Object()->sendCheckpointAck(patchID, replica, pe);
5279  return;
5280  }
5281  CheckpointAtomsMsg *msg;
5282  if ( task == SCRIPT_CHECKPOINT_LOAD || task == SCRIPT_CHECKPOINT_SWAP ) {
5283  if ( ! checkpoints.count(key) ) {
5284  NAMD_die("Unable to load checkpoint, requested key was never stored.");
5285  }
5286  checkpoint_t &cp = *checkpoints[key];
5287  msg = new (cp.numAtoms,1,0) CheckpointAtomsMsg;
5288  msg->lattice = cp.lattice;
5289  msg->berendsenPressure_count = cp.berendsenPressure_count;
5290  msg->numAtoms = cp.numAtoms;
5291  memcpy(msg->atoms,cp.atoms.begin(),cp.numAtoms*sizeof(FullAtom));
5292  } else {
5293  msg = new (0,1,0) CheckpointAtomsMsg;
5294  }
5295  msg->pid = patchID;
5296  msg->replica = CmiMyPartition();
5297  msg->pe = CkMyPe();
5298  PatchMgr::Object()->sendCheckpointLoad(msg, replica, pe);
5299 }
FullAtom * atoms
Definition: PatchMgr.h:89
void sendCheckpointAck(int pid, int dst, int dstpe)
Definition: PatchMgr.C:360
std::map< std::string, checkpoint_t * > checkpoints
Definition: HomePatch.h:508
void NAMD_die(const char *err_msg)
Definition: common.C:147
int berendsenPressure_count
Definition: PatchMgr.h:87
void sendCheckpointLoad(CheckpointAtomsMsg *msg, int dst, int dstpe)
Definition: PatchMgr.C:310
const PatchID patchID
Definition: Patch.h:150
Lattice lattice
Definition: PatchMgr.h:82
static PatchMgr * Object()
Definition: PatchMgr.h:152

◆ recvCheckpointStore()

void HomePatch::recvCheckpointStore ( CheckpointAtomsMsg msg)

Definition at line 5351 of file HomePatch.C.

References CheckpointAtomsMsg::atoms, HomePatch::checkpoint_t::atoms, ResizeArray< Elem >::begin(), CheckpointAtomsMsg::berendsenPressure_count, HomePatch::checkpoint_t::berendsenPressure_count, checkpoints, CheckpointAtomsMsg::key, CheckpointAtomsMsg::lattice, HomePatch::checkpoint_t::lattice, CheckpointAtomsMsg::numAtoms, HomePatch::checkpoint_t::numAtoms, PatchMgr::Object(), Patch::patchID, CheckpointAtomsMsg::pe, CheckpointAtomsMsg::replica, ResizeArray< Elem >::resize(), and PatchMgr::sendCheckpointAck().

Referenced by PatchMgr::recvCheckpointStore().

5351  { // responding replica
5352  if ( ! checkpoints.count(msg->key) ) {
5353  checkpoints[msg->key] = new checkpoint_t;
5354  }
5355  checkpoint_t &cp = *checkpoints[msg->key];
5356  cp.lattice = msg->lattice;
5357  cp.berendsenPressure_count = msg->berendsenPressure_count;
5358  cp.numAtoms = msg->numAtoms;
5359  cp.atoms.resize(cp.numAtoms);
5360  memcpy(cp.atoms.begin(),msg->atoms,cp.numAtoms*sizeof(FullAtom));
5362  delete msg;
5363 }
FullAtom * atoms
Definition: PatchMgr.h:89
void sendCheckpointAck(int pid, int dst, int dstpe)
Definition: PatchMgr.C:360
std::map< std::string, checkpoint_t * > checkpoints
Definition: HomePatch.h:508
int berendsenPressure_count
Definition: PatchMgr.h:87
const PatchID patchID
Definition: Patch.h:150
Lattice lattice
Definition: PatchMgr.h:82
static PatchMgr * Object()
Definition: PatchMgr.h:152

◆ recvExchangeMsg()

void HomePatch::recvExchangeMsg ( ExchangeAtomsMsg msg)

Definition at line 5402 of file HomePatch.C.

References Patch::atomMapper, ExchangeAtomsMsg::atoms, ResizeArray< Elem >::begin(), buildRattleList_SOA(), ResizeArray< Elem >::end(), ExchangeAtomsMsg::lattice, Patch::lattice, ExchangeAtomsMsg::numAtoms, Patch::numAtoms, Node::Object(), rattleListValid, rattleListValid_SOA, AtomMapper::registerIDsFullAtom(), ResizeArray< Elem >::resize(), RIGID_NONE, Node::simParameters, simParams, and AtomMapper::unregisterIDsFullAtom().

Referenced by PatchMgr::recvExchangeMsg().

5402  {
5403  // CkPrintf("recvExchangeMsg %d %d\n", CmiMyPartition(), exchange_src);
5404  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
5405  lattice = msg->lattice;
5406  numAtoms = msg->numAtoms;
5407  atom.resize(numAtoms);
5408  memcpy(atom.begin(),msg->atoms,numAtoms*sizeof(FullAtom));
5409  delete msg;
5410  CkpvAccess(_qd)->process();
5411  doAtomUpdate = true;
5412  rattleListValid = false;
5413  rattleListValid_SOA = false;
5414  if ( ! numNeighbors ) atomMapper->registerIDsFullAtom(atom.begin(),atom.end());
5416  if (simParams->SOAintegrateOn) {
5417  sort_solvent_atoms();
5418  copy_atoms_to_SOA();
5419 #if 0
5420  if (simParams->rigidBonds != RIGID_NONE) {
5422  rattleListValid_SOA = true;
5423  }
5424 #endif
5425  }
5426 }
static Node * Object()
Definition: Node.h:86
Lattice & lattice
Definition: Patch.h:127
void registerIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:50
SimParameters * simParameters
Definition: Node.h:181
AtomMapper * atomMapper
Definition: Patch.h:159
bool rattleListValid
Definition: HomePatch.h:453
void resize(int i)
Definition: ResizeArray.h:84
Lattice lattice
Definition: PatchMgr.h:109
int numAtoms
Definition: Patch.h:151
void buildRattleList_SOA()
Definition: HomePatch.C:4520
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
iterator end(void)
Definition: ResizeArray.h:37
bool rattleListValid_SOA
Definition: HomePatch.h:454
void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:100
#define RIGID_NONE
Definition: SimParameters.h:80
FullAtom * atoms
Definition: PatchMgr.h:112

◆ recvExchangeReq()

void HomePatch::recvExchangeReq ( int  req)

Definition at line 5391 of file HomePatch.C.

References exchange_dst, exchange_msg, exchange_req, PatchMgr::Object(), and PatchMgr::sendExchangeMsg().

Referenced by exchangeAtoms(), and PatchMgr::recvExchangeReq().

5391  {
5392  exchange_req = req;
5393  if ( exchange_msg ) {
5394  // CkPrintf("recvExchangeReq %d %d\n", CmiMyPartition(), exchange_dst);
5396  exchange_msg = 0;
5397  exchange_req = -1;
5398  CkpvAccess(_qd)->process();
5399  }
5400 }
int exchange_dst
Definition: HomePatch.h:514
ExchangeAtomsMsg * exchange_msg
Definition: HomePatch.h:517
int exchange_req
Definition: HomePatch.h:516
static PatchMgr * Object()
Definition: PatchMgr.h:152
void sendExchangeMsg(ExchangeAtomsMsg *msg, int dst, int dstpe)
Definition: PatchMgr.C:419

◆ recvNodeAwareSpanningTree()

void HomePatch::recvNodeAwareSpanningTree ( ProxyNodeAwareSpanningTreeMsg msg)

Definition at line 671 of file HomePatch.C.

Referenced by ProxyMgr::recvNodeAwareSpanningTreeOnHomePatch().

671 {}

◆ recvSpanningTree()

void HomePatch::recvSpanningTree ( int *  t,
int  n 
)

Definition at line 677 of file HomePatch.C.

References proxySpanDim, ResizeArray< Elem >::resize(), sendSpanningTree(), and ResizeArray< Elem >::size().

Referenced by ProxyMgr::recvSpanningTreeOnHomePatch().

678 {
679  int i;
680  nChild=0;
681  tree.resize(n);
682  for (i=0; i<n; i++) {
683  tree[i] = t[i];
684  }
685 
686  for (i=1; i<=proxySpanDim; i++) {
687  if (tree.size() <= i) break;
688  child[i-1] = tree[i];
689  nChild++;
690  }
691 
692 #if CMK_PERSISTENT_COMM && USE_PERSISTENT_TREE
693  isProxyChanged = 1;
694 #endif
695 
696  // send down to children
698 }
int size(void) const
Definition: ResizeArray.h:131
void resize(int i)
Definition: ResizeArray.h:84
void sendSpanningTree()
Definition: HomePatch.C:700
int proxySpanDim
Definition: ProxyMgr.C:47

◆ registerProxy()

void HomePatch::registerProxy ( RegisterProxyMsg msg)

Definition at line 443 of file HomePatch.C.

References ResizeArray< Elem >::add(), ResizeArray< Elem >::begin(), OwnerBox< Owner, Data >::clientAdd(), DebugM, Patch::forceBox, RegisterProxyMsg::node, Patch::patchID, Random::reorder(), and ResizeArray< Elem >::size().

Referenced by ProxyMgr::recvRegisterProxy().

443  {
444  DebugM(4, "registerProxy("<<patchID<<") - adding node " <<msg->node<<"\n");
445  proxy.add(msg->node);
447 
448  isNewProxyAdded = 1;
449 #if CMK_PERSISTENT_COMM && USE_PERSISTENT_TREE
450  isProxyChanged = 1;
451 #endif
452 
453  Random((patchID + 37) * 137).reorder(proxy.begin(),proxy.size());
454  delete msg;
455 }
int size(void) const
Definition: ResizeArray.h:131
OwnerBox< Patch, Results > forceBox
Definition: Patch.h:246
#define DebugM(x, y)
Definition: Debug.h:75
int add(const Elem &elem)
Definition: ResizeArray.h:101
void reorder(Elem *a, int n)
Definition: Random.h:234
Definition: Random.h:37
iterator begin(void)
Definition: ResizeArray.h:36
void clientAdd()
Definition: OwnerBox.h:77
const PatchID patchID
Definition: Patch.h:150

◆ replaceForces()

void HomePatch::replaceForces ( ExtForce f)

Definition at line 2310 of file HomePatch.C.

References Patch::f.

2311 {
2312  replacementForces = f;
2313 }
ForceList f[Results::maxNumForces]
Definition: Patch.h:214

◆ revert()

void HomePatch::revert ( void  )

Definition at line 5232 of file HomePatch.C.

References Patch::atomMapper, ResizeArray< Elem >::begin(), buildRattleList_SOA(), ResizeArray< Elem >::copy(), ResizeArray< Elem >::end(), Patch::lattice, Patch::numAtoms, Node::Object(), rattleListValid, rattleListValid_SOA, AtomMapper::registerIDsFullAtom(), RIGID_NONE, Node::simParameters, simParams, ResizeArray< Elem >::size(), and AtomMapper::unregisterIDsFullAtom().

Referenced by Sequencer::algorithm().

5232  {
5233  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
5234 
5235  atom.copy(checkpoint_atom);
5236  numAtoms = atom.size();
5237  lattice = checkpoint_lattice;
5238 
5239  doAtomUpdate = true;
5240  rattleListValid = false;
5241  rattleListValid_SOA = false;
5242 
5243  if ( ! numNeighbors ) atomMapper->registerIDsFullAtom(atom.begin(),atom.end());
5244 
5246  if (simParams->SOAintegrateOn) {
5247  sort_solvent_atoms();
5248  copy_atoms_to_SOA();
5249 #if 0
5250  if (simParams->rigidBonds != RIGID_NONE) {
5252  rattleListValid_SOA = true;
5253  }
5254 #endif
5255  }
5256 
5257  // DMK - Atom Separation (water vs. non-water)
5258  #if NAMD_SeparateWaters != 0
5259  numWaterAtoms = checkpoint_numWaterAtoms;
5260  #endif
5261 }
static Node * Object()
Definition: Node.h:86
void copy(ResizeArray< Elem > &ra)
Definition: ResizeArray.h:59
int size(void) const
Definition: ResizeArray.h:131
Lattice & lattice
Definition: Patch.h:127
void registerIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:50
SimParameters * simParameters
Definition: Node.h:181
AtomMapper * atomMapper
Definition: Patch.h:159
bool rattleListValid
Definition: HomePatch.h:453
int numAtoms
Definition: Patch.h:151
void buildRattleList_SOA()
Definition: HomePatch.C:4520
#define simParams
Definition: Output.C:131
iterator begin(void)
Definition: ResizeArray.h:36
iterator end(void)
Definition: ResizeArray.h:37
bool rattleListValid_SOA
Definition: HomePatch.h:454
void unregisterIDsFullAtom(const FullAtom *begin, const FullAtom *end)
Definition: AtomMap.C:100
#define RIGID_NONE
Definition: SimParameters.h:80

◆ runSequencer()

void HomePatch::runSequencer ( void  )

Definition at line 305 of file HomePatch.C.

References Sequencer::run().

Referenced by Node::run().

306 { sequencer->run(); }
void run(void)
Definition: Sequencer.C:269

◆ saveForce()

void HomePatch::saveForce ( const int  ftag = Results::normal)

Definition at line 2315 of file HomePatch.C.

References Patch::f, Patch::numAtoms, and ResizeArray< Elem >::resize().

Referenced by Sequencer::saveForce().

2316 {
2317  f_saved[ftag].resize(numAtoms);
2318  for ( int i = 0; i < numAtoms; ++i )
2319  {
2320  f_saved[ftag][i] = f[ftag][i];
2321  }
2322 }
void resize(int i)
Definition: ResizeArray.h:84
int numAtoms
Definition: Patch.h:151
ForceList f[Results::maxNumForces]
Definition: Patch.h:214

◆ sendNodeAwareSpanningTree()

void HomePatch::sendNodeAwareSpanningTree ( )

Definition at line 672 of file HomePatch.C.

672 {}

◆ sendProxies()

void HomePatch::sendProxies ( )

Definition at line 509 of file HomePatch.C.

References ResizeArray< Elem >::begin(), ProxyMgr::Object(), Patch::patchID, ProxyMgr::sendProxies(), NodeProxyMgr::sendProxyList(), and ResizeArray< Elem >::size().

Referenced by ProxyMgr::buildProxySpanningTree2().

510 {
511 #if USE_NODEPATCHMGR
512  CProxy_NodeProxyMgr pm(CkpvAccess(BOCclass_group).nodeProxyMgr);
513  NodeProxyMgr *npm = pm[CkMyNode()].ckLocalBranch();
514  npm->sendProxyList(patchID, proxy.begin(), proxy.size());
515 #else
516  ProxyMgr::Object()->sendProxies(patchID, proxy.begin(), proxy.size());
517 #endif
518 }
int size(void) const
Definition: ResizeArray.h:131
static ProxyMgr * Object()
Definition: ProxyMgr.h:394
void sendProxies(int pid, int *list, int n)
Definition: ProxyMgr.C:599
void sendProxyList(int pid, int *plist, int size)
Definition: ProxyMgr.C:1978
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150

◆ sendSpanningTree()

void HomePatch::sendSpanningTree ( )

Definition at line 700 of file HomePatch.C.

References ResizeArray< Elem >::copy(), ProxySpanningTreeMsg::node, ProxyMgr::Object(), ProxySpanningTreeMsg::patch, Patch::patchID, ProxyMgr::sendSpanningTree(), ResizeArray< Elem >::size(), and ProxySpanningTreeMsg::tree.

Referenced by buildSpanningTree(), and recvSpanningTree().

701 {
702  if (tree.size() == 0) return;
704  msg->patch = patchID;
705  msg->node = CkMyPe();
706  msg->tree.copy(tree); // copy data for thread safety
708 }
void copy(ResizeArray< Elem > &ra)
Definition: ResizeArray.h:59
int size(void) const
Definition: ResizeArray.h:131
static ProxyMgr * Object()
Definition: ProxyMgr.h:394
NodeIDList tree
Definition: ProxyMgr.h:265
void sendSpanningTree(ProxySpanningTreeMsg *)
Definition: ProxyMgr.C:1154
const PatchID patchID
Definition: Patch.h:150

◆ setGBISIntrinsicRadii()

void HomePatch::setGBISIntrinsicRadii ( )

Definition at line 4900 of file HomePatch.C.

References Patch::intRad, MassToRadius(), MassToScreen(), Node::molecule, Patch::numAtoms, Node::Object(), ResizeArray< Elem >::resize(), ResizeArray< Elem >::setall(), Node::simParameters, and simParams.

Referenced by positionsReady(), and positionsReady_SOA().

4900  {
4901  intRad.resize(numAtoms*2);
4902  intRad.setall(0);
4903  Molecule *mol = Node::Object()->molecule;
4905  Real offset = simParams->coulomb_radius_offset;
4906  for (int i = 0; i < numAtoms; i++) {
4907  Real rad = MassToRadius(atom[i].mass);//in ComputeGBIS.inl
4908  Real screen = MassToScreen(atom[i].mass);//same
4909  intRad[2*i+0] = rad - offset;//r0
4910  intRad[2*i+1] = screen*(rad - offset);//s0
4911  }
4912 }
static Node * Object()
Definition: Node.h:86
RealList intRad
Definition: Patch.h:162
SimParameters * simParameters
Definition: Node.h:181
float Real
Definition: common.h:118
Molecule stores the structural information for the system.
Definition: Molecule.h:174
void resize(int i)
Definition: ResizeArray.h:84
void setall(const Elem &elem)
Definition: ResizeArray.h:94
int numAtoms
Definition: Patch.h:151
#define simParams
Definition: Output.C:131
static float MassToRadius(Mass mi)
Definition: ComputeGBIS.inl:55
static float MassToScreen(Mass mi)
Molecule * molecule
Definition: Node.h:179

◆ setLcpoType()

void HomePatch::setLcpoType ( )

Definition at line 4889 of file HomePatch.C.

References Molecule::getLcpoParamType(), Patch::lcpoType, Node::molecule, Patch::numAtoms, Node::Object(), Patch::pExt, and ResizeArray< Elem >::resize().

Referenced by positionsReady(), and positionsReady_SOA().

4889  {
4890  Molecule *mol = Node::Object()->molecule;
4891  const int *lcpoParamType = mol->getLcpoParamType();
4892 
4894  for (int i = 0; i < numAtoms; i++) {
4895  lcpoType[i] = lcpoParamType[pExt[i].id];
4896  }
4897 }
static Node * Object()
Definition: Node.h:86
Molecule stores the structural information for the system.
Definition: Molecule.h:174
void resize(int i)
Definition: ResizeArray.h:84
int const * getLcpoParamType()
Definition: Molecule.h:508
IntList lcpoType
Definition: Patch.h:171
int numAtoms
Definition: Patch.h:151
CompAtomExtList pExt
Definition: Patch.h:181
Molecule * molecule
Definition: Node.h:179

◆ submitLoadStats()

void HomePatch::submitLoadStats ( int  timestep)

Definition at line 5428 of file HomePatch.C.

References Patch::numAtoms, LdbCoordinator::Object(), Patch::patchID, and LdbCoordinator::patchLoad().

Referenced by Sequencer::rebalanceLoad().

5429 {
5431 }
void patchLoad(PatchID id, int nAtoms, int timestep)
int numAtoms
Definition: Patch.h:151
static LdbCoordinator * Object()
const PatchID patchID
Definition: Patch.h:150

◆ unregisterProxy()

void HomePatch::unregisterProxy ( UnregisterProxyMsg msg)

Definition at line 457 of file HomePatch.C.

References ResizeArray< Elem >::begin(), OwnerBox< Owner, Data >::clientRemove(), ResizeArray< Elem >::del(), Patch::forceBox, and UnregisterProxyMsg::node.

Referenced by ProxyMgr::recvUnregisterProxy().

457  {
458 #if CMK_PERSISTENT_COMM && USE_PERSISTENT_TREE
459  isProxyChanged = 1;
460 #endif
461  int n = msg->node;
462  NodeID *pe = proxy.begin();
463  for ( ; *pe != n; ++pe );
465  proxy.del(pe - proxy.begin());
466  delete msg;
467 }
OwnerBox< Patch, Results > forceBox
Definition: Patch.h:246
void clientRemove()
Definition: OwnerBox.h:91
int32 NodeID
Definition: NamdTypes.h:289
iterator begin(void)
Definition: ResizeArray.h:36
void del(int index, int num=1)
Definition: ResizeArray.h:108

◆ updateAtomBuffers()

void HomePatch::updateAtomBuffers ( )

◆ updateAtomCount()

void HomePatch::updateAtomCount ( const int  n,
const int  reallocate 
)

◆ useSequencer()

void HomePatch::useSequencer ( Sequencer sequencerPtr)

Definition at line 301 of file HomePatch.C.

302 { sequencer=sequencerPtr; }

Friends And Related Function Documentation

◆ ComputeGlobal

friend class ComputeGlobal
friend

Definition at line 336 of file HomePatch.h.

◆ PatchMgr

friend class PatchMgr
friend

Definition at line 330 of file HomePatch.h.

◆ Sequencer

friend class Sequencer
friend

Definition at line 331 of file HomePatch.h.

◆ SequencerCUDA

friend class SequencerCUDA
friend

Definition at line 334 of file HomePatch.h.

Member Data Documentation

◆ checkpoint_task

int HomePatch::checkpoint_task

Definition at line 501 of file HomePatch.h.

Referenced by exchangeCheckpoint(), and recvCheckpointLoad().

◆ checkpoints

std::map<std::string,checkpoint_t*> HomePatch::checkpoints

Definition at line 508 of file HomePatch.h.

Referenced by recvCheckpointReq(), and recvCheckpointStore().

◆ exchange_dst

int HomePatch::exchange_dst

Definition at line 514 of file HomePatch.h.

Referenced by exchangeAtoms(), and recvExchangeReq().

◆ exchange_msg

ExchangeAtomsMsg* HomePatch::exchange_msg

Definition at line 517 of file HomePatch.h.

Referenced by exchangeAtoms(), and recvExchangeReq().

◆ exchange_req

int HomePatch::exchange_req

Definition at line 516 of file HomePatch.h.

Referenced by exchangeAtoms(), and recvExchangeReq().

◆ exchange_src

int HomePatch::exchange_src

Definition at line 515 of file HomePatch.h.

Referenced by exchangeAtoms().

◆ gridForceIdxChecked

bool HomePatch::gridForceIdxChecked

Definition at line 402 of file HomePatch.h.

Referenced by ComputeGridForce::doForce(), and positionsReady().

◆ inMigration

int HomePatch::inMigration
protected

Definition at line 569 of file HomePatch.h.

Referenced by depositMigration(), and doAtomMigration().

◆ ldObjHandle

LDObjHandle HomePatch::ldObjHandle

◆ marginViolations

int HomePatch::marginViolations

◆ msgbuf

MigrateAtomsMsg* HomePatch::msgbuf[PatchMap::MaxOneAway]
protected

Definition at line 571 of file HomePatch.h.

Referenced by depositMigration(), and doAtomMigration().

◆ noconstList

std::vector<int> HomePatch::noconstList

Definition at line 451 of file HomePatch.h.

Referenced by buildRattleList(), buildRattleList_SOA(), rattle1(), and rattle1_SOA().

◆ numMlBuf

int HomePatch::numMlBuf
protected

Definition at line 570 of file HomePatch.h.

Referenced by depositMigration(), and doAtomMigration().

◆ posNew

std::vector<Vector> HomePatch::posNew

Definition at line 458 of file HomePatch.h.

Referenced by buildRattleList(), and rattle1().

◆ rattleList

std::vector<RattleList> HomePatch::rattleList

Definition at line 449 of file HomePatch.h.

Referenced by buildRattleList(), buildRattleList_SOA(), rattle1(), and rattle1_SOA().

◆ rattleListValid

bool HomePatch::rattleListValid

◆ rattleListValid_SOA

bool HomePatch::rattleListValid_SOA

◆ rattleParam

std::vector<RattleParam> HomePatch::rattleParam

Definition at line 450 of file HomePatch.h.

Referenced by buildRattleList(), buildRattleList_SOA(), rattle1(), and rattle1_SOA().

◆ settleList

std::vector<int> HomePatch::settleList

Definition at line 448 of file HomePatch.h.

Referenced by buildRattleList(), and rattle1().

◆ velNew

std::vector<Vector> HomePatch::velNew

Definition at line 457 of file HomePatch.h.

Referenced by addRattleForce(), buildRattleList(), and rattle1().


The documentation for this class was generated from the following files: