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

ComputeGlobal Class Reference

#include <ComputeGlobal.h>

Inheritance diagram for ComputeGlobal:

ComputeHomePatches Compute List of all members.

Public Member Functions

 ComputeGlobal (ComputeID, ComputeMgr *)
virtual ~ComputeGlobal ()
void doWork ()
void recvConfig (ComputeGlobalConfigMsg *)
void recvResults (ComputeGlobalResultsMsg *)
void saveTotalForces (HomePatch *)

Constructor & Destructor Documentation

ComputeGlobal::ComputeGlobal ComputeID  ,
ComputeMgr
 

Definition at line 32 of file ComputeGlobal.C.

References AtomIDList, DebugM, SimParameters::FMAOn, ForceList, SimParameters::fullDirectOn, Node::molecule, Molecule::numAtoms, ReductionMgr::Object(), Node::Object(), SimParameters::PMEOn, REDUCTIONS_BASIC, ResizeArray< Elem >::resize(), Node::simParameters, and ReductionMgr::willSubmit().

00033         : ComputeHomePatches(c)
00034 {
00035   DebugM(3,"Constructing client\n");
00036   aid.resize(0);
00037   gdef.resize(0);
00038   comm = m;
00039   firsttime = 1;
00040   int i, numAtoms=Node::Object()->molecule->numAtoms;
00041   isRequested = new int[numAtoms];
00042   for (i=0; i<numAtoms; ++i)
00043     isRequested[i] = 0;
00044   SimParameters *sp = Node::Object()->simParameters;
00045   dofull = (sp->fullDirectOn || sp->FMAOn || sp->PMEOn);
00046   fid = new AtomIDList;
00047   totalForce = new ForceList;
00048   reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
00049 }

ComputeGlobal::~ComputeGlobal  )  [virtual]
 

Definition at line 51 of file ComputeGlobal.C.

00052 {
00053   delete[] isRequested;
00054   delete fid;
00055   delete totalForce;
00056   delete reduction;
00057 }


Member Function Documentation

void ComputeGlobal::doWork  )  [virtual]
 

Reimplemented from Compute.

Definition at line 192 of file ComputeGlobal.C.

References DebugM, and ComputeMgr::sendComputeGlobalData().

00193 {
00194   DebugM(2,"doWork\n");
00195   if(!firsttime) sendData();
00196   else {
00197     ComputeGlobalDataMsg *msg = new ComputeGlobalDataMsg;
00198     comm->sendComputeGlobalData(msg);
00199     firsttime = 0;
00200   }
00201   DebugM(2,"done with doWork\n");
00202 }

void ComputeGlobal::recvConfig ComputeGlobalConfigMsg  ) 
 

Definition at line 89 of file ComputeGlobal.C.

References ComputeGlobalConfigMsg::aid, DebugM, and ComputeGlobalConfigMsg::gdef.

Referenced by ComputeMgr::recvComputeGlobalConfig().

00089                                                           {
00090   DebugM(3,"Receiving configure on client\n");
00091   configure(msg->aid,msg->gdef);
00092   delete msg;
00093   sendData();
00094 }

void ComputeGlobal::recvResults ComputeGlobalResultsMsg  ) 
 

Definition at line 96 of file ComputeGlobal.C.

References ADD_TENSOR_OBJECT, ADD_VECTOR_OBJECT, ComputeGlobalResultsMsg::aid, Molecule::atommass(), ResizeArray< Elem >::begin(), ResizeArrayIter< T >::begin(), DebugM, ResizeArray< Elem >::end(), ResizeArrayIter< T >::end(), ComputeGlobalResultsMsg::f, Force, ComputeGlobalResultsMsg::gforce, LocalID::index, AtomMap::localID(), Node::molecule, ComputeGlobalResultsMsg::newaid, ComputeGlobalResultsMsg::newgdef, notUsed, PatchMap::numPatches(), Node::Object(), AtomMap::Object(), PatchMap::Object(), outer(), LocalID::pid, CompAtom::position, Position, ComputeGlobalResultsMsg::reconfig, REDUCTION_EXT_FORCE_NORMAL, REDUCTION_VIRIAL_NORMAL, ComputeGlobalResultsMsg::resendCoordinates, Lattice::reverse_transform(), ResizeArray< Elem >::size(), SubmitReduction::submit(), and FullAtom::transform.

Referenced by ComputeMgr::recvComputeGlobalResults().

00096                                                             {
00097   DebugM(3,"Receiving results (" << msg->aid.size() << " forces, "
00098          << msg->newgdef.size() << " new group atoms) on client\n");
00099 
00100   // set the forces only if we aren't going to resend the data
00101   int setForces = !msg->resendCoordinates;
00102 
00103   if(setForces) { // we are requested to 
00104     // Store forces to patches
00105     PatchMap *patchMap = PatchMap::Object();
00106     int numPatches = patchMap->numPatches();
00107     AtomMap *atomMap = AtomMap::Object();
00108     const Lattice & lattice = patchList[0].p->lattice;
00109     ResizeArrayIter<PatchElem> ap(patchList);
00110     Force **f = new Force*[numPatches];
00111     FullAtom **t = new FullAtom*[numPatches];
00112     for ( int i = 0; i < numPatches; ++i ) { f[i] = 0; t[i] = 0; }
00113     Force extForce = 0.;
00114     Tensor extVirial;
00115 
00116     for (ap = ap.begin(); ap != ap.end(); ap++) {
00117       (*ap).r = (*ap).forceBox->open();
00118       f[(*ap).patchID] = (*ap).r->f[Results::normal];
00119       t[(*ap).patchID] = (*ap).p->getAtomList().begin();
00120     }
00121 
00122     AtomIDList::iterator a = msg->aid.begin();
00123     AtomIDList::iterator a_e = msg->aid.end();
00124     ForceList::iterator f2 = msg->f.begin();
00125     for ( ; a != a_e; ++a, ++f2 ) {
00126       DebugM(1,"processing atom "<<(*a)<<", F="<<(*f2)<<"...\n");
00127       /* XXX if (*a) is out of bounds here we get a segfault */
00128       LocalID localID = atomMap->localID(*a);
00129       if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
00130       Force f_atom = (*f2);
00131       f[localID.pid][localID.index] += f_atom;
00132       Position x_orig = t[localID.pid][localID.index].position;
00133       Transform trans = t[localID.pid][localID.index].transform;
00134       Position x_atom = lattice.reverse_transform(x_orig,trans);
00135       extForce += f_atom;
00136       extVirial += outer(f_atom,x_atom);
00137     }
00138     DebugM(1,"done with the loop\n");
00139 
00140   // calculate forces for atoms in groups
00141     Molecule *mol = Node::Object()->molecule;
00142     AtomIDList::iterator g_i, g_e;
00143     g_i = gdef.begin(); g_e = gdef.end();
00144     ResizeArray<BigReal>::iterator gm_i = gmass.begin();
00145     ForceList::iterator gf_i = msg->gforce.begin();
00146     //iout << iDEBUG << "recvResults\n" << endi;
00147     for ( ; g_i != g_e; ++g_i, ++gm_i, ++gf_i ) {
00148       //iout << iDEBUG << *gf_i << '\n' << endi;
00149       Vector accel = (*gf_i) / (*gm_i);
00150       for ( ; *g_i != -1; ++g_i ) {
00151         //iout << iDEBUG << *g_i << '\n' << endi;
00152         LocalID localID = atomMap->localID(*g_i);
00153         if ( localID.pid == notUsed || ! f[localID.pid] ) continue;
00154         Force f_atom = accel * mol->atommass(*g_i);
00155         f[localID.pid][localID.index] += f_atom;
00156         Position x_orig = t[localID.pid][localID.index].position;
00157         Transform trans = t[localID.pid][localID.index].transform;
00158         Position x_atom = lattice.reverse_transform(x_orig,trans);
00159         extForce += f_atom;
00160         extVirial += outer(f_atom,x_atom);
00161       }
00162     }
00163     DebugM(1,"done with the groups\n");
00164 
00165     for (ap = ap.begin(); ap != ap.end(); ap++) {
00166       (*ap).forceBox->close(&((*ap).r));
00167     }
00168 
00169     delete [] f;
00170     delete [] t;
00171 
00172     ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
00173     ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
00174     reduction->submit();
00175   }
00176   // done setting the forces
00177 
00178   // Get reconfiguration if present
00179   if ( msg->reconfig ) configure(msg->newaid, msg->newgdef);
00180 
00181   // send another round of data if requested
00182 
00183   if(msg->resendCoordinates) {
00184     DebugM(3,"Sending requested data right away\n");
00185     sendData();
00186   }
00187 
00188   delete msg;
00189   DebugM(3,"Done processing results\n");
00190 }

void ComputeGlobal::saveTotalForces HomePatch  ) 
 

Definition at line 285 of file ComputeGlobal.C.

References ResizeArray< Elem >::add(), HomePatch::atom, Patch::f, HomePatch::f_saved, SimParameters::fixedAtomsOn, Force, ForceList, FullAtomList, Patch::numAtoms, Node::Object(), and Node::simParameters.

Referenced by Sequencer::integrate().

00286 {
00287   int fixedAtomsOn = Node::Object()->simParameters->fixedAtomsOn;
00288   int i, index, num=homePatch->numAtoms;
00289   FullAtomList atoms = homePatch->atom;
00290   ForceList f1=homePatch->f[Results::normal], f2=homePatch->f_saved[Results::nbond],
00291             f3=homePatch->f_saved[Results::slow];
00292   Force f_sum;
00293   
00294   for (i=0; i<num; ++i)
00295     if (isRequested[index=atoms[i].id])
00296     { f_sum = f1[i]+f2[i];
00297       if (dofull)
00298         f_sum += f3[i];
00299       if ( fixedAtomsOn && atoms[i].atomFixed ) f_sum = 0.;
00300       fid->add(index);
00301       totalForce->add(f_sum);
00302     }
00303 }


The documentation for this class was generated from the following files:
Generated on Tue Nov 24 04:07:49 2009 for NAMD by  doxygen 1.3.9.1