Loading [MathJax]/extensions/tex2jax.js
Tatooine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
symbolic_field.h
Go to the documentation of this file.
1#ifndef TATOOINE_SYMBOLIC_FIELD_H
2#define TATOOINE_SYMBOLIC_FIELD_H
3//==============================================================================
4#include <tatooine/available_libraries.h>
5#if TATOOINE_GINAC_AVAILABLE
6//==============================================================================
7#include "crtp.h"
8#include "field.h"
9#include "symbolic.h"
10#include "tensor.h"
11//==============================================================================
12namespace tatooine::symbolic {
13//==============================================================================
14template <typename real_type, size_t N, size_t... TensorDims>
15struct field : tatooine::field<field<real_type, N, TensorDims...>, real_type, N,
16 TensorDims...> {
17 using this_type = field<real_type, N, TensorDims...>;
18 using parent_t = tatooine::field<this_type, real_type, N, TensorDims...>;
20 using typename parent_t::pos_type;
21 using typename parent_t::tensor_type;
22 using symtensor_type = tensor<GiNaC::ex, TensorDims...>;
23
24 static auto x(size_t i) -> auto& { return symbol::x(i); }
25 static auto t() -> auto& { return symbol::t(); }
26
27 private:
29
30 protected:
31 void set_expr(const symtensor_type& ex) { m_expr = ex; }
32 void set_expr(symtensor_type&& ex) { m_expr = std::move(ex); }
33
34 public:
35 constexpr field() = default;
36 explicit constexpr field(const symtensor_type& ex) : m_expr{ex} {}
37 explicit constexpr field(symtensor_type&& ex) : m_expr{std::move(ex)} {}
38 //----------------------------------------------------------------------------
39 [[nodiscard]] auto expr() const -> const auto& { return m_expr; }
40 //----------------------------------------------------------------------------
41 template <size_t... Is>
42 auto evaluate(const pos_type& _x, double _t,
43 std::index_sequence<Is...> /*is*/) const -> tensor_type {
44 return evtod<real_type>(m_expr, (x(Is) == _x(Is))..., t() == _t);
45 }
46 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47 auto evaluate(const pos_type& _x, double _t) const -> tensor_type {
48 return evaluate(_x, _t, std::make_index_sequence<num_dimensions()>{});
49 }
50 constexpr auto in_domain(const pos_type& /*x*/, double /*t*/) const { return true; }
51};
52
53//==============================================================================
54// operations
55//==============================================================================
56template <typename Real0, typename Real1, size_t N, size_t D>
57constexpr auto dot(const field<Real0, N, D>& lhs,
58 const field<Real1, N, D>& rhs) {
59 return field<common_type<Real0, Real1>, N>{dot(lhs.expr(), rhs.expr())};
60}
61
62//------------------------------------------------------------------------------
63template <typename Real0, typename Real1, size_t N, size_t... TensorDims>
64constexpr auto operator+(const field<Real0, N, TensorDims...>& lhs,
66 return field<common_type<Real0, Real1>, N, TensorDims...>{lhs.expr() +
67 rhs.expr()};
68}
69//------------------------------------------------------------------------------
70template <typename Real0, typename Real1, size_t N, size_t... TensorDims>
71constexpr auto operator-(const field<Real0, N, TensorDims...>& lhs,
73 return field<common_type<Real0, Real1>, N, TensorDims...>{lhs.expr() -
74 rhs.expr()};
75}
76
77//------------------------------------------------------------------------------
78template <typename Real0, typename Real1, size_t... TensorDims>
79constexpr auto operator*(const field<Real0, TensorDims...>& lhs,
80 const field<Real1, TensorDims...>& rhs) {
81 return field<common_type<Real0, Real1>, TensorDims...>{lhs.expr() *
82 rhs.expr()};
83}
84
85//------------------------------------------------------------------------------
86template <typename Real0, typename Real1, size_t... TensorDims>
87constexpr auto operator/(const field<Real0, TensorDims...>& lhs,
88 const field<Real1, TensorDims...>& rhs) {
89 return field<common_type<Real0, Real1>, TensorDims...>{lhs.expr() /
90 rhs.expr()};
91}
92
93//------------------------------------------------------------------------------
94template <typename Real0, typename Real1, size_t N, size_t D0, size_t D1>
95constexpr auto operator*(const field<Real0, N, D0, D1>& lhs,
96 const field<Real1, N, D1>& rhs) {
97 return field<common_type<Real0, Real1>, N, D0>{lhs.expr() * rhs.expr()};
98}
99//==============================================================================
100} // namespace tatooine::symbolic
101//==============================================================================
102namespace tatooine{
103//==============================================================================
104template <typename T>
105struct is_symbolic_field_impl : std::false_type {};
106// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107template <typename Real, size_t N, size_t... TensorDims>
109 field<symbolic::field<Real, N, TensorDims...>, Real, N, TensorDims...>>
110 : std::true_type {};
111// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112template <typename Real, size_t N, size_t... TensorDims>
113struct is_symbolic_field_impl<symbolic::field<Real, N, TensorDims...>>
114 : std::true_type {};
115// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116template <typename T>
118// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
119template <typename T>
120constexpr auto is_symbolic_field(T&&) noexcept {
121 return false;
122}
123// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124template <typename Real, size_t N, size_t... TensorDims>
125constexpr auto is_symbolic_field(
127 TensorDims...>&) noexcept {
128 return true;
129}
130//------------------------------------------------------------------------------
131template <typename Real, size_t N, size_t... TensorDims>
133 tensor<GiNaC::ex, TensorDims..., N> ex;
134 for (size_t i = 0; i < N; ++i) {
135 ex.template slice<sizeof...(TensorDims)>(i) =
137 }
138 return symbolic::field<Real, N, TensorDims..., N>{std::move(ex)};
139}
140//==============================================================================
141} // namespace tatooine
142//==============================================================================
143#endif
144#endif
static auto constexpr t
Definition: index.h:24
Definition: symbolic.h:8
constexpr auto operator+(const field< Real0, N, TensorDims... > &lhs, const field< Real1, N, TensorDims... > &rhs)
Definition: symbolic_field.h:64
constexpr auto dot(const field< Real0, N, D > &lhs, const field< Real1, N, D > &rhs)
Definition: symbolic_field.h:57
constexpr auto operator*(const field< Real0, TensorDims... > &lhs, const field< Real1, TensorDims... > &rhs)
Definition: symbolic_field.h:79
constexpr auto operator/(const field< Real0, TensorDims... > &lhs, const field< Real1, TensorDims... > &rhs)
Definition: symbolic_field.h:87
constexpr auto operator-(const field< Real0, N, TensorDims... > &lhs, const field< Real1, N, TensorDims... > &rhs)
Definition: symbolic_field.h:71
Definition: algorithm.h:6
constexpr auto is_symbolic_field(T &&) noexcept
Definition: symbolic_field.h:120
static constexpr auto is_symbolic_field_v
Definition: symbolic_field.h:117
constexpr auto diff(polynomial< Real, Degree > const &f)
Definition: polynomial.h:179
Definition: field.h:134
vec< real_type, NumDimensions > pos_type
Definition: field.h:20
Tensor tensor_type
Definition: field.h:18
auto num_dimensions() const -> std::size_t
Definition: hdf5.h:764
Definition: symbolic_field.h:105
Definition: symbolic.h:61
static constexpr auto num_dimensions() -> std::size_t
Definition: field.h:38
Definition: symbolic_field.h:16
auto evaluate(const pos_type &_x, double _t) const -> tensor_type
Definition: symbolic_field.h:47
auto expr() const -> const auto &
Definition: symbolic_field.h:39
symtensor_type m_expr
Definition: symbolic_field.h:28
void set_expr(const symtensor_type &ex)
Definition: symbolic_field.h:31
static auto x(size_t i) -> auto &
Definition: symbolic_field.h:24
constexpr field(const symtensor_type &ex)
Definition: symbolic_field.h:36
constexpr field()=default
void set_expr(symtensor_type &&ex)
Definition: symbolic_field.h:32
static auto t() -> auto &
Definition: symbolic_field.h:25
constexpr field(symtensor_type &&ex)
Definition: symbolic_field.h:37
field< real_type, N, TensorDims... > this_type
Definition: symbolic_field.h:17
auto evaluate(const pos_type &_x, double _t, std::index_sequence< Is... >) const -> tensor_type
Definition: symbolic_field.h:42
constexpr auto in_domain(const pos_type &, double) const
Definition: symbolic_field.h:50
Definition: vec.h:12
auto constexpr x() const -> auto const &requires(N >=1)
Definition: vec.h:102