Tatooine
tornado.h
Go to the documentation of this file.
1#ifndef TATOOINE_ANALYTICAL_NUMERICAL_H
2#define TATOOINE_ANALYTICAL_NUMERICAL_H
3//==============================================================================
4#include <tatooine/field.h>
5#include <tatooine/math.h>
6//==============================================================================
8//==============================================================================
11template <typename Real>
12struct tornado : vectorfield<tornado<Real>, Real, 3> {
15 using typename parent_type::pos_type;
16 using typename parent_type::real_type;
17 using typename parent_type::tensor_type;
18 //----------------------------------------------------------------------------
19 static constexpr real_type eps = 1e-10;
20 //----------------------------------------------------------------------------
21 constexpr auto evaluate(pos_type const& pos, real_type const t) const
22 -> tensor_type {
23 // For each z-slice, determine the spiral circle.
24 // (xc,yc) determine the center of the circle.
25 auto const c = vec{0.5 + 0.1 * sin(0.04 * t + 10 * pos.z()),
26 0.5 + 0.1 * cos(0.03 * t + 3 * pos.z())};
27
28 // The radius also changes at each z-slice.
29 auto r = 0.1 + 0.4 * pos.z() * pos.z() + 0.1 * pos.z() * sin(8 * pos.z());
30 // r is the center radius, r2 is for damping
31 auto const r2 = 0.2 + 0.1 * pos.z();
32 auto temp = euclidean_distance(pos.xy(), c);
33 auto scale = abs(r - temp);
34 // I do not like this next line. It produces a discontinuity in the
35 // magnitude. Fix it later.
36 if (scale > r2) {
37 scale = 0.8 - scale;
38 } else {
39 scale = 1;
40 }
41
42 auto z0 = 0.1 * (0.1 - temp * pos.z());
43 if (z0 < 0) {
44 z0 = 0;
45 }
46 temp = sqrt(temp * temp + z0 * z0);
47 scale = (r + r2 - temp) * scale / (temp + eps);
48 scale = scale / (1 + pos.z());
49 return tensor_type{(pos.y() - c.y()) + 0.1 * (pos.x() - c.x()),
50 -(pos.x() - c.x()) + 0.1 * (pos.y() - c.y()), z0} *
51 scale;
52 }
53};
54//==============================================================================
55tornado()->tornado<double>;
56//==============================================================================
57} // namespace tatooine::analytical::numerical
58//==============================================================================
59#endif
Definition: abcflow.h:7
constexpr auto abs(arithmetic auto const x)
Definition: math.h:26
constexpr auto cos(arithmetic auto const x)
Definition: math.h:28
constexpr auto sin(arithmetic auto const x)
Definition: math.h:27
constexpr auto sqrt(arithmetic auto const x)
Definition: math.h:29
constexpr auto euclidean_distance(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: distance.h:19
constexpr auto evaluate(pos_type const &pos, real_type const t) const -> tensor_type
Definition: tornado.h:21
static constexpr real_type eps
Definition: tornado.h:19
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: vec.h:12