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 3315 of file HomePatch.C.

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

Referenced by Sequencer::addForceToMomentum().

3320  {
3322 
3323  if ( simParams->fixedAtomsOn ) {
3324  for ( int i = 0; i < num_atoms; ++i ) {
3325  if ( atom_arr[i].atomFixed ) {
3326  atom_arr[i].velocity = 0;
3327  } else {
3328  BigReal dt_mass = dt * atom_arr[i].recipMass; // dt/mass
3329  atom_arr[i].velocity.x += force_arr[i].x * dt_mass;
3330  atom_arr[i].velocity.y += force_arr[i].y * dt_mass;
3331  atom_arr[i].velocity.z += force_arr[i].z * dt_mass;
3332  }
3333  }
3334  } else {
3335  for ( int i = 0; i < num_atoms; ++i ) {
3336  BigReal dt_mass = dt * atom_arr[i].recipMass; // dt/mass
3337  atom_arr[i].velocity.x += force_arr[i].x * dt_mass;
3338  atom_arr[i].velocity.y += force_arr[i].y * dt_mass;
3339  atom_arr[i].velocity.z += force_arr[i].z * dt_mass;
3340  }
3341  }
3342 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Velocity velocity
Definition: NamdTypes.h:201
BigReal x
Definition: Vector.h:74
#define simParams
Definition: Output.C:129
BigReal y
Definition: Vector.h:74
double recipMass
Definition: NamdTypes.h:203
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 3344 of file HomePatch.C.

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

Referenced by Sequencer::addForceToMomentum3().

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

◆ addRattleForce()

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

Definition at line 3774 of file HomePatch.C.

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

Referenced by rattle1().

3774  {
3775  for (int ig = 0; ig < numAtoms; ++ig ) {
3776  Force df = (velNew[ig] - atom[ig].velocity) * ( atom[ig].mass * invdt );
3777  Tensor vir = outer(df, atom[ig].position);
3778  wc += vir;
3779  f[Results::normal][ig] += df;
3780  atom[ig].velocity = velNew[ig];
3781  }
3782 }
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 3383 of file HomePatch.C.

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

Referenced by Sequencer::addVelocityToPosition().

3387  {
3389  if ( simParams->fixedAtomsOn ) {
3390  for ( int i = 0; i < num_atoms; ++i ) {
3391  if ( ! atom_arr[i].atomFixed ) {
3392  atom_arr[i].position.x += atom_arr[i].velocity.x * dt;
3393  atom_arr[i].position.y += atom_arr[i].velocity.y * dt;
3394  atom_arr[i].position.z += atom_arr[i].velocity.z * dt;
3395  }
3396  }
3397  } else {
3398  for ( int i = 0; i < num_atoms; ++i ) {
3399  atom_arr[i].position.x += atom_arr[i].velocity.x * dt;
3400  atom_arr[i].position.y += atom_arr[i].velocity.y * dt;
3401  atom_arr[i].position.z += atom_arr[i].velocity.z * dt;
3402  }
3403  }
3404 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Position position
Definition: NamdTypes.h:77
Velocity velocity
Definition: NamdTypes.h:201
BigReal x
Definition: Vector.h:74
#define simParams
Definition: Output.C:129
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:53
int boxesOpen
Definition: Patch.h:250
int numAtoms
Definition: Patch.h:151
int doNonbonded
Definition: PatchTypes.h:22
Force force
Definition: NamdTypes.h:297
#define simParams
Definition: Output.C:129
const PatchID patchID
Definition: Patch.h:150
OwnerBox< Patch, GBReal > dEdaSumBox
Definition: Patch.h:236
int doGBIS
Definition: PatchTypes.h:29
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 3612 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().

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

References RattleParam::dsq, Patch::flags, getWaterModelGroupSize(), PatchDataSOA::hydrogenGroupSize, RattleParam::ia, RattleParam::ib, HomePatch::RattleList::icnt, HomePatch::RattleList::ig, PatchDataSOA::mass, 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().

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

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

Referenced by Sequencer::algorithm().

5216  {
5217  checkpoint_atom.copy(atom);
5218  checkpoint_lattice = lattice;
5219 
5220  // DMK - Atom Separation (water vs. non-water)
5221  #if NAMD_SeparateWaters != 0
5222  checkpoint_numWaterAtoms = numWaterAtoms;
5223  #endif
5224 }
void copy(ResizeArray< Elem > &ra)
Definition: ResizeArray.h:59
Lattice & lattice
Definition: Patch.h:127

◆ depositMigration()

void HomePatch::depositMigration ( MigrateAtomsMsg msg)

Definition at line 5956 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().

5957 {
5958 
5959  if (!inMigration) { // We have to buffer changes due to migration
5960  // until our patch is in migration mode
5961  msgbuf[numMlBuf++] = msg;
5962  return;
5963  }
5964 
5965  // DMK - Atom Separation (water vs. non-water)
5966  #if NAMD_SeparateWaters != 0
5967 
5968 
5969  // Merge the incoming list of atoms with the current list of
5970  // atoms. Note that mergeSeparatedAtomList() will apply any
5971  // required transformations to the incoming atoms as it is
5972  // separating them.
5973  mergeAtomList(msg->migrationList);
5974 
5975 
5976  #else
5977 
5978  // Merge the incoming list of atoms with the current list of
5979  // atoms. Apply transformations to the incoming atoms as they are
5980  // added to this patch's list.
5981  {
5982  MigrationList &migrationList = msg->migrationList;
5984  Transform mother_transform;
5985  for (mi = migrationList.begin(); mi != migrationList.end(); mi++) {
5986  DebugM(1,"Migrating atom " << mi->id << " to patch "
5987  << patchID << " with position " << mi->position << "\n");
5988  if ( mi->migrationGroupSize ) {
5989  if ( mi->migrationGroupSize != mi->hydrogenGroupSize ) {
5990  Position pos = mi->position;
5991  int mgs = mi->migrationGroupSize;
5992  int c = 1;
5993  for ( int j=mi->hydrogenGroupSize; j<mgs;
5994  j+=(mi+j)->hydrogenGroupSize ) {
5995  pos += (mi+j)->position;
5996  ++c;
5997  }
5998  pos *= 1./c;
5999  // iout << "mgroup " << mi->id << " at " << pos << "\n" << endi;
6000  mother_transform = mi->transform;
6001  pos = lattice.nearest(pos,center,&mother_transform);
6003  mi->position = lattice.apply_transform(mi->position,mother_transform);
6004  mi->transform = mother_transform;
6005  } else {
6006  mi->position = lattice.nearest(mi->position,center,&(mi->transform));
6007  mother_transform = mi->transform;
6008  }
6009  } else {
6011  mi->position = lattice.apply_transform(mi->position,mother_transform);
6012  mi->transform = mother_transform;
6013  }
6014  atom.add(*mi);
6015  }
6016  }
6017 
6018 
6019  #endif // if (NAMD_SeparateWaters != 0)
6020 
6021 
6022  numAtoms = atom.size();
6023  delete msg;
6024 
6025  DebugM(3,"Counter on " << patchID << " = " << patchMigrationCounter << "\n");
6026  if (!--patchMigrationCounter) {
6027  // DH - All atoms are now incorporated from migration.
6028  // This is where we can separate waters from non-waters and
6029  // perhaps sort non-waters by hydrogen group size.
6031  if (simParams->SOAintegrateOn) {
6032  sort_solvent_atoms();
6033  copy_atoms_to_SOA();
6034 #if 0
6035  if (simParams->rigidBonds != RIGID_NONE) {
6037  rattleListValid_SOA = true;
6038  }
6039 #endif
6040  }
6041  DebugM(3,"All Migrations are in for patch "<<patchID<<"\n");
6042  allMigrationIn = true;
6043  patchMigrationCounter = numNeighbors;
6044  if (migrationSuspended) {
6045  DebugM(3,"patch "<<patchID<<" is being awakened\n");
6046  migrationSuspended = false;
6047  // fprintf(stderr, "Calling awaken() on patch %d: 8\n", this->patchID);
6048  sequencer->awaken();
6049  return;
6050  }
6051  else {
6052  DebugM(3,"patch "<<patchID<<" was not suspended\n");
6053  }
6054  }
6055 }
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:77
int inMigration
Definition: HomePatch.h:569
int add(const Elem &elem)
Definition: ResizeArray.h:101
uint32 id
Definition: NamdTypes.h:156
void awaken(void)
Definition: Sequencer.h:53
NAMD_HOST_DEVICE Position apply_transform(Position data, const Transform &t) const
Definition: Lattice.h:137
int32 migrationGroupSize
Definition: NamdTypes.h:220
int numAtoms
Definition: Patch.h:151
uint8 hydrogenGroupSize
Definition: NamdTypes.h:88
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:4516
#define simParams
Definition: Output.C:129
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:79
int numMlBuf
Definition: HomePatch.h:570
Transform transform
Definition: NamdTypes.h:219

◆ doAtomMigration()

void HomePatch::doAtomMigration ( )
protected

Definition at line 5792 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().

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

5585 {
5586  if ( ! flags.doNonbonded ) return;
5587 
5589  BigReal hgcut = 0.5 * simParams->hgroupCutoff; hgcut *= hgcut;
5590  BigReal maxrad2 = 0.;
5591 
5592  FullAtomList::iterator p_i = atom.begin();
5593  FullAtomList::iterator p_e = atom.end();
5594 
5595  while ( p_i != p_e ) {
5596  const int hgs = p_i->hydrogenGroupSize;
5597  if ( ! hgs ) break; // avoid infinite loop on bug
5598  int ngs = hgs;
5599  if ( ngs > 5 ) ngs = 5; // XXX why? limit to at most 5 atoms per group
5600  BigReal x = p_i->position.x;
5601  BigReal y = p_i->position.y;
5602  BigReal z = p_i->position.z;
5603  int i;
5604  for ( i = 1; i < ngs; ++i ) { // limit spatial extent
5605  p_i[i].nonbondedGroupSize = 0;
5606  BigReal dx = p_i[i].position.x - x;
5607  BigReal dy = p_i[i].position.y - y;
5608  BigReal dz = p_i[i].position.z - z;
5609  BigReal r2 = dx * dx + dy * dy + dz * dz;
5610  if ( r2 > hgcut ) break;
5611  else if ( r2 > maxrad2 ) maxrad2 = r2;
5612  }
5613  p_i->nonbondedGroupSize = i;
5614  for ( ; i < hgs; ++i ) {
5615  p_i[i].nonbondedGroupSize = 1;
5616  }
5617  p_i += hgs;
5618  }
5619 
5620  if ( p_i != p_e ) {
5621  NAMD_bug("hydrogenGroupSize is zero in HomePatch::doGroupSizeCheck");
5622  }
5623 
5624  flags.maxGroupRadius = sqrt(maxrad2);
5625 
5626 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
BigReal z
Definition: Vector.h:74
Position position
Definition: NamdTypes.h:77
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:88
int doNonbonded
Definition: PatchTypes.h:22
uint8 nonbondedGroupSize
Definition: NamdTypes.h:81
#define simParams
Definition: Output.C:129
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:43
double BigReal
Definition: common.h:123

◆ doGroupSizeCheck_SOA()

void HomePatch::doGroupSizeCheck_SOA ( )
protected

Definition at line 5531 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().

5532 {
5533  if ( ! flags.doNonbonded ) return;
5534 
5536  BigReal hgcut = 0.5 * simParams->hgroupCutoff; hgcut *= hgcut;
5537  BigReal maxrad2 = 0.;
5538 
5539  double * __restrict pos_x = patchDataSOA.pos_x;
5540  double * __restrict pos_y = patchDataSOA.pos_y;
5541  double * __restrict pos_z = patchDataSOA.pos_z;
5542  int * __restrict hydrogenGroupSize = patchDataSOA.hydrogenGroupSize;
5543  int * __restrict nonbondedGroupSize = patchDataSOA.nonbondedGroupSize;
5544 
5545  int j=0;
5546  while (j < numAtoms) {
5547  const int hgs = hydrogenGroupSize[j];
5548  if ( ! hgs ) break; // avoid infinite loop on bug
5549  int ngs = hgs;
5550  if ( ngs > 5 ) ngs = 5; // XXX why? limit to at most 5 atoms per group
5551  BigReal x = pos_x[j];
5552  BigReal y = pos_y[j];
5553  BigReal z = pos_z[j];
5554  int i;
5555  for ( i = 1; i < ngs; ++i ) { // limit spatial extent
5556  nonbondedGroupSize[j+i] = 0;
5557  BigReal dx = pos_x[j+i] - x;
5558  BigReal dy = pos_y[j+i] - y;
5559  BigReal dz = pos_z[j+i] - z;
5560  BigReal r2 = dx * dx + dy * dy + dz * dz;
5561  if ( r2 > hgcut ) break;
5562  else if ( r2 > maxrad2 ) maxrad2 = r2;
5563  }
5564  nonbondedGroupSize[j] = i;
5565  for ( ; i < hgs; ++i ) {
5566  nonbondedGroupSize[j+i] = 1;
5567  }
5568  j += hgs;
5569  }
5570 
5571  if (j != numAtoms) {
5572  NAMD_bug("hydrogenGroupSize is zero in HomePatch::doGroupSizeCheck");
5573  }
5574 
5575  flags.maxGroupRadius = sqrt(maxrad2);
5576 
5577 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
double * pos_y
Definition: NamdTypes.h:368
Flags flags
Definition: Patch.h:128
int32 * hydrogenGroupSize
Definition: NamdTypes.h:375
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:129
double * pos_z
Definition: NamdTypes.h:369
double * pos_x
Definition: NamdTypes.h:367
int32 * nonbondedGroupSize
Definition: NamdTypes.h:374
BigReal maxGroupRadius
Definition: PatchTypes.h:43
double BigReal
Definition: common.h:123

◆ doMarginCheck()

void HomePatch::doMarginCheck ( )
protected

Definition at line 5715 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().

5716 {
5718 
5719  BigReal sysdima = lattice.a_r().unit() * lattice.a();
5720  BigReal sysdimb = lattice.b_r().unit() * lattice.b();
5721  BigReal sysdimc = lattice.c_r().unit() * lattice.c();
5722 
5723  BigReal minSize = simParams->patchDimension - simParams->margin;
5724 
5725  if ( ( aAwayDist*sysdima < minSize*0.9999 ) ||
5726  ( bAwayDist*sysdimb < minSize*0.9999 ) ||
5727  ( cAwayDist*sysdimc < minSize*0.9999 ) ) {
5728 
5729  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5730  "Possible solutions are to restart from a recent checkpoint,\n"
5731  "increase margin, or disable useFlexibleCell for liquid simulation.");
5732  }
5733 
5734  BigReal cutoff = simParams->cutoff;
5735 
5736  BigReal margina = 0.5 * ( aAwayDist - cutoff / sysdima );
5737  BigReal marginb = 0.5 * ( bAwayDist - cutoff / sysdimb );
5738  BigReal marginc = 0.5 * ( cAwayDist - cutoff / sysdimc );
5739 
5740  if ( (margina < -0.0001) || (marginb < -0.0001) || (marginc < -0.0001) ) {
5741  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5742  "There are probably many margin violations already reported.\n"
5743  "Possible solutions are to restart from a recent checkpoint,\n"
5744  "increase margin, or disable useFlexibleCell for liquid simulation.");
5745  }
5746 
5747  BigReal minx = min.x - margina;
5748  BigReal miny = min.y - marginb;
5749  BigReal minz = min.z - marginc;
5750  BigReal maxx = max.x + margina;
5751  BigReal maxy = max.y + marginb;
5752  BigReal maxz = max.z + marginc;
5753 
5754  int xdev, ydev, zdev;
5755  int problemCount = 0;
5756 
5757  FullAtomList::iterator p_i = atom.begin();
5758  FullAtomList::iterator p_e = atom.end();
5759  for ( ; p_i != p_e; ++p_i ) {
5760 
5762 
5763  // check if atom is within bounds
5764  if (s.x < minx) xdev = 0;
5765  else if (maxx <= s.x) xdev = 2;
5766  else xdev = 1;
5767 
5768  if (s.y < miny) ydev = 0;
5769  else if (maxy <= s.y) ydev = 2;
5770  else ydev = 1;
5771 
5772  if (s.z < minz) zdev = 0;
5773  else if (maxz <= s.z) zdev = 2;
5774  else zdev = 1;
5775 
5776  if (mInfo[xdev][ydev][zdev]) { // somewhere else to be
5777  ++problemCount;
5778  }
5779 
5780  }
5781 
5782  marginViolations = problemCount;
5783  // if ( problemCount ) {
5784  // iout << iERROR <<
5785  // "Found " << problemCount << " margin violations!\n" << endi;
5786  // }
5787 
5788 }
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:77
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:129
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 5633 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().

5634 {
5636 
5637  BigReal sysdima = lattice.a_r().unit() * lattice.a();
5638  BigReal sysdimb = lattice.b_r().unit() * lattice.b();
5639  BigReal sysdimc = lattice.c_r().unit() * lattice.c();
5640 
5641  BigReal minSize = simParams->patchDimension - simParams->margin;
5642 
5643  if ( ( aAwayDist*sysdima < minSize*0.9999 ) ||
5644  ( bAwayDist*sysdimb < minSize*0.9999 ) ||
5645  ( cAwayDist*sysdimc < minSize*0.9999 ) ) {
5646 
5647  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5648  "Possible solutions are to restart from a recent checkpoint,\n"
5649  "increase margin, or disable useFlexibleCell for liquid simulation.");
5650  }
5651 
5652  BigReal cutoff = simParams->cutoff;
5653 
5654  BigReal margina = 0.5 * ( aAwayDist - cutoff / sysdima );
5655  BigReal marginb = 0.5 * ( bAwayDist - cutoff / sysdimb );
5656  BigReal marginc = 0.5 * ( cAwayDist - cutoff / sysdimc );
5657 
5658  if ( (margina < -0.0001) || (marginb < -0.0001) || (marginc < -0.0001) ) {
5659  NAMD_die("Periodic cell has become too small for original patch grid!\n"
5660  "There are probably many margin violations already reported.\n"
5661  "Possible solutions are to restart from a recent checkpoint,\n"
5662  "increase margin, or disable useFlexibleCell for liquid simulation.");
5663  }
5664 
5665  BigReal minx = min.x - margina;
5666  BigReal miny = min.y - marginb;
5667  BigReal minz = min.z - marginc;
5668  BigReal maxx = max.x + margina;
5669  BigReal maxy = max.y + marginb;
5670  BigReal maxz = max.z + marginc;
5671 
5672  int xdev, ydev, zdev;
5673  int problemCount = 0;
5674 
5675  double * __restrict pos_x = patchDataSOA.pos_x;
5676  double * __restrict pos_y = patchDataSOA.pos_y;
5677  double * __restrict pos_z = patchDataSOA.pos_z;
5678  for (int i=0; i < numAtoms; i++) {
5679  Vector pos(pos_x[i],pos_y[i],pos_z[i]);
5680 
5681  ScaledPosition s = lattice.scale(pos);
5682 
5683  // check if atom is within bounds
5684  if (s.x < minx) xdev = 0;
5685  else if (maxx <= s.x) xdev = 2;
5686  else xdev = 1;
5687 
5688  if (s.y < miny) ydev = 0;
5689  else if (maxy <= s.y) ydev = 2;
5690  else ydev = 1;
5691 
5692  if (s.z < minz) zdev = 0;
5693  else if (maxz <= s.z) zdev = 2;
5694  else zdev = 1;
5695 
5696  if (mInfo[xdev][ydev][zdev]) { // somewhere else to be
5697  ++problemCount;
5698  }
5699 
5700  }
5701 
5702  marginViolations = problemCount;
5703  // if ( problemCount ) {
5704  // iout << iERROR <<
5705  // "Found " << problemCount << " margin violations!\n" << endi;
5706  // }
5707 
5708 }
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:368
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:129
double * pos_z
Definition: NamdTypes.h:369
double * pos_x
Definition: NamdTypes.h:367
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 5432 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().

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

◆ exchangeAtoms()

void HomePatch::exchangeAtoms ( int  scriptTask)

Definition at line 5364 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().

5364  {
5366  // CkPrintf("exchangeAtoms %d %d %d %d\n", CmiMyPartition(), scriptTask, (int)(simParams->scriptArg1), (int)(simParams->scriptArg2));
5367  if ( scriptTask == SCRIPT_ATOMSEND || scriptTask == SCRIPT_ATOMSENDRECV ) {
5368  exchange_dst = (int) simParams->scriptArg1;
5369  // create and save outgoing message
5374  memcpy(exchange_msg->atoms,atom.begin(),numAtoms*sizeof(FullAtom));
5375  if ( exchange_req >= 0 ) {
5377  }
5378  }
5379  if ( scriptTask == SCRIPT_ATOMRECV || scriptTask == SCRIPT_ATOMSENDRECV ) {
5380  exchange_src = (int) simParams->scriptArg2;
5382  }
5383 }
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:129
iterator begin(void)
Definition: ResizeArray.h:36
const PatchID patchID
Definition: Patch.h:150
void recvExchangeReq(int req)
Definition: HomePatch.C:5385
FullAtom * atoms
Definition: PatchMgr.h:112
static PatchMgr * Object()
Definition: PatchMgr.h:152

◆ exchangeCheckpoint()

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

Definition at line 5257 of file HomePatch.C.

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

Referenced by Sequencer::algorithm().

5257  { // initiating replica
5259  checkpoint_task = scriptTask;
5260  const int remote = simParams->scriptIntArg1;
5261  const char *key = simParams->scriptStringArg1;
5262  PatchMgr::Object()->sendCheckpointReq(patchID, remote, key, scriptTask);
5263 }
static Node * Object()
Definition: Node.h:86
SimParameters * simParameters
Definition: Node.h:181
#define simParams
Definition: Output.C:129
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 4909 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().

4909  {
4910 
4912  BigReal alphaMax = simParams->alpha_max;
4913  BigReal delta = simParams->gbis_delta;
4914  BigReal beta = simParams->gbis_beta;
4915  BigReal gamma = simParams->gbis_gamma;
4916  BigReal coulomb_radius_offset = simParams->coulomb_radius_offset;
4917 
4918  BigReal rhoi;
4919  BigReal rhoi0;
4920  //calculate bornRad from psiSum
4921  for (int i = 0; i < numAtoms; i++) {
4922  rhoi0 = intRad[2*i];
4923  rhoi = rhoi0+coulomb_radius_offset;
4924  psiFin[i] += psiSum[i];
4925  psiFin[i] *= rhoi0;
4926  bornRad[i]=1/(1/rhoi0-1/rhoi*tanh(psiFin[i]*(delta+psiFin[i]*(-beta+gamma*psiFin[i]))));
4927  bornRad[i] = (bornRad[i] > alphaMax) ? alphaMax : bornRad[i];
4928 #ifdef PRINT_COMP
4929  CkPrintf("BORNRAD(%04i)[%04i] = % .4e\n",flags.sequence,pExt[i].id,bornRad[i]);
4930 #endif
4931  }
4932 
4933  gbisP2Ready();
4934 }
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:4981
#define simParams
Definition: Output.C:129
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 4937 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().

4937  {
4938 
4940  BigReal delta = simParams->gbis_delta;
4941  BigReal beta = simParams->gbis_beta;
4942  BigReal gamma = simParams->gbis_gamma;
4943  BigReal epsilon_s = simParams->solvent_dielectric;
4944  BigReal epsilon_p = simParams->dielectric;
4945  BigReal epsilon_s_i = 1/simParams->solvent_dielectric;
4946  BigReal epsilon_p_i = 1/simParams->dielectric;
4947  BigReal coulomb_radius_offset = simParams->coulomb_radius_offset;
4948  BigReal kappa = simParams->kappa;
4949  BigReal fij, expkappa, Dij, dEdai, dedasum;
4950  BigReal rhoi, rhoi0, psii, nbetapsi;
4951  BigReal gammapsi2, tanhi, daidr;
4952  for (int i = 0; i < numAtoms; i++) {
4953  //add diagonal dEda term
4954  dHdrPrefix[i] += dEdaSum[i];//accumulated from proxies
4955  fij = bornRad[i];//inf
4956  expkappa = exp(-kappa*fij);//0
4957  Dij = epsilon_p_i - expkappa*epsilon_s_i;//dielectric term
4958  //calculate dHij prefix
4959  dEdai = -0.5*COULOMB*atom[i].charge*atom[i].charge
4960  *(kappa*epsilon_s_i*expkappa-Dij/fij)/bornRad[i];
4961  dHdrPrefix[i] += dEdai;
4962  dedasum = dHdrPrefix[i];
4963 
4964  rhoi0 = intRad[2*i];
4965  rhoi = rhoi0+coulomb_radius_offset;
4966  psii = psiFin[i];
4967  nbetapsi = -beta*psii;
4968  gammapsi2 = gamma*psii*psii;
4969  tanhi = tanh(psii*(delta+nbetapsi+gammapsi2));
4970  daidr = bornRad[i]*bornRad[i]*rhoi0/rhoi*(1-tanhi*tanhi)
4971  * (delta+nbetapsi+nbetapsi+gammapsi2+gammapsi2+gammapsi2);
4972  dHdrPrefix[i] *= daidr;//dHdrPrefix previously equaled dEda
4973 #ifdef PRINT_COMP
4974  CkPrintf("DHDR(%04i)[%04i] = % .4e\n",flags.sequence,pExt[i].id,dHdrPrefix[i]);
4975 #endif
4976  }
4977  gbisP3Ready();
4978 }
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:5001
Flags flags
Definition: Patch.h:128
int numAtoms
Definition: Patch.h:151
int sequence
Definition: PatchTypes.h:18
#define simParams
Definition: Output.C:129
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 4981 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().

4981  {
4982  if (proxy.size() > 0) {
4983  CProxy_ProxyMgr cp(CkpvAccess(BOCclass_group).proxyMgr);
4984  for (int i = 0; i < proxy.size(); i++) {
4985  int node = proxy[i];
4987  msg->patch = patchID;
4988  msg->origPe = CkMyPe();
4989  memcpy(msg->bornRad,bornRad.begin(),numAtoms*sizeof(Real));
4990  msg->destPe = node;
4991  int seq = flags.sequence;
4993  SET_PRIORITY(msg,seq,priority);
4994  cp[node].recvData(msg);
4995  }
4996  }
4998 }
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 5001 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().

5001  {
5002  if (proxy.size() > 0) {
5003  CProxy_ProxyMgr cp(CkpvAccess(BOCclass_group).proxyMgr);
5004  //only nonzero message should be sent for doFullElec
5005  int msgAtoms = (flags.doFullElectrostatics) ? numAtoms : 0;
5006  for (int i = 0; i < proxy.size(); i++) {
5007  int node = proxy[i];
5009  msg->patch = patchID;
5010  msg->dHdrPrefixLen = msgAtoms;
5011  msg->origPe = CkMyPe();
5012  memcpy(msg->dHdrPrefix, dHdrPrefix.begin(), msgAtoms*sizeof(Real));
5013  msg->destPe = node;
5014  int seq = flags.sequence;
5016  SET_PRIORITY(msg,seq,priority);
5017  cp[node].recvData(msg);
5018  }
5019  }
5021 }
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 3406 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().

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

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

Referenced by Sequencer::runComputeObjects().

4876 {
4877  DebugM(2, "loweAndersenFinish\n");
4878  v.resize(0);
4879 }
#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 4860 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().

4861 {
4862  DebugM(2, "loweAndersenVelocities\n");
4863  Molecule *mol = Node::Object()->molecule;
4865  v.resize(numAtoms);
4866  for (int i = 0; i < numAtoms; ++i) {
4867  //v[i] = p[i];
4868  // co-opt CompAtom structure to pass velocity and mass information
4869  v[i].position = atom[i].velocity;
4870  v[i].charge = atom[i].mass;
4871  }
4872  DebugM(2, "loweAndersenVelocities\n");
4873 }
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:175
void resize(int i)
Definition: ResizeArray.h:84
int numAtoms
Definition: Patch.h:151
#define simParams
Definition: Output.C:129
Molecule * molecule
Definition: Node.h:179

◆ minimize_rattle2()

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

Definition at line 4378 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().

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

5080 {
5081  Molecule *mol = Node::Object()->molecule;
5083  BigReal tol = simParams->mollyTol;
5084  int maxiter = simParams->mollyIter;
5085  int i, iter;
5086  HGArrayBigReal dsq;
5087  BigReal tmp;
5088  HGArrayInt ial, ibl;
5089  HGArrayVector ref; // reference position
5090  HGArrayVector refab; // reference vector
5091  HGArrayBigReal rmass; // 1 / mass
5092  BigReal *lambda; // Lagrange multipliers
5093  CompAtom *avg; // averaged position
5094  int numLambdas = 0;
5095  HGArrayInt fixed; // is atom fixed?
5096 
5097  // iout<<iINFO << "mollyAverage: "<<std::endl<<endi;
5099  for ( i=0; i<numAtoms; ++i ) p_avg[i] = p[i];
5100 
5101  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
5102  int hgs = atom[ig].hydrogenGroupSize;
5103  if ( hgs == 1 ) continue; // only one atom in group
5104  for ( i = 0; i < hgs; ++i ) {
5105  ref[i] = atom[ig+i].position;
5106  rmass[i] = 1. / atom[ig+i].mass;
5107  fixed[i] = ( simParams->fixedAtomsOn && atom[ig+i].atomFixed );
5108  if ( fixed[i] ) rmass[i] = 0.;
5109  }
5110  avg = &(p_avg[ig]);
5111  int icnt = 0;
5112 
5113  if ( ( tmp = atom[ig].rigidBondLength ) > 0 ) { // for water
5114  if ( hgs != 3 ) {
5115  NAMD_die("Hydrogen group error caught in mollyAverage(). It's a bug!\n");
5116  }
5117  if ( !(fixed[1] && fixed[2]) ) {
5118  dsq[icnt] = tmp * tmp; ial[icnt] = 1; ibl[icnt] = 2; ++icnt;
5119  }
5120  }
5121  for ( i = 1; i < hgs; ++i ) { // normal bonds to mother atom
5122  if ( ( tmp = atom[ig+i].rigidBondLength ) > 0 ) {
5123  if ( !(fixed[0] && fixed[i]) ) {
5124  dsq[icnt] = tmp * tmp; ial[icnt] = 0; ibl[icnt] = i; ++icnt;
5125  }
5126  }
5127  }
5128  if ( icnt == 0 ) continue; // no constraints
5129  numLambdas += icnt;
5130  molly_lambda.resize(numLambdas);
5131  lambda = &(molly_lambda[numLambdas - icnt]);
5132  for ( i = 0; i < icnt; ++i ) {
5133  refab[i] = ref[ial[i]] - ref[ibl[i]];
5134  }
5135  // iout<<iINFO<<"hgs="<<hgs<<" m="<<icnt<<std::endl<<endi;
5136  iter=average(avg,ref,lambda,hgs,icnt,rmass,dsq,ial,ibl,refab,tol,maxiter);
5137  if ( iter == maxiter ) {
5138  iout << iWARN << "Exceeded maximum number of iterations in mollyAverage().\n"<<endi;
5139  }
5140  }
5141 
5142  // for ( i=0; i<numAtoms; ++i ) {
5143  // if ( ( p_avg[i].position - p[i].position ).length2() > 1.0 ) {
5144  // iout << iERROR << "MOLLY moved atom " << (p[i].id + 1) << " from "
5145  // << p[i].position << " to " << p_avg[i].position << "\n" << endi;
5146  // }
5147  // }
5148 
5149 }
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:175
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:129
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:6464

◆ mollyMollify()

void HomePatch::mollyMollify ( Tensor virial)

Definition at line 5153 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().

5154 {
5155  Molecule *mol = Node::Object()->molecule;
5157  Tensor wc; // constraint virial
5158  int i;
5159  HGArrayInt ial, ibl;
5160  HGArrayVector ref; // reference position
5161  CompAtom *avg; // averaged position
5162  HGArrayVector refab; // reference vector
5163  HGArrayVector force; // new force
5164  HGArrayBigReal rmass; // 1 / mass
5165  BigReal *lambda; // Lagrange multipliers
5166  int numLambdas = 0;
5167  HGArrayInt fixed; // is atom fixed?
5168 
5169  for ( int ig = 0; ig < numAtoms; ig += atom[ig].hydrogenGroupSize ) {
5170  int hgs = atom[ig].hydrogenGroupSize;
5171  if (hgs == 1 ) continue; // only one atom in group
5172  for ( i = 0; i < hgs; ++i ) {
5173  ref[i] = atom[ig+i].position;
5174  force[i] = f[Results::slow][ig+i];
5175  rmass[i] = 1. / atom[ig+i].mass;
5176  fixed[i] = ( simParams->fixedAtomsOn && atom[ig+i].atomFixed );
5177  if ( fixed[i] ) rmass[i] = 0.;
5178  }
5179  int icnt = 0;
5180  // c-ji I'm only going to mollify water for now
5181  if ( atom[ig].rigidBondLength > 0 ) { // for water
5182  if ( hgs != 3 ) {
5183  NAMD_die("Hydrogen group error caught in mollyMollify(). It's a bug!\n");
5184  }
5185  if ( !(fixed[1] && fixed[2]) ) {
5186  ial[icnt] = 1; ibl[icnt] = 2; ++icnt;
5187  }
5188  }
5189  for ( i = 1; i < hgs; ++i ) { // normal bonds to mother atom
5190  if ( atom[ig+i].rigidBondLength > 0 ) {
5191  if ( !(fixed[0] && fixed[i]) ) {
5192  ial[icnt] = 0; ibl[icnt] = i; ++icnt;
5193  }
5194  }
5195  }
5196 
5197  if ( icnt == 0 ) continue; // no constraints
5198  lambda = &(molly_lambda[numLambdas]);
5199  numLambdas += icnt;
5200  for ( i = 0; i < icnt; ++i ) {
5201  refab[i] = ref[ial[i]] - ref[ibl[i]];
5202  }
5203  avg = &(p_avg[ig]);
5204  mollify(avg,ref,lambda,force,hgs,icnt,rmass,ial,ibl,refab);
5205  // store data back to patch
5206  for ( i = 0; i < hgs; ++i ) {
5207  wc += outer(force[i]-f[Results::slow][ig+i],ref[i]);
5208  f[Results::slow][ig+i] = force[i];
5209  }
5210  }
5211  // check that there isn't a constant needed here!
5212  *virial += wc;
5213  p_avg.resize(0);
5214 }
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:175
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:6646
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:129
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:77
#define PROXY_DATA_PRIORITY
Definition: Priorities.h:40
CompAtomList v
Definition: Patch.h:156
void doGroupSizeCheck()
Definition: HomePatch.C:5584
CompAtom * avgPositionList
Definition: ProxyMgr.h:104
void loweAndersenVelocities()
Definition: HomePatch.C:4860
int doLoweAndersen
Definition: PatchTypes.h:27
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:78
#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:4883
CompAtom * avgPositionPtrBegin
Definition: Patch.h:204
void doPairlistCheck()
Definition: HomePatch.C:5432
void doAtomMigration()
Definition: HomePatch.C:5792
void PatchReady(void)
Definition: Sync.C:150
void setGBISIntrinsicRadii()
Definition: HomePatch.C:4894
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:129
int32 sortOrder
Definition: NamdTypes.h:149
#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:5079
iterator end(void)
Definition: ResizeArray.h:37
BigReal y
Definition: Vector.h:74
int doLCPO
Definition: PatchTypes.h:30
CompAtomExt * positionExtList
Definition: ProxyMgr.h:122
int numPatchesOnNode(int node)
Definition: PatchMap.h:60
int doGBIS
Definition: PatchTypes.h:29
#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:5715
int doMolly
Definition: PatchTypes.h:24
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:5633
#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:376
static ProxyMgr * Object()
Definition: ProxyMgr.h:394
int32 * groupFixed
Definition: NamdTypes.h:384
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:381
int32 * unsortOrder
Definition: NamdTypes.h:379
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:4860
int doLoweAndersen
Definition: PatchTypes.h:27
CompAtom * velocityList
Definition: ProxyMgr.h:107
CudaAtom * cudaAtomPtr
Definition: Patch.h:212
double * pos_y
Definition: NamdTypes.h:368
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:290
void doGroupSizeCheck_SOA()
Definition: HomePatch.C:5531
#define PRIORITY_SIZE
Definition: Priorities.h:13
int32 * hydrogenGroupSize
Definition: NamdTypes.h:375
void qmSwapAtoms()
Definition: HomePatch.C:907
#define NAMD_EVENT_START(eon, id)
uint32_t uint32
Definition: common.h:42
int32 * vdwType
Definition: NamdTypes.h:372
#define NAMD_GROUP_FIXED_MASK
Definition: NamdTypes.h:145
IntList lcpoType
Definition: Patch.h:171
int32 * sortOrder
Definition: NamdTypes.h:378
CudaAtom * cudaAtomList
Definition: ProxyMgr.h:123
int32 * id
Definition: NamdTypes.h:380
CompAtomList p_avg
Definition: Patch.h:154
float * charge
Definition: NamdTypes.h:371
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:144
BigReal x
Definition: Vector.h:74
PatchID getPatchID() const
Definition: Patch.h:114
int sequence
Definition: PatchTypes.h:18
int32 * partition
Definition: NamdTypes.h:373
void setLcpoType()
Definition: HomePatch.C:4883
CompAtom * avgPositionPtrBegin
Definition: Patch.h:204
PatchID pid
Definition: NamdTypes.h:289
void doPairlistCheck()
Definition: HomePatch.C:5432
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:5792
void PatchReady(void)
Definition: Sync.C:150
void setGBISIntrinsicRadii()
Definition: HomePatch.C:4894
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:129
#define NAMD_EVENT_START_EX(eon, id, str)
iterator begin(void)
Definition: ResizeArray.h:36
double * pos_z
Definition: NamdTypes.h:369
void sendProxyAll(ProxyDataMsg *, int, int *)
Definition: ProxyMgr.C:1676
const PatchID patchID
Definition: Patch.h:150
void mollyAverage()
Definition: HomePatch.C:5079
iterator end(void)
Definition: ResizeArray.h:37
bool rattleListValid_SOA
Definition: HomePatch.h:454
double * pos_x
Definition: NamdTypes.h:367
BigReal y
Definition: Vector.h:74
int doLCPO
Definition: PatchTypes.h:30
CompAtomExt * positionExtList
Definition: ProxyMgr.h:122
int32 * sigId
Definition: NamdTypes.h:382
int numPatchesOnNode(int node)
Definition: PatchMap.h:60
int doGBIS
Definition: PatchTypes.h:29
#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:383
int32 * nonbondedGroupSize
Definition: NamdTypes.h:374
CompAtomExtList pExt
Definition: Patch.h:181
void positionsReady(int n=0, int startup=1)
Definition: Patch.C:403
int doMolly
Definition: PatchTypes.h:24
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:857
SimParameters * simParameters
Definition: Node.h:181
int get_numQMAtoms()
Definition: Molecule.h:859
float Real
Definition: common.h:118
uint32 id
Definition: NamdTypes.h:156
Charge charge
Definition: NamdTypes.h:78
int newVdWType
Definition: ComputeQM.h:33
int16 vdwType
Definition: NamdTypes.h:79
Real * get_qmAtmChrg()
Definition: Molecule.h:856
int numAtoms
Definition: Patch.h:151
const Real * get_qmAtomGroup() const
Definition: Molecule.h:853
Real newCharge
Definition: ComputeQM.h:34
#define simParams
Definition: Output.C:129
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 3784 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().

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

◆ rattle1_SOA()

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

Definition at line 4653 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().

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

◆ rattle1old()

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

Definition at line 3975 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().

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

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

5024  {
5025  ++numGBISP1Arrived;
5026  for ( int i = 0; i < msg->psiSumLen; ++i ) {
5027  psiFin[i] += msg->psiSum[i];
5028  }
5029  delete msg;
5030 
5031  if (flags.doNonbonded) {
5032  //awaken if phase 1 done
5033  if (phase1BoxClosedCalled == true &&
5034  numGBISP1Arrived==proxy.size() ) {
5035  // fprintf(stderr, "Calling awaken() on patch %d: 4\n", this->patchID);
5036  sequencer->awaken();
5037  }
5038  } else {
5039  //awaken if all phases done on noWork step
5040  if (boxesOpen == 0 &&
5041  numGBISP1Arrived == proxy.size() &&
5042  numGBISP2Arrived == proxy.size() &&
5043  numGBISP3Arrived == proxy.size()) {
5044  // fprintf(stderr, "Calling awaken() on patch %d: 5\n", this->patchID);
5045  sequencer->awaken();
5046  }
5047  }
5048 }
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:53
int boxesOpen
Definition: Patch.h:250
int doNonbonded
Definition: PatchTypes.h:22

◆ receiveResult() [2/2]

void HomePatch::receiveResult ( ProxyGBISP2ResultMsg msg)

Definition at line 5051 of file HomePatch.C.

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

5051  {
5052  ++numGBISP2Arrived;
5053  //accumulate dEda
5054  for ( int i = 0; i < msg->dEdaSumLen; ++i ) {
5055  dHdrPrefix[i] += msg->dEdaSum[i];
5056  }
5057  delete msg;
5058 
5059  if (flags.doNonbonded) {
5060  //awaken if phase 2 done
5061  if (phase2BoxClosedCalled == true &&
5062  numGBISP2Arrived==proxy.size() ) {
5063  // fprintf(stderr, "Calling awaken() on patch %d: 6\n", this->patchID);
5064  sequencer->awaken();
5065  }
5066  } else {
5067  //awaken if all phases done on noWork step
5068  if (boxesOpen == 0 &&
5069  numGBISP1Arrived == proxy.size() &&
5070  numGBISP2Arrived == proxy.size() &&
5071  numGBISP3Arrived == proxy.size()) {
5072  // fprintf(stderr, "Calling awaken() on patch %d: 7\n", this->patchID);
5073  sequencer->awaken();
5074  }
5075  }
5076 }
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:53
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:146
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:146
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:146
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 5359 of file HomePatch.C.

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

5359  { // initiating replica
5360  CkpvAccess(_qd)->process();
5361 }

◆ recvCheckpointLoad()

void HomePatch::recvCheckpointLoad ( CheckpointAtomsMsg msg)

Definition at line 5295 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().

5295  { // initiating replica
5297  const int remote = simParams->scriptIntArg1;
5298  const char *key = simParams->scriptStringArg1;
5300  NAMD_bug("HomePatch::recvCheckpointLoad called during checkpointFree.");
5301  }
5302  if ( msg->replica != remote ) {
5303  NAMD_bug("HomePatch::recvCheckpointLoad message from wrong replica.");
5304  }
5306  CheckpointAtomsMsg *newmsg = new (numAtoms,1+strlen(key),0) CheckpointAtomsMsg;
5307  strcpy(newmsg->key,key);
5308  newmsg->lattice = lattice;
5309  newmsg->berendsenPressure_count = sequencer->berendsenPressure_count;
5310  newmsg->pid = patchID;
5311  newmsg->pe = CkMyPe();
5312  newmsg->replica = CmiMyPartition();
5313  newmsg->numAtoms = numAtoms;
5314  memcpy(newmsg->atoms,atom.begin(),numAtoms*sizeof(FullAtom));
5315  PatchMgr::Object()->sendCheckpointStore(newmsg, remote, msg->pe);
5316  }
5318  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
5319  lattice = msg->lattice;
5321  numAtoms = msg->numAtoms;
5322  atom.resize(numAtoms);
5323  memcpy(atom.begin(),msg->atoms,numAtoms*sizeof(FullAtom));
5324  doAtomUpdate = true;
5325  rattleListValid = false;
5326  rattleListValid_SOA = false;
5327  if ( ! numNeighbors ) atomMapper->registerIDsFullAtom(atom.begin(),atom.end());
5328  if (simParams->SOAintegrateOn) {
5329  sort_solvent_atoms();
5330  copy_atoms_to_SOA();
5331 #if 0
5332  if (simParams->rigidBonds != RIGID_NONE) {
5334  rattleListValid_SOA = true;
5335  }
5336 #endif
5337  }
5338  }
5341  }
5342  delete msg;
5343 }
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:5359
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:292
void buildRattleList_SOA()
Definition: HomePatch.C:4516
int berendsenPressure_count
Definition: PatchMgr.h:87
#define simParams
Definition: Output.C:129
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:79
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 5265 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().

5265  { // responding replica
5266  if ( task == SCRIPT_CHECKPOINT_FREE ) {
5267  if ( ! checkpoints.count(key) ) {
5268  NAMD_die("Unable to free checkpoint, requested key was never stored.");
5269  }
5270  delete checkpoints[key];
5271  checkpoints.erase(key);
5272  PatchMgr::Object()->sendCheckpointAck(patchID, replica, pe);
5273  return;
5274  }
5275  CheckpointAtomsMsg *msg;
5276  if ( task == SCRIPT_CHECKPOINT_LOAD || task == SCRIPT_CHECKPOINT_SWAP ) {
5277  if ( ! checkpoints.count(key) ) {
5278  NAMD_die("Unable to load checkpoint, requested key was never stored.");
5279  }
5280  checkpoint_t &cp = *checkpoints[key];
5281  msg = new (cp.numAtoms,1,0) CheckpointAtomsMsg;
5282  msg->lattice = cp.lattice;
5283  msg->berendsenPressure_count = cp.berendsenPressure_count;
5284  msg->numAtoms = cp.numAtoms;
5285  memcpy(msg->atoms,cp.atoms.begin(),cp.numAtoms*sizeof(FullAtom));
5286  } else {
5287  msg = new (0,1,0) CheckpointAtomsMsg;
5288  }
5289  msg->pid = patchID;
5290  msg->replica = CmiMyPartition();
5291  msg->pe = CkMyPe();
5292  PatchMgr::Object()->sendCheckpointLoad(msg, replica, pe);
5293 }
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 5345 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().

5345  { // responding replica
5346  if ( ! checkpoints.count(msg->key) ) {
5347  checkpoints[msg->key] = new checkpoint_t;
5348  }
5349  checkpoint_t &cp = *checkpoints[msg->key];
5350  cp.lattice = msg->lattice;
5351  cp.berendsenPressure_count = msg->berendsenPressure_count;
5352  cp.numAtoms = msg->numAtoms;
5353  cp.atoms.resize(cp.numAtoms);
5354  memcpy(cp.atoms.begin(),msg->atoms,cp.numAtoms*sizeof(FullAtom));
5356  delete msg;
5357 }
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 5396 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().

5396  {
5397  // CkPrintf("recvExchangeMsg %d %d\n", CmiMyPartition(), exchange_src);
5398  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
5399  lattice = msg->lattice;
5400  numAtoms = msg->numAtoms;
5401  atom.resize(numAtoms);
5402  memcpy(atom.begin(),msg->atoms,numAtoms*sizeof(FullAtom));
5403  delete msg;
5404  CkpvAccess(_qd)->process();
5405  doAtomUpdate = true;
5406  rattleListValid = false;
5407  rattleListValid_SOA = false;
5408  if ( ! numNeighbors ) atomMapper->registerIDsFullAtom(atom.begin(),atom.end());
5410  if (simParams->SOAintegrateOn) {
5411  sort_solvent_atoms();
5412  copy_atoms_to_SOA();
5413 #if 0
5414  if (simParams->rigidBonds != RIGID_NONE) {
5416  rattleListValid_SOA = true;
5417  }
5418 #endif
5419  }
5420 }
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:4516
#define simParams
Definition: Output.C:129
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:79
FullAtom * atoms
Definition: PatchMgr.h:112

◆ recvExchangeReq()

void HomePatch::recvExchangeReq ( int  req)

Definition at line 5385 of file HomePatch.C.

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

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

5385  {
5386  exchange_req = req;
5387  if ( exchange_msg ) {
5388  // CkPrintf("recvExchangeReq %d %d\n", CmiMyPartition(), exchange_dst);
5390  exchange_msg = 0;
5391  exchange_req = -1;
5392  CkpvAccess(_qd)->process();
5393  }
5394 }
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:231
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 5226 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().

5226  {
5227  atomMapper->unregisterIDsFullAtom(atom.begin(),atom.end());
5228 
5229  atom.copy(checkpoint_atom);
5230  numAtoms = atom.size();
5231  lattice = checkpoint_lattice;
5232 
5233  doAtomUpdate = true;
5234  rattleListValid = false;
5235  rattleListValid_SOA = false;
5236 
5237  if ( ! numNeighbors ) atomMapper->registerIDsFullAtom(atom.begin(),atom.end());
5238 
5240  if (simParams->SOAintegrateOn) {
5241  sort_solvent_atoms();
5242  copy_atoms_to_SOA();
5243 #if 0
5244  if (simParams->rigidBonds != RIGID_NONE) {
5246  rattleListValid_SOA = true;
5247  }
5248 #endif
5249  }
5250 
5251  // DMK - Atom Separation (water vs. non-water)
5252  #if NAMD_SeparateWaters != 0
5253  numWaterAtoms = checkpoint_numWaterAtoms;
5254  #endif
5255 }
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:4516
#define simParams
Definition: Output.C:129
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:79

◆ 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:257

◆ 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 4894 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().

4894  {
4895  intRad.resize(numAtoms*2);
4896  intRad.setall(0);
4897  Molecule *mol = Node::Object()->molecule;
4899  Real offset = simParams->coulomb_radius_offset;
4900  for (int i = 0; i < numAtoms; i++) {
4901  Real rad = MassToRadius(atom[i].mass);//in ComputeGBIS.inl
4902  Real screen = MassToScreen(atom[i].mass);//same
4903  intRad[2*i+0] = rad - offset;//r0
4904  intRad[2*i+1] = screen*(rad - offset);//s0
4905  }
4906 }
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:175
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:129
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 4883 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().

4883  {
4884  Molecule *mol = Node::Object()->molecule;
4885  const int *lcpoParamType = mol->getLcpoParamType();
4886 
4888  for (int i = 0; i < numAtoms; i++) {
4889  lcpoType[i] = lcpoParamType[pExt[i].id];
4890  }
4891 }
static Node * Object()
Definition: Node.h:86
Molecule stores the structural information for the system.
Definition: Molecule.h:175
void resize(int i)
Definition: ResizeArray.h:84
int const * getLcpoParamType()
Definition: Molecule.h:507
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 5422 of file HomePatch.C.

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

Referenced by Sequencer::rebalanceLoad().

5423 {
5425 }
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:279
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: