ode_iv_solve.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2018, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_ODE_IV_SOLVE_H
24 #define O2SCL_ODE_IV_SOLVE_H
25 
26 /** \file ode_iv_solve.h
27  \brief File defining \ref o2scl::ode_iv_solve
28 */
29 
30 #include <string>
31 
32 #include <boost/numeric/ublas/vector.hpp>
33 #include <boost/numeric/ublas/matrix.hpp>
34 #include <boost/numeric/ublas/matrix_proxy.hpp>
35 
36 #include <o2scl/astep.h>
37 #include <o2scl/astep_gsl.h>
38 
39 #ifndef DOXYGEN_NO_O2NS
40 namespace o2scl {
41 #endif
42 
43  /** \brief Solve an initial-value ODE problems given an adaptive ODE
44  stepper
45 
46  This class is experimental.
47 
48  This class gives several functions which solve an initial
49  value ODE problem. The functions \ref solve_final_value()
50  give only the final value of the functions at the end
51  of the ODE integration and are relatively fast.
52 
53  The function solve_store() stores the solution of the ODE over
54  the full range into a set of vectors and matrices which are
55  allocated and specified by the user. This function is designed
56  to give exactly the same results (though this cannot be
57  guaranteed) as solve_final_value() and additionally records some
58  or all of the results from the adaptive steps which were taken.
59 
60  The functions solve_grid() works as in solve_store() except
61  that the solution is stored on a grid of points in the
62  independent variable specified by the user, at the cost of
63  taking extra steps to ensure that function values,
64  derivatives, and errors are computed at each grid point.
65 
66  All of these functions automatically evaluate the derivatives
67  from the specified function at the initial point and
68  user-specified initial derivatives are ignored. The total
69  number of steps taken is limited by \ref ntrial and \ref
70  nsteps stores the number of steps taken by the most recent
71  solution. The variable \ref nsteps_out is the maximum number
72  of points in the interval for which verbose output will be
73  given when \ref o2scl::ode_iv_solve::verbose is greater than zero.
74 
75  There is an example for the usage of this class in
76  <tt>examples/ex_ode.cpp</tt> documented in the \ref ex_ode_sect
77  section.
78 
79  Documentation links for default template arguments
80  - \c func_t - \ref ode_funct
81  - \c vec_t - \ref boost::numeric::ublas::vector < double >
82 
83  The default adaptive stepper is an object of type \ref astep_gsl.
84 
85  \future The form of solve_final_value() is very similar to that
86  of astep_base::astep_full(), but not quite the same. Maybe
87  these functions should be consistent with each other?
88  */
89  template<class func_t=ode_funct,
91  class ode_iv_solve {
92 
93  public:
94 
96 
97 #ifndef DOXYGEN_INTERNAL
98 
99  protected:
100 
101  /// \name Vectors for temporary storage
102  //@{
103  vec_t vtemp, vtemp2, vtemp3, vtemp4;
104  //@}
105 
106  /// The size of the temporary vectors
107  size_t mem_size;
108 
109  /// The adaptive stepper
111 
112  /// Print out iteration information
113  virtual int print_iter(double x, size_t nv, vec_t &y) {
114  std::cout << type() << " x: " << x << " y: ";
115  for(size_t i=0;i<nv;i++) std::cout << y[i] << " ";
116  std::cout << std::endl;
117  if (verbose>1) {
118  char ch;
119  std::cin >> ch;
120  }
121  return 0;
122  }
123 
124  /// Free allocated memory
125  void free() {
126  if (mem_size>0) {
127  vtemp.clear();
128  vtemp2.clear();
129  vtemp3.clear();
130  vtemp4.clear();
131  }
132  }
133 
134  /** \brief Allocate space for temporary vectors
135  */
136  void allocate(size_t n) {
137  if (n!=mem_size) {
138  free();
139  vtemp.resize(n);
140  vtemp2.resize(n);
141  vtemp3.resize(n);
142  vtemp4.resize(n);
143  mem_size=n;
144  }
145  }
146 
147 #endif
148 
149  public:
150 
151  ode_iv_solve() {
152  verbose=0;
153  ntrial=1000;
154  nsteps_out=10;
155  astp=&gsl_astp;
156  exit_on_fail=true;
157  mem_size=0;
158  }
159 
160  virtual ~ode_iv_solve() {
161  free();
162  }
163 
164  /// \name Main solver functions
165  //@{
166  /** \brief Solve the initial-value problem to get the final value
167 
168  Given the \c n initial values of the functions in \c ystart,
169  this function integrates the ODEs specified in \c derivs over
170  the interval from \c x0 to \c x1 with an initial stepsize of \c
171  h. The final values of the function are given in \c yend and the
172  initial values of \c yend are ignored.
173 
174  If \ref verbose is greater than zero, The solution at less than
175  or approximately equal to \ref nsteps_out points will be written
176  to \c std::cout. If \ref verbose is greater than one, a
177  character will be required after each selected point.
178  */
179  int solve_final_value(double x0, double x1, double h, size_t n,
180  vec_t &ystart, vec_t &yend, func_t &derivs) {
181 
182  allocate(n);
183  return solve_final_value(x0,x1,h,n,ystart,yend,vtemp2,
184  vtemp3,derivs);
185  }
186 
187  /** \brief Solve the initial-value problem to get the final value
188  with errors
189 
190  Given the \c n initial values of the functions in \c ystart,
191  this function integrates the ODEs specified in \c derivs over
192  the interval from \c x0 to \c x1 with an initial stepsize of \c
193  h. The final values of the function are given in \c yend and the
194  associated errors are given in \c yerr. The initial values of \c
195  yend and \c yerr are ignored.
196 
197  If \ref verbose is greater than zero, The solution at less
198  than or approximately equal to \ref nsteps_out points will be
199  written to \c std::cout. If \ref verbose is greater than one,
200  a character will be required after each selected point.
201  */
202  int solve_final_value(double x0, double x1, double h, size_t n,
203  vec_t &ystart, vec_t &yend, vec_t &yerr,
204  func_t &derivs) {
205 
206  allocate(n);
207  return solve_final_value(x0,x1,h,n,ystart,yend,yerr,
208  vtemp2,derivs);
209  }
210 
211  /** \brief Solve the initial-value problem to get the final value,
212  derivatives, and errors
213 
214  Given the \c n initial values of the functions in \c ystart,
215  this function integrates the ODEs specified in \c derivs over
216  the interval from \c x0 to \c x1 with an initial stepsize of \c
217  h. The final values of the function are given in \c yend, the
218  derivatives in \c dydx_end, and the associated errors are given
219  in \c yerr. The initial values of \c yend and \c yerr are
220  ignored.
221 
222  This function is designed to be relatively fast,
223  avoiding extra copying of vectors back and forth.
224 
225  If \ref verbose is greater than zero, The solution at less
226  than or approximately equal to \ref nsteps_out points will be
227  written to \c std::cout. If \ref verbose is greater than one,
228  a character will be required after each selected point.
229 
230  This function computes \c dydx_start automatically and the
231  values given by the user are ignored.
232 
233  The solution fails if more than \ref ntrial steps are required.
234  This function will also fail if <tt>x1>x0</tt> and <tt>h<0</tt>
235  or if <tt>x1-x0</tt> and <tt>h>0</tt> do not have the same sign.
236  */
237  int solve_final_value(double x0, double x1, double h, size_t n,
238  vec_t &ystart, vec_t &yend, vec_t &yerr,
239  vec_t &dydx_end, func_t &derivs) {
240 
241  if ((x1>x0 && h<=0.0) || (x0>x1 && h>=0.0)) {
242  std::string str="Interval direction (x1-x0="+o2scl::dtos(x1-x0)+
243  ") does not match step direction (h="+o2scl::dtos(h)+
244  " in ode_iv_solve::solve_final_value().";
245  O2SCL_ERR(str.c_str(),exc_einval);
246  }
247  if (x0==x1) {
248  O2SCL_ERR2("Starting and final endpoints identical in ",
249  "ode_iv_solve::solve_final_value().",exc_einval);
250  }
251 
252  // Allocate for temporary vectors
253  allocate(n);
254 
255  // The variable 'x' is the current independent variable, xnext is
256  // the next value of x, xverb is the next value of x for which
257  // verbose output should be provided, and dxverb is the stepsize
258  // for xverb.
259  double x=x0, xverb=0.0, dxverb=0.0, xnext;
260  int ret=0, first_ret=0;
261 
262  nsteps=0;
263 
264  // Create a reference to make the code easier to read
265  vec_t &dydx_start=vtemp;
266 
267  // Compute stepsize for verbose output
268  if (verbose>0) {
269  print_iter(x0,n,ystart);
270  if (verbose>1) {
271  char ch;
272  std::cin >> ch;
273  }
274  // Ensure that 'dxverb' is positive
275  if (x1>x0) {
276  dxverb=(x1-x0)/((double)nsteps_out);
277  xverb=x0+dxverb;
278  } else {
279  dxverb=(x0-x1)/((double)nsteps_out);
280  xverb=x0-dxverb;
281  }
282  }
283 
284  // Use yend as workspace
285  for(size_t i=0;i<n;i++) yend[i]=ystart[i];
286 
287  // Compute initial derivative
288  derivs(x,n,yend,dydx_start);
289 
290  bool done=false;
291  while (done==false) {
292 
293  // Take a step of the first type
294  ret=astp->astep_full(x,x1,xnext,h,n,ystart,dydx_start,
295  yend,yerr,dydx_end,derivs);
296 
297  if (ret!=0) {
298  if (exit_on_fail) {
299  O2SCL_ERR2("Adaptive stepper failed in ",
300  "ode_iv_solve::solve_final_value()",ret);
301  } else if (first_ret!=0) {
302  first_ret=ret;
303  }
304  }
305 
306  // Print out verbose info
307  if (verbose>0 && xnext>xverb) {
308  print_iter(xnext,n,yend);
309  if (verbose>1) {
310  char ch;
311  std::cin >> ch;
312  }
313  xverb+=dxverb;
314  }
315 
316  // Check number of iterations
317  nsteps++;
318  if (nsteps>ntrial) {
319  std::string str="Too many steps required (ntrial="+itos(ntrial)+
320  ", x="+o2scl::dtos(x)+") in ode_iv_solve::solve_final_value().";
321  O2SCL_ERR(str.c_str(),exc_emaxiter);
322  }
323 
324  if (ret!=0) {
325  done=true;
326  } else {
327  if (x1>x0) {
328  if (xnext>=x1) done=true;
329  } else {
330  if (xnext<=x1) done=true;
331  }
332  }
333 
334  if (done==false) {
335 
336  // Take a step of the second type
337  ret=astp->astep_full(xnext,x1,x,h,n,yend,dydx_end,ystart,yerr,
338  dydx_start,derivs);
339 
340  if (ret!=0) {
341  if (exit_on_fail) {
342  O2SCL_ERR2("Adaptive stepper failed in ",
343  "ode_iv_solve::solve_final_value()",ret);
344  } else if (first_ret!=0) {
345  first_ret=ret;
346  }
347  }
348 
349  // Print out verbose info
350  if (verbose>0 && x>xverb) {
351  print_iter(x,n,ystart);
352  if (verbose>1) {
353  char ch;
354  std::cin >> ch;
355  }
356  xverb+=dxverb;
357  }
358 
359  // Check number of iterations
360  nsteps++;
361  if (nsteps>ntrial) {
362  std::string str="Too many steps required (ntrial="+itos(ntrial)+
363  ", x="+o2scl::dtos(x)+") in ode_iv_solve::solve_final_value().";
364  O2SCL_ERR(str.c_str(),exc_emaxiter);
365  }
366 
367  if (ret!=0) {
368  done=true;
369  } else {
370  if (x1>x0) {
371  if (x>=x1) {
372  done=true;
373  for(size_t j=0;j<n;j++) {
374  yend[j]=ystart[j];
375  dydx_end[j]=dydx_start[j];
376  }
377  }
378  } else {
379  if (x<=x1) {
380  done=true;
381  for(size_t j=0;j<n;j++) {
382  yend[j]=ystart[j];
383  dydx_end[j]=dydx_start[j];
384  }
385  }
386  }
387  }
388 
389  }
390 
391  // End of while loop
392  }
393 
394  // Print out final verbose info
395  if (verbose>0) {
396  print_iter(x1,n,yend);
397  if (verbose>1) {
398  char ch;
399  std::cin >> ch;
400  }
401  }
402 
403  return first_ret;
404  }
405 
406  /** \brief Solve the initial-value problem and store the
407  associated output
408 
409  Initially, \c x_sol should be a vector of size \c n_sol, and \c
410  y_sol, \c dydx_sol, and \c yerr_sol should be matrices with size
411  \c [n_sol][n]. On exit, \c n_sol will will be number of points
412  store, less than or equal to the original value of \c
413  n_sol. This function avoids performing extra calls to the
414  adaptive stepper, and the solution will be approximately evenly
415  spaced.
416 
417  This function is also designed to give the exactly the same
418  results as solve_final_value(). This cannot be strictly
419  guaranteed, but will likely hold in most applications.
420 
421  This template function works with any matrix class \c mat_t
422  which can be accessed using successive applications of
423  operator[] and which has an associated class \c mat_row_t
424  which returns a row of a matrix of type \c mat_t as
425  an object with type \c vec_t.
426 
427  If \ref verbose is greater than zero, The solution at each
428  internal point will be written to \c std::cout. If \ref verbose
429  is greater than one, a character will be required after each
430  point.
431  */
432  template<class mat_t>
433  int solve_store(double x0, double x1, double h, size_t n, size_t &n_sol,
434  vec_t &x_sol, mat_t &y_sol, mat_t &yerr_sol,
435  mat_t &dydx_sol, func_t &derivs, size_t istart=0) {
436 
437  int ret=0;
438  int first_ret=0;
439  size_t nmax=n_sol-1;
440  nsteps=0;
441 
442  // Stepsize for next verbose output. Use nsteps_out-1 instead of
443  // nsteps_out since the first point is always output below.
444  double dx_verb=(x1-x0)/((double)(nsteps_out-1));
445  // Stepsize for next point for storage
446  double dx_tab=(x1-x0)/((double)(n_sol-istart-1));
447 
448  double x_verb=x0+dx_verb;
449  double x_tab=x0+dx_tab;
450 
451  // Allocate space for errors and derivatives and extra storage
452  allocate(n);
453 
454  // Create some references just to make the code easier
455  // to read
456  vec_t &ystart=vtemp4;
457  vec_t &dydx_start=vtemp2;
458 
459  // Copy first point to ystart
460  for(size_t j=0;j<n;j++) ystart[j]=y_sol(istart,j);
461 
462  // Output first point
463  if (verbose>0) {
464  print_iter(x0,n,ystart);
465  if (verbose>1) {
466  char ch;
467  std::cin >> ch;
468  }
469  }
470 
471  // Initial derivative evaulation
472  derivs(x0,n,ystart,dydx_start);
473 
474  // Add first derivatives to storage, and set the errors to zero
475  x_sol[istart]=x0;
476  for(size_t j=0;j<n;j++) {
477  dydx_sol(istart,j)=dydx_start[j];
478  yerr_sol(istart,j)=0.0;
479  }
480 
481  // Copy first point to storage again for first step
482  size_t icurr=istart+1;
483  x_sol[icurr]=x0;
484  for(size_t j=0;j<n;j++) y_sol(icurr,j)=ystart[j];
485 
486  double xnext;
487 
488  bool done=false;
489  while (done==false) {
490 
491  // Create some references just to make the code easier
492  // to read
493  vec_t &yerr=vtemp;
494  vec_t &dydx_out=vtemp3;
495 
496  // Use ystart as temporary storage for the end of the current
497  // adaptive step
498  vec_t yrow(n);
499  for(size_t i=0;i<n;i++) yrow[i]=y_sol(icurr,i);
500  ret=astp->astep_full(x0,x1,xnext,h,n,yrow,dydx_start,ystart,yerr,
501  dydx_out,derivs);
502 
503  if (ret!=0) {
504  if (exit_on_fail) {
505  n_sol=icurr+1;
506  // call error handler
507  O2SCL_ERR2("Adaptive stepper returned non-zero in ",
508  "ode_iv_solve::solve_store().",exc_efailed);
509  } else if (first_ret==0) {
510  first_ret=ret;
511  }
512  }
513 
514  // Update step counter and abort if necessary
515  nsteps++;
516  if (nsteps>ntrial) {
517  std::string str="Too many steps required (ntrial="+itos(ntrial)+
518  ", x="+o2scl::dtos(x0)+") in ode_iv_solve::solve_store().";
519  O2SCL_ERR(str.c_str(),exc_emaxiter);
520  }
521 
522  // If we've made enough progress, do verbose output
523  if (xnext>=x_verb && verbose>0) {
524  print_iter(xnext,n,ystart);
525  if (verbose>1) {
526  char ch;
527  std::cin >> ch;
528  }
529  x_verb+=dx_verb;
530  }
531 
532  // If we're at the end
533  if (xnext>=x1) {
534 
535  // Exit the loop
536  done=true;
537 
538  // Store the final entry
539  x_sol[icurr]=xnext;
540  for(size_t j=0;j<n;j++) {
541  y_sol(icurr,j)=ystart[j];
542  dydx_sol(icurr,j)=dydx_out[j];
543  yerr_sol(icurr,j)=yerr[j];
544  }
545 
546  // Update the solution size
547  n_sol=icurr+1;
548 
549  } else {
550 
551  if (xnext>=x_tab && icurr<nmax) {
552 
553  // If we've made enough progress, store an entry in the table
554  x_sol[icurr]=xnext;
555  for(size_t j=0;j<n;j++) {
556  y_sol(icurr,j)=ystart[j];
557  dydx_sol(icurr,j)=dydx_out[j];
558  yerr_sol(icurr,j)=yerr[j];
559 
560  // Also prepare for the next step
561  y_sol(icurr+1,j)=ystart[j];
562  dydx_start[j]=dydx_out[j];
563  }
564  x_tab+=dx_tab;
565 
566  // Update x0 and the current and next indicies
567  x0=xnext;
568  icurr++;
569 
570  } else {
571 
572  // Otherwise, just prepare for the next step
573  // without updating icurr
574  x0=xnext;
575  for(size_t j=0;j<n;j++) {
576  dydx_start[j]=dydx_out[j];
577  y_sol(icurr,j)=ystart[j];
578  }
579 
580  }
581 
582  }
583 
584  // End of loop 'while (done==false)'
585  }
586 
587  return first_ret;
588  }
589 
590  /** \brief Solve the initial-value problem from \c x0 to \c x1 over
591  a grid storing derivatives and errors
592 
593  Initially, \c xsol should be an array of size \c nsol, and \c
594  ysol should be a \c ubmatrix of size \c [nsol][n]. This function
595  never takes a step larger than the grid size.
596 
597  If \ref verbose is greater than zero, The solution at each grid
598  point will be written to \c std::cout. If \ref verbose is
599  greater than one, a character will be required after each point.
600 
601  \future Consider making a version of grid which gives the
602  same answers as solve_final_value(). After each proposed step,
603  it would go back and fill in the grid points if the proposed
604  step was past the next grid point.
605  */
606  template<class mat_t, class mat_row_t>
607  int solve_grid(double h, size_t n, size_t nsol, vec_t &xsol,
608  mat_t &ysol, mat_t &err_sol, mat_t &dydx_sol,
609  func_t &derivs) {
610 
611  double x0=xsol[0];
612  double x1=xsol[nsol-1];
613 
614  double x=x0, xnext;
615  int ret=0, first_ret=0;
616  nsteps=0;
617 
618  // Copy the initial point to the first row
619  xsol[0]=x0;
620 
621  // Create space for the initial point of each step
622  allocate(n);
623 
624  // Create some references just to make the code easier
625  // to read
626  vec_t &ystart=vtemp;
627  vec_t &dydx_start=vtemp2;
628 
629  // Copy ysol[0] to ystart
630  for(size_t j=0;j<n;j++) {
631  ystart[j]=ysol(0,j);
632  }
633 
634  // Verbose output for the first row
635  if (verbose>0) print_iter(xsol[0],n,ystart);
636 
637  // Evalulate the first derivative
638  derivs(x0,n,ystart,dydx_start);
639 
640  // Set the derivatives and the uncertainties for the first row
641  for(size_t j=0;j<n;j++) {
642  dydx_sol(0,j)=dydx_start[j];
643  err_sol(0,j)=0.0;
644  }
645 
646  for(size_t i=1;i<nsol && ret==0;i++) {
647 
648  mat_row_t y_row(ysol,i);
649  mat_row_t dydx_row(dydx_sol,i);
650  mat_row_t yerr_row(err_sol,i);
651 
652  // Step until we reach the next grid point
653  bool done=false;
654  while(done==false && ret==0) {
655 
656  ret=astp->astep_full(x,xsol[i],xnext,h,n,ystart,dydx_start,
657  y_row,yerr_row,dydx_row,derivs);
658 
659  nsteps++;
660  if (ret!=0) {
661  if (exit_on_fail) {
662  O2SCL_ERR2("Adaptive stepper failed in ",
663  "ode_iv_solve::solve_grid()",ret);
664  } else if (first_ret!=0) {
665  first_ret=ret;
666  }
667  }
668 
669  if (nsteps>ntrial) {
670  std::string str="Too many steps required (ntrial="+itos(ntrial)+
671  ", x="+o2scl::dtos(x)+") in ode_iv_solve::solve_grid().";
672  O2SCL_ERR(str.c_str(),exc_emaxiter);
673  }
674 
675  // Copy the results of the last step to the starting
676  // point for the next step
677  x=xnext;
678  for(size_t j=0;j<n;j++) {
679  ystart[j]=y_row[j];
680  dydx_start[j]=dydx_row[j];
681  }
682 
683  // Decide if we have reached the grid point
684  if (x1>x0) {
685  if (x>=xsol[i]) done=true;
686  } else {
687  if (x<=xsol[i]) done=true;
688  }
689 
690  }
691 
692  if (verbose>0) print_iter(xsol[i],n,ystart);
693 
694  }
695 
696  return first_ret;
697  }
698  //@}
699 
700  /// Set output level
701  int verbose;
702 
703  /** \brief Number of output points for verbose output (default 10)
704 
705  This is used in functions solve_store() and solve_final_value()
706  to control how often steps are output when verbose is greater
707  than zero.
708  */
709  size_t nsteps_out;
710 
711  /// Maximum number of applications of the adaptive stepper (default 1000)
712  size_t ntrial;
713 
714  /// Number of adaptive ste!ps employed
715  size_t nsteps;
716 
717  /// \name The adaptive stepper
718  //@{
719  /// Set the adaptive stepper to use
721  astp=&as;
722  return 0;
723  }
724 
725  /** \brief If true, stop the solution if the adaptive stepper fails
726  (default true)
727 
728  If this is false, then failures in the adaptive stepper are
729  ignored.
730  */
732 
733  /// The default adaptive stepper
735  //@}
736 
737  /// Return the type, \c "ode_iv_solve".
738  virtual const char *type() { return "ode_iv_solve"; }
739 
740  };
741 
742 #ifndef DOXYGEN_NO_O2NS
743 }
744 #endif
745 
746 #endif
Solve an initial-value ODE problems given an adaptive ODE stepper.
Definition: ode_iv_solve.h:91
astep_base< vec_t, vec_t, vec_t, func_t > * astp
The adaptive stepper.
Definition: ode_iv_solve.h:110
The main O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl names...
Definition: anneal.h:42
astep_gsl< vec_t, vec_t, vec_t, func_t > gsl_astp
The default adaptive stepper.
Definition: ode_iv_solve.h:734
invalid argument supplied by user
Definition: err_hnd.h:59
virtual const char * type()
Return the type, "ode_iv_solve".
Definition: ode_iv_solve.h:738
size_t nsteps
Number of adaptive ste!ps employed.
Definition: ode_iv_solve.h:715
exceeded max number of iterations
Definition: err_hnd.h:73
bool exit_on_fail
If true, stop the solution if the adaptive stepper fails (default true)
Definition: ode_iv_solve.h:731
int verbose
Set output level.
Definition: ode_iv_solve.h:701
generic failure
Definition: err_hnd.h:61
int solve_final_value(double x0, double x1, double h, size_t n, vec_t &ystart, vec_t &yend, vec_t &yerr, func_t &derivs)
Solve the initial-value problem to get the final value with errors.
Definition: ode_iv_solve.h:202
int solve_final_value(double x0, double x1, double h, size_t n, vec_t &ystart, vec_t &yend, vec_t &yerr, vec_t &dydx_end, func_t &derivs)
Solve the initial-value problem to get the final value, derivatives, and errors.
Definition: ode_iv_solve.h:237
int solve_final_value(double x0, double x1, double h, size_t n, vec_t &ystart, vec_t &yend, func_t &derivs)
Solve the initial-value problem to get the final value.
Definition: ode_iv_solve.h:179
std::function< int(double, size_t, const boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> ode_funct
Ordinary differential equation function.
Definition: ode_funct.h:46
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Definition: err_hnd.h:273
virtual int astep_full(double x, double xlimit, double &x_out, double &h, size_t n, vec_y_t &y, vec_dydx_t &dydx, vec_y_t &yout, vec_yerr_t &yerr, vec_dydx_t &dydx_out, func_t &derivs)=0
Make an adaptive integration step of the system derivs with derivatives.
size_t ntrial
Maximum number of applications of the adaptive stepper (default 1000)
Definition: ode_iv_solve.h:712
int set_astep(astep_base< vec_t, vec_t, vec_t, func_t > &as)
Set the adaptive stepper to use.
Definition: ode_iv_solve.h:720
int solve_store(double x0, double x1, double h, size_t n, size_t &n_sol, vec_t &x_sol, mat_t &y_sol, mat_t &yerr_sol, mat_t &dydx_sol, func_t &derivs, size_t istart=0)
Solve the initial-value problem and store the associated output.
Definition: ode_iv_solve.h:433
void allocate(size_t n)
Allocate space for temporary vectors.
Definition: ode_iv_solve.h:136
virtual int print_iter(double x, size_t nv, vec_t &y)
Print out iteration information.
Definition: ode_iv_solve.h:113
void free()
Free allocated memory.
Definition: ode_iv_solve.h:125
int solve_grid(double h, size_t n, size_t nsol, vec_t &xsol, mat_t &ysol, mat_t &err_sol, mat_t &dydx_sol, func_t &derivs)
Solve the initial-value problem from x0 to x1 over a grid storing derivatives and errors...
Definition: ode_iv_solve.h:607
size_t nsteps_out
Number of output points for verbose output (default 10)
Definition: ode_iv_solve.h:709
size_t mem_size
The size of the temporary vectors.
Definition: ode_iv_solve.h:107
std::string itos(int x)
Convert an integer to a string.
static const double x1[5]
Definition: inte_qng_gsl.h:48

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).