Reference documentation for deal.II version GIT relicensing-487-ge9eb5ab491 2024-04-25 07:20:02+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(
67 out.unrolled_to_component_indices(i));
68 out[indices] = Expression(sym + std::string("_") +
69 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(
101 out.unrolled_to_component_indices(i));
102 out[indices] = Expression(sym + std::string("_") +
103 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] =
127 Expression(sym + std::string("_") +
128 internal::make_index_string(indices));
129 }
130 return out;
131 }
132 };
133
134
135 template <int rank, int dim>
136 struct Symbol_Function_Tensor;
137
138
139 template <int rank, int dim>
140 struct Symbol_Function_Tensor
141 {
143 create(const std::string &sym,
144 const types::substitution_map &arguments)
145 {
147 const types::symbol_vector args =
149 for (unsigned int i = 0; i < out.n_independent_components; ++i)
150 {
151 const TableIndices<rank> indices(
152 out.unrolled_to_component_indices(i));
153 out[indices] =
154 Expression(sym + std::string("_") +
155 internal::make_index_string(indices),
156 args);
157 }
158 return out;
159 }
160 };
161
162
163 template <int dim>
164 struct Symbol_Function_Tensor<0, dim>
165 {
167 create(const std::string &sym,
168 const types::substitution_map &arguments)
169 {
170 return make_symbolic_function(sym, arguments);
171 }
172 };
173
174
175 template <int rank, int dim>
176 struct Symbol_Function_SymmetricTensor;
177
178
179 template <int rank, int dim>
180 struct Symbol_Function_SymmetricTensor
181 {
183 create(const std::string &sym,
184 const types::substitution_map &arguments)
185 {
187 const types::symbol_vector args =
189 for (unsigned int i = 0; i < out.n_independent_components; ++i)
190 {
191 const TableIndices<rank> indices(
192 out.unrolled_to_component_indices(i));
193 out[indices] =
194 Expression(sym + std::string("_") +
195 internal::make_index_string(indices),
196 args);
197 }
198 return out;
199 }
200 };
201
202
203 template <int dim>
204 struct Symbol_Function_SymmetricTensor<4, dim>
205 {
207 create(const std::string &sym,
208 const types::substitution_map &arguments)
209 {
211 const types::symbol_vector args =
213 for (unsigned int i = 0;
214 i < SymmetricTensor<2, dim>::n_independent_components;
215 ++i)
216 for (unsigned int j = 0;
217 j < SymmetricTensor<2, dim>::n_independent_components;
218 ++j)
219 {
220 const TableIndices<4> indices =
221 make_rank_4_tensor_indices<dim>(i, j);
222 out[indices] =
223 Expression(sym + std::string("_") +
224 internal::make_index_string(indices),
225 args);
226 }
227 return out;
228 }
229 };
230 } // namespace
231 } // namespace internal
232
233
234 template <int dim>
236 make_vector_of_symbols(const std::string &sym)
237 {
238 return internal::Symbol_Tensor<1, dim>::create(sym);
239 }
240
241
242# ifndef DOXYGEN
243 template <int dim>
245 make_vector_of_symbolic_functions(const std::string &sym,
246 const types::substitution_map &arguments)
247 {
248 return internal::Symbol_Function_Tensor<1, dim>::create(sym, arguments);
249 }
250# endif
251
252
253 template <int rank, int dim>
255 make_tensor_of_symbols(const std::string &sym)
256 {
257 return internal::Symbol_Tensor<rank, dim>::create(sym);
258 }
259
260
261 template <int rank, int dim>
263 make_symmetric_tensor_of_symbols(const std::string &sym)
264 {
265 return internal::Symbol_SymmetricTensor<rank, dim>::create(sym);
266 }
267
268
269# ifndef DOXYGEN
270 template <int rank, int dim>
272 make_tensor_of_symbolic_functions(const std::string &sym,
273 const types::substitution_map &arguments)
274 {
275 return internal::Symbol_Function_Tensor<rank, dim>::create(sym,
276 arguments);
277 }
278
279
280 template <int rank, int dim>
283 const std::string &sym,
284 const types::substitution_map &arguments)
285 {
286 return internal::Symbol_Function_SymmetricTensor<rank, dim>::create(
287 sym, arguments);
288 }
289# endif // DOXYGEN
290
291 } // namespace SD
292} // namespace Differentiation
293
294/* --- Explicit instantiations --- */
295
296# include "symengine_tensor_operations.inst"
297
299
300#endif // DEAL_II_WITH_SYMENGINE
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
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)
const InputIterator OutputIterator out
Definition parallel.h:167