Changeset e83114 for src/Potentials


Ignore:
Timestamp:
Aug 30, 2025, 2:41:40 PM (2 months ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
a0d8aa
Parents:
72b6d7
git-author:
Frederik Heber <frederik.heber@…> (08/16/25 10:32:39)
git-committer:
Frederik Heber <frederik.heber@…> (08/30/25 14:41:40)
Message:

StreamFactory_EmpiricalPotential creates potential instances with params.

  • EmpiricalPotential expose getter and setter for parameters.
  • potential and stream factor for EmpiricalPotential have new createInstance that also takes a present parameter set.
  • this is used in StreamFactory_EmpiricalPotential::createInstance from istream to create the correct instance with parameters directly.
Location:
src/Potentials
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/EmpiricalPotential.hpp

    r72b6d7 re83114  
    9595  virtual unsigned int getParticleTypeNumber() const=0;
    9696
     97  /** Sets the parameters from a given vector.
     98   *
     99   * \param params vector of parameters, specific to a specialized potential
     100   */
     101  virtual void setParameters(const parameters_t &params)=0;
     102
     103  /** Getter for the parameter set for this specialized potential.
     104   *
     105   * \return vector of parameters
     106   */
     107  virtual parameters_t getParameters() const=0;
     108
    97109protected:
    98110  /** Default constructor for class EmpiricalPotential.
  • src/Potentials/PotentialFactory.cpp

    r72b6d7 re83114  
    137137}
    138138
    139 EmpiricalPotential* PotentialFactory::getDefaultPotential(const std::string &_name) const
    140 {
    141   EmpiricalPotential *potential = NULL;
    142   switch (getTypeForName(_name)) {
     139EmpiricalPotential *PotentialFactory::createInstance(
     140    const std::string &potentialtype,
     141    const SerializablePotential::ParticleTypes_t &types,
     142                const FunctionModel::parameters_t &params) const
     143{
     144        EmpiricalPotential *potential = NULL;
     145  switch (getTypeForName(potentialtype)) {
    143146  case constant:
    144     potential = new ConstantPotential();
    145     break;
     147      potential = new ConstantPotential(types);
     148      break;
    146149  case tersoff:
    147     potential = new ManyBodyPotential_Tersoff();
    148     break;
     150      potential = new ManyBodyPotential_Tersoff(types);
     151      break;
    149152  case morse:
    150     potential = new PairPotential_Morse();
    151     break;
     153      potential = new PairPotential_Morse(types);
     154      break;
    152155  case harmonic_bond:
    153     potential = new PairPotential_Harmonic();
    154     break;
     156      potential = new PairPotential_Harmonic(types);
     157      break;
    155158  case harmonic_angle:
    156     potential = new ThreeBodyPotential_Angle();
    157     break;
     159      potential = new ThreeBodyPotential_Angle(types);
     160      break;
    158161  case lennardjones:
    159     potential = new PairPotential_LennardJones();
    160     break;
     162      potential = new PairPotential_LennardJones(types);
     163      break;
    161164  case torsion:
    162     potential = new FourBodyPotential_Torsion();
    163     break;
     165      potential = new FourBodyPotential_Torsion(types);
     166      break;
    164167  case improper:
    165     potential = new FourBodyPotential_Improper();
    166     break;
     168      potential = new FourBodyPotential_Improper(types);
     169      break;
    167170  default:
    168171    ASSERT(0, "PotentialFactory::createInstance() - unknown potential desired to create.");
    169172    break;
    170173  }
     174  if (potential != NULL)
     175        potential->setParameters(params);
    171176  return potential;
     177}
     178
     179EmpiricalPotential* PotentialFactory::getDefaultPotential(const std::string &_name) const
     180{
     181  switch (getTypeForName(_name)) {
     182  case constant:
     183    return new ConstantPotential();
     184  case tersoff:
     185    return new ManyBodyPotential_Tersoff();
     186  case morse:
     187    return new PairPotential_Morse();
     188  case harmonic_bond:
     189    return new PairPotential_Harmonic();
     190  case harmonic_angle:
     191    return new ThreeBodyPotential_Angle();
     192  case lennardjones:
     193    return new PairPotential_LennardJones();
     194  case torsion:
     195    return new FourBodyPotential_Torsion();
     196  case improper:
     197    return new FourBodyPotential_Improper();
     198  default:
     199    ASSERT(0, "PotentialFactory::createInstance() - unknown potential desired to create.");
     200    break;
     201  }
     202  return NULL;
    172203}
    173204
  • src/Potentials/PotentialFactory.hpp

    r72b6d7 re83114  
    5959      const SerializablePotential::ParticleTypes_t &charges) const;
    6060
     61  /** Creates an instance of the requested potential.
     62   *
     63   * \param potentialtype key of potential to create
     64   * \param charges charges for which the potential is (to be) fitted
     65   */
     66  EmpiricalPotential *createInstance(
     67      const std::string &potentialtype,
     68      const SerializablePotential::ParticleTypes_t &charges,
     69                        const FunctionModel::parameters_t &params) const;
     70
    6171  //!> typedef for map to lookup type for a given name
    6272  typedef std::map< std::string, enum PotentialTypes > NameToType_t;
  • src/Potentials/StreamFactory_EmpiricalPotential.cpp

    r72b6d7 re83114  
    5656    potential->stream_from(serialized);
    5757    // then create a proper instance which also has the correct BindingModel
    58     full_potential = createInstance(potentialtype, potential->getParticleTypes());
    59     // finally, serialize&deserialize parameters from default into the full instance
    60     std::stringstream parameter_stream;
    61     potential->stream_to(parameter_stream);
    62     full_potential->stream_from(parameter_stream);
     58    full_potential = createInstance(potentialtype, potential->getParticleTypes(), potential->getParameters());
    6359    LOG(3, "Deserialized full potential: " << *full_potential);
    6460    delete potential;
  • src/Potentials/StreamFactory_EmpiricalPotential.hpp

    r72b6d7 re83114  
    5555      const SerializablePotential::ParticleTypes_t &charges) const=0;
    5656
     57  virtual EmpiricalPotential *createInstance(
     58      const std::string &potentialtype,
     59      const SerializablePotential::ParticleTypes_t &charges,
     60                        const FunctionModel::parameters_t &params) const=0;
     61
    5762};
    5863
Note: See TracChangeset for help on using the changeset viewer.