Program Listing for File mxd_end_only.hpp#

↰ Return to documentation for file (source/pele/mxd_end_only.hpp)

#ifndef _PELE_MXD_END_ONLY_HPP
#define _PELE_MXD_END_ONLY_HPP

#include <complex>
#include <cstdint>
#include <iostream>

#include "base_potential.hpp"
#include "pele/array.hpp"
#include "pele/cvode.hpp"
#include "pele/newton.hpp"

namespace pele {

class MixedDescentEndOnly : public GradientOptimizer {
 private:
  double _tol;
  double _newton_step_tol;
  bool use_newton_step;
  Array<double> particle_disp;   // Stores displacement for a single particle
  double _max_dist;              // Maximum distance a single particle has moved
  Array<uint8_t> _not_rattlers;  // TODO: only because we need to save this

  CVODEBDFOptimizer _cvode_optimizer;
  Newton _newton_optimizer;

 public:
  MixedDescentEndOnly(std::shared_ptr<BasePotential> potential,
                      const pele::Array<double> x0, double tol = 1e-6,
                      double newton_step_tol = 1e-6, double rtol = 1e-6,
                      double atol = 1e-6, double threshold = 1e-10,
                      bool iterative = false);
  ~MixedDescentEndOnly(){};

  void one_iteration();
  // since most of the calculations are done in the attached optimizers, we
  // defer the calculations to them
  inline int get_nhev() {
    std::cout << "cvode nhev" << _cvode_optimizer.get_nhev() << std::endl;
    std::cout << "newton nhev" << _newton_optimizer.get_nhev() << std::endl;
    return _cvode_optimizer.get_nhev() + _newton_optimizer.get_nhev();
  }
  inline int get_niter() { return iter_number_; }
  inline double get_nfev() {
    return _cvode_optimizer.get_nfev() + _newton_optimizer.get_nfev();
  }
  bool stop_criterion_satisfied();
  inline Array<double> get_step_vec() {
    Eigen::VectorXd step = _newton_optimizer.get_step();
    return Array<double>(step.data(), step.size());
  }
};
}  // namespace pele

#endif  // _PELE_MXD_END_ONLY_HPP