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

ComputeEwald Class Reference

#include <ComputeEwald.h>

Inheritance diagram for ComputeEwald:

ComputeHomePatches Compute List of all members.

Public Member Functions

 ComputeEwald (ComputeID, ComputeMgr *)
virtual ~ComputeEwald ()
void doWork ()
void recvData (ComputeEwaldMsg *)
void recvResults (ComputeEwaldMsg *)
int getMasterNode () const

Constructor & Destructor Documentation

ComputeEwald::ComputeEwald ComputeID  ,
ComputeMgr
 

Definition at line 51 of file ComputeEwald.C.

References DebugM, generateAtomTypeTable(), PatchMap::Object(), ReductionMgr::Object(), Node::Object(), SimParameters::pressureProfileAtomTypes, SimParameters::pressureProfileEwaldX, SimParameters::pressureProfileEwaldY, SimParameters::pressureProfileEwaldZ, SimParameters::pressureProfileSlabs, REDUCTIONS_PPROF_NONBONDED, Node::simParameters, and ReductionMgr::willSubmit().

00052         : ComputeHomePatches(c)
00053 {
00054   DebugM(3,"Constructing client\n");
00055   comm = m;
00056   SimParameters *sp = Node::Object()->simParameters;
00057   kxmax = sp->pressureProfileEwaldX;
00058   kymax = sp->pressureProfileEwaldY;
00059   kzmax = sp->pressureProfileEwaldZ;
00060   
00061   ktot = (1+kxmax) * (2*kymax+1) * (2*kzmax+1);
00062   kappa = ComputeNonbondedUtil::ewaldcof;
00063   pressureProfileSlabs = sp->pressureProfileSlabs;
00064   numAtomTypes = sp->pressureProfileAtomTypes;
00065   int nelements = 3*pressureProfileSlabs * (numAtomTypes*(numAtomTypes+1))/2;
00066   pressureProfileData = new float[nelements];
00067   reduction = ReductionMgr::Object()->willSubmit(
00068                                 REDUCTIONS_PPROF_NONBONDED, nelements);
00069 
00070   // figure out who da masta be
00071   numWorkingPes = (PatchMap::Object())->numNodesWithPatches();
00072   masterNode = numWorkingPes - 1;
00073 
00074   recvCount = 0;
00075   localAtoms = NULL;
00076   localPartitions = NULL;
00077 
00078   expx = new float[kxmax+1];
00079   expy = new float[kymax+1];
00080   expz = new float[kzmax+1];
00081 
00082   if (CkMyPe() == masterNode) {
00083     eiktotal = new float[2 * ktot * numAtomTypes]; 
00084     memset(eiktotal, 0, 2 * ktot * numAtomTypes*sizeof(float));
00085   } else {
00086     eiktotal = NULL;
00087   }
00088   // space for exp(iky), k=-kymax, ..., kymax
00089   eiky = new floatcomplex[2*kymax+1];
00090   // space for exp(ikz), k=-kzmax, ..., kzmax
00091   eikz = new floatcomplex[2*kzmax+1];
00092   Qk = new float[3*ktot];
00093 
00094   gridsForAtomType = generateAtomTypeTable(numAtomTypes);
00095 }

ComputeEwald::~ComputeEwald  )  [virtual]
 

Definition at line 97 of file ComputeEwald.C.

00098 {
00099   delete reduction;
00100   delete [] expx;
00101   delete [] expy;
00102   delete [] expz;
00103   delete [] eiktotal;
00104   delete [] eiky;
00105   delete [] eikz;
00106   delete [] pressureProfileData;
00107   delete [] Qk;
00108   delete [] gridsForAtomType;
00109   
00110   if (localAtoms) free(localAtoms);
00111   if (localPartitions) free(localPartitions);
00112 }


Member Function Documentation

void ComputeEwald::doWork  )  [virtual]
 

Reimplemented from Compute.

Definition at line 114 of file ComputeEwald.C.

References ResizeArrayIter< T >::begin(), BigReal, Lattice::c(), EwaldParticle::cg, CompAtom::charge, COLOUMB, ComputeEwaldMsg::eik, ResizeArrayIter< T >::end(), Lattice::origin(), CompAtom::partition, CompAtom::position, ComputeMgr::sendComputeEwaldData(), SubmitReduction::submit(), Lattice::wrap_delta(), Vector::x, EwaldParticle::x, Vector::y, EwaldParticle::y, EwaldParticle::z, and Vector::z.

00114                           {
00115   ResizeArrayIter<PatchElem> ap(patchList);
00116   // Skip computations if nothing to do.
00117   if ( ! patchList[0].p->flags.doFullElectrostatics )
00118   {
00119     for (ap = ap.begin(); ap != ap.end(); ap++) {
00120       CompAtom *x = (*ap).positionBox->open();
00121       Results *r = (*ap).forceBox->open();
00122       (*ap).positionBox->close(&x);
00123       (*ap).forceBox->close(&r);
00124     }
00125     reduction->submit();
00126     return;
00127   }
00128 
00129 
00130   lattice = patchList[0].p->lattice;
00131   Vector o = lattice.origin();
00132 
00133   // recompute pressure profile cell parameters based on current lattice
00134   pressureProfileThickness = lattice.c().z / pressureProfileSlabs;
00135   pressureProfileMin = lattice.origin().z - 0.5*lattice.c().z;
00136 
00137   const BigReal coloumb_sqrt = sqrt( COLOUMB * ComputeNonbondedUtil::scaling
00138                                 * ComputeNonbondedUtil::dielectric_1 );
00139 
00140   // get coordinates and store them
00141   numLocalAtoms = 0;
00142   for (ap = ap.begin(); ap != ap.end(); ap++) {
00143     numLocalAtoms += (*ap).p->getNumAtoms();
00144   }
00145   localAtoms = (EwaldParticle *)realloc(localAtoms, numLocalAtoms*sizeof(EwaldParticle));
00146   localPartitions = (int *)realloc(localPartitions, numLocalAtoms*sizeof(int));
00147 
00148   EwaldParticle *data_ptr = localAtoms;
00149   int *part_ptr = localPartitions;
00150 
00151   for (ap = ap.begin(); ap != ap.end(); ap++) {
00152     CompAtom *x = (*ap).positionBox->open();
00153     Results *r = (*ap).forceBox->open();
00154     if ( patchList[0].p->flags.doMolly ) {
00155       (*ap).positionBox->close(&x);
00156       x = (*ap).avgPositionBox->open();
00157     }
00158     int numAtoms = (*ap).p->getNumAtoms();
00159 
00160     for(int i=0; i<numAtoms; ++i) {
00161       // wrap back to unit cell, centered on origin
00162       Vector pos = x[i].position;
00163       pos += lattice.wrap_delta(pos) - o;
00164       *part_ptr++ = x[i].partition; 
00165       data_ptr->x = pos.x;
00166       data_ptr->y = pos.y;
00167       data_ptr->z = pos.z;
00168       data_ptr->cg = coloumb_sqrt * x[i].charge;
00169       ++data_ptr;
00170     }
00171     (*ap).positionBox->close(&x);
00172     (*ap).forceBox->close(&r);
00173   }
00174 
00175   // compute structure factor contribution from local atoms
00176   // 2*ktot since charm++ uses float instead of floatcomplex
00177   int msgsize = 2 * numAtomTypes * ktot;
00178   ComputeEwaldMsg *msg = new (msgsize,0) ComputeEwaldMsg;
00179   memset(msg->eik, 0, msgsize*sizeof(float));
00180   compute_structurefactor(msg->eik);
00181 
00182   // send our partial sum
00183   comm->sendComputeEwaldData(msg);
00184 }

int ComputeEwald::getMasterNode  )  const [inline]
 

Definition at line 86 of file ComputeEwald.h.

Referenced by ComputeMgr::sendComputeEwaldData().

00086 { return masterNode; }

void ComputeEwald::recvData ComputeEwaldMsg  ) 
 

Definition at line 186 of file ComputeEwald.C.

References ComputeEwaldMsg::eik, and ComputeMgr::sendComputeEwaldResults().

Referenced by ComputeMgr::recvComputeEwaldData().

00186                                                 {
00187   // sum the data...
00188   int nvecs = 2 * ktot * numAtomTypes;
00189   for (int i=0; i<nvecs; i++) {
00190     eiktotal[i] += msg->eik[i];
00191   }
00192   delete msg;
00193   if (++recvCount == numWorkingPes) {
00194     recvCount = 0;
00195     int msgsize = 2 * ktot * numAtomTypes;
00196     msg = new (msgsize,0) ComputeEwaldMsg; 
00197     memcpy(msg->eik, eiktotal, msgsize*sizeof(float));
00198     memset(eiktotal, 0, msgsize*sizeof(float));
00199     comm->sendComputeEwaldResults(msg);
00200   }
00201 }

void ComputeEwald::recvResults ComputeEwaldMsg  ) 
 

Definition at line 203 of file ComputeEwald.C.

References ComputeEwaldMsg::eik, SubmitReduction::item(), M_PI, SubmitReduction::submit(), and Lattice::volume().

Referenced by ComputeMgr::recvComputeEwaldResults().

00203                                                    {
00204   // receive total sum
00205   computePprofile(msg->eik);
00206   delete msg;
00207   float scalefac = 1.0 / (2 * M_PI * lattice.volume());
00208 
00209   int nelements = 3*pressureProfileSlabs * (numAtomTypes*(numAtomTypes+1))/2;
00210   for (int i=0; i<nelements; i++) {
00211     reduction->item(i) += pressureProfileData[i] * scalefac;
00212   }
00213   reduction->submit();
00214 }


The documentation for this class was generated from the following files:
Generated on Sun Oct 12 04:08:17 2008 for NAMD by  doxygen 1.3.9.1