ComputeHomeTuples< T, S, P > Class Template Reference

#include <ComputeHomeTuples.h>

Inheritance diagram for ComputeHomeTuples< T, S, P >:
Compute ComputeSelfTuples< T, S, P > ComputeSelfTuples< AngleElem, Angle, AngleValue > ComputeSelfTuples< AnisoElem, Aniso, AnisoValue > ComputeSelfTuples< BondElem, Bond, BondValue > ComputeSelfTuples< CrosstermElem, Crossterm, CrosstermValue > ComputeSelfTuples< DihedralElem, Dihedral, DihedralValue > ComputeSelfTuples< ExclElem, Exclusion, int > ComputeSelfTuples< GromacsPairElem, GromacsPair, GromacsPairValue > ComputeSelfTuples< ImproperElem, Improper, ImproperValue > ComputeSelfTuples< TholeElem, Thole, TholeValue >

List of all members.

Public Member Functions

virtual ~ComputeHomeTuples ()
virtual void initialize (void)
void atomUpdate (void)
virtual void doWork (void)

Protected Member Functions

virtual void loadTuples (void)
 ComputeHomeTuples (ComputeID c)
 ComputeHomeTuples (ComputeID c, PatchIDList &pids)

Protected Attributes

int doLoadTuples
ResizeArray< T > tupleList
TuplePatchList tuplePatchList
PatchMappatchMap
AtomMapatomMap
SubmitReductionreduction
int accelMDdoDihe
SubmitReductionpressureProfileReduction
BigRealpressureProfileData
int pressureProfileSlabs
char * isBasePatch

Detailed Description

template<class T, class S, class P>
class ComputeHomeTuples< T, S, P >

Definition at line 365 of file ComputeHomeTuples.h.


Constructor & Destructor Documentation

template<class T, class S, class P>
ComputeHomeTuples< T, S, P >::ComputeHomeTuples ( ComputeID  c  )  [inline, protected]

Definition at line 557 of file ComputeHomeTuples.h.

00557                                    : Compute(c) {
00558       patchMap = PatchMap::Object();
00559       atomMap = AtomMap::Object();
00560       reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00561       
00562       SimParameters *params = Node::Object()->simParameters;
00563       accelMDdoDihe=false;
00564       if (params->accelMDOn) {
00565          if (params->accelMDdihe || params->accelMDdual) accelMDdoDihe=true;
00566       }
00567       if (params->pressureProfileOn) {
00568         pressureProfileSlabs = T::pressureProfileSlabs = 
00569           params->pressureProfileSlabs;
00570         int n = T::pressureProfileAtomTypes = params->pressureProfileAtomTypes;
00571         pressureProfileReduction = ReductionMgr::Object()->willSubmit(
00572           REDUCTIONS_PPROF_BONDED, 3*pressureProfileSlabs*((n*(n+1))/2));
00573         int numAtomTypePairs = n*n;
00574         pressureProfileData = new BigReal[3*pressureProfileSlabs*numAtomTypePairs];
00575       } else {
00576         pressureProfileReduction = NULL;
00577         pressureProfileData = NULL;
00578       }
00579       doLoadTuples = false;
00580       isBasePatch = 0;
00581 #ifdef USE_HOMETUPLES
00582       tuples = NULL;
00583 #endif
00584     }

template<class T, class S, class P>
ComputeHomeTuples< T, S, P >::ComputeHomeTuples ( ComputeID  c,
PatchIDList pids 
) [inline, protected]

Definition at line 586 of file ComputeHomeTuples.h.

00586                                                       : Compute(c) {
00587       patchMap = PatchMap::Object();
00588       atomMap = AtomMap::Object();
00589       reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00590       SimParameters *params = Node::Object()->simParameters;
00591       accelMDdoDihe=false;
00592       if (params->accelMDOn) {
00593          if (params->accelMDdihe || params->accelMDdual) accelMDdoDihe=true;
00594       }
00595       if (params->pressureProfileOn) {
00596         pressureProfileSlabs = T::pressureProfileSlabs = 
00597           params->pressureProfileSlabs;
00598         int n = T::pressureProfileAtomTypes = params->pressureProfileAtomTypes;
00599         pressureProfileReduction = ReductionMgr::Object()->willSubmit(
00600           REDUCTIONS_PPROF_BONDED, 3*pressureProfileSlabs*((n*(n+1))/2));
00601         int numAtomTypePairs = n*n;
00602         pressureProfileData = new BigReal[3*pressureProfileSlabs*numAtomTypePairs];
00603       } else {
00604         pressureProfileReduction = NULL;
00605         pressureProfileData = NULL;
00606       }
00607       doLoadTuples = false;
00608       int nPatches = patchMap->numPatches();
00609       isBasePatch = new char[nPatches];
00610       int i;
00611       for (i=0; i<nPatches; ++i) { isBasePatch[i] = 0; }
00612       for (i=0; i<pids.size(); ++i) { isBasePatch[pids[i]] = 1; }
00613 #ifdef USE_HOMETUPLES
00614       tuples = NULL;
00615 #endif
00616     }

template<class T, class S, class P>
virtual ComputeHomeTuples< T, S, P >::~ComputeHomeTuples (  )  [inline, virtual]

Definition at line 620 of file ComputeHomeTuples.h.

00620                                  {
00621       delete reduction;
00622       delete [] isBasePatch;
00623       delete pressureProfileReduction;
00624       delete pressureProfileData;
00625 #ifdef USE_HOMETUPLES
00626       if (tuples != NULL) delete tuples;
00627 #endif
00628     }


Member Function Documentation

template<class T, class S, class P>
void ComputeHomeTuples< T, S, P >::atomUpdate ( void   )  [inline, virtual]

Reimplemented from Compute.

Definition at line 684 of file ComputeHomeTuples.h.

00684                           {
00685       doLoadTuples = true;
00686     }

template<class T, class S, class P>
virtual void ComputeHomeTuples< T, S, P >::doWork ( void   )  [inline, virtual]

Reimplemented from Compute.

Reimplemented in ComputeSelfTuples< T, S, P >, ComputeSelfTuples< AnisoElem, Aniso, AnisoValue >, ComputeSelfTuples< AngleElem, Angle, AngleValue >, ComputeSelfTuples< GromacsPairElem, GromacsPair, GromacsPairValue >, ComputeSelfTuples< ExclElem, Exclusion, int >, ComputeSelfTuples< DihedralElem, Dihedral, DihedralValue >, ComputeSelfTuples< ImproperElem, Improper, ImproperValue >, ComputeSelfTuples< BondElem, Bond, BondValue >, ComputeSelfTuples< CrosstermElem, Crossterm, CrosstermValue >, and ComputeSelfTuples< TholeElem, Thole, TholeValue >.

Definition at line 693 of file ComputeHomeTuples.h.

00693                               {
00694 
00695       LdbCoordinator::Object()->startWork(ldObjHandle);
00696 
00697       // Open Boxes - register that we are using Positions
00698       // and will be depositing Forces.
00699       UniqueSetIter<TuplePatchElem> ap(tuplePatchList);
00700       for (ap = ap.begin(); ap != ap.end(); ap++) {
00701         ap->x = ap->positionBox->open();
00702         ap->xExt = ap->p->getCompAtomExtInfo();
00703         if ( ap->p->flags.doMolly ) ap->x_avg = ap->avgPositionBox->open();
00704         ap->r = ap->forceBox->open();
00705         ap->f = ap->r->f[Results::normal];
00706         if (accelMDdoDihe) ap->af = ap->r->f[Results::amdf]; // for dihedral-only or dual-boost accelMD
00707       } 
00708     
00709       BigReal reductionData[T::reductionDataSize];
00710       int tupleCount = 0;
00711       int numAtomTypes = T::pressureProfileAtomTypes;
00712       int numAtomTypePairs = numAtomTypes*numAtomTypes;
00713     
00714       for ( int i = 0; i < T::reductionDataSize; ++i ) reductionData[i] = 0;
00715       if (pressureProfileData) {
00716         memset(pressureProfileData, 0, 3*pressureProfileSlabs*numAtomTypePairs*sizeof(BigReal));
00717         // Silly variable hiding of the previous iterator
00718         UniqueSetIter<TuplePatchElem> newap(tuplePatchList);
00719         newap = newap.begin();
00720         const Lattice &lattice = newap->p->lattice;
00721         T::pressureProfileThickness = lattice.c().z / pressureProfileSlabs;
00722         T::pressureProfileMin = lattice.origin().z - 0.5*lattice.c().z;
00723       }
00724 
00725       if ( ! Node::Object()->simParameters->commOnly ) {
00726       if ( doLoadTuples ) {
00727 #ifdef USE_HOMETUPLES
00728         tuples->loadTuples(tuplePatchList, isBasePatch, AtomMap::Object());
00729 #else
00730         loadTuples();
00731 #endif
00732         doLoadTuples = false;
00733       }
00734       // take triplet and pass with tuple info to force eval
00735 #ifdef USE_HOMETUPLES
00736       T *al = (T *)tuples->getTupleList();
00737       const int ntuple = tuples->getNumTuples();
00738 #else
00739       T *al = tupleList.begin();
00740       const int ntuple = tupleList.size();
00741 #endif
00742       if ( ntuple ) T::computeForce(al, ntuple, reductionData, pressureProfileData);
00743       tupleCount += ntuple;
00744       }
00745  
00746     LdbCoordinator::Object()->endWork(ldObjHandle);
00747 
00748       T::submitReductionData(reductionData,reduction);
00749       reduction->item(T::reductionChecksumLabel) += (BigReal)tupleCount;
00750       reduction->submit();
00751 
00752       if (pressureProfileReduction) {
00753         // For ease of calculation we stored interactions between types
00754         // i and j in (ni+j).  For efficiency now we coalesce the
00755         // cross interactions so that just i<=j are stored.
00756         const int arraysize = 3*pressureProfileSlabs;
00757         const BigReal *data = pressureProfileData;
00758         for (int i=0; i<numAtomTypes; i++) {
00759           for (int j=0; j<numAtomTypes; j++) {
00760             int ii=i;
00761             int jj=j;
00762             if (ii > jj) { int tmp=ii; ii=jj; jj=tmp; }
00763             const int reductionOffset = 
00764               (ii*numAtomTypes - (ii*(ii+1))/2 + jj)*arraysize;
00765             for (int k=0; k<arraysize; k++) {
00766               pressureProfileReduction->item(reductionOffset+k) += data[k];
00767             }
00768             data += arraysize;
00769           }
00770         }
00771         pressureProfileReduction->submit();
00772       }
00773     
00774       // Close boxes - i.e. signal we are done with Positions and
00775       // AtomProperties and that we are depositing Forces
00776       for (ap = ap.begin(); ap != ap.end(); ap++) {
00777         ap->positionBox->close(&(ap->x));
00778         if ( ap->p->flags.doMolly ) ap->avgPositionBox->close(&(ap->x_avg));
00779         ap->forceBox->close(&(ap->r));
00780       }
00781     }

template<class T, class S, class P>
virtual void ComputeHomeTuples< T, S, P >::initialize ( void   )  [inline, virtual]

Reimplemented from Compute.

Reimplemented in ComputeSelfTuples< T, S, P >, ComputeSelfTuples< AnisoElem, Aniso, AnisoValue >, ComputeSelfTuples< AngleElem, Angle, AngleValue >, ComputeSelfTuples< GromacsPairElem, GromacsPair, GromacsPairValue >, ComputeSelfTuples< ExclElem, Exclusion, int >, ComputeSelfTuples< DihedralElem, Dihedral, DihedralValue >, ComputeSelfTuples< ImproperElem, Improper, ImproperValue >, ComputeSelfTuples< BondElem, Bond, BondValue >, ComputeSelfTuples< CrosstermElem, Crossterm, CrosstermValue >, and ComputeSelfTuples< TholeElem, Thole, TholeValue >.

Definition at line 634 of file ComputeHomeTuples.h.

00634                                   {
00635 
00636 #ifdef NAMD_CUDA
00637       ProxyMgr *proxyMgr = ProxyMgr::Object();
00638 #endif
00639 
00640 #ifdef USE_HOMETUPLES
00641       tuples = new HomeTuples<T, S, P>();
00642 #endif
00643 
00644       // Start with empty list
00645       tuplePatchList.clear();
00646     
00647       int nPatches = patchMap->numPatches();
00648       int pid;
00649       for (pid=0; pid<nPatches; ++pid) {
00650         if ( isBasePatch[pid] ) {
00651 #ifdef NAMD_CUDA
00652           proxyMgr->createProxy(pid);
00653 #endif
00654           Patch *patch = patchMap->patch(pid);
00655           tuplePatchList.add(TuplePatchElem(patch, this));
00656         }
00657       }
00658     
00659       // Gather all proxy patches (neighbors, that is)
00660       PatchID neighbors[PatchMap::MaxOneOrTwoAway];
00661     
00662       for (pid=0; pid<nPatches; ++pid) if ( isBasePatch[pid] ) {
00663         int numNeighbors = patchMap->upstreamNeighbors(pid,neighbors);
00664         for ( int i = 0; i < numNeighbors; ++i ) {
00665           if ( ! tuplePatchList.find(TuplePatchElem(neighbors[i])) ) {
00666 #ifdef NAMD_CUDA
00667             proxyMgr->createProxy(neighbors[i]);
00668 #endif
00669             Patch *patch = patchMap->patch(neighbors[i]);
00670             tuplePatchList.add(TuplePatchElem(patch, this));
00671           }
00672         }
00673       }
00674       setNumPatches(tuplePatchList.size());
00675       doLoadTuples = true;
00676 
00677       basePriority = COMPUTE_PROXY_PRIORITY;  // no patch dependence
00678     }

template<class T, class S, class P>
virtual void ComputeHomeTuples< T, S, P >::loadTuples ( void   )  [inline, protected, virtual]

Definition at line 370 of file ComputeHomeTuples.h.

00370                                   {
00371       int numTuples;
00372 
00373       #ifdef MEM_OPT_VERSION
00374       typename ElemTraits<T>::signature *allSigs;      
00375       #else
00376       int32 **tuplesByAtom;
00377       /* const (need to propagate const) */ S *tupleStructs;
00378       #endif
00379       
00380       const P *tupleValues;
00381       Node *node = Node::Object();
00382 
00383       #ifdef MEM_OPT_VERSION
00384       allSigs = ElemTraits<T>::get_sig_pointer(node->molecule);
00385       #else      
00386       T::getMoleculePointers(node->molecule,
00387                     &numTuples, &tuplesByAtom, &tupleStructs);      
00388       #endif
00389       
00390       T::getParameterPointers(node->parameters, &tupleValues);
00391 
00392       tupleList.resize(0);
00393 
00394       LocalID aid[T::size];
00395       int partition[T::size];
00396 
00397       const int lesOn = node->simParameters->lesOn;
00398       const int soluteScalingOn = node->simParameters->soluteScalingOn;
00399       const int fepOn = node->simParameters->singleTopology;
00400       const int sdScaling = node->simParameters->sdScaling;
00401       Real invLesFactor = lesOn ? 
00402                           1.0/node->simParameters->lesFactor :
00403                           1.0;
00404       const Real soluteScalingFactor = node->simParameters->soluteScalingFactor;
00405       const Bool soluteScalingAll = node->simParameters->soluteScalingAll;
00406       BigReal OneMinusLambda = 1.0 - node->simParameters->alchLambda;
00407       BigReal Lambda = node->simParameters->alchLambda;
00408       const int num_unpert_bonds = node->molecule->num_alch_unpert_Bonds;
00409       const int num_unpert_angles = node->molecule->num_alch_unpert_Angles;
00410       const int num_unpert_dihedrals = node->molecule->num_alch_unpert_Dihedrals;
00411       Bond *unpert_bonds = node->molecule->alch_unpert_bonds;
00412       Angle *unpert_angles = node->molecule->alch_unpert_angles;
00413       Dihedral *unpert_dihedrals = node->molecule->alch_unpert_dihedrals;
00414 
00415       // cycle through each patch and gather all tuples
00416       TuplePatchListIter ai(tuplePatchList);
00417     
00418       for ( ai = ai.begin(); ai != ai.end(); ai++ )
00419       {
00420         // CompAtom *atom = (*ai).x;
00421         Patch *patch = (*ai).p;
00422         int numAtoms = patch->getNumAtoms();
00423         CompAtomExt *atomExt = (*ai).xExt; //patch->getCompAtomExtInfo();
00424     
00425         // cycle through each atom in the patch and load up tuples
00426         for (int j=0; j < numAtoms; j++)
00427         {              
00428            /* cycle through each tuple */
00429            #ifdef MEM_OPT_VERSION
00430            typename ElemTraits<T>::signature *thisAtomSig =
00431                    &allSigs[ElemTraits<T>::get_sig_id(atomExt[j])];
00432            TupleSignature *allTuples;
00433            T::getTupleInfo(thisAtomSig, &numTuples, &allTuples);
00434            for(int k=0; k<numTuples; k++) {
00435                T t(atomExt[j].id, &allTuples[k], tupleValues);
00436            #else
00437            /* get list of all tuples for the atom */
00438            int32 *curTuple = tuplesByAtom[atomExt[j].id];
00439            for( ; *curTuple != -1; ++curTuple) {             
00440              T t(&tupleStructs[*curTuple],tupleValues);
00441            #endif            
00442              register int i;
00443              aid[0] = atomMap->localID(t.atomID[0]);
00444              int homepatch = aid[0].pid;
00445              int samepatch = 1;
00446              partition[0] = fepOn ? node->molecule->get_fep_type(t.atomID[0]) : 0;
00447              int has_les = lesOn ? node->molecule->get_fep_type(t.atomID[0]) : 0;
00448              int has_ss = soluteScalingOn ? node->molecule->get_ss_type(t.atomID[0]) : 0;
00449              int is_fep_ss = partition[0] > 2;
00450              int is_fep_sd = 0;
00451              int fep_tuple_type = 0;
00452              for (i=1; i < T::size; i++) {
00453                aid[i] = atomMap->localID(t.atomID[i]);
00454                samepatch = samepatch && ( homepatch == aid[i].pid );
00455                partition[i] = fepOn ? node->molecule->get_fep_type(t.atomID[i]) : 0;
00456                has_les |= lesOn ? node->molecule->get_fep_type(t.atomID[i]) : 0;
00457                has_ss |= soluteScalingOn ? node->molecule->get_ss_type(t.atomID[i]) : 0;  
00458                if (fepOn) {
00459                  is_fep_ss &= partition[i] > 2;
00460                  is_fep_sd |= (abs(partition[i] - partition[0]) == 2);
00461                  fep_tuple_type = partition[i];
00462                }
00463              }
00464              if (sdScaling && is_fep_sd) {
00465                for (i=0; i < num_unpert_bonds; i++) {
00466                  if (T::size == 2
00467                      && t.atomID[0]==unpert_bonds[i].atom1
00468                      && t.atomID[1]==unpert_bonds[i].atom2) is_fep_sd = 0;
00469                }
00470                for (i=0; i < num_unpert_angles; i++) {
00471                  if (T::size == 3
00472                      && t.atomID[0]==unpert_angles[i].atom1
00473                      && t.atomID[1]==unpert_angles[i].atom2
00474                      && t.atomID[2]==unpert_angles[i].atom3) is_fep_sd = 0;
00475                }
00476                for (i=0; i < num_unpert_dihedrals; i++) {
00477                  if (T::size == 4
00478                      && t.atomID[0]==unpert_dihedrals[i].atom1
00479                      && t.atomID[1]==unpert_dihedrals[i].atom2
00480                      && t.atomID[2]==unpert_dihedrals[i].atom3
00481                      && t.atomID[3]==unpert_dihedrals[i].atom4) is_fep_sd = 0;
00482                }
00483              }
00484              if (T::size < 4 && !soluteScalingAll) has_ss = false;
00485              if ( samepatch ) continue;
00486              t.scale = (!has_les && !has_ss) ? 1.0 : ( has_les ? invLesFactor : soluteScalingFactor );
00487              if (is_fep_ss) t.scale = (fep_tuple_type == 4) ? OneMinusLambda : Lambda;
00488              if (is_fep_sd && sdScaling) t.scale = (fep_tuple_type == 4 || fep_tuple_type == 2) ? OneMinusLambda : Lambda;
00489 
00490              for (i=1; i < T::size; i++) {
00491                  homepatch = patchMap->downstream(homepatch,aid[i].pid);
00492              }
00493              if ( homepatch != notUsed && isBasePatch[homepatch] ) {
00494                TuplePatchElem *p;
00495                for (i=0; i < T::size; i++) {
00496                  t.p[i] = p = tuplePatchList.find(TuplePatchElem(aid[i].pid));
00497                  if ( ! p ) {
00498                      #ifdef MEM_OPT_VERSION
00499                      iout << iWARN << "Tuple with atoms ";
00500                      #else
00501                    iout << iWARN << "Tuple " << *curTuple << " with atoms ";
00502                      #endif
00503                    int erri;
00504                    for( erri = 0; erri < T::size; erri++ ) {
00505                      iout << t.atomID[erri] << "(" <<  aid[erri].pid << ") ";
00506                    }
00507                    iout << "missing patch " << aid[i].pid << "\n" << endi;
00508                    break;
00509                  }
00510                  t.localIndex[i] = aid[i].index;
00511                }
00512                if ( ! p ) continue;
00513              #ifdef MEM_OPT_VERSION
00514                //avoid adding Tuples whose atoms are all fixed
00515                if(node->simParameters->fixedAtomsOn &&
00516                   !node->simParameters->fixedAtomsForces) {
00517                  int allfixed = 1;
00518                  for(i=0; i<T::size; i++){
00519                    CompAtomExt *one = &(t.p[i]->xExt[aid[i].index]);
00520                    allfixed = allfixed & one->atomFixed;
00521                  }
00522                  if(!allfixed) tupleList.add(t);
00523                }else{
00524                  tupleList.add(t);
00525                }
00526              #else
00527                tupleList.add(t);
00528              #endif               
00529              }
00530            }
00531         }
00532       }
00533     }


Member Data Documentation

template<class T, class S, class P>
int ComputeHomeTuples< T, S, P >::accelMDdoDihe [protected]

Definition at line 551 of file ComputeHomeTuples.h.

template<class T, class S, class P>
AtomMap* ComputeHomeTuples< T, S, P >::atomMap [protected]

Definition at line 549 of file ComputeHomeTuples.h.

template<class T, class S, class P>
int ComputeHomeTuples< T, S, P >::doLoadTuples [protected]

Definition at line 536 of file ComputeHomeTuples.h.

template<class T, class S, class P>
char* ComputeHomeTuples< T, S, P >::isBasePatch [protected]

Definition at line 555 of file ComputeHomeTuples.h.

template<class T, class S, class P>
PatchMap* ComputeHomeTuples< T, S, P >::patchMap [protected]

Definition at line 548 of file ComputeHomeTuples.h.

template<class T, class S, class P>
BigReal* ComputeHomeTuples< T, S, P >::pressureProfileData [protected]

Definition at line 553 of file ComputeHomeTuples.h.

template<class T, class S, class P>
SubmitReduction* ComputeHomeTuples< T, S, P >::pressureProfileReduction [protected]

Definition at line 552 of file ComputeHomeTuples.h.

template<class T, class S, class P>
int ComputeHomeTuples< T, S, P >::pressureProfileSlabs [protected]

Definition at line 554 of file ComputeHomeTuples.h.

template<class T, class S, class P>
SubmitReduction* ComputeHomeTuples< T, S, P >::reduction [protected]

Definition at line 550 of file ComputeHomeTuples.h.

template<class T, class S, class P>
ResizeArray<T> ComputeHomeTuples< T, S, P >::tupleList [protected]

Definition at line 544 of file ComputeHomeTuples.h.

template<class T, class S, class P>
TuplePatchList ComputeHomeTuples< T, S, P >::tuplePatchList [protected]

Definition at line 545 of file ComputeHomeTuples.h.


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

Generated on 12 Jul 2020 for NAMD by  doxygen 1.6.1