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

Detailed Description

Definition at line 78 of file ComputeEwald.h.


Constructor & Destructor Documentation

ComputeEwald::ComputeEwald ( ComputeID  ,
ComputeMgr  
)

Definition at line 51 of file ComputeEwald.C.

References DebugM, ComputeNonbondedUtil::ewaldcof, 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(), Lattice::c(), EwaldParticle::cg, COULOMB, ComputeNonbondedUtil::dielectric_1, ComputeEwaldMsg::eik, ResizeArrayIter< T >::end(), Lattice::origin(), ComputeHomePatches::patchList, ComputeNonbondedUtil::scaling, ComputeMgr::sendComputeEwaldData(), SubmitReduction::submit(), Lattice::wrap_delta(), EwaldParticle::x, x, 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 coulomb_sqrt = sqrt( COULOMB * 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     // CompAtomExt *xExt = (*ap).p->getCompAtomExtInfo();
00154     Results *r = (*ap).forceBox->open();
00155     if ( patchList[0].p->flags.doMolly ) {
00156       (*ap).positionBox->close(&x);
00157       x = (*ap).avgPositionBox->open();
00158     }
00159     int numAtoms = (*ap).p->getNumAtoms();
00160 
00161     for(int i=0; i<numAtoms; ++i) {
00162       // wrap back to unit cell, centered on origin
00163       Vector pos = x[i].position;
00164       pos += lattice.wrap_delta(pos) - o;
00165       *part_ptr++ = x[i].partition; 
00166       data_ptr->x = pos.x;
00167       data_ptr->y = pos.y;
00168       data_ptr->z = pos.z;
00169       data_ptr->cg = coulomb_sqrt * x[i].charge;
00170       ++data_ptr;
00171     }
00172     (*ap).positionBox->close(&x);
00173     (*ap).forceBox->close(&r);
00174   }
00175 
00176   // compute structure factor contribution from local atoms
00177   // 2*ktot since charm++ uses float instead of floatcomplex
00178   int msgsize = 2 * numAtomTypes * ktot;
00179   ComputeEwaldMsg *msg = new (msgsize,0) ComputeEwaldMsg;
00180   memset(msg->eik, 0, msgsize*sizeof(float));
00181   compute_structurefactor(msg->eik);
00182 
00183   // send our partial sum
00184   comm->sendComputeEwaldData(msg);
00185 }

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 187 of file ComputeEwald.C.

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

Referenced by ComputeMgr::recvComputeEwaldData().

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

void ComputeEwald::recvResults ( ComputeEwaldMsg  ) 

Definition at line 204 of file ComputeEwald.C.

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

Referenced by ComputeMgr::recvComputeEwaldResults().

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


The documentation for this class was generated from the following files:
Generated on Thu Nov 23 01:17:16 2017 for NAMD by  doxygen 1.4.7