1#ifndef INCLUDE_RICCATI_SOLVER_HPP
2#define INCLUDE_RICCATI_SOLVER_HPP
22 typename SolverInfo,
typename Scalar,
23 std::enable_if_t<!std::is_same<typename std::decay_t<SolverInfo>::funtype,
24 pybind11::object>::value>* =
nullptr>
26 return info.gamma_fun_(x);
30 typename SolverInfo,
typename Scalar,
31 std::enable_if_t<!std::is_same<typename std::decay_t<SolverInfo>::funtype,
32 pybind11::object>::value>* =
nullptr>
34 return info.omega_fun_(x);
38template <
typename OmegaFun,
typename GammaFun,
typename Scalar_,
40 typename Allocator = arena_allocator<Scalar_, arena_alloc>>
59 std::vector<std::tuple<Integral, matrixd_t, vectord_t>>
chebyshev_;
99 std::vector<std::tuple<Integral, matrixd_t, vectord_t>> res;
100 res.reserve(n_nodes + 1);
102 bool n_found =
false;
103 bool p_found =
false;
104 for (
Integral i = 0; i <= n_nodes; ++i) {
105 auto it_v = nini * std::pow(2, i);
106 n_found = n_found || (it_v == n);
107 p_found = p_found || (it_v == p);
109 res.emplace_back(it_v, std::move(cheb_v.first), std::move(cheb_v.second));
113 res.emplace_back(n, std::move(cheb_v.first), std::move(cheb_v.second));
115 if (!p_found && n != p) {
117 res.emplace_back(p, std::move(cheb_v.first), std::move(cheb_v.second));
119 std::sort(res.begin(), res.end(),
120 [](
auto& a,
auto& b) { return std::get<0>(a) < std::get<0>(b); });
142 template <
typename OmegaFun_,
typename GammaFun_,
typename Allocator_>
143 SolverInfo(OmegaFun_&& omega_fun, GammaFun_&& gamma_fun, Allocator_&& alloc,
145 :
omega_fun_(std::forward<OmegaFun_>(omega_fun)),
146 gamma_fun_(std::forward<GammaFun_>(gamma_fun)),
147 alloc_(std::forward<Allocator_>(alloc)),
153 [n](auto& x) {
return std::get<0>(x) == n; }))),
157 [p](
auto& x) { return std::get<0>(x) == p; }))),
172 template <
typename OmegaFun_,
typename GammaFun_>
175 :
omega_fun_(std::forward<OmegaFun_>(omega_fun)),
176 gamma_fun_(std::forward<GammaFun_>(gamma_fun)),
183 [n](auto& x) {
return std::get<0>(x) == n; }))),
187 [p](
auto& x) { return std::get<0>(x) == p; }))),
204 auto* mem =
alloc_.alloc_;
205 std::cout <<
"mem info: " << std::endl;
206 std::cout <<
"blocks_ size: " << mem->blocks_.size() << std::endl;
207 std::cout <<
"sizes_ size: " << mem->sizes_.size() << std::endl;
208 std::cout <<
"cur_block_: " << mem->cur_block_ << std::endl;
209 std::cout <<
"cur_block_end_: " << mem->cur_block_end_ << std::endl;
210 std::cout <<
"next_loc_: " << mem->next_loc_ << std::endl;
272template <
typename Scalar,
typename OmegaFun,
typename Allocator,
273 typename GammaFun,
typename Integral>
274inline auto make_solver(OmegaFun&& omega_fun, GammaFun&& gamma_fun,
275 Allocator&& alloc, Integral nini, Integral nmax,
276 Integral n, Integral p) {
278 Integral, std::decay_t<Allocator>>(
279 std::forward<OmegaFun>(omega_fun), std::forward<GammaFun>(gamma_fun),
280 std::forward<Allocator>(alloc), nini, nmax, n, p);
matrixd_t integration_matrix_
std::vector< std::tuple< Integral, matrixd_t, vectord_t > > chebyshev_
RICCATI_ALWAYS_INLINE const auto & xp() const noexcept
SolverInfo(OmegaFun_ &&omega_fun, GammaFun_ &&gamma_fun, Allocator_ &&alloc, Integral nini, Integral nmax, Integral n, Integral p)
Construct a new Solver Info object.
SolverInfo(OmegaFun_ &&omega_fun, GammaFun_ &&gamma_fun, Integral nini, Integral nmax, Integral n, Integral p)
RICCATI_ALWAYS_INLINE const auto & Dn(std::size_t idx) const noexcept
RICCATI_ALWAYS_INLINE const auto & Dn() const noexcept
matrix_t< Scalar > matrixd_t
vector_t< Scalar > vectord_t
std::decay_t< OmegaFun > funtype
RICCATI_ALWAYS_INLINE const auto & xp_interp() const noexcept
RICCATI_ALWAYS_INLINE const auto & xn() const noexcept
vector_t< complex_t > vectorc_t
RICCATI_ALWAYS_INLINE const auto & L() const noexcept
std::complex< Scalar > complex_t
#define RICCATI_ALWAYS_INLINE
RICCATI_ALWAYS_INLINE auto quad_weights(Integral n)
Calculates Clenshaw-Curtis quadrature weights.
RICCATI_ALWAYS_INLINE auto integration_matrix(Integral n)
Constructs a Chebyshev integration matrix.
Eigen::Matrix< Scalar, -1, -1 > matrix_t
auto make_solver(OmegaFun &&omega_fun, GammaFun &&gamma_fun, Allocator &&alloc, Integral nini, Integral nmax, Integral n, Integral p)
Construct a new Solver Info object.
auto gamma(SolverInfo &&info, const Scalar &x)
auto omega(SolverInfo &&info, const Scalar &x)
Eigen::Matrix< Scalar, -1, 1 > vector_t
RICCATI_ALWAYS_INLINE auto chebyshev(Integral n)
Computes the Chebyshev differentiation matrix and Chebyshev nodes.
RICCATI_ALWAYS_INLINE auto interpolate(Vec1 &&s, Vec2 &&t, Allocator &&alloc)
Creates an interpolation matrix from an array of source nodes to target nodes.