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 1528 by gezelter, Fri Dec 17 20:11:05 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 684 | Line 681 | namespace OpenMD {
681      Atom* atom;
682      set<AtomType*> atomTypes;
683      
684 <    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {
688 <      
684 >    for(mol = beginMolecule(mi); mol != NULL; mol = nextMolecule(mi)) {      
685        for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) {
686          atomTypes.insert(atom->getAtomType());
687 <      }
688 <      
693 <    }
694 <    
695 <    return atomTypes;        
696 <  }
687 >      }      
688 >    }    
689  
690 <  /**
699 <   * setupCutoffRadius
700 <   *
701 <   *  If the cutoffRadius was explicitly set, use that value.
702 <   *  If the cutoffRadius was not explicitly set:
703 <   *      Are there electrostatic atoms?  Use 12.0 Angstroms.
704 <   *      No electrostatic atoms?  Poll the atom types present in the
705 <   *      simulation for suggested cutoff values (e.g. 2.5 * sigma).
706 <   *      Use the maximum suggested value that was found.
707 <   */
708 <  void SimInfo::setupCutoffRadius() {
709 <    
710 <    if (simParams_->haveCutoffRadius()) {
711 <      cutoffRadius_ = simParams_->getCutoffRadius();
712 <    } else {      
713 <      if (usesElectrostaticAtoms_) {
714 <        sprintf(painCave.errMsg,
715 <                "SimInfo Warning: No value was set for the cutoffRadius.\n"
716 <                "\tOpenMD will use a default value of 12.0 angstroms"
717 <                "\tfor the cutoffRadius.\n");
718 <        painCave.isFatal = 0;
719 <        simError();
720 <        cutoffRadius_ = 12.0;
721 <      } else {
722 <        RealType thisCut;
723 <        set<AtomType*>::iterator i;
724 <        set<AtomType*> atomTypes;
725 <        atomTypes = getSimulatedAtomTypes();        
726 <        for (i = atomTypes.begin(); i != atomTypes.end(); ++i) {
727 <          thisCut = InteractionManager::Instance()->getSuggestedCutoffRadius((*i));
728 <          cutoffRadius_ = max(thisCut, cutoffRadius_);
729 <        }
730 <        sprintf(painCave.errMsg,
731 <                "SimInfo Warning: No value was set for the cutoffRadius.\n"
732 <                "\tOpenMD will use %lf angstroms.\n",
733 <                cutoffRadius_);
734 <        painCave.isFatal = 0;
735 <        simError();
736 <      }            
737 <    }
690 > #ifdef IS_MPI
691  
692 <    InteractionManager::Instance()->setCutoffRadius(cutoffRadius_);
693 <  }
694 <  
695 <  /**
696 <   * setupSwitchingRadius
697 <   *
698 <   *  If the switchingRadius was explicitly set, use that value (but check it)
699 <   *  If the switchingRadius was not explicitly set: use 0.85 * cutoffRadius_
700 <   */
701 <  void SimInfo::setupSwitchingRadius() {
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 >    // 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();
752 <      if (switchingRadius_ > cutoffRadius_) {        
753 <        sprintf(painCave.errMsg,
754 <                "SimInfo Error: switchingRadius (%f) is larger than cutoffRadius(%f)\n",
755 <                switchingRadius_, cutoffRadius_);
756 <        painCave.isFatal = 1;
757 <        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()) {
780 <      skinThickness_ = simParams_->getSkinThickness();
781 <    } else {      
782 <      skinThickness_ = 1.0;
783 <      sprintf(painCave.errMsg,
784 <              "SimInfo Warning: No value was set for the skinThickness.\n"
785 <              "\tOpenMD will use a default value of %f Angstroms\n"
786 <              "\tfor this simulation\n", skinThickness_);
787 <      painCave.isFatal = 0;
788 <      simError();
789 <    }            
790 <  }
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  
792  void SimInfo::setupSimType() {
750      set<AtomType*>::iterator i;
751      set<AtomType*> atomTypes;
752 <    atomTypes = getSimulatedAtomTypes();
796 <
797 <    useAtomicVirial_ = simParams_->getUseAtomicVirial();
798 <
752 >    atomTypes = getSimulatedAtomTypes();    
753      int usesElectrostatic = 0;
754      int usesMetallic = 0;
755      int usesDirectional = 0;
# Line 825 | 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      
833    notifyFortranSkinThickness(&skinThickness_);
834
835    int ljsp = cutoffMethod_ == SHIFTED_POTENTIAL ? 1 : 0;
836    int ljsf = cutoffMethod_ == SHIFTED_FORCE ? 1 : 0;
837    notifyFortranCutoffs(&cutoffRadius_, &switchingRadius_, &ljsp, &ljsf);
838
787      isError = 0;
788  
789      //globalGroupMembership_ is filled by SimCreator    
# Line 870 | 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 930 | Line 879 | namespace OpenMD {
879        setNeighbors(&nlistNeighbors);
880      }
881    
933
934  }
935
936
937  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;
942    SimInfo::MoleculeIterator mi;
943    Molecule::AtomIterator ai;
944    Molecule::CutoffGroupIterator ci;
945    Molecule* mol;
946    Atom* atom;
947    CutoffGroup* cg;
887      mpiSimData parallelData;
949    int isError;
888  
889      for (mol = beginMolecule(mi); mol != NULL; mol  = nextMolecule(mi)) {
890  
# Line 986 | Line 924 | namespace OpenMD {
924  
925      sprintf(checkPointMsg, " mpiRefresh successful.\n");
926      errorCheckPoint();
989
927   #endif
991  }
928  
929 <
930 <  void SimInfo::setupSwitchingFunction() {    
931 <    int ft = CUBIC;
932 <    
933 <    if (simParams_->haveSwitchingFunctionType()) {
934 <      string funcType = simParams_->getSwitchingFunctionType();
999 <      toUpper(funcType);
1000 <      if (funcType == "CUBIC") {
1001 <        ft = CUBIC;
1002 <      } else {
1003 <        if (funcType == "FIFTH_ORDER_POLYNOMIAL") {
1004 <          ft = FIFTH_ORDER_POLY;
1005 <        } else {
1006 <          // throw error        
1007 <          sprintf( painCave.errMsg,
1008 <                   "SimInfo error: Unknown switchingFunctionType. (Input file specified %s .)\n\tswitchingFunctionType must be one of: \"cubic\" or \"fifth_order_polynomial\".", funcType.c_str() );
1009 <          painCave.isFatal = 1;
1010 <          simError();
1011 <        }          
1012 <      }
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 <
1015 <    // send switching function notification to switcheroo
1016 <    setFunctionType(&ft);
1017 <
1018 <  }
1019 <
1020 <  void SimInfo::setupAccumulateBoxDipole() {    
1021 <
1022 <    // we only call setAccumulateBoxDipole if the accumulateBoxDipole parameter is true
1023 <    if ( simParams_->haveAccumulateBoxDipole() )
1024 <      if ( simParams_->getAccumulateBoxDipole() ) {
1025 <        calcBoxDipole_ = true;
1026 <      }
1027 <
936 >    fortranInitialized_ = true;
937    }
938  
939    void SimInfo::addProperty(GenericData* genData) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines