Changeset e6a2ef


Ignore:
Timestamp:
Mar 24, 2017, 10:12:23 AM (8 years ago)
Author:
Frederik Heber <heber@…>
Branches:
FitPartialCharges_GlobalError
Children:
fa2c89
Parents:
a3d08c
git-author:
Frederik Heber <heber@…> (10/10/16 12:34:32)
git-committer:
Frederik Heber <heber@…> (03/24/17 10:12:23)
Message:

Extracted PartialNucleiChargeFitter::calculateResiduum().

Location:
src/Potentials
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Potentials/PartialNucleiChargeFitter.cpp

    ra3d08c re6a2ef  
    305305}
    306306
    307 double PartialNucleiChargeFitter::operator()()
     307VectorContent PartialNucleiChargeFitter::calculateResiduum()
     308{
     309  constructMatrix();
     310
     311  // calculate residual vector
     312  VectorContent residuum = (*PotentialFromCharges) * (*PartialCharges) - SampledPotential;
     313
     314  return residuum;
     315}
     316
     317void PartialNucleiChargeFitter::prepareCharges(const size_t _size)
    308318{
    309319  // prepare PartialCharges
     
    312322    PartialCharges = NULL;
    313323  }
    314   PartialCharges = new VectorContent(positions.size());
     324  PartialCharges = new VectorContent(_size);
     325}
     326
     327double PartialNucleiChargeFitter::operator()()
     328{
     329  prepareCharges(positions.size());
    315330
    316331  // set up over-determined system's problem matrix A for Ax=b
     
    327342  LOG(2, "DEBUG: Norm of right-hand side is " << SampledPotential.Norm());
    328343
    329   // need to reconstruct matrix as it was overwritten by SVD
    330   constructMatrix();
    331 
    332   // calculate residual vector
    333   VectorContent residuum = (*PotentialFromCharges) * (*PartialCharges) - SampledPotential;
     344  // calculate residuum (forces matrix reconstruction)
     345  VectorContent residuum = calculateResiduum();
    334346
    335347#ifndef NDEBUG
     
    367379
    368380  return residuum.Norm();
     381}
     382
     383bool PartialNucleiChargeFitter::setCharges(const charges_t &_charges)
     384{
     385  // check sizes
     386  if (positions.size() != _charges.size()) {
     387    return false;
     388  }
     389  // (re-)allocate memory
     390  prepareCharges(positions.size());
     391  // and place charges in vector
     392  for(size_t i=0;i<_charges.size();++i)
     393    (*PartialCharges)[i] = _charges[i];
     394
     395  return true;
    369396}
    370397
  • src/Potentials/PartialNucleiChargeFitter.hpp

    ra3d08c re6a2ef  
    105105   charges_t getSolutionAsCharges_t() const;
    106106
     107   /** Helper function to construct the discretized Coulomb operator for the
     108    * nuclei charges.
     109    *
     110    */
    107111   void writeMatrix();
     112
     113   /** Setter for solution as charges_t
     114    *
     115    * \param _charges solution vector x as type charges_t
     116    * \return false - if charges does not match in size with internal positions
     117    */
     118   bool setCharges(const charges_t &_charges);
     119
     120   /** Calculates the residuum for the currently set charges.
     121    *
     122    * \return residual for every charge
     123    */
     124   VectorContent calculateResiduum();
    108125
    109126private:
     
    132149       const Vector &grid_position) const;
    133150
     151   /** Helper function to allocate memory for charges.
     152    *
     153    * \param _size size to allocate
     154    */
     155   void prepareCharges(const size_t _size);
     156
    134157private:
    135158   //!> grid dimensions per axis for internal use
Note: See TracChangeset for help on using the changeset viewer.