deal.II version GIT relicensing-2206-gaa53ff9447 2024-12-02 09:10:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
symengine_tensor_operations.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2019 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
16#include <deal.II/base/config.h>
17
18#ifdef DEAL_II_WITH_SYMENGINE
19
21# include <deal.II/base/tensor.h>
23
29
31
32namespace Differentiation
33{
34 namespace SD
35 {
36 // --- Symbolic variable creation ---
37
38 namespace internal
39 {
40 namespace
41 {
42 template <int rank>
43 std::string
44 make_index_string(const TableIndices<rank> &indices)
45 {
46 std::string out;
47 for (unsigned int i = 0; i < rank; ++i)
48 out += std::to_string(indices[i]);
49 return out;
50 }
51
52
53 template <int rank, int dim>
54 struct Symbol_Tensor;
55
56
57 template <int rank, int dim>
58 struct Symbol_Tensor
59 {
61 create(const std::string &sym)
62 {
64 for (unsigned int i = 0; i < out.n_independent_components; ++i)
65 {
66 const TableIndices<rank> indices(
68 out[indices] =
69 Expression(sym + "_" + internal::make_index_string(indices));
70 }
71 return out;
72 }
73 };
74
75
76 template <int dim>
77 struct Symbol_Tensor<0, dim>
78 {
80 create(const std::string &sym)
81 {
82 return make_symbol(sym);
83 }
84 };
85
86
87 template <int rank, int dim>
88 struct Symbol_SymmetricTensor;
89
90
91 template <int rank, int dim>
92 struct Symbol_SymmetricTensor
93 {
95 create(const std::string &sym)
96 {
98 for (unsigned int i = 0; i < out.n_independent_components; ++i)
99 {
100 const TableIndices<rank> indices(
102 out[indices] =
103 Expression(sym + "_" + internal::make_index_string(indices));
104 }
105 return out;
106 }
107 };
108
109
110 template <int dim>
111 struct Symbol_SymmetricTensor<4, dim>
112 {
114 create(const std::string &sym)
115 {
117 for (unsigned int i = 0;
118 i < SymmetricTensor<2, dim>::n_independent_components;
119 ++i)
120 for (unsigned int j = 0;
121 j < SymmetricTensor<2, dim>::n_independent_components;
122 ++j)
123 {
124 const TableIndices<4> indices =
125 make_rank_4_tensor_indices<dim>(i, j);
126 out[indices] = Expression(
127 sym + "_" + internal::make_index_string(indices));
128 }
129 return out;
130 }
131 };
132
133
134 template <int rank, int dim>
135 struct Symbol_Function_Tensor;
136
137
138 template <int rank, int dim>
139 struct Symbol_Function_Tensor
140 {
142 create(const std::string &sym,
143 const types::substitution_map &arguments)
144 {
146 const types::symbol_vector args =
148 for (unsigned int i = 0; i < out.n_independent_components; ++i)
149 {
150 const TableIndices<rank> indices(
152 out[indices] =
153 Expression(sym + "_" + internal::make_index_string(indices),
154 args);
155 }
156 return out;
157 }
158 };
159
160
161 template <int dim>
162 struct Symbol_Function_Tensor<0, dim>
163 {
165 create(const std::string &sym,
166 const types::substitution_map &arguments)
167 {
168 return make_symbolic_function(sym, arguments);
169 }
170 };
171
172
173 template <int rank, int dim>
174 struct Symbol_Function_SymmetricTensor;
175
176
177 template <int rank, int dim>
178 struct Symbol_Function_SymmetricTensor
179 {
181 create(const std::string &sym,
182 const types::substitution_map &arguments)
183 {
185 const types::symbol_vector args =
187 for (unsigned int i = 0; i < out.n_independent_components; ++i)
188 {
189 const TableIndices<rank> indices(
191 out[indices] =
192 Expression(sym + "_" + internal::make_index_string(indices),
193 args);
194 }
195 return out;
196 }
197 };
198
199
200 template <int dim>
201 struct Symbol_Function_SymmetricTensor<4, dim>
202 {
204 create(const std::string &sym,
205 const types::substitution_map &arguments)
206 {
208 const types::symbol_vector args =
210 for (unsigned int i = 0;
211 i < SymmetricTensor<2, dim>::n_independent_components;
212 ++i)
213 for (unsigned int j = 0;
214 j < SymmetricTensor<2, dim>::n_independent_components;
215 ++j)
216 {
217 const TableIndices<4> indices =
218 make_rank_4_tensor_indices<dim>(i, j);
219 out[indices] =
220 Expression(sym + "_" + internal::make_index_string(indices),
221 args);
222 }
223 return out;
224 }
225 };
226 } // namespace
227 } // namespace internal
228
229
230 template <int dim>
232 make_vector_of_symbols(const std::string &sym)
233 {
234 return internal::Symbol_Tensor<1, dim>::create(sym);
235 }
236
237
238# ifndef DOXYGEN
239 template <int dim>
241 make_vector_of_symbolic_functions(const std::string &sym,
242 const types::substitution_map &arguments)
243 {
244 return internal::Symbol_Function_Tensor<1, dim>::create(sym, arguments);
245 }
246# endif
247
248
249 template <int rank, int dim>
251 make_tensor_of_symbols(const std::string &sym)
252 {
253 return internal::Symbol_Tensor<rank, dim>::create(sym);
254 }
255
256
257 template <int rank, int dim>
259 make_symmetric_tensor_of_symbols(const std::string &sym)
260 {
261 return internal::Symbol_SymmetricTensor<rank, dim>::create(sym);
262 }
263
264
265# ifndef DOXYGEN
266 template <int rank, int dim>
268 make_tensor_of_symbolic_functions(const std::string &sym,
269 const types::substitution_map &arguments)
270 {
271 return internal::Symbol_Function_Tensor<rank, dim>::create(sym,
272 arguments);
273 }
274
275
276 template <int rank, int dim>
279 const std::string &sym,
280 const types::substitution_map &arguments)
281 {
282 return internal::Symbol_Function_SymmetricTensor<rank, dim>::create(
283 sym, arguments);
284 }
285# endif // DOXYGEN
286
287 } // namespace SD
288} // namespace Differentiation
289
290/* --- Explicit instantiations --- */
291
292# include "symengine_tensor_operations.inst"
293
295
296#endif // DEAL_II_WITH_SYMENGINE
static DEAL_II_HOST constexpr TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
static constexpr unsigned int n_independent_components
static constexpr TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
static constexpr unsigned int n_independent_components
Definition tensor.h:497
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
SD::types::symbol_vector extract_symbols(const SD::types::substitution_map &substitution_values)
std::vector< SD::Expression > symbol_vector
std::map< SD::Expression, SD::Expression, internal::ExpressionKeyLess > substitution_map
Tensor< rank, dim, Expression > make_tensor_of_symbols(const std::string &symbol)
Expression make_symbolic_function(const std::string &symbol, const types::symbol_vector &arguments)
SymmetricTensor< rank, dim, Expression > make_symmetric_tensor_of_symbols(const std::string &symbol)
Tensor< 1, dim, Expression > make_vector_of_symbolic_functions(const std::string &symbol, const types::substitution_map &arguments)
SymmetricTensor< rank, dim, Expression > make_symmetric_tensor_of_symbolic_functions(const std::string &symbol, const types::substitution_map &arguments)
Tensor< 1, dim, Expression > make_vector_of_symbols(const std::string &symbol)
Tensor< rank, dim, Expression > make_tensor_of_symbolic_functions(const std::string &symbol, const types::substitution_map &arguments)
Expression make_symbol(const std::string &symbol)