27#ifndef BERTINI_FIXED_PRECISION_TRACKER_HPP
28#define BERTINI_FIXED_PRECISION_TRACKER_HPP
54 template<
class DerivedT>
149 solution_at_endtime.resize(num_vars);
150 for (
unsigned ii=0; ii<num_vars; ii++)
152 solution_at_endtime(ii) = std::get<Vec<ComplexT> >(this->
current_space_)(ii);
169 static_assert(std::is_same< typename Eigen::NumTraits<RealT>::Real,
170 typename Eigen::NumTraits<ComplexT>::Real>::value,
171 "underlying complex type and the type for comparisons must match");
180 SuccessCode predictor_code =
Predict(predicted_space, current_space, current_time, delta_t);
184 this->
NotifyObservers(FirstStepPredictorMatrixSolveFailure<EmitterType >(*
this));
190 return predictor_code;
197 ComplexT tentative_next_time = current_time + delta_t;
201 tentative_next_time);
206 return corrector_code;
210 this->
NotifyObservers(CorrectorMatrixSolveFailure<EmitterType >(*
this));
215 return corrector_code;
222 current_space = tentative_next_space;
311 current_space, current_time,
335 return this->
corrector_.Correct(corrected_space,
393 NumErrorT const& tolerance,
unsigned max_iterations)
const
462 throw std::runtime_error(
"double-precision tracking is fixed at "
464 +
" digits; cannot set precision to " + std::to_string(c.
precision)
465 +
" (use mptype 'multiple' or 'adaptive')");
519 SyncPrecisionToConfig();
545 SyncPrecisionToConfig();
577 std::stringstream err_msg;
578 err_msg <<
"start point for fixed multiple precision tracker has differing precision from default (" << start_point(0).precision() <<
"!=" <<
ThreadPrecision() <<
"), tracking cannot start";
579 throw std::runtime_error(err_msg.str());
584 std::stringstream err_msg;
585 err_msg <<
"start point for fixed multiple precision tracker has differing precision from tracker's precision (" << start_point(0).precision() <<
"!=" << this->
CurrentPrecision() <<
"), tracking cannot start";
586 throw std::runtime_error(err_msg.str());
591 std::stringstream err_msg;
592 err_msg <<
"current default precision differs from tracker's precision (" <<
ThreadPrecision() <<
"!=" << this->
CurrentPrecision() <<
"), tracking cannot start";
593 throw std::runtime_error(err_msg.str());
603 this->
endtime_.precision(precision_);
604 this->
delta_t_.precision(precision_);
631 std::get<Vec<complex_mp> >(
current_space_)(0).precision() == precision_ &&
632 std::get<Vec<complex_mp> >(
tentative_space_)(0).precision() == precision_ &&
633 std::get<Vec<complex_mp> >(
temporary_space_)(0).precision() == precision_ &&
641 void SyncPrecisionToConfig()
Contains the abstract base Tracker type, from which all other Trackers inherit.
void NotifyObservers(AnyEvent const &e) const
Definition observable.hpp:185
The fundamental polynomial system class for Bertini2.
Definition system.hpp:106
size_t NumVariables() const
Get the total number of variables in this system, including homogenizing variables.
complex_dbl BaseComplexT
The complex number type.
Definition fixed_precision_tracker.hpp:425
void PrecisionSetup(FixedPrecisionConfig const &c)
Double-precision tracking is fixed at DoublePrecision() digits.
Definition fixed_precision_tracker.hpp:459
DoublePrecisionTracker(class System const &sys)
Construct a tracker, associating to it a System.
Definition fixed_precision_tracker.hpp:434
unsigned CurrentPrecision() const override
Get the current working precision (always DoublePrecision() for this tracker).
Definition fixed_precision_tracker.hpp:449
SuccessCode TrackerLoopInitialization(BaseComplexT const &start_time, BaseComplexT const &end_time, Vec< BaseComplexT > const &start_point) const override
Set up the internals of the tracker for a fresh start.
Definition fixed_precision_tracker.hpp:478
DoublePrecisionTracker()=delete
virtual ~DoublePrecisionTracker()=default
typename TrackerTraits< DoublePrecisionTracker >::EventEmitterType EmitterType
The event-emitter type for this tracker.
Definition fixed_precision_tracker.hpp:428
double BaseRealT
The real number type.
Definition fixed_precision_tracker.hpp:426
void OnInfiniteTruncation() const override
React to a path being truncated for going to infinity, by notifying observers.
Definition fixed_precision_tracker.hpp:280
BaseComplexT ComplexT
The complex number type.
Definition fixed_precision_tracker.hpp:62
SuccessCode RefineImpl(Vec< ComplexT > &new_space, Vec< ComplexT > const &start_point, ComplexT const ¤t_time, NumErrorT const &tolerance, unsigned max_iterations) const
Run Newton's method from a start point with a current time.
Definition fixed_precision_tracker.hpp:391
typename Base::Newton Newton
The Newton corrector configuration type.
Definition fixed_precision_tracker.hpp:73
SuccessCode TrackerIteration() const override
Run an iteration of the tracker loop.
Definition fixed_precision_tracker.hpp:167
SuccessCode Predict(Vec< ComplexT > &predicted_space, Vec< ComplexT > const ¤t_space, ComplexT const ¤t_time, ComplexT const &delta_t) const
Wrapper function for calling the correct predictor.
Definition fixed_precision_tracker.hpp:302
SuccessCode RefineImpl(Vec< ComplexT > &new_space, Vec< ComplexT > const &start_point, ComplexT const ¤t_time) const
Run Newton's method from a start point with a current time.
Definition fixed_precision_tracker.hpp:359
typename Base::Stepping Stepping
The stepping configuration type.
Definition fixed_precision_tracker.hpp:72
FixedPrecisionTracker(System const &sys)
Construct a fixed-precision tracker for a system.
Definition fixed_precision_tracker.hpp:76
SuccessCode UpdateStepsize() const
Commit the next stepsize, and adjust internals.
Definition fixed_precision_tracker.hpp:242
typename Base::Config Config
The configuration-holding base type.
Definition fixed_precision_tracker.hpp:70
typename TrackerTraits< DerivedT >::BaseRealT BaseRealT
The real number type.
Definition fixed_precision_tracker.hpp:60
SuccessCode Correct(Vec< ComplexT > &corrected_space, Vec< ComplexT > const ¤t_space, ComplexT const ¤t_time) const
Run Newton's method.
Definition fixed_precision_tracker.hpp:331
void PrecisionSetup(FixedPrecisionConfig const &)
An additional no-op call, provided for conformity of interface with AMP tracker in generic code.
Definition fixed_precision_tracker.hpp:81
void ResetCounters() const override
Reset counters used during tracking.
Definition fixed_precision_tracker.hpp:93
SuccessCode PreIterationCheck() const override
Ensure that number of steps, stepsize, and precision still ok.
Definition fixed_precision_tracker.hpp:108
SuccessCode CheckGoingToInfinity() const override
Check whether the path is going to infinity.
Definition fixed_precision_tracker.hpp:230
void OnStepFail() const override
Increment and reset counters after a failed TrackerIteration().
Definition fixed_precision_tracker.hpp:270
FixedPrecisionTracker< DerivedT > EmitterType
The event-emitter type for this tracker.
Definition fixed_precision_tracker.hpp:67
virtual ~FixedPrecisionTracker()=default
typename TrackerTraits< DerivedT >::BaseComplexT BaseComplexT
The complex number type.
Definition fixed_precision_tracker.hpp:59
Tracker< FixedPrecisionTracker< DerivedT > > Base
The base tracker type.
Definition fixed_precision_tracker.hpp:68
void OnStepSuccess() const override
Increment and reset counters after a successful TrackerIteration().
Definition fixed_precision_tracker.hpp:261
void CopySolution(Vec< ComplexT > &solution_at_endtime) const override
Copy from the internally stored current solution into a final solution.
Definition fixed_precision_tracker.hpp:143
Vec< ComplexT > CurrentPoint() const override
Get the current space point of the track.
Definition fixed_precision_tracker.hpp:86
void PostTrackCleanup() const override
Function to be called before exiting the tracker loop.
Definition fixed_precision_tracker.hpp:131
BaseRealT RealT
The real number type.
Definition fixed_precision_tracker.hpp:63
TrackPath is initializing the tracker.
Definition events.hpp:295
void PrecisionSetup(FixedPrecisionConfig const &c)
Adopt the precision named in a FixedPrecisionConfig (its sentinel 0 means "leave asis").
Definition fixed_precision_tracker.hpp:552
MultiplePrecisionTracker()=delete
complex_mp BaseComplexT
The complex number type.
Definition fixed_precision_tracker.hpp:506
unsigned CurrentPrecision() const override
Get the current (fixed multiple) working precision of this tracker.
Definition fixed_precision_tracker.hpp:529
bool PrecisionSanityCheck() const
Check that the system, thread precision, and all tracker state are at the expected precision.
Definition fixed_precision_tracker.hpp:626
real_mp BaseRealT
The real number type.
Definition fixed_precision_tracker.hpp:507
virtual ~MultiplePrecisionTracker()=default
FixedPrecisionTracker< MultiplePrecisionTracker > EmitterType
The event-emitter type for this tracker.
Definition fixed_precision_tracker.hpp:509
void SetPrecision(unsigned p)
Set the fixed precision this tracker works at.
Definition fixed_precision_tracker.hpp:542
MultiplePrecisionTracker(class System const &sys)
Construct a tracker, associating to it a System.
Definition fixed_precision_tracker.hpp:517
SuccessCode TrackerLoopInitialization(BaseComplexT const &start_time, BaseComplexT const &end_time, Vec< BaseComplexT > const &start_point) const override
Set up the internals of the tracker for a fresh start.
Definition fixed_precision_tracker.hpp:568
The correct part of a time step was successful.
Definition events.hpp:102
The predict part of tracking step was successful.
Definition events.hpp:72
predict::ExplicitRKPredictor predictor_
Definition base_tracker.hpp:815
ComplexT delta_t_
Definition base_tracker.hpp:826
Tracker(System const &sys)
Definition base_tracker.hpp:181
SteppingConfig Stepping
Definition base_tracker.hpp:176
const System & GetSystem() const
Definition base_tracker.hpp:507
unsigned num_successful_steps_since_stepsize_increase_
Definition base_tracker.hpp:837
correct::NewtonCorrector corrector_
Definition base_tracker.hpp:818
ComplexT endtime_
Definition base_tracker.hpp:824
NewtonConfig Newton
Definition base_tracker.hpp:177
unsigned NumTotalStepsTaken() const
Definition base_tracker.hpp:517
TupOfVec current_space_
Definition base_tracker.hpp:842
RealT current_stepsize_
Definition base_tracker.hpp:827
unsigned num_steps_since_last_condition_number_computation_
Definition base_tracker.hpp:836
bool reinitialize_stepsize_
Definition base_tracker.hpp:790
TupOfVec temporary_space_
Definition base_tracker.hpp:844
void IncrementBaseCountersFail() const
Definition base_tracker.hpp:761
TupOfVec tentative_space_
Definition base_tracker.hpp:843
auto TrackingTolerance() const
Definition base_tracker.hpp:614
RealT next_stepsize_
Definition base_tracker.hpp:831
std::reference_wrapper< const System > tracked_system_
Definition base_tracker.hpp:787
StepMetadata last_step_
Definition base_tracker.hpp:850
detail::Configured< typename TrackerTraits< FixedPrecisionTracker< DerivedT > >::NeededConfigs > Config
Definition base_tracker.hpp:175
void ResetCountersBase() const
Definition base_tracker.hpp:727
void SetStepSize(RealT const &new_stepsize) const
Definition base_tracker.hpp:595
void IncrementBaseCountersSuccess() const
Definition base_tracker.hpp:742
ComplexT current_time_
Definition base_tracker.hpp:825
Definition adaptive_precision_utilities.hpp:35
Definition algorithm_builder.hpp:36
constexpr unsigned DoublePrecision()
The number of digits considered "double precision" (16).
Definition num_traits.hpp:152
std::complex< double > complex_dbl
The double-precision complex number type.
Definition double_extensions.hpp:47
Eigen::Matrix< NumT, Eigen::Dynamic, 1 > Vec
A dynamically-sized column vector of NumT.
Definition eigen_extensions.hpp:296
double NumErrorT
The numeric type used to hold error/tolerance magnitudes throughout Bertini2 – tracking tolerances,...
Definition num_traits.hpp:48
bmp::number< mpc_complex_backend< 0 >, bmp::et_on > complex_mp
The arbitrary-precision complex number type.
Definition mpfr_complex.hpp:58
auto DefaultPrecision()
Get the global default precision (digits) for multiprecision numbers.
Definition mpfr_complex.hpp:135
SuccessCode
Definition config.hpp:42
@ MinStepSizeReached
Definition config.hpp:60
@ Success
Definition config.hpp:51
@ MaxNumStepsTaken
Definition config.hpp:58
@ GoingToInfinity
Definition config.hpp:54
boost::multiprecision::number< boost::multiprecision::mpfr_float_backend< 0 >, boost::multiprecision::et_on > real_mp
The arbitrary-precision real number type.
Definition mpfr_extensions.hpp:53
unsigned ThreadPrecision()
Get the current thread's precision (digits).
Definition mpfr_complex.hpp:183
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object.
Definition eigen_extensions.hpp:339
T max(T const &a, T const &b, T const &c)
Three-argument form of max.
Definition mpfr_extensions.hpp:96
Settings for a fixed-precision tracker (carries the single working precision in effect).
Definition config.hpp:157
unsigned precision
The number of digits to always work at.
Definition config.hpp:170
Trait lookup mapping a tracker type to its numeric types, event-emitter type, precision config,...
Definition config.hpp:387