OpenAtom  Version1.5a
AtomsCache.C
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////=
2 ///////////////////////////////////////////////////////////////////////////////c
3 ///////////////////////////////////////////////////////////////////////////////=
4 /** \file AtomsCache.C
5  * Atom coordinate, forces, and iteration
6  **/
7 ///////////////////////////////////////////////////////////////////////////////=
8 
9 #include "AtomsCache.h"
10 #include "energyGroup.h"
11 #include "eesCache.h"
12 #include "cp_state_ctrl/CP_State_GSpacePlane.h"
13 #include "utility/util.h"
14 #include "CPcharmParaInfoGrp.h"
15 #include "load_balance/IntMap.h"
16 #include "charm++.h"
17 
18 #include <cmath>
19 
20 //----------------------------------------------------------------------------
21 #define CHARM_ON
22 #include "src_piny_physics_v1.0/include/class_defs/Interface_ctrl.h"
23 #include "src_piny_physics_v1.0/include/class_defs/piny_constants.h"
24 #include "src_piny_physics_v1.0/include/class_defs/ATOM_OPERATIONS/class_atomintegrate.h"
25 #include "src_piny_physics_v1.0/include/class_defs/ATOM_OPERATIONS/class_atomoutput.h"
26 #include "src_piny_physics_v1.0/include/class_defs/CP_OPERATIONS/class_cprspaceion.h"
27 
28 //----------------------------------------------------------------------------
29 
30 extern CkVec <IntMap2on2> GSImaptable;
31 extern Config config;
32 extern CkVec <CProxy_CP_State_GSpacePlane> UgSpacePlaneProxy;
33 extern CkVec <CProxy_GSpaceDriver> UgSpaceDriverProxy;
34 extern CkVec <CProxy_AtomsCache> UatomsCacheProxy;
35 extern CkVec <CProxy_AtomsCompute> UatomsComputeProxy;
36 extern CkVec <CProxy_EnergyGroup> UegroupProxy;
37 extern CkVec <CProxy_StructFactCache> UsfCacheProxy;
38 extern CkVec <CProxy_eesCache> UeesCacheProxy;
39 extern CProxy_TemperController temperControllerProxy;
40 extern CProxy_InstanceController instControllerProxy;
41 extern CProxy_CPcharmParaInfoGrp scProxy;
42 
43 
44 ///////////////////////////////////////////////////////////////////////////////=
45 ///////////////////////////////////////////////////////////////////////////////c
46 ///////////////////////////////////////////////////////////////////////////////=
47 /**
48  *
49  * @addtogroup Atoms
50  * @{
51  */
52 ///////////////////////////////////////////////////////////////////////////////=
53 AtomsCache::AtomsCache( int _natm, int n_nl, Atom *a, UberCollection _thisInstance) : natm(_natm), natm_nl(n_nl), thisInstance(_thisInstance)
54 ///////////////////////////////////////////////////////////////////////////////=
55  {// begin routine
56 ///////////////////////////////////////////////////////////////////////////////=
57 
58  fastAtoms.natm = natm;
59  iteration=0;
60  temperScreenFile = NULL;
61  fastAtoms.q = new double[natm];
62  fastAtoms.x = new double[natm];
63  fastAtoms.y = new double[natm];
64  fastAtoms.z = new double[natm];
65  fastAtoms.fx = new double[natm];
66  fastAtoms.fy = new double[natm];
67  fastAtoms.fz = new double[natm];
68  fastAtoms.fxu = new double[natm];
69  fastAtoms.fyu = new double[natm];
70  fastAtoms.fzu = new double[natm];
71  for(int i=0;i<natm;i++){
72  fastAtoms.q[i] = a[i].q;
73  fastAtoms.x[i] = a[i].x;
74  fastAtoms.y[i] = a[i].y;
75  fastAtoms.z[i] = a[i].z;
76  fastAtoms.fx[i] = a[i].fx;
77  fastAtoms.fy[i] = a[i].fy;
78  fastAtoms.fz[i] = a[i].fz;
79  }//endfor
80  if(config.UberKmax>1 || config.UberImax>1 )
81  {
82  // we will do the file output
83  temperScreenFile = openScreenfWrite("TEMPER_OUT", "screen", thisInstance.idxU.z,thisInstance.idxU.x, true);
84  }
85  else
86  {
87  temperScreenFile = stdout;
88  }
89 
90  }
91 
92 
93 
94 
95 ///////////////////////////////////////////////////////////////////////////=
96 ///////////////////////////////////////////////////////////////////////////c
97 ///////////////////////////////////////////////////////////////////////////=
98 /** Contributeforces
99  * Every proc assigned an electronic structure chare of the bead=i temper=j
100  * (i,j) uber instance that generates an atom force MUST be in (i,j) atom group
101  * and so contribute to the reduction below. Otherwise, all the pieces of the
102  * atom forces of (i,j) will not be collected and the user will be very sad!
103  **/
104 ///////////////////////////////////////////////////////////////////////////=
106 ///////////////////////////////////////////////////////////////////////////=
107 
108  int i,j;
109  // collate all the forces that RS RHO NL deposited on the atoms
110  double *ftot = new double[(3*natm)];
111  for(i=0,j=0; i<natm; i++,j+=3){
112  ftot[j] = fastAtoms.fx[i];
113  ftot[j+1] = fastAtoms.fy[i];
114  ftot[j+2] = fastAtoms.fz[i];
115  }//endfor
116 #ifdef _CP_DEBUG_ATMS_
117  int myid = CkMyPe();
118  CkPrintf("GJM_DBG: inside contribute forces %d : %d\n",myid,natm);
119 #endif
120  CkCallback cb(CkIndex_AtomsCompute::recvContributeForces(NULL), UatomsComputeProxy[thisInstance.proxyOffset]);
121  contribute((3*natm)*sizeof(double),ftot,CkReduction::sum_double,cb);
122  delete [] ftot;
123  zeroforces();
124 ///////////////////////////////////////////////////////////////////////////=
125  }//end routine
126 ///////////////////////////////////////////////////////////////////////////=
127 
128 
129 ///////////////////////////////////////////////////////////////////////////=
130 ///////////////////////////////////////////////////////////////////////////c
131 ///////////////////////////////////////////////////////////////////////////=
132 /** acceptAtoms
133 
134  * AtomCompute gives us a coordinate update after force integration
135  */
136 ///////////////////////////////////////////////////////////////////////////=
138 {
139  for(int atomI = msg->natmStr, j=0; atomI < msg->natmEnd ; atomI++ ,j+=9){
140 #ifdef _CP_DEBUG_ATMS_
141  if(CkMyPe()==0)
142  {
143  CkPrintf("{%d} AtomPos[%d] updated to %.5g,%.5g,%.5g from %.5g,%.5g,%.5g\n",thisInstance.proxyOffset, atomI, msg->data[j], msg->data[j+1], msg->data[j+2], fastAtoms.x[atomI], fastAtoms.y[atomI], fastAtoms.z[atomI]);
144  }
145 #endif
146  fastAtoms.x[atomI]=msg->data[j];
147  fastAtoms.y[atomI]=msg->data[j+1];
148  fastAtoms.z[atomI]=msg->data[j+2];
149  }
150  zeroforces();
151  int i=0;
152  CkCallback cb(CkIndex_AtomsCache::atomsDone(NULL),UatomsCacheProxy[thisInstance.proxyOffset]);
153  contribute(sizeof(int),&i,CkReduction::sum_int,cb);
154  EnergyGroup *eg = UegroupProxy[thisInstance.proxyOffset].ckLocalBranch();
155  eg->estruct.potPIMDChain = msg->data[(msg->nsize-4)];
156  eg->estruct.eKinetic_atm = msg->data[(msg->nsize-2)];
157  eg->estruct.eKineticNhc_atm = msg->data[(msg->nsize-2)];
158  eg->estruct.potNhc_atm = msg->data[(msg->nsize-2)];
159 
160  delete msg;
161 }
162 
163 ///////////////////////////////////////////////////////////////////////////=
164 ///////////////////////////////////////////////////////////////////////////c
165 ///////////////////////////////////////////////////////////////////////////=
166 /** AtomsDone
167  *
168  * everyone has the new coordinates in dynamics
169  */
170 ///////////////////////////////////////////////////////////////////////////=
171 void AtomsCache::atomsDone(CkReductionMsg *msg)
172 {
173  // CkPrintf("{%d}[%d] AtomsCache::atomsDone(msg)\n ", thisInstance.proxyOffset, CkMyPe());
174 ///////////////////////////////////////////////////////////////////////////=
175  delete msg;
176  atomsDone();
177 }
178 
179 
180 ///////////////////////////////////////////////////////////////////////////=
181 /// Needs to have each proc invoke directly doneMovingAtoms method of the
182 /// GSpaceDrivers which are mapped to it. Without migration, we have that map
183 /// at startup. With migration, one must write an enroll/dropout routine.
184 /// All
185 ///////////////////////////////////////////////////////////////////////////=
186 ///////////////////////////////////////////////////////////////////////////c
187 ///////////////////////////////////////////////////////////////////////////=
189 ///////////////////////////////////////////////////////////////////////////=
190 /// Increment iteration counters
191 /// CkPrintf("{%d}[%d] AtomsCache::atomsDone()\n ", thisInstance.proxyOffset, CkMyPe());
192  int myid = CkMyPe();
193 
194  EnergyGroup *eg = UegroupProxy[thisInstance.proxyOffset].ckLocalBranch();
195  iteration++;
196  eg->estruct.iteration_atm = iteration;
197  eg->iteration_atm = iteration;
198  // CkPrintf("{%d}[%d] atomsDone now at eg->iteration_atm %d \n",thisInstance.proxyOffset,myid,eg->iteration_atm);
199 
200 #ifdef _DEBUG_CHECK_ATOM_COMM_
201  char fname[100];
202  sprintf(fname,"atoms.out.%d.%d",iteration,myid);
203  FILE *fp = fopen(fname,"w");
204  for(int i=0;i<natm;i++){
205  fprintf(fp,"%.10g %.10g %.10g\n",atoms[i].x,atoms[i].y,atoms[i].z);
206  }//endfor
207  fclose(fp);
208 #endif
209  releaseGSP();
210 
211 }
212 
213 
214 ///////////////////////////////////////////////////////////////////////////=
215 /// Use eesCache's registered GSPs to
216 ///////////////////////////////////////////////////////////////////////////=
217 ///////////////////////////////////////////////////////////////////////////c
218 ///////////////////////////////////////////////////////////////////////////=
220  int myid = CkMyPe();
221  // CkPrintf("{%d}[%d] running release GSP\n",thisInstance.proxyOffset, myid);
222 ///////////////////////////////////////////////////////////////////////////=
223 /// Use the cool new data caching system to say we're done.
224 
225 
226  //each k-point needs to be handled
227  for(int kpoint=0; kpoint< config.UberJmax; kpoint++){
228 
229  UberCollection thisPoint=thisInstance;
230  thisPoint.idxU.y=kpoint; // not at the gamma point
231  thisPoint.setPO();
232  eesCache *eesData = UeesCacheProxy[thisPoint.proxyOffset].ckLocalBranch ();
233  CkAssert(eesData!=NULL);
234  int *indState = eesData->gspStateInd;
235  int *indPlane = eesData->gspPlaneInd;
236  int ngo = eesData->nchareGSPProcT;
237 
238  for(int i=0; i<ngo; i++){
239  int iadd = UgSpacePlaneProxy[thisPoint.proxyOffset](indState[i],indPlane[i]).ckLocal()->registrationFlag;
240  if(iadd!=1){
241  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
242  CkPrintf("atom : Bad registration cache flag on proc %d %d %d %d\n",
243  myid,iadd,indState[i],indPlane[i]);
244  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
245  CkExit();
246  }//endif
247  // CkPrintf("{%d}[%d] AtomsCache::atomsDone() calling doneMovingAtoms\n ", thisInstance.proxyOffset, CkMyPe());
248  UgSpaceDriverProxy[thisPoint.proxyOffset](indState[i],indPlane[i]).doneMovingAtoms(iteration);
249  }//endfor
250  }//endfor
251 
252 ///////////////////////////////////////////////////////////////////////////////=
253  }//end routine
254 ///////////////////////////////////////////////////////////////////////////////=
255 
256 ///////////////////////////////////////////////////////////////////////////////=
257 ///////////////////////////////////////////////////////////////////////////////c
258 ///////////////////////////////////////////////////////////////////////////////=
259 /** Destructor
260  *
261  *
262  **/
263 ///////////////////////////////////////////////////////////////////////////////=
265  delete [] fastAtoms.q;
266  delete [] fastAtoms.x;
267  delete [] fastAtoms.y;
268  delete [] fastAtoms.z;
269  delete [] fastAtoms.fx;
270  delete [] fastAtoms.fy;
271  delete [] fastAtoms.fz;
272  delete [] fastAtoms.fxu;
273  delete [] fastAtoms.fyu;
274  delete [] fastAtoms.fzu;
275 }
276 ///////////////////////////////////////////
277 /*@}*/
FILE * openScreenfWrite(const char *dirnameBase, const char *fname, int temper, int bead, bool beadfile)
this stuff is in a C file because multiple includes of .def will give you too many implementations of...
Definition: util.C:2479
holds the UberIndex and the offset for proxies
Definition: Uber.h:68
CProxy_InstanceController instControllerProxy
Definition: cpaimd.ci:236
~AtomsCache()
Destructor.
Definition: AtomsCache.C:264
void contributeforces()
Contributeforces Every proc assigned an electronic structure chare of the bead=i temper=j (i...
Definition: AtomsCache.C:105
Author: Eric J Bohm Date Created: June 4th, 2006.
void atomsDone()
= Needs to have each proc invoke directly doneMovingAtoms method of the GSpaceDrivers which are mappe...
Definition: AtomsCache.C:188
void acceptAtoms(AtomMsg *)
acceptAtoms
Definition: AtomsCache.C:137
Definition: Atoms.h:20
void releaseGSP()
= Use eesCache's registered GSPs to
Definition: AtomsCache.C:219
Group Container class : Only allowed chare data classes have data.
Definition: eesCache.h:18
EnergyGroup class.
Definition: energyGroup.h:14