Reference documentation for deal.II version 9.4.1
\(\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// Copyright (C) 2016 - 2020 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE at
12// the top level of the deal.II distribution.
13//
14// ---------------------------------------------------------------------
15
16
17#include <deal.II/base/config.h>
18
19#ifdef DEAL_II_WITH_SYMENGINE
20
22# include <deal.II/base/tensor.h>
24
30
32
33namespace Differentiation
34{
35 namespace SD
36 {
37 // --- Symbolic variable creation ---
38
39 namespace internal
40 {
41 namespace
42 {
43 template <int rank>
44 std::string
45 make_index_string(const TableIndices<rank> &indices)
46 {
47 std::string out;
48 for (unsigned int i = 0; i < rank; ++i)
49 out += std::to_string(indices[i]);
50 return out;
51 }
52
53
54 template <int rank, int dim>
55 struct Symbol_Tensor;
56
57
58 template <int rank, int dim>
59 struct Symbol_Tensor
60 {
62 create(const std::string &sym)
63 {
65 for (unsigned int i = 0; i < out.n_independent_components; ++i)
66 {
67 const TableIndices<rank> indices(
69 out[indices] = Expression(sym + std::string("_") +
70 internal::make_index_string(indices));
71 }
72 return out;
73 }
74 };
75
76
77 template <int dim>
78 struct Symbol_Tensor<0, dim>
79 {
81 create(const std::string &sym)
82 {
83 return make_symbol(sym);
84 }
85 };
86
87
88 template <int rank, int dim>
89 struct Symbol_SymmetricTensor;
90
91
92 template <int rank, int dim>
93 struct Symbol_SymmetricTensor
94 {
96 create(const std::string &sym)
97 {
99 for (unsigned int i = 0; i < out.n_independent_components; ++i)
100 {
101 const TableIndices<rank> indices(
103 out[indices] = Expression(sym + std::string("_") +
104 internal::make_index_string(indices));
105 }
106 return out;
107 }
108 };
109
110
111 template <int dim>
112 struct Symbol_SymmetricTensor<4, dim>
113 {
115 create(const std::string &sym)
116 {
118 for (unsigned int i = 0;
119 i < SymmetricTensor<2, dim>::n_independent_components;
120 ++i)
121 for (unsigned int j = 0;
122 j < SymmetricTensor<2, dim>::n_independent_components;
123 ++j)
124 {
125 const TableIndices<4> indices =
126 make_rank_4_tensor_indices<dim>(i, j);
127 out[indices] =
128 Expression(sym + std::string("_") +
129 internal::make_index_string(indices));
130 }
131 return out;
132 }
133 };
134
135
136 template <int rank, int dim>
137 struct Symbol_Function_Tensor;
138
139
140 template <int rank, int dim>
141 struct Symbol_Function_Tensor
142 {
144 create(const std::string & sym,
145 const types::substitution_map &arguments)
146 {
148 const types::symbol_vector args =
150 for (unsigned int i = 0; i < out.n_independent_components; ++i)
151 {
152 const TableIndices<rank> indices(
154 out[indices] =
155 Expression(sym + std::string("_") +
156 internal::make_index_string(indices),
157 args);
158 }
159 return out;
160 }
161 };
162
163
164 template <int dim>
165 struct Symbol_Function_Tensor<0, dim>
166 {
168 create(const std::string & sym,
169 const types::substitution_map &arguments)
170 {
171 return make_symbolic_function(sym, arguments);
172 }
173 };
174
175
176 template <int rank, int dim>
177 struct Symbol_Function_SymmetricTensor;
178
179
180 template <int rank, int dim>
181 struct Symbol_Function_SymmetricTensor
182 {
184 create(const std::string & sym,
185 const types::substitution_map &arguments)
186 {
188 const types::symbol_vector args =
190 for (unsigned int i = 0; i < out.n_independent_components; ++i)
191 {
192 const TableIndices<rank> indices(
194 out[indices] =
195 Expression(sym + std::string("_") +
196 internal::make_index_string(indices),
197 args);
198 }
199 return out;
200 }
201 };
202
203
204 template <int dim>
205 struct Symbol_Function_SymmetricTensor<4, dim>
206 {
208 create(const std::string & sym,
209 const types::substitution_map &arguments)
210 {
212 const types::symbol_vector args =
214 for (unsigned int i = 0;
215 i < SymmetricTensor<2, dim>::n_independent_components;
216 ++i)
217 for (unsigned int j = 0;
218 j < SymmetricTensor<2, dim>::n_independent_components;
219 ++j)
220 {
221 const TableIndices<4> indices =
222 make_rank_4_tensor_indices<dim>(i, j);
223 out[indices] =
224 Expression(sym + std::string("_") +
225 internal::make_index_string(indices),
226 args);
227 }
228 return out;
229 }
230 };
231 } // namespace
232 } // namespace internal
233
234
235 template <int dim>
237 make_vector_of_symbols(const std::string &sym)
238 {
239 return internal::Symbol_Tensor<1, dim>::create(sym);
240 }
241
242
243# ifndef DOXYGEN
244 template <int dim>
246 make_vector_of_symbolic_functions(const std::string & sym,
247 const types::substitution_map &arguments)
248 {
249 return internal::Symbol_Function_Tensor<1, dim>::create(sym, arguments);
250 }
251# endif
252
253
254 template <int rank, int dim>
256 make_tensor_of_symbols(const std::string &sym)
257 {
258 return internal::Symbol_Tensor<rank, dim>::create(sym);
259 }
260
261
262 template <int rank, int dim>
264 make_symmetric_tensor_of_symbols(const std::string &sym)
265 {
266 return internal::Symbol_SymmetricTensor<rank, dim>::create(sym);
267 }
268
269
270# ifndef DOXYGEN
271 template <int rank, int dim>
273 make_tensor_of_symbolic_functions(const std::string & sym,
274 const types::substitution_map &arguments)
275 {
276 return internal::Symbol_Function_Tensor<rank, dim>::create(sym,
277 arguments);
278 }
279
280
281 template <int rank, int dim>
284 const std::string & sym,
285 const types::substitution_map &arguments)
286 {
287 return internal::Symbol_Function_SymmetricTensor<rank, dim>::create(
288 sym, arguments);
289 }
290# endif // DOXYGEN
291
292 } // namespace SD
293} // namespace Differentiation
294
295/* --- Explicit instantiations --- */
296
297# include "symengine_tensor_operations.inst"
298
300
301#endif // DEAL_II_WITH_SYMENGINE
static constexpr TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
static constexpr unsigned int n_independent_components
Definition: tensor.h:503
static constexpr TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
static constexpr unsigned int n_independent_components
Definition: tensor.h:528
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
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)