Changeset f6abb1 for src/Potentials


Ignore:
Timestamp:
May 7, 2016, 7:03:56 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
fde8e7
Parents:
086e30
git-author:
Frederik Heber <heber@…> (02/27/16 13:09:08)
git-committer:
Frederik Heber <heber@…> (05/07/16 07:03:56)
Message:

PotentialFactory now also complies to templated StreamFactory.

Location:
src/Potentials
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/Makefile.am

    r086e30 rf6abb1  
    2929  Potentials/Specifics/PairPotential_Morse.cpp \
    3030  Potentials/Specifics/PotentialTypes.cpp \
    31   Potentials/Specifics/ThreeBodyPotential_Angle.cpp
     31  Potentials/Specifics/ThreeBodyPotential_Angle.cpp \
     32  Potentials/StreamFactory_EmpiricalPotential.cpp
    3233
    3334POTENTIALSHEADER = \
     
    5758  Potentials/Specifics/PotentialTypes.def \
    5859  Potentials/Specifics/PotentialTypes.undef \
    59   Potentials/StreamFactory.hpp
     60  Potentials/StreamFactory.hpp \
     61  Potentials/StreamFactory_EmpiricalPotential.hpp
    6062
    6163if CONDLEVMAR
  • src/Potentials/PotentialDeserializer.cpp

    r086e30 rf6abb1  
    6262      // instantiate type
    6363      EmpiricalPotential *potential =
    64           PotentialFactory::getInstance().createInstance(
    65               token, potentialstream);
     64          static_cast<StreamFactory<EmpiricalPotential>&>(PotentialFactory::getInstance()).
     65              createInstance(token, potentialstream);
    6666
    6767      // and register
  • src/Potentials/PotentialFactory.cpp

    r086e30 rf6abb1  
    9696#include "Potentials/Specifics/PotentialTypes.undef"
    9797
     98enum PotentialTypes PotentialFactory::getTypeForName(const std::string &_name)
     99{
     100  ASSERT (NameToType.count(_name),
     101      "PotentialFactory::getTypeForName() - cannot find potential of name "+_name);
     102  return NameToType[_name];
     103}
     104
     105const std::string & PotentialFactory::getNameForType(enum PotentialTypes _type)
     106{
     107  ASSERT (TypeToName.count(_type),
     108      "PotentialFactory::getNameForType() - cannot find potential of name "+_type);
     109  return TypeToName[_type];
     110}
     111
    98112EmpiricalPotential *PotentialFactory::createInstance(
    99113    const std::string &potentialtype,
    100114    const SerializablePotential::ParticleTypes_t &types) const
    101115{
    102   ASSERT (NameToType.count(potentialtype),
    103       "PotentialFactory::createInstance() - cannot find potential of name "+potentialtype);
    104   switch (NameToType[potentialtype]) {
     116  switch (getTypeForName(potentialtype)) {
    105117  case constant:
    106118      return new ConstantPotential(types);
     
    125137}
    126138
    127 EmpiricalPotential *PotentialFactory::createInstance(
    128     const std::string &potentialtype,
    129     std::istream &serialized) const
     139EmpiricalPotential* PotentialFactory::getDefaultPotential(const std::string &_name) const
    130140{
    131141  EmpiricalPotential *potential = NULL;
    132   ASSERT (NameToType.count(potentialtype),
    133       "PotentialFactory::createInstance() - cannot find potential of name "+potentialtype);
    134   switch (NameToType[potentialtype]) {
     142  switch (getTypeForName(_name)) {
    135143  case constant:
    136144    potential = new ConstantPotential();
     
    161169    break;
    162170  }
    163   // now stream in types and parameters
    164   potential->stream_from(serialized);
    165 
    166171  return potential;
    167172}
  • src/Potentials/PotentialFactory.hpp

    r086e30 rf6abb1  
    2121#include "Potentials/EmpiricalPotential.hpp"
    2222#include "Potentials/Specifics/PotentialTypes.hpp"
     23#include "Potentials/StreamFactory_EmpiricalPotential.hpp"
    2324
    2425/** Class that creates instances of potentials.
     
    2728 *
    2829 */
    29 class PotentialFactory : public Singleton<PotentialFactory>
     30class PotentialFactory :
     31    public Singleton<PotentialFactory>,
     32    public StreamFactory<EmpiricalPotential>
    3033{
    3134  //!> make Singleton template friend
    3235  friend class Singleton<PotentialFactory>;
    3336
     37protected:
     38
     39  /** Returns a default potential to which only we have access.
     40   *
     41   */
     42  EmpiricalPotential* getDefaultPotential(const std::string &_name) const;
     43
    3444public:
     45
    3546  /** Creates an instance of the requested potential.
    3647   *
     
    4152      const std::string &potentialtype,
    4253      const SerializablePotential::ParticleTypes_t &charges) const;
    43 
    44   /** Creates an instance of the requested potential.
    45    *
    46    * \param potentialtype key of potential to create
    47    * \param serialized stream to parser SerializablePotential from
    48    */
    49   EmpiricalPotential *createInstance(
    50       const std::string &potentialtype,
    51       std::istream &serialized) const;
    5254
    5355  //!> typedef for map to lookup type for a given name
     
    6365  static TypeToName_t TypeToName;
    6466
     67  static enum PotentialTypes getTypeForName(const std::string &_name);
     68
     69  static const std::string & getNameForType(enum PotentialTypes _type);
     70
    6571private:
    6672  PotentialFactory() {}
Note: See TracChangeset for help on using the changeset viewer.