33#ifndef BERTINI_BASE_TRACKER_HPP
34#define BERTINI_BASE_TRACKER_HPP
39#include "bertini2/trackers/newton_corrector.hpp"
139 typename TrackerTraits< D >::NeededConfigs
142 using NeededTypes =
typename TrackerTraits< D >::NeededTypes;
143 using BaseComplexType =
typename TrackerTraits<D>::BaseComplexType;
144 using BaseRealType =
typename TrackerTraits<D>::BaseRealType;
146 using CT = BaseComplexType;
147 using RT = BaseRealType;
152 using Stepping = SteppingConfig;
153 using Newton = NewtonConfig;
154 using PrecConf =
typename TrackerTraits< D >::PrecisionConfig;
159 corrector_ = std::make_shared< correct::NewtonCorrector >(
tracked_system_);
171 void Setup(Predictor new_predictor_choice,
172 double const& tracking_tolerance,
173 double const& path_truncation_threshold,
174 SteppingConfig
const& stepping,
175 NewtonConfig
const& newton)
178 corrector_->Settings(newton);
184 this->
template Set(stepping);
185 this->
template Set(newton);
204 if (tracking_tolerance <= 0)
205 throw std::runtime_error(
"tracking tolerance must be strictly positive");
212 void SetInfiniteTruncationTolerance(
double const& tol)
215 throw std::runtime_error(
"truncation threshold must be strictly positive");
233 CT
const& start_time, CT
const& endtime,
234 Vec<CT>
const& start_point
237 if (start_point.size()!=
GetSystem().NumVariables())
238 throw std::runtime_error(
"start point size must match the number of variables in the system to be tracked");
242 SuccessCode initialization_code = TrackerLoopInitialization(start_time, endtime, start_point);
243 if (initialization_code!=SuccessCode::Success)
246 return initialization_code;
252 SuccessCode pre_iteration_code = PreIterationCheck();
253 if (pre_iteration_code!=SuccessCode::Success)
256 return pre_iteration_code;
269 if (infinite_path_truncation_ && (CheckGoingToInfinity()==SuccessCode::GoingToInfinity))
271 OnInfiniteTruncation();
273 return SuccessCode::GoingToInfinity;
283 CopyFinalSolution(solution_at_endtime);
285 return SuccessCode::Success;
304 Vec<C>
const& start_point, C
const& current_time)
const
307 static_assert(detail::IsTemplateParameter<C,NeededTypes>::value,
"complex type for refinement must be a used type for the tracker");
308 return this->AsDerived().RefineImpl(new_space, start_point, current_time);
329 Vec<C>
const& start_point, C
const& current_time,
double const& tolerance,
unsigned max_iterations)
const
331 static_assert(detail::IsTemplateParameter<C,NeededTypes>::value,
"complex type for refinement must be a used type for the tracker");
333 return this->AsDerived().RefineImpl(new_space, start_point, current_time, tolerance, max_iterations);
346 predictor_->PredictorMethod(new_predictor_choice);
356 return predictor_->PredictorMethod();
411 auto TrackingTolerance()
const
416 auto InfiniteTruncationTolerance()
const
424 const D& AsDerived()
const
426 return static_cast<const D&
>(*this);
437 SuccessCode TrackerLoopInitialization(CT
const& start_time, CT
const& end_time, Vec<CT>
const& start_point)
const = 0;
446 SuccessCode PreIterationCheck()
const = 0;
454 SuccessCode TrackerIteration()
const = 0;
462 void CopyFinalSolution(Vec<CT> & solution_at_endtime)
const = 0;
474 template <
typename ComplexType>
475 SuccessCode CheckGoingToInfinity()
const
478 return SuccessCode::GoingToInfinity;
480 return SuccessCode::Success;
503 void ResetCountersBase()
const
528 void OnStepSuccess()
const = 0;
545 void OnStepFail()
const = 0;
556 void OnInfiniteTruncation()
const = 0;
561 bool infinite_path_truncation_ =
true;
573 std::shared_ptr<predict::ExplicitRKPredictor > predictor_;
576 std::shared_ptr<correct::NewtonCorrector> corrector_;
592 mutable RT next_stepsize_;
601 using TupOfVec =
typename NeededTypes::ToTupleOfVec;
602 using TupOfReal =
typename NeededTypes::ToTupleOfReal;
622 NumErrorT LatestConditionNumber()
const
624 return this->condition_number_estimate_;
628 NumErrorT LatestErrorEstimate()
const
630 return this->error_estimate_;
634 NumErrorT LatestNormOfStep()
const
636 return this->norm_delta_z_;
639 void SetInfiniteTruncation(
bool b)
641 infinite_path_truncation_ = b;
644 auto InfiniteTruncation()
646 return infinite_path_truncation_;
649 unsigned NumVariables()
const
654 auto CurrentTime()
const
664 auto CurrentStepsize()
const
670 virtual Vec<CT> CurrentPoint()
const = 0;
673 virtual unsigned CurrentPrecision()
const = 0;
Predictor DefaultPredictor()
Get the Bertini2 default predictor.
Definition base_predictor.hpp:58
An abstract observable type, maintaining a list of observers, who can be notified in case of Events.
Definition observable.hpp:48
The fundamental polynomial system class for Bertini2.
Definition system/system.hpp:99
size_t NumVariables() const
Base tracker class for trackers offered in Bertini2.
Definition base_tracker.hpp:141
void ReinitializeInitialStepSize(bool should_reinitialize_stepsize)
Switch resetting of initial step size to that of the stepping settings.
Definition base_tracker.hpp:404
unsigned predictor_order_
Definition base_tracker.hpp:574
Predictor GetPredictor() const
Query the currently set predictor.
Definition base_tracker.hpp:354
SuccessCode Refine(Vec< C > &new_space, Vec< C > const &start_point, C const ¤t_time, double const &tolerance, unsigned max_iterations) const
Refine a point to a given tolerance.
Definition base_tracker.hpp:328
NumErrorT error_estimate_
Definition base_tracker.hpp:610
virtual void PostTrackCleanup() const
Function to be called before exiting the tracker loop.
Definition base_tracker.hpp:489
CT current_time_
Definition base_tracker.hpp:586
const System & GetSystem() const
Definition base_tracker.hpp:373
unsigned num_successful_steps_since_stepsize_increase_
Definition base_tracker.hpp:598
NumErrorT size_proportion_
Definition base_tracker.hpp:614
SuccessCode TrackPath(Vec< CT > &solution_at_endtime, CT const &start_time, CT const &endtime, Vec< CT > const &start_point) const
Track a start point through time, from a start time to a target time.
Definition base_tracker.hpp:232
void SetSystem(const System &new_sys)
get a const reference to the system.
Definition base_tracker.hpp:363
NumErrorT path_truncation_threshold_
Definition base_tracker.hpp:583
void SetPredictor(Predictor new_predictor_choice)
Change tracker to use a predictor.
Definition base_tracker.hpp:344
unsigned digits_final_
Definition base_tracker.hpp:580
unsigned num_consecutive_successful_steps_
Definition base_tracker.hpp:567
CT endtime_
Definition base_tracker.hpp:585
RT current_stepsize_
Definition base_tracker.hpp:588
unsigned num_total_steps_taken_
Definition base_tracker.hpp:565
unsigned NumTotalStepsTaken() const
See how many steps have been taken.
Definition base_tracker.hpp:383
virtual void ResetCounters() const =0
Reset counters used during tracking.
NumErrorT condition_number_estimate_
Definition base_tracker.hpp:609
TupOfVec current_space_
The current space value.
Definition base_tracker.hpp:604
SuccessCode step_success_code_
Definition base_tracker.hpp:593
unsigned num_failed_steps_taken_
Definition base_tracker.hpp:569
unsigned num_steps_since_last_condition_number_computation_
Definition base_tracker.hpp:597
bool reinitialize_stepsize_
Definition base_tracker.hpp:562
NumErrorT norm_J_inverse_
Definition base_tracker.hpp:612
TupOfVec temporary_space_
Definition base_tracker.hpp:606
void IncrementBaseCountersFail() const
Increment and reset counters after a failed TrackerIteration()
Definition base_tracker.hpp:536
CT delta_t_
Definition base_tracker.hpp:587
void SetStepSize(RT const &new_stepsize) const
Set how large the stepsize should be.
Definition base_tracker.hpp:393
unsigned num_successful_steps_taken_
Definition base_tracker.hpp:566
TupOfVec tentative_space_
Definition base_tracker.hpp:605
unsigned digits_tracking_tolerance_
Definition base_tracker.hpp:581
virtual SuccessCode CheckGoingToInfinity() const =0
Check whether the path is going to infinity, as it tracks.
std::reference_wrapper< const System > tracked_system_
Reference to the system being tracked.
Definition base_tracker.hpp:559
void Setup(Predictor new_predictor_choice, double const &tracking_tolerance, double const &path_truncation_threshold, SteppingConfig const &stepping, NewtonConfig const &newton)
Get the tracker set up for tracking.
Definition base_tracker.hpp:171
unsigned num_consecutive_failed_steps_
Definition base_tracker.hpp:568
NumErrorT tracking_tolerance_
Definition base_tracker.hpp:582
NumErrorT norm_delta_z_
Definition base_tracker.hpp:613
SuccessCode Refine(Vec< C > &new_space, Vec< C > const &start_point, C const ¤t_time) const
Refine a point to tolerance implicitly internally set.
Definition base_tracker.hpp:303
unsigned num_successful_steps_since_precision_decrease_
Definition base_tracker.hpp:599
NumErrorT norm_J_
Definition base_tracker.hpp:611
void SetTrackingTolerance(double const &tracking_tolerance)
Set how tightly to track the path.
Definition base_tracker.hpp:202
void IncrementBaseCountersSuccess() const
Increment and reset counters after a successful TrackerIteration()
Definition base_tracker.hpp:519
bool IsSymmRelDiffSmall(T const &a, T const &b, typename Eigen::NumTraits< T >::Real const &e)
Check whether two values are very close to each other.
Definition eigen_extensions.hpp:369
Contains the detail/is_template_parameter helper, for checking whether a type is a template parameter...
Logging in Bertini using Boost.Log.
Contains the observable base types.
Includes for the suite of ODE predictors.
Contains the tracker/events base types.