Tatooine
particle.h
Go to the documentation of this file.
1#ifndef TATOOINE_PARTICLE
2#define TATOOINE_PARTICLE
3//==============================================================================
4#include <tatooine/pointset.h>
5#include <tatooine/vec.h>
6//==============================================================================
7namespace tatooine {
8//==============================================================================
9template <typename Real, std::size_t NumDimensions>
10struct particle {
11 static constexpr auto num_dimensions() -> std::size_t { return NumDimensions; }
12 //----------------------------------------------------------------------------
13 // typedefs
14 //----------------------------------------------------------------------------
15 public:
17 using real_type = Real;
19 using pos_type = vec_t;
20 //----------------------------------------------------------------------------
21 // members
22 //----------------------------------------------------------------------------
23 private:
26
27 //----------------------------------------------------------------------------
28 // ctors
29 //----------------------------------------------------------------------------
30 public:
31 particle(particle const& other);
32 particle(particle&& other) noexcept;
33 //----------------------------------------------------------------------------
34 auto operator=(particle const& other) -> particle&;
35 auto operator=(particle&& other) noexcept -> particle&;
36 //----------------------------------------------------------------------------
37 ~particle() = default;
38 //----------------------------------------------------------------------------
39 particle() = default;
40 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41 particle(pos_type const& x0, real_type t0);
42 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43 particle(pos_type const& x0, pos_type const& x1, real_type t1);
44 //----------------------------------------------------------------------------
45 // getters / setters
46 //----------------------------------------------------------------------------
47 auto x0() -> auto& { return m_x0; }
48 auto x0() const -> auto const& { return m_x0; }
49 auto x0(std::size_t const i) const { return m_x0(i); }
50 //----------------------------------------------------------------------------
51 auto x1() -> auto& { return m_x1; }
52 auto x1() const -> auto const& { return m_x1; }
53 auto x1(std::size_t const i) const { return m_x1(i); }
54 //----------------------------------------------------------------------------
55 auto t1() -> auto& { return m_t1; }
56 auto t1() const { return m_t1; }
57 //----------------------------------------------------------------------------
58 template <typename Flowmap>
59 auto advect(Flowmap&& phi, real_type const tau) {
60 m_x1 = phi(m_x1, m_t1, tau);
61 m_t1 += tau;
62 }
63};
64//==============================================================================
65template <typename Real, std::size_t NumDimensions>
67 : m_x0{other.m_x0}, m_x1{other.m_x1}, m_t1{other.m_t1} {}
68// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69template <typename Real, std::size_t NumDimensions>
71 : m_x0{std::move(other.m_x0)},
72 m_x1{std::move(other.m_x1)},
73 m_t1{other.m_t1} {}
74
75//----------------------------------------------------------------------------
76template <typename Real, std::size_t NumDimensions>
78 -> particle& {
79 if (&other == this) {
80 return *this;
81 };
82 m_x0 = other.m_x0;
83 m_x1 = other.m_x1;
84 m_t1 = other.m_t1;
85 return *this;
86}
87// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
88template <typename Real, std::size_t NumDimensions>
90 -> particle& {
91 m_x0 = std::move(other.m_x0);
92 m_x1 = std::move(other.m_x1);
93 m_t1 = other.m_t1;
94 return *this;
95}
96//----------------------------------------------------------------------------
97template <typename Real, std::size_t NumDimensions>
99 : m_x0{x0}, m_x1{x0}, m_t1{t0} {}
100//----------------------------------------------------------------------------
101template <typename Real, std::size_t NumDimensions>
103 real_type const t1)
104 : m_x0{x0}, m_x1{x1}, m_t1{t1} {}
105//==============================================================================
106template <std::size_t NumDimensions>
110//==============================================================================
111template <typename Real, std::size_t NumDimensions>
113 std::vector<particle<Real, NumDimensions>> const& particles) {
115 for (auto const& p : particles) {
116 ps.insert_vertex(p.x0());
117 }
118 return ps;
119}
120//------------------------------------------------------------------------------
121template <typename Real, std::size_t NumDimensions>
123 std::vector<particle<Real, NumDimensions>> const& particles) {
125 for (auto const& p : particles) {
126 ps.insert_vertex(p.x1());
127 }
128 return ps;
129}
130//==============================================================================
131} // namespace tatooine
132//==============================================================================
133#endif
Definition: algorithm.h:6
auto x0_to_pointset(std::vector< particle< Real, NumDimensions > > const &particles)
Definition: particle.h:112
auto x1_to_pointset(std::vector< particle< Real, NumDimensions > > const &particles)
Definition: particle.h:122
Definition: particle.h:10
auto x0(std::size_t const i) const
Definition: particle.h:49
auto x0() -> auto &
Definition: particle.h:47
auto operator=(particle const &other) -> particle &
Definition: particle.h:77
vec< real_type, NumDimensions > vec_t
Definition: particle.h:18
real_type m_t1
Definition: particle.h:25
pos_type m_x0
Definition: particle.h:24
auto x1() -> auto &
Definition: particle.h:51
auto t1() -> auto &
Definition: particle.h:55
auto x1(std::size_t const i) const
Definition: particle.h:53
auto x0() const -> auto const &
Definition: particle.h:48
auto t1() const
Definition: particle.h:56
auto x1() const -> auto const &
Definition: particle.h:52
Real real_type
Definition: particle.h:17
auto advect(Flowmap &&phi, real_type const tau)
Definition: particle.h:59
pos_type m_x1
Definition: particle.h:24
static constexpr auto num_dimensions() -> std::size_t
Definition: particle.h:11
Definition: pointset.h:69
auto insert_vertex(arithmetic auto const ... ts)
Definition: pointset.h:243
Definition: vec.h:12