Go to the documentation of this file.
23 #ifndef O2SCL_ODE_BV_SOLVE_H
24 #define O2SCL_ODE_BV_SOLVE_H
31 #include <o2scl/astep.h>
32 #include <o2scl/astep_gsl.h>
33 #include <o2scl/ode_iv_solve.h>
34 #include <o2scl/mroot_hybrids.h>
36 #ifndef DOXYGEN_NO_O2NS
57 static const int unk=0;
125 vec_t &ystart, vec_t ¥d, vec_int_t &index,
126 vec_t &yerr, vec_t &dydx_end, func_t &derivs) {
142 int lhs_unks=0, rhs_conts=0;
145 for (
size_t i=0;i<n;i++) {
146 if (index[i]<2) lhs_unks++;
147 if (index[i]%2==1) rhs_conts++;
151 if (lhs_unks!=rhs_conts) {
152 O2SCL_ERR2(
"Incorrect boundary conditions in ",
153 "ode_bv_shoot::solve()",gsl_einval);
161 for (
size_t i=0;i<n;i++) {
171 mm_funct_mfptr<ode_bv_shoot<func_t,vec_t,vec_int_t> >
177 O2SCL_ERR(
"Solver failed in ode_bv_shoot::solve().",ret);
182 for (
size_t i=0;i<n;i++) {
195 template<
class mat_t,
class mat_row_t>
197 vec_t &ystart, vec_t ¥d,
198 vec_int_t &index,
size_t &n_sol, vec_t &x_sol,
199 mat_t &y_sol, mat_t &yerr_sol, mat_t &dydx_sol,
202 mat_row_t yerr(yerr_sol,0);
203 mat_row_t dydx_end(dydx_sol,0);
209 for(
size_t i=0;i<n;i++) {
210 y_sol[0][i]=ystart[i];
215 this->
l_n,n_sol,x_sol,
216 y_sol,yerr_sol,dydx_sol,derivs);
219 for (
size_t i=0;i<n;i++) {
221 yend[i]=y_sol[n_sol-1][i];
223 ystart[i]=y_sol[0][i];
248 #ifndef DOXYGEN_INTERNAL
290 vec_t sy, sy2, syerr, sdydx;
304 for(
size_t i=0;i<this->
l_n;i++) {
305 if ((*this->l_index)[i]<2) {
316 oisp->solve_final_value(this->l_x0,this->l_x1,this->l_h,
317 this->l_n,sy,sy2,*this->l_yerr,
318 *this->l_dydx_end,*this->l_derivs);
321 for(
size_t i=0;i<this->
l_n;i++) {
322 if ((*this->l_index)[i]%2==1) {
324 if ((*this->l_yend)[i]==0.0) {
332 (*this->
l_yend)[i]=sy2[i];
353 template<
class mat_t=boost::numeric::ublas::matrix<
double>,
354 class mat_row_t=boost::numeric::ublas::matrix_row<
355 boost::numeric::ublas::matrix<
double> >,
356 class func_t=ode_funct<>,
357 class vec_t=boost::numeric::ublas::vector<
double>,
358 class vec_
int_t=boost::numeric::ublas::vector<
int> >
376 vec_t &ystart, vec_t ¥d, vec_int_t &index,
377 size_t nsol, vec_t &xsol, mat_t &ysol,
378 mat_t &err_sol, mat_t &dydx_sol, func_t &derivs) {
382 int lhs_unks=0, rhs_conts=0;
385 for (
size_t i=0;i<n;i++) {
386 if (index[i]<2) lhs_unks++;
387 if (index[i]%2==1) rhs_conts++;
391 if (lhs_unks!=rhs_conts) {
392 O2SCL_ERR2(
"Incorrect boundary conditions in ",
393 "ode_bv_shoot_grid::solve_grid()",gsl_einval);
414 for (
size_t i=0;i<n;i++) {
426 func_t,vec_t,vec_int_t> >
433 O2SCL_ERR(
"Solver failed in ode_bv_shoot_grid::solve_grid().",ret);
438 for (
size_t i=0;i<n;i++) {
448 #ifndef DOXYGEN_INTERNAL
475 for(
size_t i=0;i<this->
l_n;i++) {
477 (*l_ysol)[0][i]=tx[j];
483 this->
oisp->template solve_grid<mat_t,mat_row_t>
491 for(
size_t i=0;i<this->
l_n;i++) {
492 if ((*this->
l_index)[i]%2==1) {
494 if ((*this->
l_yend)[i]==0.0) {
510 #ifndef DOXYGEN_NO_O2NS
Solve an initial-value ODE problems given an adaptive ODE stepper.
double l_x0
Storage for the starting point.
func_t * l_derivs
The functions to integrate.
int solve_grid_fun(size_t nv, const vec_t &tx, vec_t &ty)
The shooting function to be solved by the multidimensional solver
mroot< mm_funct<> > * mrootp
The equation solver.
size_t mem_size
Size of recent allocation.
int verbose
Set output level.
ode_iv_solve< func_t, vec_t > * oisp
The solver for the initial value problem.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
vec_t * l_dydx_end
Storage for the ending vector.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
int solve_store(double x0, double x1, double h, size_t n, vec_t &ystart, vec_t ¥d, vec_int_t &index, size_t &n_sol, vec_t &x_sol, mat_t &y_sol, mat_t &yerr_sol, mat_t &dydx_sol, func_t &derivs)
Solve the boundary-value problem and store the solution.
int solve_final_value(double x0, double x1, double h, size_t n, vec_t &ystart, vec_t ¥d, vec_int_t &index, vec_t &yerr, vec_t &dydx_end, func_t &derivs)
Solve the boundary-value problem and store the solution.
vec_t * l_yerr
Storage for the starting vector.
void allocate(size_t n)
Allocate internal storage.
One-dimensional solver [abstract base].
ode_iv_solve< func_t, vec_t > def_ois
The default initial value solver.
static const double x1[5]
double l_x1
Storage for the ending abcissa.
int set_mroot(mroot< mm_funct<> > &root)
Set the equation solver.
static const int unk
Unknown on both the left and right boundaries.
std::function< int(double, size_t, const boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &)> ode_funct
Ordinary differential equation function in src/ode/ode_funct.h.
static const int both
Known on both the left and right boundaries.
int set_iv(ode_iv_solve< func_t, vec_t > &ois)
Set initial value solver.
virtual int msolve(size_t n, vec_t &x, func_t &func)=0
Solve func using x as an initial guess, returning x.
vec_t * l_yend
Storage for the ending vector.
int solve_fun(size_t nv, const vec_t &tx, vec_t &ty)
The shooting function to be solved by the multidimensional solver.
Multidimensional root-finding [abstract base].
Solve boundary-value ODE problems by shooting from one boundary to the other on a grid.
std::function< int(size_t, const boost::numeric::ublas::vector< double > &, boost::numeric::ublas::vector< double > &) > mm_funct
Array of multi-dimensional functions typedef in src/base/mm_funct.h.
static const int left
Known on the left boundary.
double l_h
Storage for the stepsize.
vec_int_t * l_index
The index defining the boundary conditions.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
int solve_grid(double x0, double x1, double h, size_t n, vec_t &ystart, vec_t ¥d, vec_int_t &index, size_t nsol, vec_t &xsol, mat_t &ysol, mat_t &err_sol, mat_t &dydx_sol, func_t &derivs)
Desc.
size_t l_n
The number of functions.
vec_t * l_ystart
Storage for the starting vector.
gsl_mroot_hybrids< mm_funct<> > def_mroot
The default equation solver.
Base class for boundary-value ODE solvers.
static const int right
Known on the right boundary.
Solve boundary-value ODE problems by shooting from one boundary to the other.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).