Sandals  v0.0.0
A C++ library for ODEs/DAEs integration
Loading...
Searching...
No Matches
BVP.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Sandals project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * e-mail: davide.stocco@unitn.it e-mail: enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#ifndef SANDALS_BVP_HH
12#define SANDALS_BVP_HH
13
14#include <Sandals/RungeKutta.hh>
15
16namespace Sandals
17{
18
19 /*\
20 | ______ ______
21 | | __ ) \ / / _ \
22 | | _ \\ \ / /| |_) |
23 | | |_) |\ V / | __/
24 | |____/ \_/ |_|
25 |
26 \*/
27
37 template <typename Real, Integer N, Integer M = 0>
38 class BVP
39 {
40 public:
42 using Pointer = std::shared_ptr<Implicit<Real, N, M>>;
43 using NewtonB = Optimist::RootFinder::Newton<Real, N>;
44
45 private:
46 mutable NewtonB m_newton;
47
49 std::string m_name;
50
51 public:
56 BVP(std::string t_name) : m_name(t_name) {}
57
62 RungeKutta<Real, N, M> & rk() {return this->m_rk;}
63
68 RungeKutta<Real, N, M> const & rk() const {return this->m_rk;}
69
77 virtual VectorF b(VectorF const & x_ini, VectorF const & x_end) const = 0;
78
87 virtual MatrixJF Jb_x_ini(VectorF const & x_ini, VectorF const & x_end) const = 0;
88
97 virtual MatrixJF Jb_x_end(VectorF const & x_ini, VectorF const & x_end) const = 0;
98
108 bool solve_single_shooting(VectorX const & t_mesh, VectorN const & ics, Solution<Real, N, M> & sol) const
109 {
110 using Eigen::last;
111
112 #define CMD "Sandals::BVP::solve_single_shooting(...): "
113
114 // Create the lambda function that evaluates the boundary conditions after integration
115 auto b = [this](VectorF const & x_ini, VectorF & b_fun) -> VectorF {
116 // Integrate the system using the Runge-Kutta method
117 if (!this->m_rk.solve(t_mesh, x_ini, sol)) {
118 SANDALS_ERROR(CMD "failed to integrate the system " << this->m_name << ".");
119 return VectorF::Zero(N);
120 }
121 return this->b(x_ini, sol.x.col(last));
122 };
123
124 // Istantiate a Newton solver for the boundary conditions
125 return this->m_newton.solve(b, Jb, x_ini, x_sol);
126
127 #undef CMD
128 }
129
130 }; // class BVP
131
132} // namespace Sandals
133
134#endif // SANDALS_BVP_HH
#define CMD
#define SANDALS_ERROR(MSG)
Definition Sandals.hh:34
BVP(std::string t_name)
Definition BVP.hh:56
Optimist::RootFinder::Newton< Real, N > NewtonB
Definition BVP.hh:43
NewtonB m_newton
Definition BVP.hh:46
RungeKutta< Real, N, M > m_rk
Definition BVP.hh:48
typename Implicit< Real, N, M >::VectorF VectorF
Definition BVP.hh:41
virtual MatrixJF Jb_x_ini(VectorF const &x_ini, VectorF const &x_end) const =0
std::string m_name
Definition BVP.hh:49
RungeKutta< Real, N, M > & rk()
Definition BVP.hh:62
virtual VectorF b(VectorF const &x_ini, VectorF const &x_end) const =0
std::shared_ptr< Implicit< Real, N, M > > Pointer
Definition BVP.hh:42
RungeKutta< Real, N, M > const & rk() const
Definition BVP.hh:68
bool solve_single_shooting(VectorX const &t_mesh, VectorN const &ics, Solution< Real, N, M > &sol) const
Definition BVP.hh:108
virtual MatrixJF Jb_x_end(VectorF const &x_ini, VectorF const &x_end) const =0
Eigen::Vector< Real, N > VectorF
Definition Implicit.hh:46
Class container for the generic implicit, explicit, and diagonally implicit Runge-Kutta methods.
Definition RungeKutta.hh:52
bool solve(VectorX const &t_mesh, VectorN const &ics, Solution< Real, N, M > &sol) const
Definition RungeKutta.hh:1338
The namespace for the Sandals library.
Definition Sandals.hh:89
Class container for the numerical solution of a system of ODEs/DAEs.
Definition Solution.hh:62
MatrixN x
Definition Solution.hh:68