1#ifndef TATOOINE_NUMERICAL_FLOWMAP_H
2#define TATOOINE_NUMERICAL_FLOWMAP_H
14template <
typename V,
template <
typename, std::
size_t>
typename ODESolver,
15 template <
typename>
typename InterpolationKernel =
20 using real_type =
typename raw_field_type::real_type;
22 return raw_field_type::num_dimensions();
31 std::map<std::pair<pos_type, real_type>, std::pair<bool, bool>>;
53 :
m_v{std::move(other.m_v)},
68 m_v = std::move(other.m_v);
76 template <std::convertible_to<V> W, arithmetic WReal,
77 std::
size_t NumDimensions,
typename V_ = V>
84 template <std::convertible_to<V> W, arithmetic WReal,
85 std::
size_t NumDimensions,
typename V_ = V>
92 template <arithmetic WReal, std::
size_t NumDimensions,
typename V_ = V>
99 template <arithmetic WReal, std::
size_t NumDimensions,
typename V_ = V>
106 template <
typename V_ = V>
112 template <
typename W,
typename WReal, std::size_t NumDimensions,
126 auto xes =
mat<
real_type, x0s.dimension(0), x0s.dimension(1)>{x0s};
127 for (std::size_t i = 0; i < xes.dimension(1); ++i) {
140 auto const t_end = t0 + tau;
141 auto callback = [t_end, &x1](
const auto& y,
auto const t) {
155 return std::pair{
pos_type{x0}, arc_length};
158 auto const t_end = t0 + tau;
159 auto callback = [t_end, &x1, &arc_length](
const auto& y,
auto const ) {
164 return std::pair{x1, arc_length};
174 auto const t_end = t0 + tau;
176 auto callback = [t_end, &x1](
const auto& y,
auto const t) {
191 if (t + security_eps <
203 if (t - security_eps <
231 return std::pair{std::move(c), full_integration};
240 bool const backward_full = [
this, &c, btau] {
246 bool const forward_full = [
this, &c, ftau] {
252 return std::tuple{std::move(c), backward_full, forward_full};
276 auto callback = [&
integral_curve, ¶meterization, &tangents, tau](
277 const auto& y,
auto const t,
const auto& dy) {
279 std::abs(parameterization[
integral_curve.vertices().back()] - t) <
289 parameterization[v] = t;
294 solver_copy.solve(
vectorfield(), y0, t0, tau, callback);
299 parameterization[
integral_curve.vertices().front()] < t0 + tau)) {
312 real_type const tau)
const ->
auto const& {
313 return cached_curve(y0, t0, tau < 0 ? tau : 0, tau > 0 ? tau : 0);
319 auto& curve = curve_it->second;
321 auto& [backward_on_border, forward_on_border] =
324 if (new_integral_curve || curve.empty()) {
326 auto [fresh_curve, fullback, fullforw] =
328 curve = std::move(fresh_curve);
329 backward_on_border = !fullback;
330 forward_on_border = !fullforw;
333 std::swap(btau, ftau);
335 if (
auto const tf = curve.parameterization()[curve.vertices().front()];
336 btau < 0 && tf > t0 + btau && !backward_on_border) {
339 backward_on_border = !full;
341 if (
auto const tb = curve.parameterization()[curve.vertices().back()];
342 ftau > 0 && tb < t0 + ftau && !forward_on_border) {
345 forward_on_border = !full;
367 template <
typename =
void>
386template <
typename V,
typename Real, std::
size_t NumDimensions>
391template <
typename V,
typename Real, std::
size_t NumDimensions>
395template <
typename V,
typename Real, std::size_t NumDimensions,
396 template <
typename, std::
size_t>
typename ODESolver>
398 ODESolver<Real, NumDimensions>
const&)
401template <
typename V,
typename Real, std::size_t NumDimensions,
402 template <
typename, std::
size_t>
typename ODESolver>
404 ODESolver<Real, NumDimensions>
const&)
408 template <
typename, std::
size_t>
411 typename V,
typename Real, std::size_t NumDimensions>
418 template <
typename>
typename InterpolationKernel = interpolation::cubic,
419 template <
typename, std::
size_t>
typename ODESolver,
420 typename V,
typename Real, std::size_t NumDimensions>
422 ODESolver<Real, NumDimensions>
const& ode_solver,
429 template <
typename, std::
size_t>
430 typename ODESolver = ode::boost::rungekuttafehlberg78,
431 template <
typename>
typename InterpolationKernel = interpolation::cubic,
432 typename V,
typename Real, std::size_t NumDimensions>
439 template <
typename, std::
size_t>
typename ODESolver,
440 template <
typename>
typename InterpolationKernel = interpolation::cubic,
441 typename V,
typename Real, std::size_t NumDimensions>
443 ODESolver<Real, NumDimensions>
const& ode_solver,
450 template <
typename, std::
size_t>
451 typename ODESolver = ode::boost::rungekuttafehlberg78,
452 template <
typename>
typename InterpolationKernel = interpolation::cubic,
453 typename V,
typename Real, std::size_t NumDimensions>
459 template <
typename, std::
size_t>
typename ODESolver,
460 template <
typename>
typename InterpolationKernel = interpolation::cubic,
461 typename V,
typename Real, std::size_t NumDimensions>
463 ODESolver<Real, NumDimensions>
const& ode_solver) {
469 template <
typename, std::
size_t>
470 typename ODESolver = ode::boost::rungekuttafehlberg78,
471 template <
typename>
typename InterpolationKernel = interpolation::cubic,
472 typename V,
typename Real, std::size_t NumDimensions>
474 ODESolver<Real, NumDimensions>
const& ode_solver) {
480 template <
typename, std::
size_t>
481 typename ODESolver = ode::boost::rungekuttafehlberg78,
482 template <
typename>
typename InterpolationKernel = interpolation::cubic,
483 typename V,
typename Real, std::size_t NumDimensions>
489 template <
typename, std::
size_t>
490 typename ODESolver = ode::boost::rungekuttafehlberg78,
491 template <
typename>
typename InterpolationKernel = interpolation::cubic,
492 typename Real, std::size_t NumDimensions>
495 ODESolver, InterpolationKernel>(&v);
499 template <
typename, std::
size_t>
500 typename ODESolver = ode::boost::rungekuttafehlberg78,
501 template <
typename>
typename InterpolationKernel = interpolation::cubic,
502 typename Real, std::size_t NumDimensions>
504 ODESolver<Real, NumDimensions>
const& ode_solver) {
506 ODESolver, InterpolationKernel>(&v, ode_solver);
517template <arithmetic Real, std::size_t NumDimensions,
518 template <
typename, std::
size_t>
typename ODESolver,
519 template <
typename>
typename InterpolationKernel>
522 InterpolationKernel>;
529template <
typename V,
template <
typename, std::
size_t>
typename ODESolver,
530 template <
typename>
typename InterpolationKernel>
void clear()
Definition: cache.h:145
auto emplace(const Key &key, Args &&... args)
Definition: cache.h:112
Definition: tensor_concepts.h:48
Definition: tensor_concepts.h:33
Definition: algorithm.h:6
auto flowmap(vectorfield< V, Real, NumDimensions > const &v, tag::numerical_t)
Definition: numerical_flowmap.h:412
static constexpr auto is_numerical_flowmap
Definition: numerical_flowmap.h:535
constexpr auto euclidean_distance(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: distance.h:19
auto as_derived() -> auto &
Definition: field.h:161
Definition: interpolation.h:216
Definition: numerical_flowmap.h:527
auto push_back(arithmetic auto const ... components)
Definition: line.h:176
auto parameterization() -> auto &
Definition: line.h:502
Definition: numerical_flowmap.h:17
auto integral_curve(pos_type const &y0, real_type const t0, real_type const tau) const
Definition: numerical_flowmap.h:225
std::remove_pointer_t< std::decay_t< V > > raw_field_type
Definition: numerical_flowmap.h:19
static constexpr auto holds_field_pointer
Definition: numerical_flowmap.h:32
auto integral_curve(pos_type const &y0, real_type const t0, real_type const btau, real_type const ftau) const
Definition: numerical_flowmap.h:234
constexpr numerical_flowmap(bool const use_caching=default_use_caching)
Definition: numerical_flowmap.h:108
bool m_use_caching
Definition: numerical_flowmap.h:42
constexpr auto operator()(fixed_num_rows_mat< num_dimensions()> auto const &x0s, real_type const t0, real_type const tau) const
Definition: numerical_flowmap.h:213
constexpr auto evaluate_uncached_with_arc_length(fixed_size_vec< num_dimensions()> auto const &x0, real_type const t0, real_type const tau) const
Definition: numerical_flowmap.h:150
auto vectorfield() -> auto &
Definition: numerical_flowmap.h:359
auto cached_curve(pos_type const &y0, real_type const t0) const -> auto const &
Definition: numerical_flowmap.h:306
auto operator=(numerical_flowmap const &other) -> numerical_flowmap &
Definition: numerical_flowmap.h:57
auto cached_curve(pos_type const &y0, real_type const t0, real_type btau, real_type ftau) const -> auto const &
Definition: numerical_flowmap.h:316
constexpr numerical_flowmap(vectorfield< W, WReal, NumDimensions > const &w, ode_solver_type const &ode_solver, bool const use_caching=default_use_caching)
Definition: numerical_flowmap.h:115
constexpr numerical_flowmap(vectorfield< W, WReal, NumDimensions > const &w, bool const use_caching=default_use_caching)
Definition: numerical_flowmap.h:79
constexpr numerical_flowmap(polymorphic::vectorfield< WReal, NumDimensions > const *w, bool const use_caching=default_use_caching)
Definition: numerical_flowmap.h:94
numerical_flowmap(numerical_flowmap const &other)
Definition: numerical_flowmap.h:47
V m_v
Definition: numerical_flowmap.h:38
constexpr numerical_flowmap(vectorfield< W, WReal, NumDimensions > const *w, bool const use_caching=default_use_caching)
Definition: numerical_flowmap.h:87
typename raw_field_type::real_type real_type
Definition: numerical_flowmap.h:20
constexpr auto evaluate(fixed_num_rows_mat< num_dimensions()> auto const &x0s, real_type const t0, real_type tau) const
Definition: numerical_flowmap.h:123
vec< real_type, num_dimensions()> vec_type
Definition: numerical_flowmap.h:24
numerical_flowmap(numerical_flowmap &&other) noexcept
Definition: numerical_flowmap.h:52
auto ode_solver() const -> auto const &
Definition: numerical_flowmap.h:373
constexpr numerical_flowmap(polymorphic::vectorfield< WReal, NumDimensions > *w, bool const use_caching=default_use_caching)
Definition: numerical_flowmap.h:101
auto cached_curve(pos_type const &y0, real_type const t0, real_type const tau) const -> auto const &
Definition: numerical_flowmap.h:311
constexpr auto operator()(fixed_size_vec< num_dimensions()> auto const &y0, real_type const t0, real_type const tau) const -> pos_type
Definition: numerical_flowmap.h:219
auto operator=(numerical_flowmap &&other) noexcept -> numerical_flowmap &
Definition: numerical_flowmap.h:67
~numerical_flowmap()=default
domain_border_flags_type m_on_domain_border
Definition: numerical_flowmap.h:41
auto is_using_caching() -> auto &
Definition: numerical_flowmap.h:378
auto continue_integration(integral_curve_type &integral_curve, real_type const tau) const -> bool
Definition: numerical_flowmap.h:260
auto use_caching(bool const b=true) -> void
Definition: numerical_flowmap.h:376
ode_solver_type m_ode_solver
Definition: numerical_flowmap.h:39
static constexpr auto num_dimensions() -> std::size_t
Definition: numerical_flowmap.h:21
cache_type m_cache
Definition: numerical_flowmap.h:40
constexpr auto evaluate(fixed_size_vec< num_dimensions()> auto const &x0, real_type const t0, real_type const tau) const -> pos_type
Definition: numerical_flowmap.h:167
auto invalidate_cache() const
Definition: numerical_flowmap.h:380
auto vectorfield() const -> auto const &
Definition: numerical_flowmap.h:351
std::map< std::pair< pos_type, real_type >, std::pair< bool, bool > > domain_border_flags_type
Definition: numerical_flowmap.h:31
auto set_vectorfield(polymorphic::vectorfield< real_type, num_dimensions()> *w)
Definition: numerical_flowmap.h:368
auto ode_solver() -> auto &
Definition: numerical_flowmap.h:374
constexpr auto evaluate_uncached(fixed_size_vec< num_dimensions()> auto const &x0, real_type const t0, real_type const tau) const -> pos_type
Definition: numerical_flowmap.h:133
static constexpr auto default_use_caching
Definition: numerical_flowmap.h:33
auto is_using_caching() const
Definition: numerical_flowmap.h:377
Definition: rungekuttafehlberg78.h:28
Definition: exceptions.h:8