32#ifndef BERTINI_BASE_PREDICTORS_HPP
33#define BERTINI_BASE_PREDICTORS_HPP
42#include <boost/type_index.hpp>
50 using Predictor = Predictor;
60 return Predictor::Euler;
68 unsigned Order(Predictor predictor_choice)
70 switch (predictor_choice)
72 case (Predictor::Euler):
74 case (Predictor::HeunEuler):
76 case (Predictor::RK4):
78 case (Predictor::RKF45):
80 case (Predictor::RKCashKarp45):
82 case (Predictor::RKDormandPrince56):
84 case (Predictor::RKVerner67):
88 throw std::runtime_error(
"incompatible predictor choice in Order");
96 switch (predictor_choice)
98 case (Predictor::Euler):
100 case (Predictor::HeunEuler):
102 case (Predictor::RK4):
104 case (Predictor::RKF45):
106 case (Predictor::RKCashKarp45):
108 case (Predictor::RKDormandPrince56):
110 case (Predictor::RKVerner67):
114 throw std::runtime_error(
"incompatible predictor choice in HasErrorEstimate");
156 BasePredictor(Predictor method){};
174 template<
typename ComplexType,
typename RealType>
175 SuccessCode
Predict(Vec<ComplexType> & next_space,
177 Vec<ComplexType>
const& current_space, ComplexType current_time,
178 ComplexType
const& delta_t,
179 RealType & condition_number_estimate,
180 unsigned & num_steps_since_last_condition_number_computation,
181 unsigned frequency_of_CN_estimation,
182 RealType
const& tracking_tolerance)
212 template<
typename ComplexType,
typename RealType>
213 SuccessCode
Predict(Vec<ComplexType> & next_space,
214 RealType & size_proportion,
216 RealType & norm_J_inverse,
218 Vec<ComplexType>
const& current_space, ComplexType current_time,
219 ComplexType
const& delta_t,
220 RealType & condition_number_estimate,
221 unsigned & num_steps_since_last_condition_number_computation,
222 unsigned frequency_of_CN_estimation,
223 RealType
const& tracking_tolerance,
229 condition_number_estimate, num_steps_since_last_condition_number_computation,
230 frequency_of_CN_estimation, tracking_tolerance);
232 if(success_code != SuccessCode::Success)
236 Eigen::PartialPivLU<Mat<ComplexType>>& dhdxref = std::get< Eigen::PartialPivLU<Mat<ComplexType>> >(dh_dx_);
237 Mat<ComplexType>& LUref = std::get< Mat<ComplexType> >(LU_);
240 Vec<ComplexType> temp_soln = LUref.solve(randy);
242 norm_J = dhdxref.norm();
243 norm_J_inverse = temp_soln.norm();
245 if (num_steps_since_last_condition_number_computation >= frequency_of_CN_estimation)
247 condition_number_estimate = norm_J * norm_J_inverse;
248 num_steps_since_last_condition_number_computation = 1;
251 num_steps_since_last_condition_number_computation++;
261 return SuccessCode::HigherPrecisionNecessary;
262 else if (!
amp::CriterionC(norm_J_inverse, current_space, tracking_tolerance, AMP_config))
263 return SuccessCode::HigherPrecisionNecessary;
291 template<
typename ComplexType,
typename RealType>
292 SuccessCode
Predict(Vec<ComplexType> & next_space,
293 RealType & error_estimate,
294 RealType & size_proportion,
296 RealType & norm_J_inverse,
298 Vec<ComplexType>
const& current_space, ComplexType current_time,
299 ComplexType
const& delta_t,
300 RealType & condition_number_estimate,
301 unsigned & num_steps_since_last_condition_number_computation,
302 unsigned frequency_of_CN_estimation,
303 RealType
const& tracking_tolerance,
310 throw std::runtime_error(
"incompatible predictor choice in ExplicitPredict, no error estimator");
317 S, current_space, current_time, delta_t,
318 condition_number_estimate, num_steps_since_last_condition_number_computation,
319 frequency_of_CN_estimation, tracking_tolerance, AMP_config);
321 if(success_code != SuccessCode::Success)
388 template<
typename ComplexType,
typename RealType>
389 virtual SuccessCode
FullStep(Vec<ComplexType> & next_space,
391 Vec<ComplexType>
const& current_space, ComplexType current_time,
392 ComplexType
const& delta_t) = 0;
405 template<
typename ComplexType,
typename RealType>
406 virtual SuccessCode
SetErrorEstimate(RealType & error_estimate, ComplexType
const& delta_t) = 0;
420 template<
typename ComplexType,
typename RealType>
421 virtual SuccessCode
SetSizeProportion(RealType & size_proportion, ComplexType
const& delta_t) = 0;
437 template<
typename ComplexType>
439 Vec<ComplexType>
const& space, ComplexType time, Mat<ComplexType> & K,
int stage) = 0;
456 Predictor predictor_;
458 std::tuple< Mat<dbl>, Mat<mpfr> > dh_dx_;
459 std::tuple< Eigen::PartialPivLU<Mat<dbl>>, Eigen::PartialPivLU<Mat<mpfr>> > LU_;
Provides the Adaptive Multiple Precision criteria functions.
bool CriterionC(double const &norm_J_inverse, const Eigen::MatrixBase< Derived > &z, double tracking_tolerance, AdaptiveMultiplePrecisionConfig const &_config)
Check AMP Criterion C.
Definition amp_criteria.hpp:206
bool CriterionA(double const &norm_J, double const &norm_J_inverse, AdaptiveMultiplePrecisionConfig const &_config)
Check AMP Criterion A.
Definition amp_criteria.hpp:71
bool HasErrorEstimate(Predictor predictor_choice)
Ask whether a predictor method provides an error estimate.
Definition base_predictor.hpp:94
Predictor DefaultPredictor()
Get the Bertini2 default predictor.
Definition base_predictor.hpp:58
unsigned Order(Predictor predictor_choice)
The order of the predictor.
Definition base_predictor.hpp:68
The fundamental polynomial system class for Bertini2.
Definition system/system.hpp:99
size_t NumVariables() const
virtual SuccessCode SetSizeProportion(RealType &size_proportion, ComplexType const &delta_t)=0
Compute the size proportion variable for AMP computation.
virtual SuccessCode SetErrorEstimate(RealType &error_estimate, ComplexType const &delta_t)=0
Computes the error estimate of this prediction step.
virtual SuccessCode EvalRHS(System const &S, Vec< ComplexType > const &space, ComplexType time, Mat< ComplexType > &K, int stage)=0
Evaluates the RHS of the Davidenko differential equation at a particular time and space.
virtual SuccessCode FullStep(Vec< ComplexType > &next_space, System const &S, Vec< ComplexType > const ¤t_space, ComplexType current_time, ComplexType const &delta_t)=0
Performs a full prediction step from current_time to current_time + delta_t.
SuccessCode Predict(Vec< ComplexType > &next_space, System const &S, Vec< ComplexType > const ¤t_space, ComplexType current_time, ComplexType const &delta_t, RealType &condition_number_estimate, unsigned &num_steps_since_last_condition_number_computation, unsigned frequency_of_CN_estimation, RealType const &tracking_tolerance)
Perform a generic predictor step.
Definition base_predictor.hpp:175
virtual void PredictorMethod(Predictor method)=0
SuccessCode Predict(Vec< ComplexType > &next_space, RealType &size_proportion, RealType &norm_J, RealType &norm_J_inverse, System const &S, Vec< ComplexType > const ¤t_space, ComplexType current_time, ComplexType const &delta_t, RealType &condition_number_estimate, unsigned &num_steps_since_last_condition_number_computation, unsigned frequency_of_CN_estimation, RealType const &tracking_tolerance, AdaptiveMultiplePrecisionConfig const &_config)
Perform a generic predictor step and return size_proportion and condition number information.
Definition base_predictor.hpp:213
unsigned Order()
Definition base_predictor.hpp:354
SuccessCode Predict(Vec< ComplexType > &next_space, RealType &error_estimate, RealType &size_proportion, RealType &norm_J, RealType &norm_J_inverse, System const &S, Vec< ComplexType > const ¤t_space, ComplexType current_time, ComplexType const &delta_t, RealType &condition_number_estimate, unsigned &num_steps_since_last_condition_number_computation, unsigned frequency_of_CN_estimation, RealType const &tracking_tolerance, AdaptiveMultiplePrecisionConfig const &_config)
Perform a generic predictor step and return error estimate, size_proportion and condition number info...
Definition base_predictor.hpp:292
Mat< NumberType > RandomOfUnits(uint rows, uint cols)
Make a random matrix of units (numbers with norm 1).
Definition eigen_extensions.hpp:502
Extensions to the Boost.Multiprecision library.
Definition trackers/config.hpp:154
Configs and settings for tracking.