Tatooine
autonomous_particles_test.h
Go to the documentation of this file.
1#ifndef TATOOINE_AUTONOMOUS_PARTICLES_FIELD_H
2#define TATOOINE_AUTONOMOUS_PARTICLES_FIELD_H
3//==============================================================================
5#include <tatooine/field.h>
6#include <tatooine/flowmap_gradient_central_differences.h>
8//==============================================================================
10//==============================================================================
11template <std::floating_point Real>
13 : vectorfield<autonomous_particles_test<Real>, Real, 2> {
16 using typename parent_type::pos_type;
17 using typename parent_type::real_type;
18 using typename parent_type::tensor_type;
19 //============================================================================
20 constexpr autonomous_particles_test() noexcept {}
22 default;
24 default;
25 constexpr auto operator=(autonomous_particles_test const&)
26 -> autonomous_particles_test& = default;
27 constexpr auto operator=(autonomous_particles_test&&) noexcept
28 -> autonomous_particles_test& = default;
29 //----------------------------------------------------------------------------
30 ~autonomous_particles_test() override = default;
31 //----------------------------------------------------------------------------
32 [[nodiscard]] constexpr auto evaluate(pos_type const& x,
33 real_type const /*t*/) const
34 -> tensor_type final {
35 return {x(0) * x(0) * x(0) - x(0), (1 - 3 * x(0) * x(0)) * x(1)};
36 }
37 //----------------------------------------------------------------------------
38 [[nodiscard]] constexpr auto in_domain(pos_type const& /*x*/,
39 real_type const /*t*/) const
40 -> bool final {
41 return true;
42 }
43};
44//==============================================================================
46//==============================================================================
47template <std::floating_point Real>
49 using real_type = Real;
51 using pos_type = vec_t;
52 static constexpr auto num_dimensions() -> std::size_t { return 2; }
53 //----------------------------------------------------------------------------
54 constexpr auto evaluate(pos_type const& x, real_type const /*t*/,
55 real_type const tau) const -> pos_type {
56 auto const a = std::exp(2 * tau);
57 auto const b = std::exp(-2 * tau);
58 auto const c = std::sqrt((1 - a) * x(0) * x(0) + a);
59 return {x(0) / c, -b * c * ((a - 1) * x(0) * x(0) - a) * x(1)
60
61 };
62 }
63 //----------------------------------------------------------------------------
64 constexpr auto operator()(pos_type const& x, real_type const t,
65 real_type const tau) const -> pos_type {
66 return evaluate(x, t, tau);
67 }
68};
69//------------------------------------------------------------------------------
70template <template <typename, size_t>
71 typename ODESolver = ode::boost::rungekuttafehlberg78,
72 template <typename>
73 typename InterpolationKernel = interpolation::cubic,
74 std::floating_point Real>
75constexpr auto flowmap(
77 tag::numerical_t /*tag*/) {
79 InterpolationKernel>{v};
80}
81// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82template <std::floating_point Real>
83constexpr auto flowmap(
85 tag::analytical_t /*tag*/) {
87}
88// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89template <std::floating_point Real>
90constexpr auto flowmap(
92 return flowmap(v, tag::analytical);
93}
94//==============================================================================
95template <std::floating_point Real>
97 using real_type = Real;
99 using pos_type = vec_t;
102 static constexpr auto num_dimensions() -> std::size_t { return 2; }
103 //----------------------------------------------------------------------------
104 constexpr auto evaluate(pos_type const& x, real_type const /*t*/,
105 real_type const tau) const -> gradient_t {
106 auto const a = std::exp(2 * tau);
107 auto const b = std::exp(-2 * tau);
108 auto const c = std::sqrt(-a * x(0) * x(0) + x(0) * x(0) + a);
109 auto const d = std::pow((-a * x(0) * x(0) + x(0) * x(0) + a),
110 real_type(3) / real_type(2));
111 return {
112 {1 / c - (x(0) * (2 * x(0) - 2 * a * x(0))) / (2 * d), real_type(0)},
113 {(3 * b * (2 * x(0) - 2 * a * x(0)) * c * x(1)) / 2, b * d}};
114 }
115 //----------------------------------------------------------------------------
116 constexpr auto operator()(pos_type const& x, Real const t,
117 real_type const tau) const {
118 return evaluate(x, t, tau);
119 }
120};
121//------------------------------------------------------------------------------
122template <std::floating_point Real>
124 tag::analytical_t /*tag*/) {
126}
127// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
128template <std::floating_point VReal, std::floating_point EpsReal = VReal>
130 tag::central_t /*tag*/, EpsReal epsilon = 1e-7) {
131 return flowmap_gradient_central_differences<
133}
134// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135template <std::floating_point VReal, std::floating_point EpsReal>
137 tag::central_t /*tag*/, vec<EpsReal, 2> epsilon) {
138 return flowmap_gradient_central_differences<
140}
141// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
142template <std::floating_point Real>
145}
146//==============================================================================
147} // namespace tatooine::analytical::numerical
148//==============================================================================
149namespace tatooine {
150//==============================================================================
151template <std::floating_point Real>
153 analytical::numerical::autonomous_particles_test<Real>, 2, 2>
154 : field<analytical::numerical::autonomous_particles_test<Real>, Real, 2, 2,
155 2> {
159 using typename parent_type::pos_type;
160 using typename parent_type::real_type;
161 using typename parent_type::tensor_type;
162
163 //============================================================================
164 public:
165 constexpr auto evaluate(pos_type const& x, real_type const /*t*/) const
166 -> tensor_type final {
167 return {{3 * x(0) * x(0) - 1, 0}, {-6 * x(0) * x(1), 1 - 3 * x(0) * x(0)}};
168 }
169 //----------------------------------------------------------------------------
170 constexpr auto in_domain(pos_type const& /*x*/, real_type const /*t*/) const
171 -> bool final {
172 return true;
173 }
174};
175//------------------------------------------------------------------------------
176template <std::floating_point Real>
180}
181// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182template <std::floating_point Real>
183constexpr auto diff(
185 2> const&) {
188}
189//==============================================================================
190} // namespace tatooine
191//==============================================================================
192#endif
Definition: abcflow.h:7
constexpr auto flowmap(vectorfield< autonomous_particles_test< Real >, Real, 2 > const &v, tag::numerical_t)
Definition: autonomous_particles_test.h:75
auto diff(autonomous_particles_test_flowmap< Real > const &, tag::analytical_t)
Definition: autonomous_particles_test.h:123
static constexpr analytical_t analytical
Definition: tags.h:91
Definition: algorithm.h:6
constexpr auto diff(polynomial< Real, Degree > const &f)
Definition: polynomial.h:179
vec< real_type, 2 > vec_t
Definition: autonomous_particles_test.h:98
mat< real_type, 2, 2 > mat_t
Definition: autonomous_particles_test.h:100
static constexpr auto num_dimensions() -> std::size_t
Definition: autonomous_particles_test.h:102
constexpr auto evaluate(pos_type const &x, real_type const, real_type const tau) const -> gradient_t
Definition: autonomous_particles_test.h:104
constexpr auto operator()(pos_type const &x, Real const t, real_type const tau) const
Definition: autonomous_particles_test.h:116
constexpr auto operator()(pos_type const &x, real_type const t, real_type const tau) const -> pos_type
Definition: autonomous_particles_test.h:64
constexpr auto evaluate(pos_type const &x, real_type const, real_type const tau) const -> pos_type
Definition: autonomous_particles_test.h:54
static constexpr auto num_dimensions() -> std::size_t
Definition: autonomous_particles_test.h:52
Real real_type
Definition: autonomous_particles_test.h:49
vec< real_type, 2 > vec_t
Definition: autonomous_particles_test.h:50
Definition: autonomous_particles_test.h:13
constexpr autonomous_particles_test(autonomous_particles_test const &)=default
constexpr auto in_domain(pos_type const &, real_type const) const -> bool final
Definition: autonomous_particles_test.h:38
constexpr autonomous_particles_test() noexcept
Definition: autonomous_particles_test.h:20
constexpr autonomous_particles_test(autonomous_particles_test &&) noexcept=default
constexpr auto evaluate(pos_type const &x, real_type const) const -> tensor_type final
Definition: autonomous_particles_test.h:32
vec_type pos_type
Definition: axis_aligned_bounding_box.h:109
constexpr auto evaluate(pos_type const &x, real_type const) const -> tensor_type final
Definition: autonomous_particles_test.h:165
constexpr auto in_domain(pos_type const &, real_type const) const -> bool final
Definition: autonomous_particles_test.h:170
Definition: differentiated_field.h:173
Definition: field.h:134
Real real_type
Definition: field.h:17
vec< real_type, NumDimensions > pos_type
Definition: field.h:20
Tensor tensor_type
Definition: field.h:18
Definition: interpolation.h:216
Real real_type
Definition: interpolation.h:25
interpolation_tensor_type< tensor< Real, Dims... > > tensor_type
Definition: interpolation.h:135
Definition: mat.h:14
Definition: numerical_flowmap.h:17
Definition: rungekuttafehlberg78.h:28
Definition: tags.h:90
Definition: tags.h:92
Definition: vec.h:12