v0.16.0
Loading...
Searching...
No Matches
MatrixFunction.hpp
Go to the documentation of this file.
1/** \file FunctionMatrix.hpp
2 \brief Get function from matrix
3 \ingroup ftensor
4
5 For reference see \cite miehe2001algorithms
6
7 Usage:
8
9 To calculate exponent of matrix, first and second derivatives
10 \code
11 auto f = [](double v) { return exp(v); };
12 auto d_f = [](double v) { return exp(v); };
13 auto dd_f = [](double v) { return exp(v); };
14 \endcode
15
16 Calculate matrix here t_L are vector of eigen values, and t_N is matrix of
17 eigen vectors.
18 \code
19 auto t_A = EigenMatrix::getMat(t_L, t_N, f);
20 \endcode
21 Return t_A is symmetric tensor rank two.
22
23 Calculate derivative
24 \code
25 auto t_P = EigenMatrix::getDiffMat(t_L, t_N, f, d_f ,nb);
26 \endcode
27 where return t_SL is 4th order tensor (symmetry on first two and
28 second to indices, i.e. minor symmetrise)
29
30 Calculate second derivative, L, such that S:L, for given S,
31 \code
32 FTensor::Tensor2<double, 3, 3> t_S{
33
34 1., 0., 0.,
35
36 0., 1., 0.,
37
38 0., 0., 1.};
39
40 auto t_SL = EigenMatrix::getDiffDiffMat( t_L, t_N, f, d_f, dd_f, t_S, nb)
41 \endcode
42 where return t_SL is 4th order tensor (symmetry on first two and
43 second to indices, i.e. minor symmetrise)
44
45 You can calculate eigen values using lapack.
46
47 Eiegn values should be sorted such that unique values are first, and last eiegn
48 value is reapitting. For example if eiegn values are \f[ \lambda = \{1,1,2} \f]
49 should be sorted such that
50 \f[
51 \lambda = \{1,2,1}
52 \f]
53 Eigen vectors should be updated, such that order of eigen vectors follow order
54 of eigen values.
55
56 *
57 */
58
59#pragma once
60
61namespace EigenMatrix {
62
63template <typename T, int Dim> using Val = const FTensor::Tensor1<T, Dim>;
64template <typename T, int Dim> using Vec = const FTensor::Tensor2<T, Dim, Dim>;
65template <typename T, int Dim>
67
68template <typename T> using Fun = boost::function<T(const T)>;
69
70/**
71 * @copydoc EigenMatrix::getMat
72 */
75
76/**
77 * @copydoc EigenMatrix::getMat
78 */
82
86
90
91/**
92 * @copydoc EigenMatrix::getMat
93 */
96
97/**
98 * @copydoc EigenMatrix::getMat
99 */
103
107
111
114
115/**
116 * @brief Get the Mat object
117 *
118 * \f[
119 * \mathbf{B} = f(\mathbf{A})
120 * \f]
121 *
122 * \f[
123 * B_{ij} = \sum_{a}^d f(\lambda^a) n^a_i n^a_j
124 * \f]
125 * where \f$a\f$ is eigen value number.
126 *
127 * @param t_val eigen values
128 * @param t_vec eigen vector
129 * @param f function
130 * @return FTensor::Tensor2_symmetric<double, 3>
131 */
132template <typename A, typename B>
133auto inline getMat(A &&t_val, B &&t_vec, Fun<double> f) {
134 return getMatSpecial(std::forward<A>(t_val), std::forward<B>(t_vec), f);
135}
136
137/**
138 * @copydoc EigenMatrix::getDiffMat
139 */
141 Vec<double, 3> &t_vec,
142 Fun<double> f, Fun<double> d_f,
143 const int nb);
144/**
145 * @copydoc EigenMatrix::getDiffMat
146 */
149 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
150 Fun<double> d_f, const int nb);
153 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
154 Fun<double> d_f, const int nb);
157 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
158 Fun<double> d_f, const int nb);
159
160/**
161 * @copydoc EigenMatrix::getDiffMat
162 */
164 Vec<double, 2> &t_vec,
165 Fun<double> f, Fun<double> d_f,
166 const int nb);
167
168/**
169 * @copydoc EigenMatrix::getDiffMat
170 */
173 Vec<FTensor::PackPtr<double *, 4>, 2> &t_vec, Fun<double> f,
174 Fun<double> d_f, const int nb);
177 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
178 Fun<double> d_f, const int nb);
181 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
182 Fun<double> d_f, const int nb);
183
184/**
185 * @brief Get the Diff Mat object
186 *
187 * \f[
188 * P_{ijkl} = \frac{\partial B_{ij}}{\partial A_{kl}}
189 * \f]
190 *
191 * \note Eigen vector are in rows.
192 *
193 * @param t_val eigen values
194 * @param t_vec eigen vector
195 * @param f function
196 * @param d_f directive of function
197 * @param nb number of nonequal eigen valuse
198 * @return FTensor::Ddg<double, 3, 3>
199 */
200template <typename A, typename B>
201inline auto getDiffMat(A &&t_val, B &&t_vec, Fun<double> f, Fun<double> d_f,
202 const int nb) {
203 return getDiffMatSpecial(std::forward<A>(t_val), std::forward<B>(t_vec), f,
204 d_f, nb);
205}
206
207/**
208 * @copydoc EigenMatrix::getDiffDiffMat
209 */
211getDiffDiffMatSpecial(Val<double, 3> &t_val, Vec<double, 3> &t_vec,
212 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
213 FTensor::Tensor2_symmetric<double, 3> &t_S, const int nb);
214
215/**
216 * @copydoc EigenMatrix::getDiffDiffMat
217 */
221 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
222 FTensor::Tensor2_symmetric<double, 3> &t_S, const int nb);
226 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
227 FTensor::Tensor2_symmetric<double, 3> &t_S, const int nb);
231 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
232 FTensor::Tensor2_symmetric<double, 3> &t_S, const int nb);
233
234/**
235 * @copydoc EigenMatrix::getDiffDiffMat
236 */
238getDiffDiffMatSpecial(Val<double, 3> &t_val, Vec<double, 3> &t_vec,
239 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
240 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
241/**
242 * @copydoc EigenMatrix::getDiffDiffMat
243 */
247 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
248 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
252 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
253 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
257 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
258 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
259
260/**
261 * @copydoc EigenMatrix::getDiffDiffMat
262 */
265 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
266 Fun<double> d_f, Fun<double> dd_f,
268 const int nb);
271 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
272 Fun<double> d_f, Fun<double> dd_f,
274 const int nb);
277 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
278 Fun<double> d_f, Fun<double> dd_f,
280 const int nb);
283 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
284 Fun<double> d_f, Fun<double> dd_f,
286 const int nb);
289 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
290 Fun<double> d_f, Fun<double> dd_f,
292 const int nb);
295 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
296 Fun<double> d_f, Fun<double> dd_f,
298 const int nb);
299
300/**
301 * @copydoc EigenMatrix::getDiffDiffMat
302 */
304getDiffDiffMatSpecial(Val<double, 2> &t_val, Vec<double, 2> &t_vec,
305 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
306 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
307
308/**
309 * @copydoc EigenMatrix::getDiffDiffMat
310 */
312getDiffDiffMatSpecial(Val<double, 2> &t_val, Vec<double, 2> &t_vec,
313 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
314 FTensor::Tensor2_symmetric<double, 2> &t_S, const int nb);
315
316/**
317 * @copydoc EigenMatrix::getDiffDiffMat
318 */
322 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
323 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
327 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
328 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
332 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
333 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
334
335/**
336 * @copydoc EigenMatrix::getDiffDiffMat
337 */
341 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
342 FTensor::Tensor2_symmetric<double, 2> &t_S, const int nb);
346 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
347 FTensor::Tensor2_symmetric<double, 2> &t_S, const int nb);
351 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
352 FTensor::Tensor2_symmetric<double, 2> &t_S, const int nb);
353
354/**
355 * @copydoc EigenMatrix::getDiffDiffMat
356 */
359 Vec<FTensor::PackPtr<double *, 4>, 2> &t_vec, Fun<double> f,
360 Fun<double> d_f, Fun<double> dd_f,
362 const int nb);
365 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
366 Fun<double> d_f, Fun<double> dd_f,
368 const int nb);
371 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
372 Fun<double> d_f, Fun<double> dd_f,
374 const int nb);
377 Vec<FTensor::PackPtr<double *, 4>, 2> &t_vec, Fun<double> f,
378 Fun<double> d_f, Fun<double> dd_f,
380 const int nb);
383 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
384 Fun<double> d_f, Fun<double> dd_f,
386 const int nb);
389 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
390 Fun<double> d_f, Fun<double> dd_f,
392 const int nb);
393
394/**
395 * @brief Get the Diff Diff Mat object
396 *
397 * \f[
398 * LS_{klmn} =
399 * S_{ij} \frac{\partial^2 B_{ij}}{\partial A_{kl} \partial A_{mn} }
400 * \f]
401 *
402 * \note Eigen vector are in rows.
403 *
404 * @param t_val eigen values
405 * @param t_vec eigen vectors
406 * @param f function
407 * @param d_f directive of function
408 * @param dd_f second directive of function
409 * @param t_S S tensor
410 * @param nb number of nonzero eigen values
411 * @return FTensor::Ddg<double, 3, 3>
412 */
413template <typename A, typename B, typename C>
414inline auto getDiffDiffMat(A &&t_val, B &&t_vec, Fun<double> f, Fun<double> d_f,
415 Fun<double> dd_f, C &&t_S, const int nb) {
416 return getDiffDiffMatSpecial(std::forward<A>(t_val), std::forward<B>(t_vec),
417 f, d_f, dd_f, std::forward<C>(t_S), nb);
418}
419
420} // namespace EigenMatrix
const FTensor::Tensor1< T, Dim > Val
boost::function< T(const T)> Fun
const FTensor::Tensor2< T, Dim, Dim > Vec
auto getMat(A &&t_val, B &&t_vec, Fun< double > f)
Get the Mat object.
auto getDiffMat(A &&t_val, B &&t_vec, Fun< double > f, Fun< double > d_f, const int nb)
Get the Diff Mat object.
FTensor::Ddg< double, 3, 3 > getDiffMatSpecial(Val< double, 3 > &t_val, Vec< double, 3 > &t_vec, Fun< double > f, Fun< double > d_f, const int nb)
Get the Diff Mat object.
FTensor::Ddg< double, 3, 3 > getDiffDiffMatSpecial(Val< double, 3 > &t_val, Vec< double, 3 > &t_vec, Fun< double > f, Fun< double > d_f, Fun< double > dd_f, FTensor::Tensor2< double, 3, 3 > &t_S, const int nb)
Get the Diff Diff Mat object.
FTensor::Tensor2_symmetric< double, 3 > getMatSpecial(Val< double, 3 > &t_val, Vec< double, 3 > &t_vec, Fun< double > f)
Get the Mat object.
auto getDiffDiffMat(A &&t_val, B &&t_vec, Fun< double > f, Fun< double > d_f, Fun< double > dd_f, C &&t_S, const int nb)
Get the Diff Diff Mat object.
constexpr AssemblyType A