Changeset f6f761


Ignore:
Timestamp:
Oct 2, 2016, 11:51:00 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Fix_FitPotential_needs_atomicnumbers
Children:
8d5db8
Parents:
5cdfac
git-author:
Frederik Heber <heber@…> (10/02/16 11:50:53)
git-committer:
Frederik Heber <heber@…> (10/02/16 11:51:00)
Message:

REFACTOR: Extracted registerPotentialIfNotPresent out of PotentialFitPotentialAction::performCall().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/PotentialAction/FitPotentialAction.cpp

    r5cdfac rf6f761  
    6969/** =========== define the function ====================== */
    7070
     71static void registerPotentialIfNotPresent(
     72    const std::string &_potentialtype,
     73    const SerializablePotential::ParticleTypes_t &_types)
     74{
     75  EmpiricalPotential *potential =
     76      PotentialFactory::getInstance().createInstance(_potentialtype,_types);
     77  // check whether such a potential already exists
     78  const std::string potential_name = potential->getName();
     79  if (PotentialRegistry::getInstance().isPresentByName(potential_name)) {
     80    delete potential;
     81    potential = PotentialRegistry::getInstance().getByName(potential_name);
     82  } else
     83    PotentialRegistry::getInstance().registerInstance(potential);
     84}
     85
     86
    7187ActionState::ptr PotentialFitPotentialAction::performCall() {
    7288  // fragment specifies the homology fragment to use
     
    87103
    88104    // register desired potential and an additional constant one
    89     {
    90       EmpiricalPotential *potential =
    91           PotentialFactory::getInstance().createInstance(
    92               params.potentialtype.get(),
    93               chargenumbers);
    94       // check whether such a potential already exists
    95       const std::string potential_name = potential->getName();
    96       if (PotentialRegistry::getInstance().isPresentByName(potential_name)) {
    97         delete potential;
    98         potential = PotentialRegistry::getInstance().getByName(potential_name);
    99       } else
    100         PotentialRegistry::getInstance().registerInstance(potential);
    101     }
    102     {
    103       EmpiricalPotential *constant =
    104           PotentialFactory::getInstance().createInstance(
    105               std::string("constant"),
    106               SerializablePotential::ParticleTypes_t());
    107       // check whether such a potential already exists
    108       const std::string constant_name = constant->getName();
    109       if (PotentialRegistry::getInstance().isPresentByName(constant_name)) {
    110         delete constant;
    111         constant = PotentialRegistry::getInstance().getByName(constant_name);
    112       } else
    113         PotentialRegistry::getInstance().registerInstance(constant);
    114     }
     105    registerPotentialIfNotPresent(params.potentialtype.get(),chargenumbers);
     106    registerPotentialIfNotPresent(
     107        std::string("constant"),
     108        SerializablePotential::ParticleTypes_t());
    115109  }
    116110
Note: See TracChangeset for help on using the changeset viewer.