1 |
#include <cstdlib> |
2 |
#include <iostream> |
3 |
#include <cmath> |
4 |
|
5 |
#include "SimSetup.hpp" |
6 |
#include "parse_me.h" |
7 |
#include "Integrator.hpp" |
8 |
#include "simError.h" |
9 |
|
10 |
#ifdef IS_MPI |
11 |
#include "mpiBASS.h" |
12 |
#include "mpiSimulation.hpp" |
13 |
#endif |
14 |
|
15 |
SimSetup::SimSetup(){ |
16 |
stamps = new MakeStamps(); |
17 |
globals = new Globals(); |
18 |
|
19 |
#ifdef IS_MPI |
20 |
strcpy( checkPointMsg, "SimSetup creation successful" ); |
21 |
MPIcheckPoint(); |
22 |
#endif // IS_MPI |
23 |
} |
24 |
|
25 |
SimSetup::~SimSetup(){ |
26 |
delete stamps; |
27 |
delete globals; |
28 |
} |
29 |
|
30 |
void SimSetup::parseFile( char* fileName ){ |
31 |
|
32 |
#ifdef IS_MPI |
33 |
if( worldRank == 0 ){ |
34 |
#endif // is_mpi |
35 |
|
36 |
inFileName = fileName; |
37 |
set_interface_stamps( stamps, globals ); |
38 |
|
39 |
#ifdef IS_MPI |
40 |
mpiEventInit(); |
41 |
#endif |
42 |
|
43 |
yacc_BASS( fileName ); |
44 |
|
45 |
#ifdef IS_MPI |
46 |
throwMPIEvent(NULL); |
47 |
} |
48 |
else receiveParse(); |
49 |
#endif |
50 |
|
51 |
} |
52 |
|
53 |
#ifdef IS_MPI |
54 |
void SimSetup::receiveParse(void){ |
55 |
|
56 |
set_interface_stamps( stamps, globals ); |
57 |
mpiEventInit(); |
58 |
MPIcheckPoint(); |
59 |
mpiEventLoop(); |
60 |
|
61 |
} |
62 |
|
63 |
#endif // is_mpi |
64 |
|
65 |
void SimSetup::createSim( void ){ |
66 |
|
67 |
MakeStamps *the_stamps; |
68 |
Globals* the_globals; |
69 |
int i, j; |
70 |
|
71 |
// get the stamps and globals; |
72 |
the_stamps = stamps; |
73 |
the_globals = globals; |
74 |
|
75 |
// set the easy ones first |
76 |
simnfo->target_temp = the_globals->getTargetTemp(); |
77 |
simnfo->dt = the_globals->getDt(); |
78 |
simnfo->run_time = the_globals->getRunTime(); |
79 |
|
80 |
// get the ones we know are there, yet still may need some work. |
81 |
n_components = the_globals->getNComponents(); |
82 |
strcpy( force_field, the_globals->getForceField() ); |
83 |
strcpy( ensemble, the_globals->getEnsemble() ); |
84 |
strcpy( simnfo->ensemble, ensemble ); |
85 |
|
86 |
strcpy( simnfo->mixingRule, the_globals->getMixingRule() ); |
87 |
simnfo->usePBC = the_globals->getPBC(); |
88 |
|
89 |
|
90 |
|
91 |
if( !strcmp( force_field, "TraPPE" ) ) the_ff = new TraPPEFF(); |
92 |
else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF(); |
93 |
else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF(); |
94 |
else if( !strcmp( force_field, "LJ" ) ) the_ff = new LJ_FF(); |
95 |
else{ |
96 |
sprintf( painCave.errMsg, |
97 |
"SimSetup Error. Unrecognized force field -> %s\n", |
98 |
force_field ); |
99 |
painCave.isFatal = 1; |
100 |
simError(); |
101 |
} |
102 |
|
103 |
#ifdef IS_MPI |
104 |
strcpy( checkPointMsg, "ForceField creation successful" ); |
105 |
MPIcheckPoint(); |
106 |
#endif // is_mpi |
107 |
|
108 |
|
109 |
|
110 |
// get the components and calculate the tot_nMol and indvidual n_mol |
111 |
the_components = the_globals->getComponents(); |
112 |
components_nmol = new int[n_components]; |
113 |
comp_stamps = new MoleculeStamp*[n_components]; |
114 |
|
115 |
if( !the_globals->haveNMol() ){ |
116 |
// we don't have the total number of molecules, so we assume it is |
117 |
// given in each component |
118 |
|
119 |
tot_nmol = 0; |
120 |
for( i=0; i<n_components; i++ ){ |
121 |
|
122 |
if( !the_components[i]->haveNMol() ){ |
123 |
// we have a problem |
124 |
sprintf( painCave.errMsg, |
125 |
"SimSetup Error. No global NMol or component NMol" |
126 |
" given. Cannot calculate the number of atoms.\n" ); |
127 |
painCave.isFatal = 1; |
128 |
simError(); |
129 |
} |
130 |
|
131 |
tot_nmol += the_components[i]->getNMol(); |
132 |
components_nmol[i] = the_components[i]->getNMol(); |
133 |
} |
134 |
} |
135 |
else{ |
136 |
sprintf( painCave.errMsg, |
137 |
"SimSetup error.\n" |
138 |
"\tSorry, the ability to specify total" |
139 |
" nMols and then give molfractions in the components\n" |
140 |
"\tis not currently supported." |
141 |
" Please give nMol in the components.\n" ); |
142 |
painCave.isFatal = 1; |
143 |
simError(); |
144 |
|
145 |
|
146 |
// tot_nmol = the_globals->getNMol(); |
147 |
|
148 |
// //we have the total number of molecules, now we check for molfractions |
149 |
// for( i=0; i<n_components; i++ ){ |
150 |
|
151 |
// if( !the_components[i]->haveMolFraction() ){ |
152 |
|
153 |
// if( !the_components[i]->haveNMol() ){ |
154 |
// //we have a problem |
155 |
// std::cerr << "SimSetup error. Neither molFraction nor " |
156 |
// << " nMol was given in component |
157 |
|
158 |
} |
159 |
|
160 |
#ifdef IS_MPI |
161 |
strcpy( checkPointMsg, "Have the number of components" ); |
162 |
MPIcheckPoint(); |
163 |
#endif // is_mpi |
164 |
|
165 |
// make an array of molecule stamps that match the components used. |
166 |
// also extract the used stamps out into a separate linked list |
167 |
|
168 |
simnfo->nComponents = n_components; |
169 |
simnfo->componentsNmol = components_nmol; |
170 |
simnfo->compStamps = comp_stamps; |
171 |
simnfo->headStamp = new LinkedMolStamp(); |
172 |
|
173 |
char* id; |
174 |
LinkedMolStamp* headStamp = simnfo->headStamp; |
175 |
LinkedMolStamp* currentStamp = NULL; |
176 |
for( i=0; i<n_components; i++ ){ |
177 |
|
178 |
id = the_components[i]->getType(); |
179 |
comp_stamps[i] = NULL; |
180 |
|
181 |
// check to make sure the component isn't already in the list |
182 |
|
183 |
comp_stamps[i] = headStamp->match( id ); |
184 |
if( comp_stamps[i] == NULL ){ |
185 |
|
186 |
// extract the component from the list; |
187 |
|
188 |
currentStamp = the_stamps->extractMolStamp( id ); |
189 |
if( currentStamp == NULL ){ |
190 |
sprintf( painCave.errMsg, |
191 |
"SimSetup error: Component \"%s\" was not found in the " |
192 |
"list of declared molecules\n", |
193 |
id ); |
194 |
painCave.isFatal = 1; |
195 |
simError(); |
196 |
} |
197 |
|
198 |
headStamp->add( currentStamp ); |
199 |
comp_stamps[i] = headStamp->match( id ); |
200 |
} |
201 |
} |
202 |
|
203 |
#ifdef IS_MPI |
204 |
strcpy( checkPointMsg, "Component stamps successfully extracted\n" ); |
205 |
MPIcheckPoint(); |
206 |
#endif // is_mpi |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
// caclulate the number of atoms, bonds, bends and torsions |
212 |
|
213 |
tot_atoms = 0; |
214 |
tot_bonds = 0; |
215 |
tot_bends = 0; |
216 |
tot_torsions = 0; |
217 |
for( i=0; i<n_components; i++ ){ |
218 |
|
219 |
tot_atoms += components_nmol[i] * comp_stamps[i]->getNAtoms(); |
220 |
tot_bonds += components_nmol[i] * comp_stamps[i]->getNBonds(); |
221 |
tot_bends += components_nmol[i] * comp_stamps[i]->getNBends(); |
222 |
tot_torsions += components_nmol[i] * comp_stamps[i]->getNTorsions(); |
223 |
} |
224 |
|
225 |
tot_SRI = tot_bonds + tot_bends + tot_torsions; |
226 |
|
227 |
simnfo->n_atoms = tot_atoms; |
228 |
simnfo->n_bonds = tot_bonds; |
229 |
simnfo->n_bends = tot_bends; |
230 |
simnfo->n_torsions = tot_torsions; |
231 |
simnfo->n_SRI = tot_SRI; |
232 |
simnfo->n_mol = tot_nmol; |
233 |
|
234 |
|
235 |
#ifdef IS_MPI |
236 |
|
237 |
// divide the molecules among processors here. |
238 |
|
239 |
mpiSim = new mpiSimulation( simnfo ); |
240 |
|
241 |
|
242 |
|
243 |
globalIndex = mpiSim->divideLabor(); |
244 |
|
245 |
|
246 |
|
247 |
// set up the local variables |
248 |
|
249 |
int localMol, allMol; |
250 |
int local_atoms, local_bonds, local_bends, local_torsions, local_SRI; |
251 |
|
252 |
allMol = 0; |
253 |
localMol = 0; |
254 |
local_atoms = 0; |
255 |
local_bonds = 0; |
256 |
local_bends = 0; |
257 |
local_torsions = 0; |
258 |
for( i=0; i<n_components; i++ ){ |
259 |
|
260 |
for( j=0; j<components_nmol[i]; j++ ){ |
261 |
|
262 |
if( mpiSim->getMyMolStart() <= allMol && |
263 |
allMol <= mpiSim->getMyMolEnd() ){ |
264 |
|
265 |
local_atoms += comp_stamps[i]->getNAtoms(); |
266 |
local_bonds += comp_stamps[i]->getNBonds(); |
267 |
local_bends += comp_stamps[i]->getNBends(); |
268 |
local_torsions += comp_stamps[i]->getNTorsions(); |
269 |
localMol++; |
270 |
} |
271 |
allMol++; |
272 |
} |
273 |
} |
274 |
local_SRI = local_bonds + local_bends + local_torsions; |
275 |
|
276 |
|
277 |
simnfo->n_atoms = mpiSim->getMyNlocal(); |
278 |
|
279 |
if( local_atoms != simnfo->n_atoms ){ |
280 |
sprintf( painCave.errMsg, |
281 |
"SimSetup error: mpiSim's localAtom (%d) and SimSetup's" |
282 |
" localAtom (%d) are note equal.\n", |
283 |
simnfo->n_atoms, |
284 |
local_atoms ); |
285 |
painCave.isFatal = 1; |
286 |
simError(); |
287 |
} |
288 |
|
289 |
simnfo->n_bonds = local_bonds; |
290 |
simnfo->n_bends = local_bends; |
291 |
simnfo->n_torsions = local_torsions; |
292 |
simnfo->n_SRI = local_SRI; |
293 |
simnfo->n_mol = localMol; |
294 |
|
295 |
strcpy( checkPointMsg, "Passed nlocal consistency check." ); |
296 |
MPIcheckPoint(); |
297 |
|
298 |
|
299 |
#endif // is_mpi |
300 |
|
301 |
|
302 |
// create the atom and short range interaction arrays |
303 |
|
304 |
Atom::createArrays(simnfo->n_atoms); |
305 |
the_atoms = new Atom*[simnfo->n_atoms]; |
306 |
the_molecules = new Molecule[simnfo->n_mol]; |
307 |
|
308 |
|
309 |
if( simnfo->n_SRI ){ |
310 |
the_sris = new SRI*[simnfo->n_SRI]; |
311 |
the_excludes = new ex_pair[simnfo->n_SRI]; |
312 |
} |
313 |
|
314 |
// set the arrays into the SimInfo object |
315 |
|
316 |
simnfo->atoms = the_atoms; |
317 |
simnfo->sr_interactions = the_sris; |
318 |
simnfo->n_exclude = tot_SRI; |
319 |
simnfo->excludes = the_excludes; |
320 |
|
321 |
|
322 |
// get some of the tricky things that may still be in the globals |
323 |
|
324 |
if( simnfo->n_dipoles ){ |
325 |
|
326 |
if( !the_globals->haveRRF() ){ |
327 |
sprintf( painCave.errMsg, |
328 |
"SimSetup Error, system has dipoles, but no rRF was set.\n"); |
329 |
painCave.isFatal = 1; |
330 |
simError(); |
331 |
} |
332 |
if( !the_globals->haveDielectric() ){ |
333 |
sprintf( painCave.errMsg, |
334 |
"SimSetup Error, system has dipoles, but no" |
335 |
" dielectric was set.\n" ); |
336 |
painCave.isFatal = 1; |
337 |
simError(); |
338 |
} |
339 |
|
340 |
simnfo->rRF = the_globals->getRRF(); |
341 |
simnfo->dielectric = the_globals->getDielectric(); |
342 |
} |
343 |
|
344 |
#ifdef IS_MPI |
345 |
strcpy( checkPointMsg, "rRf and dielectric check out" ); |
346 |
MPIcheckPoint(); |
347 |
#endif // is_mpi |
348 |
|
349 |
if( the_globals->haveBox() ){ |
350 |
simnfo->box_x = the_globals->getBox(); |
351 |
simnfo->box_y = the_globals->getBox(); |
352 |
simnfo->box_z = the_globals->getBox(); |
353 |
} |
354 |
else if( the_globals->haveDensity() ){ |
355 |
|
356 |
double vol; |
357 |
vol = (double)tot_nmol / the_globals->getDensity(); |
358 |
simnfo->box_x = pow( vol, ( 1.0 / 3.0 ) ); |
359 |
simnfo->box_y = simnfo->box_x; |
360 |
simnfo->box_z = simnfo->box_x; |
361 |
} |
362 |
else{ |
363 |
if( !the_globals->haveBoxX() ){ |
364 |
sprintf( painCave.errMsg, |
365 |
"SimSetup error, no periodic BoxX size given.\n" ); |
366 |
painCave.isFatal = 1; |
367 |
simError(); |
368 |
} |
369 |
simnfo->box_x = the_globals->getBoxX(); |
370 |
|
371 |
if( !the_globals->haveBoxY() ){ |
372 |
sprintf( painCave.errMsg, |
373 |
"SimSetup error, no periodic BoxY size given.\n" ); |
374 |
painCave.isFatal = 1; |
375 |
simError(); |
376 |
} |
377 |
simnfo->box_y = the_globals->getBoxY(); |
378 |
|
379 |
if( !the_globals->haveBoxZ() ){ |
380 |
sprintf( painCave.errMsg, |
381 |
"SimSetup error, no periodic BoxZ size given.\n" ); |
382 |
painCave.isFatal = 1; |
383 |
simError(); |
384 |
} |
385 |
simnfo->box_z = the_globals->getBoxZ(); |
386 |
} |
387 |
|
388 |
#ifdef IS_MPI |
389 |
strcpy( checkPointMsg, "Box size set up" ); |
390 |
MPIcheckPoint(); |
391 |
#endif // is_mpi |
392 |
|
393 |
|
394 |
// initialize the arrays |
395 |
|
396 |
the_ff->setSimInfo( simnfo ); |
397 |
|
398 |
makeAtoms(); |
399 |
// |
400 |
if( tot_bonds ){ |
401 |
makeBonds(); |
402 |
} |
403 |
|
404 |
if( tot_bends ){ |
405 |
makeBends(); |
406 |
} |
407 |
|
408 |
if( tot_torsions ){ |
409 |
makeTorsions(); |
410 |
} |
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
if( the_globals->haveInitialConfig() ){ |
418 |
|
419 |
InitializeFromFile* fileInit; |
420 |
#ifdef IS_MPI // is_mpi |
421 |
if( worldRank == 0 ){ |
422 |
#endif //is_mpi |
423 |
fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); |
424 |
#ifdef IS_MPI |
425 |
}else fileInit = new InitializeFromFile( NULL ); |
426 |
#endif |
427 |
fileInit->read_xyz( simnfo ); // default velocities on |
428 |
|
429 |
delete fileInit; |
430 |
} |
431 |
else{ |
432 |
|
433 |
#ifdef IS_MPI |
434 |
|
435 |
// no init from bass |
436 |
|
437 |
sprintf( painCave.errMsg, |
438 |
"Cannot intialize a parallel simulation without an initial configuration file.\n" ); |
439 |
painCave.isFatal; |
440 |
simError(); |
441 |
|
442 |
#else |
443 |
|
444 |
initFromBass(); |
445 |
|
446 |
|
447 |
#endif |
448 |
} |
449 |
|
450 |
#ifdef IS_MPI |
451 |
strcpy( checkPointMsg, "Successfully read in the initial configuration" ); |
452 |
MPIcheckPoint(); |
453 |
#endif // is_mpi |
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
#ifdef IS_MPI |
462 |
if( worldRank == 0 ){ |
463 |
#endif // is_mpi |
464 |
|
465 |
if( the_globals->haveFinalConfig() ){ |
466 |
strcpy( simnfo->finalName, the_globals->getFinalConfig() ); |
467 |
} |
468 |
else{ |
469 |
strcpy( simnfo->finalName, inFileName ); |
470 |
char* endTest; |
471 |
int nameLength = strlen( simnfo->finalName ); |
472 |
endTest = &(simnfo->finalName[nameLength - 5]); |
473 |
if( !strcmp( endTest, ".bass" ) ){ |
474 |
strcpy( endTest, ".eor" ); |
475 |
} |
476 |
else if( !strcmp( endTest, ".BASS" ) ){ |
477 |
strcpy( endTest, ".eor" ); |
478 |
} |
479 |
else{ |
480 |
endTest = &(simnfo->finalName[nameLength - 4]); |
481 |
if( !strcmp( endTest, ".bss" ) ){ |
482 |
strcpy( endTest, ".eor" ); |
483 |
} |
484 |
else if( !strcmp( endTest, ".mdl" ) ){ |
485 |
strcpy( endTest, ".eor" ); |
486 |
} |
487 |
else{ |
488 |
strcat( simnfo->finalName, ".eor" ); |
489 |
} |
490 |
} |
491 |
} |
492 |
|
493 |
// make the sample and status out names |
494 |
|
495 |
strcpy( simnfo->sampleName, inFileName ); |
496 |
char* endTest; |
497 |
int nameLength = strlen( simnfo->sampleName ); |
498 |
endTest = &(simnfo->sampleName[nameLength - 5]); |
499 |
if( !strcmp( endTest, ".bass" ) ){ |
500 |
strcpy( endTest, ".dump" ); |
501 |
} |
502 |
else if( !strcmp( endTest, ".BASS" ) ){ |
503 |
strcpy( endTest, ".dump" ); |
504 |
} |
505 |
else{ |
506 |
endTest = &(simnfo->sampleName[nameLength - 4]); |
507 |
if( !strcmp( endTest, ".bss" ) ){ |
508 |
strcpy( endTest, ".dump" ); |
509 |
} |
510 |
else if( !strcmp( endTest, ".mdl" ) ){ |
511 |
strcpy( endTest, ".dump" ); |
512 |
} |
513 |
else{ |
514 |
strcat( simnfo->sampleName, ".dump" ); |
515 |
} |
516 |
} |
517 |
|
518 |
strcpy( simnfo->statusName, inFileName ); |
519 |
nameLength = strlen( simnfo->statusName ); |
520 |
endTest = &(simnfo->statusName[nameLength - 5]); |
521 |
if( !strcmp( endTest, ".bass" ) ){ |
522 |
strcpy( endTest, ".stat" ); |
523 |
} |
524 |
else if( !strcmp( endTest, ".BASS" ) ){ |
525 |
strcpy( endTest, ".stat" ); |
526 |
} |
527 |
else{ |
528 |
endTest = &(simnfo->statusName[nameLength - 4]); |
529 |
if( !strcmp( endTest, ".bss" ) ){ |
530 |
strcpy( endTest, ".stat" ); |
531 |
} |
532 |
else if( !strcmp( endTest, ".mdl" ) ){ |
533 |
strcpy( endTest, ".stat" ); |
534 |
} |
535 |
else{ |
536 |
strcat( simnfo->statusName, ".stat" ); |
537 |
} |
538 |
} |
539 |
|
540 |
#ifdef IS_MPI |
541 |
} |
542 |
#endif // is_mpi |
543 |
|
544 |
// set the status, sample, and themal kick times |
545 |
|
546 |
if( the_globals->haveSampleTime() ){ |
547 |
simnfo->sampleTime = the_globals->getSampleTime(); |
548 |
simnfo->statusTime = simnfo->sampleTime; |
549 |
simnfo->thermalTime = simnfo->sampleTime; |
550 |
} |
551 |
else{ |
552 |
simnfo->sampleTime = the_globals->getRunTime(); |
553 |
simnfo->statusTime = simnfo->sampleTime; |
554 |
simnfo->thermalTime = simnfo->sampleTime; |
555 |
} |
556 |
|
557 |
if( the_globals->haveStatusTime() ){ |
558 |
simnfo->statusTime = the_globals->getStatusTime(); |
559 |
} |
560 |
|
561 |
if( the_globals->haveThermalTime() ){ |
562 |
simnfo->thermalTime = the_globals->getThermalTime(); |
563 |
} |
564 |
|
565 |
// check for the temperature set flag |
566 |
|
567 |
if( the_globals->haveTempSet() ) simnfo->setTemp = the_globals->getTempSet(); |
568 |
|
569 |
|
570 |
// // make the longe range forces and the integrator |
571 |
|
572 |
// new AllLong( simnfo ); |
573 |
|
574 |
if( !strcmp( force_field, "TraPPE" ) ) new Verlet( *simnfo, the_ff ); |
575 |
if( !strcmp( force_field, "DipoleTest" ) ) new Symplectic( simnfo, the_ff ); |
576 |
if( !strcmp( force_field, "TraPPE_Ex" ) ) new Symplectic( simnfo, the_ff ); |
577 |
if( !strcmp( force_field, "LJ" ) ) new Verlet( *simnfo, the_ff ); |
578 |
|
579 |
} |
580 |
|
581 |
void SimSetup::makeAtoms( void ){ |
582 |
|
583 |
int i, j, k, index; |
584 |
double ux, uy, uz, uSqr, u; |
585 |
AtomStamp* current_atom; |
586 |
DirectionalAtom* dAtom; |
587 |
int molIndex, molStart, molEnd, nMemb, lMolIndex; |
588 |
|
589 |
lMolIndex = 0; |
590 |
molIndex = 0; |
591 |
index = 0; |
592 |
for( i=0; i<n_components; i++ ){ |
593 |
|
594 |
for( j=0; j<components_nmol[i]; j++ ){ |
595 |
|
596 |
#ifdef IS_MPI |
597 |
if( mpiSim->getMyMolStart() <= molIndex && |
598 |
molIndex <= mpiSim->getMyMolEnd() ){ |
599 |
#endif // is_mpi |
600 |
|
601 |
molStart = index; |
602 |
nMemb = comp_stamps[i]->getNAtoms(); |
603 |
for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){ |
604 |
|
605 |
current_atom = comp_stamps[i]->getAtom( k ); |
606 |
if( current_atom->haveOrientation() ){ |
607 |
|
608 |
dAtom = new DirectionalAtom(index); |
609 |
simnfo->n_oriented++; |
610 |
the_atoms[index] = dAtom; |
611 |
|
612 |
ux = current_atom->getOrntX(); |
613 |
uy = current_atom->getOrntY(); |
614 |
uz = current_atom->getOrntZ(); |
615 |
|
616 |
uSqr = (ux * ux) + (uy * uy) + (uz * uz); |
617 |
|
618 |
u = sqrt( uSqr ); |
619 |
ux = ux / u; |
620 |
uy = uy / u; |
621 |
uz = uz / u; |
622 |
|
623 |
dAtom->setSUx( ux ); |
624 |
dAtom->setSUy( uy ); |
625 |
dAtom->setSUz( uz ); |
626 |
} |
627 |
else{ |
628 |
the_atoms[index] = new GeneralAtom(index); |
629 |
} |
630 |
the_atoms[index]->setType( current_atom->getType() ); |
631 |
the_atoms[index]->setIndex( index ); |
632 |
|
633 |
// increment the index and repeat; |
634 |
index++; |
635 |
} |
636 |
|
637 |
molEnd = index -1; |
638 |
the_molecules[lMolIndex].setNMembers( nMemb ); |
639 |
the_molecules[lMolIndex].setStartAtom( molStart ); |
640 |
the_molecules[lMolIndex].setEndAtom( molEnd ); |
641 |
the_molecules[lMolIndex].setStampID( i ); |
642 |
lMolIndex++; |
643 |
|
644 |
#ifdef IS_MPI |
645 |
} |
646 |
#endif //is_mpi |
647 |
|
648 |
molIndex++; |
649 |
} |
650 |
} |
651 |
|
652 |
#ifdef IS_MPI |
653 |
for( i=0; i<mpiSim->getMyNlocal(); i++ ) the_atoms[i]->setGlobalIndex( globalIndex[i] ); |
654 |
|
655 |
delete[] globalIndex; |
656 |
|
657 |
mpiSim->mpiRefresh(); |
658 |
#endif //IS_MPI |
659 |
|
660 |
the_ff->initializeAtoms(); |
661 |
} |
662 |
|
663 |
void SimSetup::makeBonds( void ){ |
664 |
|
665 |
int i, j, k, index, offset, molIndex; |
666 |
bond_pair* the_bonds; |
667 |
BondStamp* current_bond; |
668 |
|
669 |
the_bonds = new bond_pair[tot_bonds]; |
670 |
index = 0; |
671 |
offset = 0; |
672 |
molIndex = 0; |
673 |
|
674 |
for( i=0; i<n_components; i++ ){ |
675 |
|
676 |
for( j=0; j<components_nmol[i]; j++ ){ |
677 |
|
678 |
#ifdef IS_MPI |
679 |
if( mpiSim->getMyMolStart() <= molIndex && |
680 |
molIndex <= mpiSim->getMyMolEnd() ){ |
681 |
#endif // is_mpi |
682 |
|
683 |
for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){ |
684 |
|
685 |
current_bond = comp_stamps[i]->getBond( k ); |
686 |
the_bonds[index].a = current_bond->getA() + offset; |
687 |
the_bonds[index].b = current_bond->getB() + offset; |
688 |
|
689 |
the_excludes[index].i = the_bonds[index].a; |
690 |
the_excludes[index].j = the_bonds[index].b; |
691 |
|
692 |
// increment the index and repeat; |
693 |
index++; |
694 |
} |
695 |
offset += comp_stamps[i]->getNAtoms(); |
696 |
|
697 |
#ifdef IS_MPI |
698 |
} |
699 |
#endif //is_mpi |
700 |
|
701 |
molIndex++; |
702 |
} |
703 |
} |
704 |
|
705 |
the_ff->initializeBonds( the_bonds ); |
706 |
} |
707 |
|
708 |
void SimSetup::makeBends( void ){ |
709 |
|
710 |
int i, j, k, index, offset, molIndex; |
711 |
bend_set* the_bends; |
712 |
BendStamp* current_bend; |
713 |
LinkedAssign* extras; |
714 |
LinkedAssign* current_extra; |
715 |
|
716 |
|
717 |
the_bends = new bend_set[tot_bends]; |
718 |
index = 0; |
719 |
offset = 0; |
720 |
molIndex = 0; |
721 |
for( i=0; i<n_components; i++ ){ |
722 |
|
723 |
for( j=0; j<components_nmol[i]; j++ ){ |
724 |
|
725 |
#ifdef IS_MPI |
726 |
if( mpiSim->getMyMolStart() <= molIndex && |
727 |
molIndex <= mpiSim->getMyMolEnd() ){ |
728 |
#endif // is_mpi |
729 |
|
730 |
for( k=0; k<comp_stamps[i]->getNBends(); k++ ){ |
731 |
|
732 |
current_bend = comp_stamps[i]->getBend( k ); |
733 |
the_bends[index].a = current_bend->getA() + offset; |
734 |
the_bends[index].b = current_bend->getB() + offset; |
735 |
the_bends[index].c = current_bend->getC() + offset; |
736 |
|
737 |
if( current_bend->haveExtras ){ |
738 |
|
739 |
extras = current_bend->getExtras(); |
740 |
current_extra = extras; |
741 |
|
742 |
while( current_extra != NULL ){ |
743 |
if( !strcmp( current_extra->getlhs(), "ghostVectorSource" )){ |
744 |
|
745 |
switch( current_extra->getType() ){ |
746 |
|
747 |
case 0: |
748 |
the_bends[index].ghost = current_extra->getInt(); |
749 |
the_bends[index].isGhost = 1; |
750 |
break; |
751 |
|
752 |
case 1: |
753 |
the_bends[index].ghost = (int)current_extra->getDouble(); |
754 |
the_bends[index].isGhost = 1; |
755 |
break; |
756 |
|
757 |
default: |
758 |
sprintf( painCave.errMsg, |
759 |
"SimSetup Error: ghostVectorSource was neiter a " |
760 |
"double nor an int.\n" |
761 |
"-->Bend[%d] in %s\n", |
762 |
k, comp_stamps[i]->getID() ); |
763 |
painCave.isFatal = 1; |
764 |
simError(); |
765 |
} |
766 |
} |
767 |
|
768 |
else{ |
769 |
|
770 |
sprintf( painCave.errMsg, |
771 |
"SimSetup Error: unhandled bend assignment:\n" |
772 |
" -->%s in Bend[%d] in %s\n", |
773 |
current_extra->getlhs(), |
774 |
k, comp_stamps[i]->getID() ); |
775 |
painCave.isFatal = 1; |
776 |
simError(); |
777 |
} |
778 |
|
779 |
current_extra = current_extra->next; |
780 |
} |
781 |
} |
782 |
|
783 |
if( !the_bends[index].isGhost ){ |
784 |
|
785 |
the_excludes[index + tot_bonds].i = the_bends[index].a; |
786 |
the_excludes[index + tot_bonds].j = the_bends[index].c; |
787 |
} |
788 |
else{ |
789 |
|
790 |
the_excludes[index + tot_bonds].i = the_bends[index].a; |
791 |
the_excludes[index + tot_bonds].j = the_bends[index].b; |
792 |
} |
793 |
|
794 |
// increment the index and repeat; |
795 |
index++; |
796 |
} |
797 |
offset += comp_stamps[i]->getNAtoms(); |
798 |
|
799 |
#ifdef IS_MPI |
800 |
} |
801 |
#endif //is_mpi |
802 |
|
803 |
molIndex++; |
804 |
} |
805 |
} |
806 |
|
807 |
#ifdef IS_MPI |
808 |
sprintf( checkPointMsg, |
809 |
"Successfully created the bends list.\n" ); |
810 |
MPIcheckPoint(); |
811 |
#endif // is_mpi |
812 |
|
813 |
|
814 |
the_ff->initializeBends( the_bends ); |
815 |
} |
816 |
|
817 |
void SimSetup::makeTorsions( void ){ |
818 |
|
819 |
int i, j, k, index, offset, molIndex; |
820 |
torsion_set* the_torsions; |
821 |
TorsionStamp* current_torsion; |
822 |
|
823 |
the_torsions = new torsion_set[tot_torsions]; |
824 |
index = 0; |
825 |
offset = 0; |
826 |
molIndex = 0; |
827 |
for( i=0; i<n_components; i++ ){ |
828 |
|
829 |
for( j=0; j<components_nmol[i]; j++ ){ |
830 |
|
831 |
#ifdef IS_MPI |
832 |
if( mpiSim->getMyMolStart() <= molIndex && |
833 |
molIndex <= mpiSim->getMyMolEnd() ){ |
834 |
#endif // is_mpi |
835 |
|
836 |
for( k=0; k<comp_stamps[i]->getNTorsions(); k++ ){ |
837 |
|
838 |
current_torsion = comp_stamps[i]->getTorsion( k ); |
839 |
the_torsions[index].a = current_torsion->getA() + offset; |
840 |
the_torsions[index].b = current_torsion->getB() + offset; |
841 |
the_torsions[index].c = current_torsion->getC() + offset; |
842 |
the_torsions[index].d = current_torsion->getD() + offset; |
843 |
|
844 |
the_excludes[index + tot_bonds + tot_bends].i = the_torsions[index].a; |
845 |
the_excludes[index + tot_bonds + tot_bends].j = the_torsions[index].d; |
846 |
|
847 |
// increment the index and repeat; |
848 |
index++; |
849 |
} |
850 |
offset += comp_stamps[i]->getNAtoms(); |
851 |
|
852 |
#ifdef IS_MPI |
853 |
} |
854 |
#endif //is_mpi |
855 |
|
856 |
molIndex++; |
857 |
} |
858 |
} |
859 |
|
860 |
the_ff->initializeTorsions( the_torsions ); |
861 |
} |
862 |
|
863 |
void SimSetup::initFromBass( void ){ |
864 |
|
865 |
int i, j, k; |
866 |
int n_cells; |
867 |
double cellx, celly, cellz; |
868 |
double temp1, temp2, temp3; |
869 |
int n_per_extra; |
870 |
int n_extra; |
871 |
int have_extra, done; |
872 |
|
873 |
temp1 = (double)tot_nmol / 4.0; |
874 |
temp2 = pow( temp1, ( 1.0 / 3.0 ) ); |
875 |
temp3 = ceil( temp2 ); |
876 |
|
877 |
have_extra =0; |
878 |
if( temp2 < temp3 ){ // we have a non-complete lattice |
879 |
have_extra =1; |
880 |
|
881 |
n_cells = (int)temp3 - 1; |
882 |
cellx = simnfo->box_x / temp3; |
883 |
celly = simnfo->box_y / temp3; |
884 |
cellz = simnfo->box_z / temp3; |
885 |
n_extra = tot_nmol - ( 4 * n_cells * n_cells * n_cells ); |
886 |
temp1 = ((double)n_extra) / ( pow( temp3, 3.0 ) - pow( n_cells, 3.0 ) ); |
887 |
n_per_extra = (int)ceil( temp1 ); |
888 |
|
889 |
if( n_per_extra > 4){ |
890 |
sprintf( painCave.errMsg, |
891 |
"SimSetup error. There has been an error in constructing" |
892 |
" the non-complete lattice.\n" ); |
893 |
painCave.isFatal = 1; |
894 |
simError(); |
895 |
} |
896 |
} |
897 |
else{ |
898 |
n_cells = (int)temp3; |
899 |
cellx = simnfo->box_x / temp3; |
900 |
celly = simnfo->box_y / temp3; |
901 |
cellz = simnfo->box_z / temp3; |
902 |
} |
903 |
|
904 |
current_mol = 0; |
905 |
current_comp_mol = 0; |
906 |
current_comp = 0; |
907 |
current_atom_ndx = 0; |
908 |
|
909 |
for( i=0; i < n_cells ; i++ ){ |
910 |
for( j=0; j < n_cells; j++ ){ |
911 |
for( k=0; k < n_cells; k++ ){ |
912 |
|
913 |
makeElement( i * cellx, |
914 |
j * celly, |
915 |
k * cellz ); |
916 |
|
917 |
makeElement( i * cellx + 0.5 * cellx, |
918 |
j * celly + 0.5 * celly, |
919 |
k * cellz ); |
920 |
|
921 |
makeElement( i * cellx, |
922 |
j * celly + 0.5 * celly, |
923 |
k * cellz + 0.5 * cellz ); |
924 |
|
925 |
makeElement( i * cellx + 0.5 * cellx, |
926 |
j * celly, |
927 |
k * cellz + 0.5 * cellz ); |
928 |
} |
929 |
} |
930 |
} |
931 |
|
932 |
if( have_extra ){ |
933 |
done = 0; |
934 |
|
935 |
int start_ndx; |
936 |
for( i=0; i < (n_cells+1) && !done; i++ ){ |
937 |
for( j=0; j < (n_cells+1) && !done; j++ ){ |
938 |
|
939 |
if( i < n_cells ){ |
940 |
|
941 |
if( j < n_cells ){ |
942 |
start_ndx = n_cells; |
943 |
} |
944 |
else start_ndx = 0; |
945 |
} |
946 |
else start_ndx = 0; |
947 |
|
948 |
for( k=start_ndx; k < (n_cells+1) && !done; k++ ){ |
949 |
|
950 |
makeElement( i * cellx, |
951 |
j * celly, |
952 |
k * cellz ); |
953 |
done = ( current_mol >= tot_nmol ); |
954 |
|
955 |
if( !done && n_per_extra > 1 ){ |
956 |
makeElement( i * cellx + 0.5 * cellx, |
957 |
j * celly + 0.5 * celly, |
958 |
k * cellz ); |
959 |
done = ( current_mol >= tot_nmol ); |
960 |
} |
961 |
|
962 |
if( !done && n_per_extra > 2){ |
963 |
makeElement( i * cellx, |
964 |
j * celly + 0.5 * celly, |
965 |
k * cellz + 0.5 * cellz ); |
966 |
done = ( current_mol >= tot_nmol ); |
967 |
} |
968 |
|
969 |
if( !done && n_per_extra > 3){ |
970 |
makeElement( i * cellx + 0.5 * cellx, |
971 |
j * celly, |
972 |
k * cellz + 0.5 * cellz ); |
973 |
done = ( current_mol >= tot_nmol ); |
974 |
} |
975 |
} |
976 |
} |
977 |
} |
978 |
} |
979 |
|
980 |
|
981 |
for( i=0; i<simnfo->n_atoms; i++ ){ |
982 |
simnfo->atoms[i]->set_vx( 0.0 ); |
983 |
simnfo->atoms[i]->set_vy( 0.0 ); |
984 |
simnfo->atoms[i]->set_vz( 0.0 ); |
985 |
} |
986 |
} |
987 |
|
988 |
void SimSetup::makeElement( double x, double y, double z ){ |
989 |
|
990 |
int k; |
991 |
AtomStamp* current_atom; |
992 |
DirectionalAtom* dAtom; |
993 |
double rotMat[3][3]; |
994 |
|
995 |
for( k=0; k<comp_stamps[current_comp]->getNAtoms(); k++ ){ |
996 |
|
997 |
current_atom = comp_stamps[current_comp]->getAtom( k ); |
998 |
if( !current_atom->havePosition() ){ |
999 |
sprintf( painCave.errMsg, |
1000 |
"SimSetup:initFromBass error.\n" |
1001 |
"\tComponent %s, atom %s does not have a position specified.\n" |
1002 |
"\tThe initialization routine is unable to give a start" |
1003 |
" position.\n", |
1004 |
comp_stamps[current_comp]->getID(), |
1005 |
current_atom->getType() ); |
1006 |
painCave.isFatal = 1; |
1007 |
simError(); |
1008 |
} |
1009 |
|
1010 |
the_atoms[current_atom_ndx]->setX( x + current_atom->getPosX() ); |
1011 |
the_atoms[current_atom_ndx]->setY( y + current_atom->getPosY() ); |
1012 |
the_atoms[current_atom_ndx]->setZ( z + current_atom->getPosZ() ); |
1013 |
|
1014 |
if( the_atoms[current_atom_ndx]->isDirectional() ){ |
1015 |
|
1016 |
dAtom = (DirectionalAtom *)the_atoms[current_atom_ndx]; |
1017 |
|
1018 |
rotMat[0][0] = 1.0; |
1019 |
rotMat[0][1] = 0.0; |
1020 |
rotMat[0][2] = 0.0; |
1021 |
|
1022 |
rotMat[1][0] = 0.0; |
1023 |
rotMat[1][1] = 1.0; |
1024 |
rotMat[1][2] = 0.0; |
1025 |
|
1026 |
rotMat[2][0] = 0.0; |
1027 |
rotMat[2][1] = 0.0; |
1028 |
rotMat[2][2] = 1.0; |
1029 |
|
1030 |
dAtom->setA( rotMat ); |
1031 |
} |
1032 |
|
1033 |
current_atom_ndx++; |
1034 |
} |
1035 |
|
1036 |
current_mol++; |
1037 |
current_comp_mol++; |
1038 |
|
1039 |
if( current_comp_mol >= components_nmol[current_comp] ){ |
1040 |
|
1041 |
current_comp_mol = 0; |
1042 |
current_comp++; |
1043 |
} |
1044 |
} |