Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

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< BondElem, Bond, BondValue > ComputeSelfTuples< CrosstermElem, Crossterm, CrosstermValue > ComputeSelfTuples< DihedralElem, Dihedral, DihedralValue > ComputeSelfTuples< ImproperElem, Improper, ImproperValue > ComputeSelfAngles ComputeSelfBonds ComputeSelfCrossterms ComputeSelfDihedrals ComputeSelfImpropers 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
SubmitReductionpressureProfileReduction
BigRealpressureProfileData
int pressureProfileSlabs
char * isBasePatch

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


Constructor & Destructor Documentation

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

Definition at line 218 of file ComputeHomeTuples.h.

00218                                    : Compute(c) {
00219       patchMap = PatchMap::Object();
00220       atomMap = AtomMap::Object();
00221       reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00222       
00223       SimParameters *params = Node::Object()->simParameters;
00224       if (params->pressureProfileOn) {
00225         pressureProfileSlabs = T::pressureProfileSlabs = 
00226           params->pressureProfileSlabs;
00227         int n = T::pressureProfileAtomTypes = params->pressureProfileAtomTypes;
00228         pressureProfileReduction = ReductionMgr::Object()->willSubmit(
00229           REDUCTIONS_PPROF_BONDED, 3*pressureProfileSlabs*((n*(n+1))/2));
00230         int numAtomTypePairs = n*n;
00231         pressureProfileData = new BigReal[3*pressureProfileSlabs*numAtomTypePairs];
00232       } else {
00233         pressureProfileReduction = NULL;
00234         pressureProfileData = NULL;
00235       }
00236       doLoadTuples = false;
00237       isBasePatch = 0;
00238     }

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

Definition at line 240 of file ComputeHomeTuples.h.

00240                                                      : Compute(c) {
00241       patchMap = PatchMap::Object();
00242       atomMap = AtomMap::Object();
00243       reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00244       SimParameters *params = Node::Object()->simParameters;
00245       if (params->pressureProfileOn) {
00246         pressureProfileSlabs = T::pressureProfileSlabs = 
00247           params->pressureProfileSlabs;
00248         int n = T::pressureProfileAtomTypes = params->pressureProfileAtomTypes;
00249         pressureProfileReduction = ReductionMgr::Object()->willSubmit(
00250           REDUCTIONS_PPROF_BONDED, 3*pressureProfileSlabs*((n*(n+1))/2));
00251         int numAtomTypePairs = n*n;
00252         pressureProfileData = new BigReal[3*pressureProfileSlabs*numAtomTypePairs];
00253       } else {
00254         pressureProfileReduction = NULL;
00255         pressureProfileData = NULL;
00256       }
00257       doLoadTuples = false;
00258       int nPatches = patchMap->numPatches();
00259       isBasePatch = new char[nPatches];
00260       int i;
00261       for (i=0; i<nPatches; ++i) { isBasePatch[i] = 0; }
00262       for (i=0; i<pids.size(); ++i) { isBasePatch[pids[i]] = 1; }
00263     }

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

Definition at line 267 of file ComputeHomeTuples.h.

00267                                  {
00268       delete reduction;
00269       delete [] isBasePatch;
00270       delete pressureProfileReduction;
00271       delete pressureProfileData;
00272     }


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 314 of file ComputeHomeTuples.h.

00314                           {
00315       doLoadTuples = true;
00316     }

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< AngleElem, Angle, AngleValue >, ComputeSelfTuples< DihedralElem, Dihedral, DihedralValue >, ComputeSelfTuples< ImproperElem, Improper, ImproperValue >, ComputeSelfTuples< BondElem, Bond, BondValue >, and ComputeSelfTuples< CrosstermElem, Crossterm, CrosstermValue >.

Definition at line 323 of file ComputeHomeTuples.h.

Referenced by ComputeSelfTuples< CrosstermElem, Crossterm, CrosstermValue >::doWork().

00323                               {
00324 
00325       // Open Boxes - register that we are using Positions
00326       // and will be depositing Forces.
00327       UniqueSetIter<TuplePatchElem> ap(tuplePatchList);
00328       for (ap = ap.begin(); ap != ap.end(); ap++) {
00329         ap->x = ap->positionBox->open();
00330 #ifdef MEM_OPT_VERSION
00331         ap->xExt = ap->p->getCompAtomExtInfo();
00332 #endif
00333         if ( ap->p->flags.doMolly ) ap->x_avg = ap->avgPositionBox->open();
00334         ap->r = ap->forceBox->open();
00335         ap->f = ap->r->f[Results::normal];
00336       } 
00337     
00338       BigReal reductionData[T::reductionDataSize];
00339       int tupleCount = 0;
00340       int numAtomTypes = T::pressureProfileAtomTypes;
00341       int numAtomTypePairs = numAtomTypes*numAtomTypes;
00342 
00343       if ( ! Node::Object()->simParameters->commOnly ) {
00344       if ( doLoadTuples ) {
00345         loadTuples();
00346         doLoadTuples = false;
00347       }
00348     
00349       for ( int i = 0; i < T::reductionDataSize; ++i ) reductionData[i] = 0;
00350       if (pressureProfileData) {
00351         memset(pressureProfileData, 0, 3*pressureProfileSlabs*numAtomTypePairs*sizeof(BigReal));
00352         // Silly variable hiding of the previous iterator
00353         UniqueSetIter<TuplePatchElem> newap(tuplePatchList);
00354         newap = newap.begin();
00355         const Lattice &lattice = newap->p->lattice;
00356         T::pressureProfileThickness = lattice.c().z / pressureProfileSlabs;
00357         T::pressureProfileMin = lattice.origin().z - 0.5*lattice.c().z;
00358       }
00359       // take triplet and pass with tuple info to force eval
00360       T *al = tupleList.begin();
00361       const int ntuple = tupleList.size();
00362       for (int i=0; i<ntuple; ++i) {
00363         al[i].computeForce(reductionData, pressureProfileData);
00364       }
00365       tupleCount += ntuple;
00366       }
00367  
00368       T::submitReductionData(reductionData,reduction);
00369       reduction->item(T::reductionChecksumLabel) += (BigReal)tupleCount;
00370       reduction->submit();
00371 
00372       if (pressureProfileReduction) {
00373         // For ease of calculation we stored interactions between types
00374         // i and j in (ni+j).  For efficiency now we coalesce the
00375         // cross interactions so that just i<=j are stored.
00376         const int arraysize = 3*pressureProfileSlabs;
00377         const BigReal *data = pressureProfileData;
00378         for (int i=0; i<numAtomTypes; i++) {
00379           for (int j=0; j<numAtomTypes; j++) {
00380             int ii=i;
00381             int jj=j;
00382             if (ii > jj) { int tmp=ii; ii=jj; jj=tmp; }
00383             const int reductionOffset = 
00384               (ii*numAtomTypes - (ii*(ii+1))/2 + jj)*arraysize;
00385             for (int k=0; k<arraysize; k++) {
00386               pressureProfileReduction->item(reductionOffset+k) += data[k];
00387             }
00388             data += arraysize;
00389           }
00390         }
00391         pressureProfileReduction->submit();
00392       }
00393     
00394       // Close boxes - i.e. signal we are done with Positions and
00395       // AtomProperties and that we are depositing Forces
00396       for (ap = ap.begin(); ap != ap.end(); ap++) {
00397         ap->positionBox->close(&(ap->x));
00398         if ( ap->p->flags.doMolly ) ap->avgPositionBox->close(&(ap->x_avg));
00399         ap->forceBox->close(&(ap->r));
00400       }
00401     }

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< AngleElem, Angle, AngleValue >, ComputeSelfTuples< DihedralElem, Dihedral, DihedralValue >, ComputeSelfTuples< ImproperElem, Improper, ImproperValue >, ComputeSelfTuples< BondElem, Bond, BondValue >, and ComputeSelfTuples< CrosstermElem, Crossterm, CrosstermValue >.

Definition at line 278 of file ComputeHomeTuples.h.

00278                                   {
00279     
00280       // Start with empty list
00281       tuplePatchList.clear();
00282     
00283       int nPatches = patchMap->numPatches();
00284       int pid;
00285       for (pid=0; pid<nPatches; ++pid) {
00286         if ( isBasePatch[pid] ) {
00287           Patch *patch = patchMap->patch(pid);
00288           tuplePatchList.add(TuplePatchElem(patch, cid));
00289         }
00290       }
00291     
00292       // Gather all proxy patches (neighbors, that is)
00293       PatchID neighbors[PatchMap::MaxOneOrTwoAway];
00294     
00295       for (pid=0; pid<nPatches; ++pid) if ( isBasePatch[pid] ) {
00296         int numNeighbors = patchMap->upstreamNeighbors(pid,neighbors);
00297         for ( int i = 0; i < numNeighbors; ++i ) {
00298           if ( ! tuplePatchList.find(TuplePatchElem(neighbors[i])) ) {
00299             Patch *patch = patchMap->patch(neighbors[i]);
00300             tuplePatchList.add(TuplePatchElem(patch, cid));
00301           }
00302         }
00303       }
00304       setNumPatches(tuplePatchList.size());
00305       doLoadTuples = true;
00306 
00307       basePriority = COMPUTE_PROXY_PRIORITY;  // no patch dependence
00308     }

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

Definition at line 102 of file ComputeHomeTuples.h.

Referenced by ComputeHomeTuples< BondElem, Bond, BondValue >::doWork().

00102                                   {
00103       int numTuples;
00104 
00105       #ifdef MEM_OPT_VERSION
00106       AtomSignature *allSigs;      
00107       #else
00108       int32 **tuplesByAtom;
00109       /* const (need to propagate const) */ S *tupleStructs;
00110       #endif
00111       
00112       const P *tupleValues;
00113       Node *node = Node::Object();
00114 
00115       #ifdef MEM_OPT_VERSION
00116       allSigs = node->molecule->atomSigPool;
00117       #else      
00118       T::getMoleculePointers(node->molecule,
00119                     &numTuples, &tuplesByAtom, &tupleStructs);      
00120       #endif
00121       
00122       T::getParameterPointers(node->parameters, &tupleValues);
00123 
00124       tupleList.resize(0);
00125 
00126       LocalID aid[T::size];
00127 
00128       const int lesOn = node->simParameters->lesOn;
00129       Real invLesFactor = lesOn ? 
00130                           1.0/node->simParameters->lesFactor :
00131                           1.0;
00132 
00133       // cycle through each patch and gather all tuples
00134       TuplePatchListIter ai(tuplePatchList);
00135     
00136       for ( ai = ai.begin(); ai != ai.end(); ai++ )
00137       {
00138         CompAtom *atom = (*ai).x;
00139         Patch *patch = (*ai).p;
00140         int numAtoms = patch->getNumAtoms();
00141         #ifdef MEM_OPT_VERSION
00142         CompAtomExt *atomExt = (*ai).xExt; //patch->getCompAtomExtInfo();
00143         #endif
00144     
00145         // cycle through each atom in the patch and load up tuples
00146         for (int j=0; j < numAtoms; j++)
00147         {              
00148            /* cycle through each tuple */
00149            #ifdef MEM_OPT_VERSION
00150            AtomSignature *thisAtomSig = &allSigs[atomExt[j].sigId];
00151            TupleSignature *allTuples;
00152            T::getTupleInfo(thisAtomSig, &numTuples, &allTuples);
00153            for(int k=0; k<numTuples; k++) {
00154                T t(atom[j].id, &allTuples[k], tupleValues);
00155            #else
00156            /* get list of all tuples for the atom */
00157            int32 *curTuple = tuplesByAtom[atom[j].id];
00158            for( ; *curTuple != -1; ++curTuple) {             
00159              T t(&tupleStructs[*curTuple],tupleValues);
00160            #endif            
00161              register int i;
00162              aid[0] = atomMap->localID(t.atomID[0]);
00163              int homepatch = aid[0].pid;
00164              int samepatch = 1;
00165              int has_les = lesOn && node->molecule->get_fep_type(t.atomID[0]);
00166              for (i=1; i < T::size; i++) {
00167                  aid[i] = atomMap->localID(t.atomID[i]);
00168                  samepatch = samepatch && ( homepatch == aid[i].pid );
00169                  has_les |= lesOn && node->molecule->get_fep_type(t.atomID[i]);
00170              }
00171              if ( samepatch ) continue;
00172              t.scale = has_les ? invLesFactor : 1;
00173              for (i=1; i < T::size; i++) {
00174                  homepatch = patchMap->downstream(homepatch,aid[i].pid);
00175              }
00176              if ( homepatch != notUsed && isBasePatch[homepatch] ) {
00177                for (i=0; i < T::size; i++) {
00178                  TuplePatchElem *p;
00179                  t.p[i] = p = tuplePatchList.find(TuplePatchElem(aid[i].pid));
00180                  if ( ! p ) {
00181                #ifdef MEM_OPT_VERSION
00182                iout << iWARN << "Tuple with atoms ";
00183                #else
00184                    iout << iWARN << "Tuple " << *curTuple << " with atoms ";
00185                #endif
00186                    int erri;
00187                    for( erri = 0; erri < T::size; erri++ ) {
00188                      iout << t.atomID[erri] << "(" <<  aid[erri].pid << ") ";
00189                    }
00190                    iout << "missing patch " << aid[i].pid << "\n" << endi;
00191                    
00192                    NAMD_die("Patch needed for tuple is missing.\n");
00193                  }
00194                  t.localIndex[i] = aid[i].index;
00195                }
00196                tupleList.add(t);
00197              }
00198            }
00199         }
00200       }
00201     }


Member Data Documentation

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

Definition at line 211 of file ComputeHomeTuples.h.

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

Definition at line 203 of file ComputeHomeTuples.h.

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

Definition at line 216 of file ComputeHomeTuples.h.

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

Definition at line 210 of file ComputeHomeTuples.h.

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

Definition at line 214 of file ComputeHomeTuples.h.

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

Definition at line 213 of file ComputeHomeTuples.h.

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

Definition at line 215 of file ComputeHomeTuples.h.

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

Definition at line 212 of file ComputeHomeTuples.h.

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

Definition at line 207 of file ComputeHomeTuples.h.

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

Definition at line 208 of file ComputeHomeTuples.h.


The documentation for this class was generated from the following file:
Generated on Sat Aug 30 04:07:42 2008 for NAMD by  doxygen 1.3.9.1