autogenu-jupyter
An automatic code generator and the continuation/GMRES (C/GMRES) based numerical solvers for nonlinear MPC
Loading...
Searching...
No Matches
logger.hpp
Go to the documentation of this file.
1#ifndef CGMRES__LOGGER_HPP_
2#define CGMRES__LOGGER_HPP_
3
4#include <fstream>
5#include <string>
6
7#include "cgmres/types.hpp"
8#include "cgmres/timer.hpp"
9
10
11namespace cgmres {
12
17class Logger {
18public:
23 explicit Logger(const std::string& log_name)
24 : log_name_(log_name),
25 t_log_(log_name+ "_t.log"),
26 x_log_(log_name+ "_x.log"),
27 u_log_(log_name + "_u.log"),
28 opterr_log_(log_name + "_opterr.log") {
29 }
30
35 t_log_.close();
36 x_log_.close();
37 u_log_.close();
38 opterr_log_.close();
39 }
40
48 template <typename StateVectorType, typename ControlInputVectorType>
49 void save(const Scalar t, const MatrixBase<StateVectorType>& x,
51 const double opterr) {
52 t_log_ << t << '\n';
53 x_log_ << x.transpose() << '\n';
54 u_log_ << u.transpose() << '\n';
55 opterr_log_ << opterr << '\n';
56 }
57
62 void save(const TimingProfile& timing_profile) const {
63 std::ofstream timing_log(log_name_ + "_timing_profile.log");
64 timing_log << timing_profile;
65 timing_log.close();
66 }
67
68private:
69 std::string log_name_;
70 std::ofstream t_log_, x_log_, u_log_, opterr_log_;
71};
72
73} // namespace cgmres
74
75#endif // CGMRES__LOGGER_HPP_
Logger for MPC.
Definition: logger.hpp:17
~Logger()
Destructor.
Definition: logger.hpp:34
void save(const TimingProfile &timing_profile) const
Save the timing profile.
Definition: logger.hpp:62
void save(const Scalar t, const MatrixBase< StateVectorType > &x, const MatrixBase< ControlInputVectorType > &u, const double opterr)
Save datas.
Definition: logger.hpp:49
Logger(const std::string &log_name)
Constructor.
Definition: logger.hpp:23
Definition: continuation_gmres.hpp:11
double Scalar
Alias of double.
Definition: types.hpp:11
Eigen::MatrixBase< MatrixType > MatrixBase
Alias of Eigen::MatrixBase.
Definition: types.hpp:29
A profile of the timing benchmark.
Definition: timer.hpp:16