54 |
|
#include "math/Vector3.hpp" |
55 |
|
#include "primitives/Molecule.hpp" |
56 |
|
#include "primitives/StuntDouble.hpp" |
57 |
– |
#include "UseTheForce/doForces_interface.h" |
57 |
|
#include "UseTheForce/DarkSide/neighborLists_interface.h" |
58 |
+ |
#include "UseTheForce/doForces_interface.h" |
59 |
|
#include "utils/MemoryUtils.hpp" |
60 |
|
#include "utils/simError.h" |
61 |
|
#include "selection/SelectionManager.hpp" |
63 |
|
#include "UseTheForce/ForceField.hpp" |
64 |
|
#include "nonbonded/SwitchingFunction.hpp" |
65 |
|
|
66 |
– |
|
66 |
|
#ifdef IS_MPI |
67 |
|
#include "UseTheForce/mpiComponentPlan.h" |
68 |
|
#include "UseTheForce/DarkSide/simParallel_interface.h" |
656 |
|
/** |
657 |
|
* update |
658 |
|
* |
659 |
< |
* Performs the global checks and variable settings after the objects have been |
660 |
< |
* created. |
659 |
> |
* Performs the global checks and variable settings after the |
660 |
> |
* objects have been created. |
661 |
|
* |
662 |
|
*/ |
663 |
< |
void SimInfo::update() { |
665 |
< |
|
663 |
> |
void SimInfo::update() { |
664 |
|
setupSimVariables(); |
667 |
– |
setupCutoffs(); |
668 |
– |
setupSwitching(); |
669 |
– |
setupElectrostatics(); |
670 |
– |
setupNeighborlists(); |
671 |
– |
|
672 |
– |
#ifdef IS_MPI |
673 |
– |
setupFortranParallel(); |
674 |
– |
#endif |
675 |
– |
setupFortranSim(); |
676 |
– |
fortranInitialized_ = true; |
677 |
– |
|
665 |
|
calcNdf(); |
666 |
|
calcNdfRaw(); |
667 |
|
calcNdfTrans(); |
668 |
|
} |
669 |
|
|
670 |
+ |
/** |
671 |
+ |
* getSimulatedAtomTypes |
672 |
+ |
* |
673 |
+ |
* Returns an STL set of AtomType* that are actually present in this |
674 |
+ |
* simulation. Must query all processors to assemble this information. |
675 |
+ |
* |
676 |
+ |
*/ |
677 |
|
set<AtomType*> SimInfo::getSimulatedAtomTypes() { |
678 |
|
SimInfo::MoleculeIterator mi; |
679 |
|
Molecule* mol; |
686 |
|
atomTypes.insert(atom->getAtomType()); |
687 |
|
} |
688 |
|
} |
695 |
– |
return atomTypes; |
696 |
– |
} |
689 |
|
|
690 |
< |
/** |
699 |
< |
* setupCutoffs |
700 |
< |
* |
701 |
< |
* Sets the values of cutoffRadius and cutoffMethod |
702 |
< |
* |
703 |
< |
* cutoffRadius : realType |
704 |
< |
* If the cutoffRadius was explicitly set, use that value. |
705 |
< |
* If the cutoffRadius was not explicitly set: |
706 |
< |
* Are there electrostatic atoms? Use 12.0 Angstroms. |
707 |
< |
* No electrostatic atoms? Poll the atom types present in the |
708 |
< |
* simulation for suggested cutoff values (e.g. 2.5 * sigma). |
709 |
< |
* Use the maximum suggested value that was found. |
710 |
< |
* |
711 |
< |
* cutoffMethod : (one of HARD, SWITCHED, SHIFTED_FORCE, SHIFTED_POTENTIAL) |
712 |
< |
* If cutoffMethod was explicitly set, use that choice. |
713 |
< |
* If cutoffMethod was not explicitly set, use SHIFTED_FORCE |
714 |
< |
*/ |
715 |
< |
void SimInfo::setupCutoffs() { |
716 |
< |
|
717 |
< |
if (simParams_->haveCutoffRadius()) { |
718 |
< |
cutoffRadius_ = simParams_->getCutoffRadius(); |
719 |
< |
} else { |
720 |
< |
if (usesElectrostaticAtoms_) { |
721 |
< |
sprintf(painCave.errMsg, |
722 |
< |
"SimInfo: No value was set for the cutoffRadius.\n" |
723 |
< |
"\tOpenMD will use a default value of 12.0 angstroms" |
724 |
< |
"\tfor the cutoffRadius.\n"); |
725 |
< |
painCave.isFatal = 0; |
726 |
< |
painCave.severity = OPENMD_INFO; |
727 |
< |
simError(); |
728 |
< |
cutoffRadius_ = 12.0; |
729 |
< |
} else { |
730 |
< |
RealType thisCut; |
731 |
< |
set<AtomType*>::iterator i; |
732 |
< |
set<AtomType*> atomTypes; |
733 |
< |
atomTypes = getSimulatedAtomTypes(); |
734 |
< |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) { |
735 |
< |
thisCut = InteractionManager::Instance()->getSuggestedCutoffRadius((*i)); |
736 |
< |
cutoffRadius_ = max(thisCut, cutoffRadius_); |
737 |
< |
} |
738 |
< |
sprintf(painCave.errMsg, |
739 |
< |
"SimInfo: No value was set for the cutoffRadius.\n" |
740 |
< |
"\tOpenMD will use %lf angstroms.\n", |
741 |
< |
cutoffRadius_); |
742 |
< |
painCave.isFatal = 0; |
743 |
< |
painCave.severity = OPENMD_INFO; |
744 |
< |
simError(); |
745 |
< |
} |
746 |
< |
} |
690 |
> |
#ifdef IS_MPI |
691 |
|
|
692 |
< |
InteractionManager::Instance()->setCutoffRadius(cutoffRadius_); |
692 |
> |
// loop over the found atom types on this processor, and add their |
693 |
> |
// numerical idents to a vector: |
694 |
|
|
695 |
< |
map<string, CutoffMethod> stringToCutoffMethod; |
696 |
< |
stringToCutoffMethod["HARD"] = HARD; |
697 |
< |
stringToCutoffMethod["SWITCHING_FUNCTION"] = SWITCHING_FUNCTION; |
698 |
< |
stringToCutoffMethod["SHIFTED_POTENTIAL"] = SHIFTED_POTENTIAL; |
754 |
< |
stringToCutoffMethod["SHIFTED_FORCE"] = SHIFTED_FORCE; |
755 |
< |
|
756 |
< |
if (simParams_->haveCutoffMethod()) { |
757 |
< |
string cutMeth = toUpperCopy(simParams_->getCutoffMethod()); |
758 |
< |
map<string, CutoffMethod>::iterator i; |
759 |
< |
i = stringToCutoffMethod.find(cutMeth); |
760 |
< |
if (i == stringToCutoffMethod.end()) { |
761 |
< |
sprintf(painCave.errMsg, |
762 |
< |
"SimInfo: Could not find chosen cutoffMethod %s\n" |
763 |
< |
"\tShould be one of: " |
764 |
< |
"HARD, SWITCHING_FUNCTION, SHIFTED_POTENTIAL, or SHIFTED_FORCE\n", |
765 |
< |
cutMeth.c_str()); |
766 |
< |
painCave.isFatal = 1; |
767 |
< |
painCave.severity = OPENMD_ERROR; |
768 |
< |
simError(); |
769 |
< |
} else { |
770 |
< |
cutoffMethod_ = i->second; |
771 |
< |
} |
772 |
< |
} else { |
773 |
< |
sprintf(painCave.errMsg, |
774 |
< |
"SimInfo: No value was set for the cutoffMethod.\n" |
775 |
< |
"\tOpenMD will use SHIFTED_FORCE.\n"); |
776 |
< |
painCave.isFatal = 0; |
777 |
< |
painCave.severity = OPENMD_INFO; |
778 |
< |
simError(); |
779 |
< |
cutoffMethod_ = SHIFTED_FORCE; |
780 |
< |
} |
695 |
> |
vector<int> foundTypes; |
696 |
> |
set<AtomType*>::iterator i; |
697 |
> |
for (i = atomTypes.begin(); i != atomTypes.end(); ++i) |
698 |
> |
foundTypes.push_back( (*i)->getIdent() ); |
699 |
|
|
700 |
< |
InteractionManager::Instance()->setCutoffMethod(cutoffMethod_); |
701 |
< |
} |
784 |
< |
|
785 |
< |
/** |
786 |
< |
* setupSwitching |
787 |
< |
* |
788 |
< |
* Sets the values of switchingRadius and |
789 |
< |
* If the switchingRadius was explicitly set, use that value (but check it) |
790 |
< |
* If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_ |
791 |
< |
*/ |
792 |
< |
void SimInfo::setupSwitching() { |
793 |
< |
|
794 |
< |
if (simParams_->haveSwitchingRadius()) { |
795 |
< |
switchingRadius_ = simParams_->getSwitchingRadius(); |
796 |
< |
if (switchingRadius_ > cutoffRadius_) { |
797 |
< |
sprintf(painCave.errMsg, |
798 |
< |
"SimInfo: switchingRadius (%f) is larger than cutoffRadius(%f)\n", |
799 |
< |
switchingRadius_, cutoffRadius_); |
800 |
< |
painCave.isFatal = 1; |
801 |
< |
painCave.severity = OPENMD_ERROR; |
802 |
< |
simError(); |
803 |
< |
} |
804 |
< |
} else { |
805 |
< |
switchingRadius_ = 0.85 * cutoffRadius_; |
806 |
< |
sprintf(painCave.errMsg, |
807 |
< |
"SimInfo: No value was set for the switchingRadius.\n" |
808 |
< |
"\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n" |
809 |
< |
"\tswitchingRadius = %f. for this simulation\n", switchingRadius_); |
810 |
< |
painCave.isFatal = 0; |
811 |
< |
painCave.severity = OPENMD_WARNING; |
812 |
< |
simError(); |
813 |
< |
} |
814 |
< |
|
815 |
< |
InteractionManager::Instance()->setSwitchingRadius(switchingRadius_); |
700 |
> |
// count_local holds the number of found types on this processor |
701 |
> |
int count_local = foundTypes.size(); |
702 |
|
|
703 |
< |
SwitchingFunctionType ft; |
703 |
> |
// count holds the total number of found types on all processors |
704 |
> |
// (some will be redundant with the ones found locally): |
705 |
> |
int count; |
706 |
> |
MPI::COMM_WORLD.Allreduce(&count_local, &count, 1, MPI::INT, MPI::SUM); |
707 |
> |
|
708 |
> |
// create a vector to hold the globally found types, and resize it: |
709 |
> |
vector<int> ftGlobal; |
710 |
> |
ftGlobal.resize(count); |
711 |
> |
vector<int> counts; |
712 |
> |
|
713 |
> |
int nproc = MPI::COMM_WORLD.Get_size(); |
714 |
> |
counts.resize(nproc); |
715 |
> |
vector<int> disps; |
716 |
> |
disps.resize(nproc); |
717 |
> |
|
718 |
> |
// now spray out the foundTypes to all the other processors: |
719 |
|
|
720 |
< |
if (simParams_->haveSwitchingFunctionType()) { |
721 |
< |
string funcType = simParams_->getSwitchingFunctionType(); |
821 |
< |
toUpper(funcType); |
822 |
< |
if (funcType == "CUBIC") { |
823 |
< |
ft = cubic; |
824 |
< |
} else { |
825 |
< |
if (funcType == "FIFTH_ORDER_POLYNOMIAL") { |
826 |
< |
ft = fifth_order_poly; |
827 |
< |
} else { |
828 |
< |
// throw error |
829 |
< |
sprintf( painCave.errMsg, |
830 |
< |
"SimInfo : Unknown switchingFunctionType. (Input file specified %s .)\n" |
831 |
< |
"\tswitchingFunctionType must be one of: " |
832 |
< |
"\"cubic\" or \"fifth_order_polynomial\".", |
833 |
< |
funcType.c_str() ); |
834 |
< |
painCave.isFatal = 1; |
835 |
< |
painCave.severity = OPENMD_ERROR; |
836 |
< |
simError(); |
837 |
< |
} |
838 |
< |
} |
839 |
< |
} |
720 |
> |
MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT, |
721 |
> |
&ftGlobal[0], &counts[0], &disps[0], MPI::INT); |
722 |
|
|
723 |
< |
InteractionManager::Instance()->setSwitchingFunctionType(ft); |
723 |
> |
// foundIdents is a stl set, so inserting an already found ident |
724 |
> |
// will have no effect. |
725 |
> |
set<int> foundIdents; |
726 |
> |
vector<int>::iterator j; |
727 |
> |
for (j = ftGlobal.begin(); j != ftGlobal.end(); ++j) |
728 |
> |
foundIdents.insert((*j)); |
729 |
> |
|
730 |
> |
// now iterate over the foundIdents and get the actual atom types |
731 |
> |
// that correspond to these: |
732 |
> |
set<int>::iterator it; |
733 |
> |
for (it = foundIdents.begin(); it != foundIdents.end(); ++it) |
734 |
> |
atomTypes.insert( forceField_->getAtomType((*it)) ); |
735 |
> |
|
736 |
> |
#endif |
737 |
> |
|
738 |
> |
return atomTypes; |
739 |
|
} |
740 |
|
|
741 |
< |
/** |
742 |
< |
* setupSkinThickness |
743 |
< |
* |
744 |
< |
* If the skinThickness was explicitly set, use that value (but check it) |
745 |
< |
* If the skinThickness was not explicitly set: use 1.0 angstroms |
746 |
< |
*/ |
747 |
< |
void SimInfo::setupSkinThickness() { |
748 |
< |
if (simParams_->haveSkinThickness()) { |
852 |
< |
skinThickness_ = simParams_->getSkinThickness(); |
853 |
< |
} else { |
854 |
< |
skinThickness_ = 1.0; |
855 |
< |
sprintf(painCave.errMsg, |
856 |
< |
"SimInfo Warning: No value was set for the skinThickness.\n" |
857 |
< |
"\tOpenMD will use a default value of %f Angstroms\n" |
858 |
< |
"\tfor this simulation\n", skinThickness_); |
859 |
< |
painCave.isFatal = 0; |
860 |
< |
simError(); |
861 |
< |
} |
862 |
< |
} |
741 |
> |
void SimInfo::setupSimVariables() { |
742 |
> |
useAtomicVirial_ = simParams_->getUseAtomicVirial(); |
743 |
> |
// we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true |
744 |
> |
calcBoxDipole_ = false; |
745 |
> |
if ( simParams_->haveAccumulateBoxDipole() ) |
746 |
> |
if ( simParams_->getAccumulateBoxDipole() ) { |
747 |
> |
calcBoxDipole_ = true; |
748 |
> |
} |
749 |
|
|
864 |
– |
void SimInfo::setupSimType() { |
750 |
|
set<AtomType*>::iterator i; |
751 |
|
set<AtomType*> atomTypes; |
752 |
< |
atomTypes = getSimulatedAtomTypes(); |
868 |
< |
|
869 |
< |
useAtomicVirial_ = simParams_->getUseAtomicVirial(); |
870 |
< |
|
752 |
> |
atomTypes = getSimulatedAtomTypes(); |
753 |
|
int usesElectrostatic = 0; |
754 |
|
int usesMetallic = 0; |
755 |
|
int usesDirectional = 0; |
779 |
|
fInfo_.SIM_uses_AtomicVirial = usesAtomicVirial_; |
780 |
|
} |
781 |
|
|
782 |
< |
void SimInfo::setupFortranSim() { |
782 |
> |
void SimInfo::setupFortran() { |
783 |
|
int isError; |
784 |
|
int nExclude, nOneTwo, nOneThree, nOneFour; |
785 |
|
vector<int> fortranGlobalGroupMembership; |
786 |
|
|
905 |
– |
notifyFortranSkinThickness(&skinThickness_); |
906 |
– |
|
907 |
– |
int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0; |
908 |
– |
int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0; |
909 |
– |
notifyFortranCutoffs(&cutoffRadius_, &switchingRadius_, &ljsp, &ljsf); |
910 |
– |
|
787 |
|
isError = 0; |
788 |
|
|
789 |
|
//globalGroupMembership_ is filled by SimCreator |
818 |
|
} |
819 |
|
} |
820 |
|
|
821 |
< |
//fill ident array of local atoms (it is actually ident of AtomType, it is so confusing !!!) |
821 |
> |
//fill ident array of local atoms (it is actually ident of |
822 |
> |
//AtomType, it is so confusing !!!) |
823 |
|
vector<int> identArray; |
824 |
|
|
825 |
|
//to avoid memory reallocation, reserve enough space identArray |
879 |
|
setNeighbors(&nlistNeighbors); |
880 |
|
} |
881 |
|
|
1005 |
– |
|
1006 |
– |
} |
1007 |
– |
|
1008 |
– |
|
1009 |
– |
void SimInfo::setupFortranParallel() { |
882 |
|
#ifdef IS_MPI |
883 |
< |
//SimInfo is responsible for creating localToGlobalAtomIndex and localToGlobalGroupIndex |
883 |
> |
//SimInfo is responsible for creating localToGlobalAtomIndex and |
884 |
> |
//localToGlobalGroupIndex |
885 |
|
vector<int> localToGlobalAtomIndex(getNAtoms(), 0); |
886 |
|
vector<int> localToGlobalCutoffGroupIndex; |
1014 |
– |
SimInfo::MoleculeIterator mi; |
1015 |
– |
Molecule::AtomIterator ai; |
1016 |
– |
Molecule::CutoffGroupIterator ci; |
1017 |
– |
Molecule* mol; |
1018 |
– |
Atom* atom; |
1019 |
– |
CutoffGroup* cg; |
887 |
|
mpiSimData parallelData; |
1021 |
– |
int isError; |
888 |
|
|
889 |
|
for (mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) { |
890 |
|
|
924 |
|
|
925 |
|
sprintf(checkPointMsg, " mpiRefresh successful.\n"); |
926 |
|
errorCheckPoint(); |
1061 |
– |
|
927 |
|
#endif |
1063 |
– |
} |
928 |
|
|
929 |
< |
|
930 |
< |
void SimInfo::setupSwitchingFunction() { |
931 |
< |
|
932 |
< |
} |
933 |
< |
|
934 |
< |
void SimInfo::setupAccumulateBoxDipole() { |
935 |
< |
|
936 |
< |
// we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true |
1073 |
< |
if ( simParams_->haveAccumulateBoxDipole() ) |
1074 |
< |
if ( simParams_->getAccumulateBoxDipole() ) { |
1075 |
< |
calcBoxDipole_ = true; |
1076 |
< |
} |
1077 |
< |
|
929 |
> |
initFortranFF(&isError); |
930 |
> |
if (isError) { |
931 |
> |
sprintf(painCave.errMsg, |
932 |
> |
"initFortranFF errror: fortran didn't like something we gave it.\n"); |
933 |
> |
painCave.isFatal = 1; |
934 |
> |
simError(); |
935 |
> |
} |
936 |
> |
fortranInitialized_ = true; |
937 |
|
} |
938 |
|
|
939 |
|
void SimInfo::addProperty(GenericData* genData) { |