10 |
|
|
11 |
|
#ifdef IS_MPI |
12 |
|
#include "mpiBASS.h" |
13 |
+ |
#include "mpiSimulation.hpp" |
14 |
|
#include "bassDiag.hpp" |
15 |
|
#endif |
16 |
|
|
74 |
|
|
75 |
|
MakeStamps *the_stamps; |
76 |
|
Globals* the_globals; |
77 |
< |
int i; |
77 |
> |
int i, j; |
78 |
|
|
79 |
|
// get the stamps and globals; |
80 |
|
the_stamps = stamps; |
93 |
|
if( !strcmp( force_field, "TraPPE" ) ) the_ff = new TraPPEFF(); |
94 |
|
else if( !strcmp( force_field, "DipoleTest" ) ) the_ff = new DipoleTestFF(); |
95 |
|
else if( !strcmp( force_field, "TraPPE_Ex" ) ) the_ff = new TraPPE_ExFF(); |
96 |
+ |
else if( !strcmp( force_field, "LJ" ) ) the_ff = new LJ_FF(); |
97 |
|
else{ |
98 |
|
sprintf( painCave.errMsg, |
99 |
|
"SimSetup Error. Unrecognized force field -> %s\n", |
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 |
< |
comp_stamps[i] = |
179 |
< |
the_stamps->getMolecule( the_components[i]->getType() ); |
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; |
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(); |
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 |
|
|
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 |
+ |
mpiSim->divideLabor(); |
242 |
|
|
243 |
+ |
// set up the local variables |
244 |
+ |
|
245 |
+ |
int localMol, allMol; |
246 |
+ |
int local_atoms, local_bonds, local_bends, local_torsions, local_SRI; |
247 |
+ |
|
248 |
+ |
allMol = 0; |
249 |
+ |
localMol = 0; |
250 |
+ |
local_atoms = 0; |
251 |
+ |
local_bonds = 0; |
252 |
+ |
local_bends = 0; |
253 |
+ |
local_torsions = 0; |
254 |
+ |
for( i=0; i<n_components; i++ ){ |
255 |
|
|
256 |
+ |
for( j=0; j<components_nmol[i]; j++ ){ |
257 |
+ |
|
258 |
+ |
if( mpiSim->getMyMolStart() <= allMol && |
259 |
+ |
allMol <= mpiSim->getMyMolEnd() ){ |
260 |
+ |
|
261 |
+ |
local_atoms += comp_stamps[i]->getNAtoms(); |
262 |
+ |
local_bonds += comp_stamps[i]->getNBonds(); |
263 |
+ |
local_bends += comp_stamps[i]->getNBends(); |
264 |
+ |
local_torsions += comp_stamps[i]->getNTorsions(); |
265 |
+ |
localMol++; |
266 |
+ |
} |
267 |
+ |
allMol++; |
268 |
+ |
} |
269 |
+ |
} |
270 |
+ |
local_SRI = local_bonds + local_bends + local_torsions; |
271 |
+ |
|
272 |
+ |
|
273 |
+ |
simnfo->n_atoms = mpiSim->getMyNlocal(); |
274 |
+ |
|
275 |
+ |
if( local_atoms != simnfo->n_atoms ){ |
276 |
+ |
sprintf( painCave.errMsg, |
277 |
+ |
"SimSetup error: mpiSim's localAtom (%d) and SimSetup's" |
278 |
+ |
" localAtom (%d) are note equal.\n", |
279 |
+ |
simnfo->n_atoms, |
280 |
+ |
local_atoms ); |
281 |
+ |
painCave.isFatal = 1; |
282 |
+ |
simError(); |
283 |
+ |
} |
284 |
+ |
|
285 |
+ |
simnfo->n_bonds = local_bonds; |
286 |
+ |
simnfo->n_bends = local_bends; |
287 |
+ |
simnfo->n_torsions = local_torsions; |
288 |
+ |
simnfo->n_SRI = local_SRI; |
289 |
+ |
simnfo->n_mol = localMol; |
290 |
+ |
|
291 |
+ |
strcpy( checkPointMsg, "Passed nlocal consistency check." ); |
292 |
+ |
MPIcheckPoint(); |
293 |
+ |
|
294 |
+ |
|
295 |
+ |
#endif // is_mpi |
296 |
+ |
|
297 |
+ |
|
298 |
|
// create the atom and short range interaction arrays |
299 |
|
|
300 |
< |
Atom::createArrays(tot_atoms); |
301 |
< |
the_atoms = new Atom*[tot_atoms]; |
302 |
< |
the_molecules = new Molecule[tot_nmol]; |
300 |
> |
Atom::createArrays(simnfo->n_atoms); |
301 |
> |
the_atoms = new Atom*[simnfo->n_atoms]; |
302 |
> |
the_molecules = new Molecule[simnfo->n_mol]; |
303 |
|
|
304 |
|
|
305 |
< |
if( tot_SRI ){ |
306 |
< |
the_sris = new SRI*[tot_SRI]; |
307 |
< |
the_excludes = new ex_pair[tot_SRI]; |
305 |
> |
if( simnfo->n_SRI ){ |
306 |
> |
the_sris = new SRI*[simnfo->n_SRI]; |
307 |
> |
the_excludes = new ex_pair[simnfo->n_SRI]; |
308 |
|
} |
309 |
|
|
310 |
|
// set the arrays into the SimInfo object |
333 |
|
makeTorsions(); |
334 |
|
} |
335 |
|
|
236 |
– |
// makeMolecules(); |
336 |
|
|
337 |
|
// get some of the tricky things that may still be in the globals |
338 |
|
|
407 |
|
|
408 |
|
|
409 |
|
|
410 |
< |
// if( the_globals->haveInitialConfig() ){ |
312 |
< |
// InitializeFromFile* fileInit; |
313 |
< |
// fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); |
314 |
< |
|
315 |
< |
// fileInit->read_xyz( simnfo ); // default velocities on |
316 |
< |
|
317 |
< |
// delete fileInit; |
318 |
< |
// } |
319 |
< |
// else{ |
320 |
< |
|
321 |
< |
initFromBass(); |
410 |
> |
if( the_globals->haveInitialConfig() ){ |
411 |
|
|
412 |
+ |
InitializeFromFile* fileInit; |
413 |
+ |
#ifdef IS_MPI // is_mpi |
414 |
+ |
if( worldRank == 0 ){ |
415 |
+ |
#endif //is_mpi |
416 |
+ |
fileInit = new InitializeFromFile( the_globals->getInitialConfig() ); |
417 |
|
#ifdef IS_MPI |
418 |
< |
strcpy( checkPointMsg, "initFromBass successfully created the lattice" ); |
418 |
> |
}else fileInit = new InitializeFromFile( NULL ); |
419 |
> |
#endif |
420 |
> |
fileInit->read_xyz( simnfo ); // default velocities on |
421 |
> |
|
422 |
> |
delete fileInit; |
423 |
> |
} |
424 |
> |
else{ |
425 |
> |
|
426 |
> |
#ifdef IS_MPI |
427 |
> |
|
428 |
> |
// no init from bass |
429 |
> |
|
430 |
> |
sprintf( painCave.errMsg, |
431 |
> |
"Cannot intialize a parallel simulation without an initial configuration file.\n" ); |
432 |
> |
painCave.isFatal; |
433 |
> |
simError(); |
434 |
> |
|
435 |
> |
#else |
436 |
> |
|
437 |
> |
initFromBass(); |
438 |
> |
|
439 |
> |
|
440 |
> |
#endif |
441 |
> |
} |
442 |
> |
|
443 |
> |
#ifdef IS_MPI |
444 |
> |
strcpy( checkPointMsg, "Successfully read in the initial configuration" ); |
445 |
|
MPIcheckPoint(); |
446 |
|
#endif // is_mpi |
447 |
|
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
< |
// } |
452 |
> |
|
453 |
|
|
454 |
|
#ifdef IS_MPI |
455 |
|
if( worldRank == 0 ){ |
575 |
|
double ux, uy, uz, uSqr, u; |
576 |
|
AtomStamp* current_atom; |
577 |
|
DirectionalAtom* dAtom; |
578 |
< |
int molIndex, molStart, molEnd, nMemb; |
578 |
> |
int molIndex, molStart, molEnd, nMemb, lMolIndex; |
579 |
|
|
580 |
< |
|
580 |
> |
lMolIndex = 0; |
581 |
|
molIndex = 0; |
582 |
|
index = 0; |
583 |
|
for( i=0; i<n_components; i++ ){ |
584 |
|
|
585 |
|
for( j=0; j<components_nmol[i]; j++ ){ |
586 |
|
|
587 |
< |
molStart = index; |
588 |
< |
nMemb = comp_stamps[i]->getNAtoms(); |
589 |
< |
for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){ |
590 |
< |
|
471 |
< |
current_atom = comp_stamps[i]->getAtom( k ); |
472 |
< |
if( current_atom->haveOrientation() ){ |
587 |
> |
#ifdef IS_MPI |
588 |
> |
if( mpiSim->getMyMolStart() <= molIndex && |
589 |
> |
molIndex <= mpiSim->getMyMolEnd() ){ |
590 |
> |
#endif // is_mpi |
591 |
|
|
592 |
< |
dAtom = new DirectionalAtom(index); |
593 |
< |
simnfo->n_oriented++; |
594 |
< |
the_atoms[index] = dAtom; |
595 |
< |
|
596 |
< |
ux = current_atom->getOrntX(); |
597 |
< |
uy = current_atom->getOrntY(); |
598 |
< |
uz = current_atom->getOrntZ(); |
599 |
< |
|
600 |
< |
uSqr = (ux * ux) + (uy * uy) + (uz * uz); |
601 |
< |
|
602 |
< |
u = sqrt( uSqr ); |
603 |
< |
ux = ux / u; |
604 |
< |
uy = uy / u; |
605 |
< |
uz = uz / u; |
606 |
< |
|
607 |
< |
dAtom->setSUx( ux ); |
608 |
< |
dAtom->setSUy( uy ); |
609 |
< |
dAtom->setSUz( uz ); |
592 |
> |
molStart = index; |
593 |
> |
nMemb = comp_stamps[i]->getNAtoms(); |
594 |
> |
for( k=0; k<comp_stamps[i]->getNAtoms(); k++ ){ |
595 |
> |
|
596 |
> |
current_atom = comp_stamps[i]->getAtom( k ); |
597 |
> |
if( current_atom->haveOrientation() ){ |
598 |
> |
|
599 |
> |
dAtom = new DirectionalAtom(index); |
600 |
> |
simnfo->n_oriented++; |
601 |
> |
the_atoms[index] = dAtom; |
602 |
> |
|
603 |
> |
ux = current_atom->getOrntX(); |
604 |
> |
uy = current_atom->getOrntY(); |
605 |
> |
uz = current_atom->getOrntZ(); |
606 |
> |
|
607 |
> |
uSqr = (ux * ux) + (uy * uy) + (uz * uz); |
608 |
> |
|
609 |
> |
u = sqrt( uSqr ); |
610 |
> |
ux = ux / u; |
611 |
> |
uy = uy / u; |
612 |
> |
uz = uz / u; |
613 |
> |
|
614 |
> |
dAtom->setSUx( ux ); |
615 |
> |
dAtom->setSUy( uy ); |
616 |
> |
dAtom->setSUz( uz ); |
617 |
> |
} |
618 |
> |
else{ |
619 |
> |
the_atoms[index] = new GeneralAtom(index); |
620 |
> |
} |
621 |
> |
the_atoms[index]->setType( current_atom->getType() ); |
622 |
> |
the_atoms[index]->setIndex( index ); |
623 |
> |
|
624 |
> |
// increment the index and repeat; |
625 |
> |
index++; |
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 ); |
627 |
> |
|
628 |
> |
molEnd = index -1; |
629 |
> |
the_molecules[lMolIndex].setNMembers( nMemb ); |
630 |
> |
the_molecules[lMolIndex].setStartAtom( molStart ); |
631 |
> |
the_molecules[lMolIndex].setEndAtom( molEnd ); |
632 |
> |
the_molecules[lMolIndex].setStampID( i ); |
633 |
> |
lMolIndex++; |
634 |
|
|
635 |
< |
// increment the index and repeat; |
500 |
< |
index++; |
635 |
> |
#ifdef IS_MPI |
636 |
|
} |
637 |
< |
|
638 |
< |
molEnd = index -1; |
504 |
< |
the_molecules[molIndex].setNMembers( nMemb ); |
505 |
< |
the_molecules[molIndex].setStartAtom( molStart ); |
506 |
< |
the_molecules[molIndex].setEndAtom( molEnd ); |
637 |
> |
#endif //is_mpi |
638 |
> |
|
639 |
|
molIndex++; |
508 |
– |
|
640 |
|
} |
641 |
|
} |
642 |
|
|
645 |
|
|
646 |
|
void SimSetup::makeBonds( void ){ |
647 |
|
|
648 |
< |
int i, j, k, index, offset; |
648 |
> |
int i, j, k, index, offset, molIndex; |
649 |
|
bond_pair* the_bonds; |
650 |
|
BondStamp* current_bond; |
651 |
|
|
652 |
|
the_bonds = new bond_pair[tot_bonds]; |
653 |
|
index = 0; |
654 |
|
offset = 0; |
655 |
+ |
molIndex = 0;g1 |
656 |
+ |
|
657 |
|
for( i=0; i<n_components; i++ ){ |
658 |
|
|
659 |
|
for( j=0; j<components_nmol[i]; j++ ){ |
660 |
|
|
661 |
< |
for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){ |
662 |
< |
|
663 |
< |
current_bond = comp_stamps[i]->getBond( k ); |
664 |
< |
the_bonds[index].a = current_bond->getA() + offset; |
665 |
< |
the_bonds[index].b = current_bond->getB() + offset; |
666 |
< |
|
667 |
< |
the_excludes[index].i = the_bonds[index].a; |
668 |
< |
the_excludes[index].j = the_bonds[index].b; |
669 |
< |
|
670 |
< |
// increment the index and repeat; |
671 |
< |
index++; |
661 |
> |
#ifdef IS_MPI |
662 |
> |
if( mpiSim->getMyMolStart() <= molIndex && |
663 |
> |
molIndex <= mpiSim->getMyMolEnd() ){ |
664 |
> |
#endif // is_mpi |
665 |
> |
|
666 |
> |
for( k=0; k<comp_stamps[i]->getNBonds(); k++ ){ |
667 |
> |
|
668 |
> |
current_bond = comp_stamps[i]->getBond( k ); |
669 |
> |
the_bonds[index].a = current_bond->getA() + offset; |
670 |
> |
the_bonds[index].b = current_bond->getB() + offset; |
671 |
> |
|
672 |
> |
the_excludes[index].i = the_bonds[index].a; |
673 |
> |
the_excludes[index].j = the_bonds[index].b; |
674 |
> |
|
675 |
> |
// increment the index and repeat; |
676 |
> |
index++; |
677 |
> |
} |
678 |
> |
offset += comp_stamps[i]->getNAtoms(); |
679 |
> |
|
680 |
> |
#ifdef IS_MPI |
681 |
|
} |
682 |
< |
offset += comp_stamps[i]->getNAtoms(); |
683 |
< |
} |
682 |
> |
#endif is_mpi |
683 |
> |
|
684 |
> |
molIndex++; |
685 |
> |
} |
686 |
|
} |
687 |
|
|
688 |
|
the_ff->initializeBonds( the_bonds ); |
690 |
|
|
691 |
|
void SimSetup::makeBends( void ){ |
692 |
|
|
693 |
< |
int i, j, k, index, offset; |
693 |
> |
int i, j, k, index, offset, molIndex; |
694 |
|
bend_set* the_bends; |
695 |
|
BendStamp* current_bend; |
696 |
|
|
697 |
|
the_bends = new bend_set[tot_bends]; |
698 |
|
index = 0; |
699 |
|
offset = 0; |
700 |
+ |
molIndex = 0; |
701 |
|
for( i=0; i<n_components; i++ ){ |
702 |
|
|
703 |
|
for( j=0; j<components_nmol[i]; j++ ){ |
704 |
|
|
705 |
< |
for( k=0; k<comp_stamps[i]->getNBends(); k++ ){ |
705 |
> |
#ifdef IS_MPI |
706 |
> |
if( mpiSim->getMyMolStart() <= molIndex && |
707 |
> |
molIndex <= mpiSim->getMyMolEnd() ){ |
708 |
> |
#endif // is_mpi |
709 |
|
|
710 |
< |
current_bend = comp_stamps[i]->getBend( k ); |
711 |
< |
the_bends[index].a = current_bend->getA() + offset; |
712 |
< |
the_bends[index].b = current_bend->getB() + offset; |
713 |
< |
the_bends[index].c = current_bend->getC() + offset; |
714 |
< |
|
715 |
< |
the_excludes[index + tot_bonds].i = the_bends[index].a; |
716 |
< |
the_excludes[index + tot_bonds].j = the_bends[index].c; |
717 |
< |
|
718 |
< |
// increment the index and repeat; |
719 |
< |
index++; |
710 |
> |
for( k=0; k<comp_stamps[i]->getNBends(); k++ ){ |
711 |
> |
|
712 |
> |
current_bend = comp_stamps[i]->getBend( k ); |
713 |
> |
the_bends[index].a = current_bend->getA() + offset; |
714 |
> |
the_bends[index].b = current_bend->getB() + offset; |
715 |
> |
the_bends[index].c = current_bend->getC() + offset; |
716 |
> |
|
717 |
> |
the_excludes[index + tot_bonds].i = the_bends[index].a; |
718 |
> |
the_excludes[index + tot_bonds].j = the_bends[index].c; |
719 |
> |
|
720 |
> |
// increment the index and repeat; |
721 |
> |
index++; |
722 |
> |
} |
723 |
> |
offset += comp_stamps[i]->getNAtoms(); |
724 |
> |
|
725 |
> |
#ifdef IS_MPI |
726 |
|
} |
727 |
< |
offset += comp_stamps[i]->getNAtoms(); |
727 |
> |
#endif //is_mpi |
728 |
> |
|
729 |
> |
molIndex++; |
730 |
|
} |
731 |
|
} |
732 |
|
|
735 |
|
|
736 |
|
void SimSetup::makeTorsions( void ){ |
737 |
|
|
738 |
< |
int i, j, k, index, offset; |
738 |
> |
int i, j, k, index, offset, molIndex; |
739 |
|
torsion_set* the_torsions; |
740 |
|
TorsionStamp* current_torsion; |
741 |
|
|
742 |
|
the_torsions = new torsion_set[tot_torsions]; |
743 |
|
index = 0; |
744 |
|
offset = 0; |
745 |
+ |
molIndex = 0; |
746 |
|
for( i=0; i<n_components; i++ ){ |
747 |
|
|
748 |
|
for( j=0; j<components_nmol[i]; j++ ){ |
749 |
|
|
750 |
+ |
#ifdef IS_MPI |
751 |
+ |
if( mpiSim->getMyMolStart() <= molIndex && |
752 |
+ |
molIndex <= mpiSim->getMyMolEnd() ){ |
753 |
+ |
#endif // is_mpi |
754 |
+ |
|
755 |
|
for( k=0; k<comp_stamps[i]->getNTorsions(); k++ ){ |
756 |
|
|
757 |
|
current_torsion = comp_stamps[i]->getTorsion( k ); |
767 |
|
index++; |
768 |
|
} |
769 |
|
offset += comp_stamps[i]->getNAtoms(); |
770 |
+ |
|
771 |
+ |
#ifdef IS_MPI |
772 |
+ |
} |
773 |
+ |
#endif //is_mpi |
774 |
+ |
|
775 |
+ |
molIndex++; |
776 |
|
} |
777 |
|
} |
778 |
|
|