54 |
|
#include "math/Vector3.hpp" |
55 |
|
#include "primitives/Molecule.hpp" |
56 |
|
#include "primitives/StuntDouble.hpp" |
57 |
– |
#include "UseTheForce/DarkSide/neighborLists_interface.h" |
58 |
– |
#include "UseTheForce/doForces_interface.h" |
57 |
|
#include "utils/MemoryUtils.hpp" |
58 |
|
#include "utils/simError.h" |
59 |
|
#include "selection/SelectionManager.hpp" |
61 |
|
#include "UseTheForce/ForceField.hpp" |
62 |
|
#include "nonbonded/SwitchingFunction.hpp" |
63 |
|
|
66 |
– |
#ifdef IS_MPI |
67 |
– |
#include "UseTheForce/mpiComponentPlan.h" |
68 |
– |
#include "UseTheForce/DarkSide/simParallel_interface.h" |
69 |
– |
#endif |
70 |
– |
|
64 |
|
using namespace std; |
65 |
|
namespace OpenMD { |
66 |
|
|
71 |
|
nGlobalIntegrableObjects_(0), nGlobalRigidBodies_(0), |
72 |
|
nAtoms_(0), nBonds_(0), nBends_(0), nTorsions_(0), nInversions_(0), |
73 |
|
nRigidBodies_(0), nIntegrableObjects_(0), nCutoffGroups_(0), |
74 |
< |
nConstraints_(0), sman_(NULL), fortranInitialized_(false), |
74 |
> |
nConstraints_(0), sman_(NULL), topologyDone_(false), |
75 |
|
calcBoxDipole_(false), useAtomicVirial_(true) { |
76 |
|
|
77 |
|
MoleculeStamp* molStamp; |
770 |
|
temp = usesElectrostatic; |
771 |
|
MPI_Allreduce(&temp, &usesElectrostaticAtoms_, 1, MPI_INT, MPI_LOR, MPI_COMM_WORLD); |
772 |
|
#endif |
780 |
– |
fInfo_.SIM_uses_PBC = usesPeriodicBoundaries_; |
781 |
– |
fInfo_.SIM_uses_DirectionalAtoms = usesDirectionalAtoms_; |
782 |
– |
fInfo_.SIM_uses_MetallicAtoms = usesMetallicAtoms_; |
783 |
– |
fInfo_.SIM_requires_SkipCorrection = usesElectrostaticAtoms_; |
784 |
– |
fInfo_.SIM_requires_SelfCorrection = usesElectrostaticAtoms_; |
785 |
– |
fInfo_.SIM_uses_AtomicVirial = usesAtomicVirial_; |
773 |
|
} |
774 |
|
|
788 |
– |
void SimInfo::setupFortran() { |
789 |
– |
int isError; |
790 |
– |
int nExclude, nOneTwo, nOneThree, nOneFour; |
791 |
– |
vector<int> fortranGlobalGroupMembership; |
792 |
– |
|
793 |
– |
isError = 0; |
775 |
|
|
776 |
< |
//globalGroupMembership_ is filled by SimCreator |
777 |
< |
for (int i = 0; i < nGlobalAtoms_; i++) { |
778 |
< |
fortranGlobalGroupMembership.push_back(globalGroupMembership_[i] + 1); |
776 |
> |
vector<int> SimInfo::getGlobalAtomIndices() { |
777 |
> |
SimInfo::MoleculeIterator mi; |
778 |
> |
Molecule* mol; |
779 |
> |
Molecule::AtomIterator ai; |
780 |
> |
Atom* atom; |
781 |
> |
|
782 |
> |
vector<int> GlobalAtomIndices(getNAtoms(), 0); |
783 |
> |
|
784 |
> |
for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
785 |
> |
|
786 |
> |
for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
787 |
> |
GlobalAtomIndices[atom->getLocalIndex()] = atom->getGlobalIndex(); |
788 |
> |
} |
789 |
> |
} |
790 |
> |
return GlobalAtomIndices; |
791 |
> |
} |
792 |
> |
|
793 |
> |
|
794 |
> |
vector<int> SimInfo::getGlobalGroupIndices() { |
795 |
> |
SimInfo::MoleculeIterator mi; |
796 |
> |
Molecule* mol; |
797 |
> |
Molecule::CutoffGroupIterator ci; |
798 |
> |
CutoffGroup* cg; |
799 |
> |
|
800 |
> |
vector<int> GlobalGroupIndices; |
801 |
> |
|
802 |
> |
for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
803 |
> |
|
804 |
> |
//local index of cutoff group is trivial, it only depends on the |
805 |
> |
//order of travesing |
806 |
> |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; |
807 |
> |
cg = mol->nextCutoffGroup(ci)) { |
808 |
> |
GlobalGroupIndices.push_back(cg->getGlobalIndex()); |
809 |
> |
} |
810 |
|
} |
811 |
+ |
return GlobalGroupIndices; |
812 |
+ |
} |
813 |
|
|
814 |
+ |
|
815 |
+ |
void SimInfo::prepareTopology() { |
816 |
+ |
int nExclude, nOneTwo, nOneThree, nOneFour; |
817 |
+ |
|
818 |
|
//calculate mass ratio of cutoff group |
801 |
– |
vector<RealType> mfact; |
819 |
|
SimInfo::MoleculeIterator mi; |
820 |
|
Molecule* mol; |
821 |
|
Molecule::CutoffGroupIterator ci; |
824 |
|
Atom* atom; |
825 |
|
RealType totalMass; |
826 |
|
|
827 |
< |
//to avoid memory reallocation, reserve enough space for mfact |
828 |
< |
mfact.reserve(getNCutoffGroups()); |
827 |
> |
//to avoid memory reallocation, reserve enough space for massFactors_ |
828 |
> |
massFactors_.clear(); |
829 |
> |
massFactors_.reserve(getNCutoffGroups()); |
830 |
|
|
831 |
|
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
832 |
< |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
832 |
> |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; |
833 |
> |
cg = mol->nextCutoffGroup(ci)) { |
834 |
|
|
835 |
|
totalMass = cg->getMass(); |
836 |
|
for(atom = cg->beginAtom(ai); atom != NULL; atom = cg->nextAtom(ai)) { |
837 |
|
// Check for massless groups - set mfact to 1 if true |
838 |
|
if (totalMass != 0) |
839 |
< |
mfact.push_back(atom->getMass()/totalMass); |
839 |
> |
massFactors_.push_back(atom->getMass()/totalMass); |
840 |
|
else |
841 |
< |
mfact.push_back( 1.0 ); |
841 |
> |
massFactors_.push_back( 1.0 ); |
842 |
|
} |
843 |
|
} |
844 |
|
} |
845 |
|
|
846 |
< |
//fill ident array of local atoms (it is actually ident of |
828 |
< |
//AtomType, it is so confusing !!!) |
829 |
< |
vector<int> identArray; |
846 |
> |
// Build the identArray_ |
847 |
|
|
848 |
< |
//to avoid memory reallocation, reserve enough space identArray |
849 |
< |
identArray.reserve(getNAtoms()); |
833 |
< |
|
848 |
> |
identArray_.clear(); |
849 |
> |
identArray_.reserve(getNAtoms()); |
850 |
|
for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
851 |
|
for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
852 |
< |
identArray.push_back(atom->getIdent()); |
852 |
> |
identArray_.push_back(atom->getIdent()); |
853 |
|
} |
854 |
|
} |
839 |
– |
|
840 |
– |
//fill molMembershipArray |
841 |
– |
//molMembershipArray is filled by SimCreator |
842 |
– |
vector<int> molMembershipArray(nGlobalAtoms_); |
843 |
– |
for (int i = 0; i < nGlobalAtoms_; i++) { |
844 |
– |
molMembershipArray[i] = globalMolMembership_[i] + 1; |
845 |
– |
} |
855 |
|
|
856 |
< |
//setup fortran simulation |
856 |
> |
//scan topology |
857 |
|
|
858 |
|
nExclude = excludedInteractions_.getSize(); |
859 |
|
nOneTwo = oneTwoInteractions_.getSize(); |
865 |
|
int* oneThreeList = oneThreeInteractions_.getPairList(); |
866 |
|
int* oneFourList = oneFourInteractions_.getPairList(); |
867 |
|
|
868 |
< |
setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray[0], |
869 |
< |
&nExclude, excludeList, |
870 |
< |
&nOneTwo, oneTwoList, |
871 |
< |
&nOneThree, oneThreeList, |
872 |
< |
&nOneFour, oneFourList, |
873 |
< |
&molMembershipArray[0], &mfact[0], &nCutoffGroups_, |
874 |
< |
&fortranGlobalGroupMembership[0], &isError); |
868 |
> |
//setFortranSim( &fInfo_, &nGlobalAtoms_, &nAtoms_, &identArray_[0], |
869 |
> |
// &nExclude, excludeList, |
870 |
> |
// &nOneTwo, oneTwoList, |
871 |
> |
// &nOneThree, oneThreeList, |
872 |
> |
// &nOneFour, oneFourList, |
873 |
> |
// &molMembershipArray[0], &mfact[0], &nCutoffGroups_, |
874 |
> |
// &fortranGlobalGroupMembership[0], &isError); |
875 |
|
|
876 |
< |
if( isError ){ |
868 |
< |
|
869 |
< |
sprintf( painCave.errMsg, |
870 |
< |
"There was an error setting the simulation information in fortran.\n" ); |
871 |
< |
painCave.isFatal = 1; |
872 |
< |
painCave.severity = OPENMD_ERROR; |
873 |
< |
simError(); |
874 |
< |
} |
875 |
< |
|
876 |
< |
|
877 |
< |
sprintf( checkPointMsg, |
878 |
< |
"succesfully sent the simulation information to fortran.\n"); |
879 |
< |
|
880 |
< |
errorCheckPoint(); |
881 |
< |
|
882 |
< |
// Setup number of neighbors in neighbor list if present |
883 |
< |
if (simParams_->haveNeighborListNeighbors()) { |
884 |
< |
int nlistNeighbors = simParams_->getNeighborListNeighbors(); |
885 |
< |
setNeighbors(&nlistNeighbors); |
886 |
< |
} |
887 |
< |
|
888 |
< |
#ifdef IS_MPI |
889 |
< |
//SimInfo is responsible for creating localToGlobalAtomIndex and |
890 |
< |
//localToGlobalGroupIndex |
891 |
< |
vector<int> localToGlobalAtomIndex(getNAtoms(), 0); |
892 |
< |
vector<int> localToGlobalCutoffGroupIndex; |
893 |
< |
mpiSimData parallelData; |
894 |
< |
|
895 |
< |
for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
896 |
< |
|
897 |
< |
//local index(index in DataStorge) of atom is important |
898 |
< |
for (atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { |
899 |
< |
localToGlobalAtomIndex[atom->getLocalIndex()] = atom->getGlobalIndex() + 1; |
900 |
< |
} |
901 |
< |
|
902 |
< |
//local index of cutoff group is trivial, it only depends on the order of travesing |
903 |
< |
for (cg = mol->beginCutoffGroup(ci); cg != NULL; cg = mol->nextCutoffGroup(ci)) { |
904 |
< |
localToGlobalCutoffGroupIndex.push_back(cg->getGlobalIndex() + 1); |
905 |
< |
} |
906 |
< |
|
907 |
< |
} |
908 |
< |
|
909 |
< |
//fill up mpiSimData struct |
910 |
< |
parallelData.nMolGlobal = getNGlobalMolecules(); |
911 |
< |
parallelData.nMolLocal = getNMolecules(); |
912 |
< |
parallelData.nAtomsGlobal = getNGlobalAtoms(); |
913 |
< |
parallelData.nAtomsLocal = getNAtoms(); |
914 |
< |
parallelData.nGroupsGlobal = getNGlobalCutoffGroups(); |
915 |
< |
parallelData.nGroupsLocal = getNCutoffGroups(); |
916 |
< |
parallelData.myNode = worldRank; |
917 |
< |
MPI_Comm_size(MPI_COMM_WORLD, &(parallelData.nProcessors)); |
918 |
< |
|
919 |
< |
//pass mpiSimData struct and index arrays to fortran |
920 |
< |
setFsimParallel(¶llelData, &(parallelData.nAtomsLocal), |
921 |
< |
&localToGlobalAtomIndex[0], &(parallelData.nGroupsLocal), |
922 |
< |
&localToGlobalCutoffGroupIndex[0], &isError); |
923 |
< |
|
924 |
< |
if (isError) { |
925 |
< |
sprintf(painCave.errMsg, |
926 |
< |
"mpiRefresh errror: fortran didn't like something we gave it.\n"); |
927 |
< |
painCave.isFatal = 1; |
928 |
< |
simError(); |
929 |
< |
} |
930 |
< |
|
931 |
< |
sprintf(checkPointMsg, " mpiRefresh successful.\n"); |
932 |
< |
errorCheckPoint(); |
933 |
< |
#endif |
934 |
< |
|
935 |
< |
initFortranFF(&isError); |
936 |
< |
if (isError) { |
937 |
< |
sprintf(painCave.errMsg, |
938 |
< |
"initFortranFF errror: fortran didn't like something we gave it.\n"); |
939 |
< |
painCave.isFatal = 1; |
940 |
< |
simError(); |
941 |
< |
} |
942 |
< |
fortranInitialized_ = true; |
876 |
> |
topologyDone_ = true; |
877 |
|
} |
878 |
|
|
879 |
|
void SimInfo::addProperty(GenericData* genData) { |