OpenAtom  Version1.5a
energyGroup.C
1 #include "energyGroup.h"
2 #include "eesCache.h"
3 #include "cp_state_ctrl/CP_State_GSpacePlane.h"
5 #include "utility/util.h"
6 #include "CPcharmParaInfoGrp.h"
7 #include "load_balance/IntMap.h"
8 #include "charm++.h"
9 extern CkVec <CProxy_EnergyGroup> UegroupProxy;
10 extern CProxy_TemperController temperControllerProxy;
11 extern CkVec <CProxy_eesCache> UeesCacheProxy;
12 extern CkVec <CProxy_CP_State_GSpacePlane> UgSpacePlaneProxy;
13 extern CkVec <CProxy_GSpaceDriver> UgSpaceDriverProxy;
14 ///////////////////////////////////////////////////////////////////////////=
15 ///Energy group that can retrieve the energies from
16 ///////////////////////////////////////////////////////////////////////////=
17 ///////////////////////////////////////////////////////////////////////////c
18 ///////////////////////////////////////////////////////////////////////////=
19 EnergyGroup::EnergyGroup (UberCollection _thisInstance) : thisInstance(_thisInstance) {
20  iteration_gsp = 0;
21  iteration_atm = 0;
22  kpointEnergyDoneCount=0;
23  //non local
24  estruct.enl = 0;
25 
26  //local external energy
27  estruct.eext = 0;
28  estruct.eke = 0;
29 
30  //hartree energy
31  estruct.ehart = 0;
32 
33  //ion-ion
34  estruct.eewald_recip = 0;
35  estruct.eewald_real = 0;
36 
37  //exchange correlation
38  estruct.egga = 0;
39  estruct.eexc = 0;
40  estruct.fmagPsi = 0;
41 
42  //CP Fict KE
43  estruct.fictEke = 0;
44 
45  // total electronic part
46  estruct.totalElecEnergy = 0; // needs ewald_real to be physical
47  estruct.iteration_gsp = 0;
48 
49  // atm stuff
50  estruct.eKinetic_atm = 0; // classical kinetic energy
51  estruct.eKineticNhc_atm = 0; // NHC kinetic energy
52  estruct.potNhc_atm = 0; // NHC pot energy
53  estruct.fmag_atm = 0; // magnitude of atm forces
54  estruct.iteration_atm = 0;
55  estruct.potPIMDChain = 0;
56 
57 //-------------------------------------------------------------------------
58  } //end routine
59 ///////////////////////////////////////////////////////////////////////////=
60 
61 
62 ///////////////////////////////////////////////////////////////////////////=
63 ///////////////////////////////////////////////////////////////////////////c
64 ///////////////////////////////////////////////////////////////////////////=
65 /**
66  * CP_StateGspacePlane(0,0) calls this to replicate the energies everywhere for
67  * consistency and tolerance checking.
68  */
70 ///////////////////////////////////////////////////////////////////////////=
71 
72  if(config.UberJmax>1 || config.UberMmax >1)
73  {// need to sum enl and eke across kpoints and spin
74  estruct.enl += es.enl;
75  estruct.eke += es.eke;
76  estruct.fictEke += es.fictEke;
77  estruct.fmagPsi += es.fmagPsi;
78  }
79  else
80  {
81  estruct.enl = es.enl;
82  estruct.eke = es.eke;
83  estruct.fictEke = es.fictEke;
84  estruct.fmagPsi = es.fmagPsi;
85  }
86  // these other stuff comes from rho and we only have one of them for
87  // all kpoints
88  estruct.eext = es.eext;
89  estruct.ehart = es.ehart;
90  estruct.eewald_recip = es.eewald_recip;
91  estruct.egga = es.egga;
92  estruct.eexc = es.eexc;
93  // these are gspace things that I don't know what to do with in
94  // the kpoint>1 case
95 
96  // we can construct this after all k-points have reported
97  if(config.UberJmax>1)
98  CkPrintf("GLENN!! you need to fix estruct.totalElecEnergy for k-points\n");
99  estruct.totalElecEnergy = es.totalElecEnergy;
100  estruct.iteration_gsp= es.iteration_gsp;
101  iteration_gsp = es.iteration_gsp;
102 #ifdef _DEBUG_ESTRUCT_
103  CkPrintf("Energies received %lf, %lf, %lf, %lf, %lf\n",
104  estruct.enl,estruct.eke,estruct.eext,estruct.ehart,
105  estruct.eewald_recipt,estruct.egga,estruct.eexc,
106  estruct.fictEke,estruct.totalEnergy);
107 #endif
108  int i=0;
109  CkCallback cb(CkIndex_EnergyGroup::energyDone(NULL),UegroupProxy[thisInstance.proxyOffset]);
110  contribute(sizeof(int),&i,CkReduction::sum_int,cb);
111 
112 //-------------------------------------------------------------------------
113  }//end routine
114 ///////////////////////////////////////////////////////////////////////////=
115 
116 
117 ///////////////////////////////////////////////////////////////////////////=
118 ///////////////////////////////////////////////////////////////////////////c
119 ///////////////////////////////////////////////////////////////////////////=
120 /**
121  * call GSpaceDriver->doneComputingEnergy() on all co-located gspace chares
122  * which allows the new step to advance with new psi
123  */
124  void EnergyGroup::energyDone(CkReductionMsg *msg) {
125 ///////////////////////////////////////////////////////////////////////////=
126  delete msg;
127  // need to receive one of these for each k-point
128  if(++kpointEnergyDoneCount==config.UberJmax)
129  {
130  kpointEnergyDoneCount=0;
131  if(config.UberKmax>1 && config.temperCycle >0 && iteration_atm % config.temperCycle == 0) // its temper time,
132  {
133  ktemps=0;
134  // resumeFromTemper will reactivate us later
135  int i=1;
136  CkCallback cb(CkIndex_EnergyGroup::sendToTemper(NULL),0, UegroupProxy[thisInstance.proxyOffset]);
137  contribute(sizeof(int),&i,CkReduction::sum_int,cb);
138  }
139  else
140  {
141  energyDone();
142  }
143  }
144 }
145 ///////////////////////////////////////////////////////////////////////////=
146 
147 
148 void EnergyGroup::sendToTemper(CkReductionMsg *m)
149 {
150  delete m;
151  temperControllerProxy[0].acceptData(thisInstance.idxU.x, estruct);
152 }
153 
154 void EnergyGroup::resumeFromTemper()
155 {
156  // you will receive 1 per kpoint, only release when all are ready
157  ktemps++;
158  if(ktemps==config.UberJmax)
159  {
160  energyDone();
161  ktemps=0;
162  }
163 }
164 
165 ///////////////////////////////////////////////////////////////////////////=
166 /// Needs to have each proc invoke directly the doneComputingEnergy method of the
167 /// GSpaceDrivers which are mapped to it. Without migration, we have that map
168 /// at startup. With migration, one must write an enroll/dropout routine.
169 ///////////////////////////////////////////////////////////////////////////=
170 ///////////////////////////////////////////////////////////////////////////c
171 ///////////////////////////////////////////////////////////////////////////=
173 ///////////////////////////////////////////////////////////////////////////=
174 /// Use the cool new data caching system
175 
176  int myid = CkMyPe();
177  for(int kpoint=0; kpoint< config.UberJmax; kpoint++){ //each
178  //k-point
179  //needs to be
180  //handled
181  // CkPrintf("{%d}[%d] EnergyGroup::energyDone.\n ", thisInstance.proxyOffset, CkMyPe());
182  UberCollection thisPoint=thisInstance;
183  thisPoint.idxU.y=kpoint; // not at the gamma point
184  thisPoint.setPO();
185 
186  eesCache *eesData = UeesCacheProxy[thisPoint.proxyOffset].ckLocalBranch ();
187  int *indState = eesData->gspStateInd;
188  int *indPlane = eesData->gspPlaneInd;
189  int ngo = eesData->nchareGSPProcT;
190  for(int i=0; i<ngo; i++){
191  int iadd = UgSpacePlaneProxy[thisPoint.proxyOffset](indState[i],indPlane[i]).ckLocal()->registrationFlag;
192  if(iadd!=1){
193  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
194  CkPrintf("Energy : Bad registration cache flag on proc %d %d %d %d\n",
195  myid,iadd,indState[i],indPlane[i]);
196  CkPrintf("@@@@@@@@@@@@@@@@@@@@_error_@@@@@@@@@@@@@@@@@@@@\n");
197  CkExit();
198  }//endif
199  UgSpaceDriverProxy[thisPoint.proxyOffset](indState[i],indPlane[i]).doneComputingEnergy(iteration_atm);
200  }//endfor
201  }//endfor
202 }//end routine
203 
204 
205 
206 
207 /*///////////////////////////////////////////////////////////////////////////=
208 ///////////////////////////////////////////////////////////////////////////c
209 ///////////////////////////////////////////////////////////////////////////=
210 EnergyStruct GetEnergyStruct() {
211  return UegroupProxy[thisInstance.proxyOffset].ckLocalBranch()->getEnergyStruct();
212 }
213 ///////////////////////////////////////////////////////////////////////////=
214 */
215 #include "EnergyGroup.def.h"
holds the UberIndex and the offset for proxies
Definition: Uber.h:68
void updateEnergiesFromGS(EnergyStruct &, UberCollection)
CP_StateGspacePlane(0,0) calls this to replicate the energies everywhere for consistency and toleranc...
Definition: energyGroup.C:69
Add type declarations for simulationConstants class (readonly vars) and once class for each type of o...
Author: Eric J Bohm Date Created: June 4th, 2006.
EnergyGroup(UberCollection thisInstance)
= Energy group that can retrieve the energies from
Definition: energyGroup.C:19
void energyDone()
= Needs to have each proc invoke directly the doneComputingEnergy method of the GSpaceDrivers which a...
Definition: energyGroup.C:172
Group Container class : Only allowed chare data classes have data.
Definition: eesCache.h:18