11#ifndef SANDALS_PROBLEM_HH
12#define SANDALS_PROBLEM_HH
37 template <
typename Real, Integer N, Integer M,
typename Integrator>
48 using VectorX =
typename Integrator::VectorX;
49 using MatrixJX =
typename Integrator::MatrixJX;
73 this->m_integrator->system(t_system);
74 this->m_solution = std::make_shared<Solution<Real, N, M>>();
86 std::string
name()
const {
return this->m_name;}
92 void name(std::string
const t_name) {this->m_name = t_name;}
135 this->m_verbose = t_verbose;
136 this->m_integrator->verbose_mode(t_verbose);
160 {this->m_tolerance = t_tolerance;}
173 {this->m_max_iterations = t_max_iterations;}
215 using ShootingF = Eigen::Matrix<Real, 2*N, 1>;
216 using ShootingJF = Eigen::Matrix<Real, 2*N, 2*N>;
218 #define CMD "Sandals::Problem::single_shooting(...): "
222 ShootingF x_sol, x_step,
b;
223 ShootingJF A(ShootingJF::Zero());
224 A.template block<N, N>(0, N) = MatrixJX::Identity();
228 this->m_solution->clear();
232 Eigen::FullPivLU<ShootingJF> lu;
233 for (
Integer i{0}; i < this->m_max_iterations; ++i) {
243 if (!this->m_integrator->solve(t_mesh, x_sol.template head<N>(), *this->m_solution, Jx)) {
244 SANDALS_ERROR(
CMD "failed to integrate the system " << this->m_integrator->name() <<
".");
249 x_ini = x_sol.template head<N>();
250 x_end = this->m_solution->x.col(this->m_solution->t.size() - 1);
253 bcs = this->
b(x_ini, x_end);
256 if (this->m_verbose) {
257 std::cout <<
"Iteration " << i <<
": |b| = " << bcs.norm() << std::endl
258 <<
" x(" << t_mesh.template head<1>() <<
") = " << x_ini.transpose() << std::endl
259 <<
" x(" << t_mesh.template tail<1>() <<
") = " << x_end.transpose() << std::endl;
263 if (bcs.norm() < this->m_tolerance) {
return true;}
266 b.template head<N>() = x_end - x_sol.template tail<N>();
267 b.template tail<N>() = -bcs;
268 A.template block<N, N>(0, 0) = -Jx;
269 A.template block<N, N>(N, 0) = this->
Jb_x_ini(x_ini, x_end);
270 A.template block<N, N>(N, N) = this->
Jb_x_end(x_ini, x_end);
275 x_step = lu.solve(
b);
#define SANDALS_BASIC_CONSTANTS(Real)
Definition Sandals.hh:70
#define SANDALS_ERROR(MSG)
Definition Sandals.hh:34
#define SANDALS_ASSERT(COND, MSG)
Definition Sandals.hh:44
#define SANDALS_WARNING(MSG)
Definition Sandals.hh:53
Eigen::Matrix< Real, N, N > MatrixJF
Definition Implicit.hh:47
Eigen::Vector< Real, N > VectorF
Definition Implicit.hh:46
std::shared_ptr< Implicit< Real, N, M > > Pointer
Definition Implicit.hh:45
void verbose_mode(bool t_verbose)
Definition Problem.hh:134
SolutionPtr m_solution
Definition Problem.hh:57
IntegratorPtr m_integrator
Definition Problem.hh:56
typename Implicit< Real, N, M >::MatrixJF MatrixJF
Definition Problem.hh:51
void name(std::string const t_name)
Definition Problem.hh:92
bool m_verbose
Definition Problem.hh:59
virtual ~Problem()
Definition Problem.hh:80
void system(SystemPtr t_system)
Definition Problem.hh:104
IntegratorPtr integrator()
Definition Problem.hh:110
Problem(std::string t_name, SystemPtr t_system, IntegratorPtr t_integrator)
Definition Problem.hh:70
Integer & max_iterations()
Definition Problem.hh:166
void integrator(IntegratorPtr t_integrator)
Definition Problem.hh:116
typename Integrator::VectorX VectorX
Definition Problem.hh:48
typename Implicit< Real, N, M >::VectorF VectorF
Definition Problem.hh:50
Integer m_max_iterations
Definition Problem.hh:61
SystemPtr m_system
Definition Problem.hh:55
virtual MatrixJF Jb_x_ini(VectorF const &x_ini, VectorF const &x_end) const =0
virtual VectorF b(VectorF const &x_ini, VectorF const &x_end) const =0
void max_iterations(Integer const t_max_iterations)
Definition Problem.hh:172
bool verbose_mode()
Definition Problem.hh:128
void disable_verbose_mode()
Definition Problem.hh:147
Real m_tolerance
Definition Problem.hh:60
const Real SQRT_EPSILON
Definition Problem.hh:42
bool single_shooting(VectorX const &t_mesh, VectorF const &ics)
Definition Problem.hh:213
typename Integrator::MatrixJX MatrixJX
Definition Problem.hh:49
void tolerance(Real const t_tolerance)
Definition Problem.hh:159
std::shared_ptr< Integrator > IntegratorPtr
Definition Problem.hh:45
std::string m_name
Definition Problem.hh:54
SolutionPtr const solution() const
Definition Problem.hh:122
SystemPtr system()
Definition Problem.hh:98
typename Implicit< Real, N, M >::Pointer SystemPtr
Definition Problem.hh:44
std::shared_ptr< Solution< Real, N, M > > SolutionPtr
Definition Problem.hh:46
void enable_verbose_mode()
Definition Problem.hh:142
Real tolerance()
Definition Problem.hh:153
std::string name() const
Definition Problem.hh:86
virtual MatrixJF Jb_x_end(VectorF const &x_ini, VectorF const &x_end) const =0
The namespace for the Sandals library.
Definition Sandals.hh:89
SANDALS_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Sandals.hh:97