18 solprev_ =
new double[neq];
33 double tend =
t_ + tint;
35 if (
t_ + dt > tend) dt = tend -
t_;
65 if (inter < 1)
ode_print_exit(
"inter must be greater than or equal to 1");
72 std::vector<double> tout;
73 std::vector<double> *solout =
new std::vector<double>[
neq_];
75 double tend =
t_ + tint;
81 for (i=0; i<
neq_; i++) solout[i].push_back(
sol_[i] );
97 if ( j % inter == 0 ) {
100 for (i=0; i<
neq_; i++) solout[i].push_back(
sol_[i] );
101 tout.push_back(
t_ );
106 if ( j-1 % inter != 0 ) {
107 for (i=0; i<
neq_; i++) solout[i].push_back(
sol_[i] );
108 tout.push_back(
t_ );
112 for (i=0; i<
neq_; i++) {
114 ode_write(fnout.data(), solout[i].data(), solout[i].size());
117 ode_write(fnout.data(), tout.data(), tout.size());
130 double tend =
t_ + tint;
132 double *tsnap =
new double[nsnap];
133 for (
unsigned long i=0; i<nsnap; i++) tsnap[i] =
t_ + i*(tend -
t_)/double(nsnap - 1);
154 for (i=0; i<nsnap; i++) {
184 ode_print_exit(
"An adaptive solving method was called without a time step choosing algorithm implemented! You must at least implement the dt_adapt() function to use solve_adaptive().");
201 memcpy(solprev_,
sol_,
neq_*
sizeof(
double));
213 memcpy(
sol_, solprev_,
neq_*
sizeof(
double));
235 if ( tend <
t_ + dt*1.01 ) dt = tend -
t_;
double reltol_
absolute error tolerance
double dt_adapt_(double tend)
wrapper around dt_adapt() to perform additional checks
long unsigned nrej_
counter for rejected steps
double dtmax_
maximum allowable time step
void solve_adaptive_(double tint, double dt0, bool extra=true)
integrates without output or any counters, trackers, extra functions...
virtual ~OdeAdaptive()
destructs
bool solve_done_adaptive(double tend)
determines whether an adaptive solve is finished
bool step_adaptive_(double dt, bool extra=true)
executes a single time and calls all necessary adapting functions
double abstol_
absolute error tolerance
void solve_adaptive(double tint, double dt0, bool extras=true)
integrates for a specified duration of independent variable without output
virtual bool is_rejected()
retreives a bool determining whether a step is accepted/rejected, false by default
OdeAdaptive(unsigned long neq, bool need_jac)
constructs
virtual double dt_adapt()
retrieves the best time step for the next step
virtual void adapt(double abstol, double reltol)
executes whatever calculations need to be performed for adapting, including a determination of whethe...
Lowest base class for all solvers.
virtual void after_capture(double t)
does any extra stuff only when a step is captured
long unsigned icheck_
interval of steps after which to check for nans and infs (zero to ignore)
unsigned long neq_
number of equations in the system of ODEs
double t_
time, initialized to zero
std::string name_
the "name" of the system, which is used for output
virtual void before_solve()
does any extra stuff before starting a solve
virtual void after_solve()
does any extra stuff after completing a solve
double dt_
time step is stored and updated during solves
void snap(std::string dirout, long isnap, double tsnap)
writes the current value of the solution to a binary file
long unsigned nstep_
number of time steps
virtual void step_(double dt)=0
advances a single time step (without changing counters or the time) and must be defined in the derive...
void check_sol_integrity()
checks solution for nans and infs, exiting the program if they're found
bool silent_snap_
whether to skip writing the solution vector to file when snapping but still execute after_snap()
void check_pre_snaps(double dt, double *tsnap, unsigned long nsnap)
checks that snap times are monotonically increasing and > current time
double * sol_
array for the solution, changing over time
virtual void after_step(double t)
does any extra stuff after each step
void check_pre_solve(double tint, double dt)
checks that a solve can be performed with given tend and dt values
std::string dirout_
output directory if one is being used by a solver
void ode_print_exit(const char *msg)
print a message and exit with failure
void ode_write(char const *fn, T *a, unsigned long n)
write an array to a binary file
std::string ode_int_to_string(long i)
converts an integer into a string
bool ode_is_close(double a, double b, double thresh)
Checks if two numbers are very close to each other.