ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/brains/SimInfo.cpp
(Generate patch)

Comparing branches/development/src/brains/SimInfo.cpp (file contents):
Revision 1529 by gezelter, Mon Dec 27 18:35:59 2010 UTC vs.
Revision 1536 by gezelter, Wed Jan 5 14:49:05 2011 UTC

# Line 54 | Line 54
54   #include "math/Vector3.hpp"
55   #include "primitives/Molecule.hpp"
56   #include "primitives/StuntDouble.hpp"
57 #include "UseTheForce/fCutoffPolicy.h"
58 #include "UseTheForce/DarkSide/fSwitchingFunctionType.h"
59 #include "UseTheForce/doForces_interface.h"
57   #include "UseTheForce/DarkSide/neighborLists_interface.h"
58 < #include "UseTheForce/DarkSide/switcheroo_interface.h"
58 > #include "UseTheForce/doForces_interface.h"
59   #include "utils/MemoryUtils.hpp"
60   #include "utils/simError.h"
61   #include "selection/SelectionManager.hpp"
62   #include "io/ForceFieldOptions.hpp"
63   #include "UseTheForce/ForceField.hpp"
64 < #include "nonbonded/InteractionManager.hpp"
68 <
64 > #include "nonbonded/SwitchingFunction.hpp"
65  
66   #ifdef IS_MPI
67   #include "UseTheForce/mpiComponentPlan.h"
# Line 656 | Line 652 | namespace OpenMD {
652      molStampIds_.insert(molStampIds_.end(), nmol, curStampId);
653    }
654  
659  void SimInfo::update() {
660
661    setupSimType();
662    setupCutoffRadius();
663    setupSwitchingRadius();
664    setupCutoffMethod();
665    setupSkinThickness();
666    setupSwitchingFunction();
667    setupAccumulateBoxDipole();
655  
656 < #ifdef IS_MPI
657 <    setupFortranParallel();
658 < #endif
659 <    setupFortranSim();
660 <    fortranInitialized_ = true;
661 <
656 >  /**
657 >   * update
658 >   *
659 >   *  Performs the global checks and variable settings after the
660 >   *  objects have been created.
661 >   *
662 >   */
663 >  void SimInfo::update() {  
664 >    setupSimVariables();
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;
# Line 689 | Line 686 | namespace OpenMD {
686          atomTypes.insert(atom->getAtomType());
687        }      
688      }    
692    return atomTypes;        
693  }
689  
690 <  /**
691 <   * setupCutoffRadius
692 <   *
693 <   *  If the cutoffRadius was explicitly set, use that value.
694 <   *  If the cutoffRadius was not explicitly set:
695 <   *      Are there electrostatic atoms?  Use 12.0 Angstroms.
696 <   *      No electrostatic atoms?  Poll the atom types present in the
697 <   *      simulation for suggested cutoff values (e.g. 2.5 * sigma).
698 <   *      Use the maximum suggested value that was found.
699 <   */
700 <  void SimInfo::setupCutoffRadius() {
701 <    
702 <    if (simParams_->haveCutoffRadius()) {
703 <      cutoffRadius_ = simParams_->getCutoffRadius();
704 <    } else {      
705 <      if (usesElectrostaticAtoms_) {
706 <        sprintf(painCave.errMsg,
712 <                "SimInfo Warning: No value was set for the cutoffRadius.\n"
713 <                "\tOpenMD will use a default value of 12.0 angstroms"
714 <                "\tfor the cutoffRadius.\n");
715 <        painCave.isFatal = 0;
716 <        simError();
717 <        cutoffRadius_ = 12.0;
718 <      } else {
719 <        RealType thisCut;
720 <        set<AtomType*>::iterator i;
721 <        set<AtomType*> atomTypes;
722 <        atomTypes = getSimulatedAtomTypes();        
723 <        for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
724 <          thisCut = InteractionManager::Instance()->getSuggestedCutoffRadius((*i));
725 <          cutoffRadius_ = max(thisCut, cutoffRadius_);
726 <        }
727 <        sprintf(painCave.errMsg,
728 <                "SimInfo Warning: No value was set for the cutoffRadius.\n"
729 <                "\tOpenMD will use %lf angstroms.\n",
730 <                cutoffRadius_);
731 <        painCave.isFatal = 0;
732 <        simError();
733 <      }            
734 <    }
690 > #ifdef IS_MPI
691 >
692 >    // loop over the found atom types on this processor, and add their
693 >    // numerical idents to a vector:
694 >
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 >    // count_local holds the number of found types on this processor
701 >    int count_local = foundTypes.size();
702 >
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 <    InteractionManager::Instance()->setCutoffRadius(cutoffRadius_);
709 <  }
710 <  
711 <  /**
712 <   * setupSwitchingRadius
713 <   *
714 <   *  If the switchingRadius was explicitly set, use that value (but check it)
715 <   *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_
716 <   */
717 <  void SimInfo::setupSwitchingRadius() {
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_->haveSwitchingRadius()) {
721 <      switchingRadius_ = simParams_->getSwitchingRadius();
749 <      if (switchingRadius_ > cutoffRadius_) {        
750 <        sprintf(painCave.errMsg,
751 <                "SimInfo Error: switchingRadius (%f) is larger than cutoffRadius(%f)\n",
752 <                switchingRadius_, cutoffRadius_);
753 <        painCave.isFatal = 1;
754 <        simError();
720 >    MPI::COMM_WORLD.Allgatherv(&foundTypes[0], count_local, MPI::INT,
721 >                               &ftGlobal[0], &counts[0], &disps[0], MPI::INT);
722  
723 <      }
724 <    } else {      
725 <      switchingRadius_ = 0.85 * cutoffRadius_;
726 <      sprintf(painCave.errMsg,
727 <              "SimInfo Warning: No value was set for the switchingRadius.\n"
728 <              "\tOpenMD will use a default value of 85 percent of the cutoffRadius.\n"
729 <              "\tswitchingRadius = %f. for this simulation\n", switchingRadius_);
730 <      painCave.isFatal = 0;
731 <      simError();
732 <    }            
733 <    InteractionManager::Instance()->setSwitchingRadius(switchingRadius_);
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()) {
777 <      skinThickness_ = simParams_->getSkinThickness();
778 <    } else {      
779 <      skinThickness_ = 1.0;
780 <      sprintf(painCave.errMsg,
781 <              "SimInfo Warning: No value was set for the skinThickness.\n"
782 <              "\tOpenMD will use a default value of %f Angstroms\n"
783 <              "\tfor this simulation\n", skinThickness_);
784 <      painCave.isFatal = 0;
785 <      simError();
786 <    }            
787 <  }
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  
789  void SimInfo::setupSimType() {
750      set<AtomType*>::iterator i;
751      set<AtomType*> atomTypes;
752 <    atomTypes = getSimulatedAtomTypes();
793 <
794 <    useAtomicVirial_ = simParams_->getUseAtomicVirial();
795 <
752 >    atomTypes = getSimulatedAtomTypes();    
753      int usesElectrostatic = 0;
754      int usesMetallic = 0;
755      int usesDirectional = 0;
# Line 822 | Line 779 | namespace OpenMD {
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      
830    notifyFortranSkinThickness(&skinThickness_);
831
832    int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0;
833    int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0;
834    notifyFortranCutoffs(&cutoffRadius_, &switchingRadius_, &ljsp, &ljsf);
835
787      isError = 0;
788  
789      //globalGroupMembership_ is filled by SimCreator    
# Line 867 | Line 818 | namespace OpenMD {
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
# Line 927 | Line 879 | namespace OpenMD {
879        setNeighbors(&nlistNeighbors);
880      }
881    
930
931  }
932
933
934  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;
939    SimInfo::MoleculeIterator mi;
940    Molecule::AtomIterator ai;
941    Molecule::CutoffGroupIterator ci;
942    Molecule* mol;
943    Atom* atom;
944    CutoffGroup* cg;
887      mpiSimData parallelData;
946    int isError;
888  
889      for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
890  
# Line 983 | Line 924 | namespace OpenMD {
924  
925      sprintf(checkPointMsg, " mpiRefresh successful.\n");
926      errorCheckPoint();
986
927   #endif
988  }
928  
929 <
930 <  void SimInfo::setupSwitchingFunction() {    
931 <    int ft = CUBIC;
932 <    
933 <    if (simParams_->haveSwitchingFunctionType()) {
934 <      string funcType = simParams_->getSwitchingFunctionType();
996 <      toUpper(funcType);
997 <      if (funcType == "CUBIC") {
998 <        ft = CUBIC;
999 <      } else {
1000 <        if (funcType == "FIFTH_ORDER_POLYNOMIAL") {
1001 <          ft = FIFTH_ORDER_POLY;
1002 <        } else {
1003 <          // throw error        
1004 <          sprintf( painCave.errMsg,
1005 <                   "SimInfo error: Unknown switchingFunctionType. (Input file specified %s .)\n"
1006 <                   "\tswitchingFunctionType must be one of: \"cubic\" or \"fifth_order_polynomial\".",
1007 <                   funcType.c_str() );
1008 <          painCave.isFatal = 1;
1009 <          simError();
1010 <        }          
1011 <      }
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 <
1014 <    // send switching function notification to switcheroo
1015 <    setFunctionType(&ft);
1016 <
936 >    fortranInitialized_ = true;
937    }
938  
1019  void SimInfo::setupAccumulateBoxDipole() {    
1020
1021    // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true
1022    if ( simParams_->haveAccumulateBoxDipole() )
1023      if ( simParams_->getAccumulateBoxDipole() ) {
1024        calcBoxDipole_ = true;
1025      }
1026
1027  }
1028
939    void SimInfo::addProperty(GenericData* genData) {
940      properties_.addProperty(genData);  
941    }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines