23 #define MIN_DEBUG_LEVEL 2 33 void ComputeDPMTA::get_FMA_cube(
int resize)
52 boxCenter = patchMap->
origin();
53 boxCenter.
x += boxSize.
x/2.0;
54 boxCenter.
y += boxSize.
y/2.0;
55 boxCenter.
z += boxSize.
z/2.0;
64 DebugM(2,
"getting patch info for FMA box\n");
69 DebugM(2,
"getting first patch info for FMA box\n");
71 DebugM(2,
"getting lattice from patch for FMA box\n");
72 Lattice lattice = (*ap).p->lattice;
74 NAMD_die(
"DPMTA (FMA) only supports orthogonal PBC's.");
76 DebugM(2,
"getting patch dimension for FMA box\n");
77 boxSize.
x = lattice.
a().
x;
78 boxSize.
y = lattice.
b().
y;
79 boxSize.
z = lattice.
c().
z;
80 DebugM(2,
"boxSize is " << boxSize <<
"\n");
81 boxCenter = lattice.
origin();
85 if (boxsize != boxSize)
87 DebugM(2,
"resetting FMA box\n");
90 boxcenter = boxCenter;
95 PmtaVector center,v1,v2,v3;
96 center.
x = boxcenter.x;
97 center.y = boxcenter.y;
98 center.z = boxcenter.z;
103 iout <<
iINFO <<
"BOX DIMENSIONS = (" << v1.x <<
"," 104 << v2.y <<
"," << v3.z <<
")\n";
105 iout <<
iINFO <<
"BOX CENTER = (" << center.x <<
"," 106 << center.y <<
"," << center.z <<
")\n";
108 DebugM(2,
"calling PMTAresize()\n");
109 PMTAresize(&v1,&v2,&v3,¢er);
110 DebugM(2,
"called PMTAresize()\n");
113 DebugM(2,
"cube center: " << boxcenter <<
" size=" << boxsize <<
"\n");
121 void ComputeDPMTA::initialize()
125 DebugM(2,
"ComputeDPMTA creating\n");
128 if (CkpvAccess(comm) == NULL)
130 NAMD_die(
"Communication protocol (Converse, PVM, etc.) not initialized.");
148 DebugM(2,
"init() getting first patch info for FMA box\n");
150 DebugM(2,
"init() getting lattice from patch for FMA box\n");
151 initLattice.x = (*ap).p->lattice.a().x;
152 initLattice.y = (*ap).p->lattice.b().y;
153 initLattice.z = (*ap).p->lattice.c().z;
154 DebugM(2,
"init() initLattice is " << initLattice <<
"\n");
163 usePBC = ( patchMap->periodic_a() ? 1 : 0 )
164 + ( patchMap->periodic_b() ? 1 : 0 )
165 + ( patchMap->periodic_c() ? 1 : 0 );
166 if ((usePBC != 0) && (usePBC != 3))
168 NAMD_die(
"DPMTA (FMA) does not support 1 or 2 dimensional PBC's.");
170 DebugM(2,
"Use PBC = " << usePBC <<
"\n");
171 usePBC = (usePBC == 3);
173 iout <<
iWARN <<
"DPMTA (FMA) pressure tensor is incorrect.\n" 174 <<
iWARN <<
"Do not use DPMTA with anisotropic pressure control.\n" 179 DebugM(2,
"DPMTA getting FMA cube\n");
181 DebugM(2,
"DPMTA got FMA cube\n");
185 DebugM(2,
"waiting for Init go-ahead\n");
191 if (PMTAregister() < 0)
195 DebugM(2,
"DPMTA done PMTAinit.\n");
198 DebugM(2,
"DPMTA configuring\n");
205 slavetids =
new int[numProcs];
206 if (slavetids == NULL)
208 NAMD_die(
"Memory allocation failed in FMAInterface::FMAInterface");
212 pvm_spawn(NULL,NULL,0,NULL,numProcs,slavetids);
213 DebugM(2,
"DPMTA slavetids allocated\n");
219 PmtaInitData pmta_data;
220 memset(&pmta_data,0,
sizeof(pmta_data));
221 pmta_data.nprocs = numProcs;
222 pmta_data.nlevels =
simParams->FMALevels;
226 pmta_data.fftblock =
simParams->FMAFFTBlock;
227 pmta_data.pbc = usePBC;
230 pmta_data.v1.x = boxsize.x;
234 pmta_data.v2.y = boxsize.y;
238 pmta_data.v3.z = boxsize.z;
239 pmta_data.cellctr.x = boxcenter.x;
240 pmta_data.cellctr.y = boxcenter.y;
241 pmta_data.cellctr.z = boxcenter.z;
242 pmta_data.calling_num = pmta_data.nprocs;
243 pmta_data.calling_tids = slavetids;
245 iout <<
iINFO <<
"DPMTA parameters are:\n";
246 iout <<
iINFO <<
" LEVELS = " << pmta_data.nlevels <<
"\n";
247 iout <<
iINFO <<
" NUMBER OF MULTIPOLE TERMS = " << pmta_data.mp <<
"\n";
248 iout <<
iINFO <<
" FFT FLAG = " << pmta_data.fft <<
"\n";
249 iout <<
iINFO <<
" FFT BLOCKING FACTOR = " << pmta_data.fftblock <<
"\n";
250 if ( usePBC )
iout <<
iINFO <<
" SYSTEM IS PERIODIC\n" <<
endi;
251 iout <<
iINFO <<
" BOX DIMENSIONS = (" << pmta_data.v1.x <<
"," 252 << pmta_data.v2.y <<
"," << pmta_data.v3.z <<
")\n";
253 iout <<
iINFO <<
" BOX CENTER = (" << pmta_data.cellctr.x <<
"," 254 << pmta_data.cellctr.y <<
"," << pmta_data.cellctr.z <<
")\n";
259 pmta_data.cellctr.x = 0.;
260 pmta_data.cellctr.y = 0.;
261 pmta_data.cellctr.z = 0.;
266 fp = fopen(
"DUMP_DPMTA.init",
"w");
267 fwrite(&pmta_data,
sizeof(PmtaInitData),1,fp);
271 DebugM(2,
"DPMTA calling PMTAinit.\n");
272 if (PMTAinit(&pmta_data,slavetids) >= 0)
287 DebugM(2,
"Init go-ahead\n");
292 DebugM(2,
"got Init go-ahead\n");
295 if (PMTAregister() < 0)
299 DebugM(2,
"DPMTA done PMTAinit.\n");
300 DebugM(2,
"DPMTA configured\n");
303 ComputeDPMTA::~ComputeDPMTA()
305 DebugM(2,
"DPMTA exiting\n");
307 if (CkMyPe() == 0) PMTAexit();
316 DebugM(2,
"DPMTA exited\n");
322 void ComputeDPMTA::doWork()
325 PmtaParticle *particle_list = NULL;
329 if (!patchList[0].p->flags.doFullElectrostatics)
331 for (ap = ap.begin(); ap != ap.end(); ap++) {
332 CompAtom *x = (*ap).positionBox->open();
333 Results *r = (*ap).forceBox->open();
334 (*ap).forceBox->close(&r);
335 (*ap).positionBox->close(&x);
343 for (totalAtoms=0, ap = ap.begin(); ap != ap.end(); ap++)
344 totalAtoms += (*ap).p->getNumAtoms();
351 Lattice lattice = (*ap).p->lattice;
353 NAMD_die(
"DPMTA (FMA) only supports orthogonal PBC's.");
355 newLattice.
x = lattice.
a().
x;
356 newLattice.
y = lattice.
b().
y;
357 newLattice.
z = lattice.
c().
z;
358 rescaleFactor.
x = initLattice.x / newLattice.
x;
359 rescaleFactor.
y = initLattice.y / newLattice.
y;
360 rescaleFactor.
z = initLattice.z / newLattice.
z;
361 DebugM(2,
"Rescale factor = " << initLattice <<
"/" << newLattice
362 <<
" = " << rescaleFactor <<
"\n");
363 DebugM(2,
"boxcenter = " << boxcenter <<
"\n");
374 particle_list = (PmtaParticle *)calloc(totalAtoms,
sizeof(PmtaParticle));
375 fmaResults = (PmtaPartInfo *)calloc(totalAtoms,
sizeof(PmtaPartInfo));
376 if (!particle_list || !fmaResults)
378 NAMD_die(
"DPMTA Failed to allocate memory.");
383 DebugM(2,
"Charge unit factor = " << unitFactor <<
"\n");
384 for (i=0, ap = ap.begin(); ap != ap.end(); ap++)
386 CompAtom *x = (*ap).positionBox->open();
387 if ( patchList[0].p->flags.doMolly ) {
388 (*ap).positionBox->close(&x);
389 x = (*ap).avgPositionBox->open();
394 for(j=0; j<(*ap).p->getNumAtoms(); j++)
399 particle_list[i].p.
x = rescaleFactor.
x * (x[j].
position.
x-boxcenter.x);
400 particle_list[i].p.y = rescaleFactor.
y * (x[j].
position.
y-boxcenter.y);
401 particle_list[i].p.z = rescaleFactor.
z * (x[j].
position.
z-boxcenter.z);
409 particle_list[i].q = x[j].
charge * unitFactor;
410 DebugM(1,
"atom[" << i <<
"]=" << x[j] <<
" " 411 << x[j].charge*unitFactor <<
"\n");
416 <<
" but " << i <<
" atoms are seen!\n" <<
endi;
417 NAMD_die(
"FMA: atom counts unequal!");
421 if ( patchList[0].p->flags.doMolly ) { (*ap).avgPositionBox->close(&x); }
422 else { (*ap).positionBox->close(&x); }
428 <<
" but " << i <<
" atoms are seen!\n" <<
endi;
429 NAMD_die(
"FMA: atom counts unequal!");
432 DebugM(2,
"DPMTA doWork() there are " << totalAtoms <<
" atoms in this node.\n");
437 sprintf(dump_file,
"DUMP_DPMTA.%d",(
int)CkMyPe());
438 fp = fopen(dump_file,
"w");
440 fwrite(&n32,
sizeof(
int32),1,fp);
441 fwrite(particle_list,
sizeof(PmtaParticle),i,fp);
446 if ( PMTAforce(i, particle_list, fmaResults, NULL) < 0 )
450 DebugM(2,
"DPMTA forces done. Now depositing.\n");
454 for (i=0, ap = ap.begin(); ap != ap.end(); ap++)
456 Results *r = (*ap).forceBox->open();
460 for(j=0; j<(*ap).p->getNumAtoms(); j++)
464 f[j].
x += fmaResults[i].f.x * rescaleFactor.
x * rescaleFactor.
x;
465 f[j].
y += fmaResults[i].f.y * rescaleFactor.
y * rescaleFactor.
y;
466 f[j].
z += fmaResults[i].f.z * rescaleFactor.
z * rescaleFactor.
z;
467 potential += fmaResults[i].v * rescaleFactor.
x;
471 f[j].
x += fmaResults[i].f.x;
472 f[j].
y += fmaResults[i].f.y;
473 f[j].
z += fmaResults[i].f.z;
474 potential += fmaResults[i].v;
479 (*ap).forceBox->close(&r);
483 DebugM(4,
"Full-electrostatics energy: " << potential <<
"\n");
486 reduction->item(REDUCTION_VIRIAL_SLOW_XX) += potential / 3.;
487 reduction->item(REDUCTION_VIRIAL_SLOW_YY) += potential / 3.;
488 reduction->item(REDUCTION_VIRIAL_SLOW_ZZ) += potential / 3.;
498 DebugM(2,
"DPMTA doWork() done\n");
std::ostream & iINFO(std::ostream &s)
NAMD_HOST_DEVICE Vector c() const
static BigReal dielectric_1
static PatchMap * Object()
SimParameters * simParameters
std::ostream & iPE(std::ostream &s)
std::ostream & endi(std::ostream &s)
std::ostream & iWARN(std::ostream &s)
SubmitReduction * willSubmit(int setID, int size=-1)
MIStream * get(char &data)
ResizeArrayIter< T > begin(void) const
static ReductionMgr * Object(void)
NAMD_HOST_DEVICE int orthogonal() const
int gridsize_c(void) const
int gridsize_a(void) const
void NAMD_die(const char *err_msg)
NAMD_HOST_DEVICE Vector b() const
virtual void initialize()
int gridsize_b(void) const
MOStream * put(char data)
ScaledPosition origin(void) const
NAMD_HOST_DEVICE Vector a() const
NAMD_HOST_DEVICE Vector origin() const