Changeset 1dca9a


Ignore:
Timestamp:
Dec 19, 2012, 3:25:31 PM (12 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_BoundInBox_CenterInBox_MoleculeActions, 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:
5b5724
Parents:
3ccea3
git-author:
Frederik Heber <heber@…> (10/03/12 19:58:07)
git-committer:
Frederik Heber <heber@…> (12/19/12 15:25:31)
Message:

Modified PairPotential_Harmonic to have an internal vector of parameters.

  • an enum gives which index in the vector refers to which parameter. This makes the subsequent implementation of the parameter derivative easier.
Location:
src/Potentials/Specifics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/Specifics/PairPotential_Harmonic.cpp

    r3ccea3 r1dca9a  
    4343#include "Potentials/helpers.hpp"
    4444
     45PairPotential_Harmonic::PairPotential_Harmonic() :
     46  params(parameters_t(MAXPARAMS, 0.))
     47{}
     48
     49PairPotential_Harmonic::PairPotential_Harmonic(
     50    const double _spring_constant,
     51    const double _equilibrium_distance,
     52    const double _energy_offset) :
     53      params(parameters_t(MAXPARAMS, 0.))
     54{
     55  params[spring_constant] = _spring_constant;
     56  params[equilibrium_distance] = _equilibrium_distance;
     57  params[energy_offset] = _energy_offset;
     58}
     59
    4560PairPotential_Harmonic::results_t
    4661PairPotential_Harmonic::operator()(
     
    5166      "PairPotential_Harmonic::operator() - requires exactly one argument.");
    5267  const argument_t &r_ij = arguments[0];
    53   const result_t result = spring_constant * Helpers::pow( r_ij.distance - equilibrium_distance, 2 ) - energy_offset;
     68  const result_t result =
     69      params[spring_constant]
     70             * Helpers::pow( r_ij.distance - params[equilibrium_distance], 2 )
     71            + params[energy_offset];
    5472  return std::vector<result_t>(1, result);
    5573}
     
    6482  derivative_components_t result;
    6583  const argument_t &r_ij = arguments[0];
    66   result.push_back( 2. * spring_constant * ( r_ij.distance - equilibrium_distance) );
     84  result.push_back( 2. * params[spring_constant] * ( r_ij.distance - params[equilibrium_distance]) );
    6785  ASSERT( result.size() == 1,
    6886      "PairPotential_Harmonic::operator() - we did not create exactly one component.");
     
    7088}
    7189
    72 void PairPotential_Harmonic::setParameters(const parameters_t &_params)
    73 {
    74   ASSERT( _params.size() == 3,
    75       "PairPotential_Harmonic::setParameters() - we need exactly two parameters.");
    76   spring_constant = _params[0];
    77   equilibrium_distance = _params[1];
    78   energy_offset = _params[2];
    79 }
    80 
    81 PairPotential_Harmonic::parameters_t PairPotential_Harmonic::getParameters() const
    82 {
    83   parameters_t params(3, 0.);
    84   params[0] = spring_constant;
    85   params[1] = equilibrium_distance;
    86   params[2] = energy_offset;
    87   return params;
    88 }
  • src/Potentials/Specifics/PairPotential_Harmonic.hpp

    r3ccea3 r1dca9a  
    1515#endif
    1616
     17#include "CodePatterns/Assert.hpp"
    1718
    1819#include "Potentials/EmpiricalPotential.hpp"
     
    3132  typedef FunctionModel::results_t results_t;
    3233  typedef EmpiricalPotential::derivative_components_t derivative_components_t;
     34  typedef FunctionModel::parameters_t parameters_t;
    3335public:
    3436  PairPotential_Harmonic();
     
    3638      const double _spring_constant,
    3739      const double _equilibrium_distance,
    38       const double _energy_offset) :
    39     spring_constant(_spring_constant),
    40     equilibrium_distance(_equilibrium_distance),
    41     energy_offset(_energy_offset)
    42   {}
     40      const double _energy_offset);
    4341  virtual ~PairPotential_Harmonic() {}
    4442
     
    4745   * \param _params given set of parameters
    4846   */
    49   void setParameters(const parameters_t &_params);
     47  void setParameters(const parameters_t &_params)
     48  {
     49    ASSERT( _params.size() <= getParameterDimension(),
     50        "PairPotential_Harmonic::setParameters() - we need not more than "
     51        +toString(getParameterDimension())+" parameters.");
     52    for(size_t i=0;i<_params.size();++i)
     53      params[i] = _params[i];
     54  }
    5055
    5156  /** Getter for parameters as required by FunctionModel interface.
     
    5358   * \return set of parameters
    5459   */
    55   parameters_t getParameters() const;
     60  parameters_t getParameters() const
     61  {
     62    return params;
     63  }
    5664
    5765  /** Getter for the number of parameters of this model function.
     
    8997
    9098private:
    91   //!> the spring constant for the harmonic potential
    92   double spring_constant;
    93   //!> the equilibrium distance indicating the potential minimum
    94   double equilibrium_distance;
    95   //!> energy offset
    96   double energy_offset;
     99  enum parameter_enum_t {
     100    spring_constant=0,
     101    equilibrium_distance=1,
     102    energy_offset=2,
     103    MAXPARAMS
     104  };
     105  //!> parameter vector with parameters as in enum parameter_enum_t
     106  parameters_t params;
    97107};
    98108
Note: See TracChangeset for help on using the changeset viewer.