v0.16.3
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 */
85 Fun<double> f);
89 Fun<double> f);
90
91/**
92 * @copydoc EigenMatrix::getMat
93 */
96
97/**
98 * @copydoc EigenMatrix::getMat
99 */
106 Fun<double> f);
110 Fun<double> f);
111
112/**
113 * @brief Get the Mat object
114 *
115 * \f[
116 * \mathbf{B} = f(\mathbf{A})
117 * \f]
118 *
119 * \f[
120 * B_{ij} = \sum_{a}^d f(\lambda^a) n^a_i n^a_j
121 * \f]
122 * where \f$a\f$ is eigen value number.
123 *
124 * @param t_val eigen values
125 * @param t_vec eigen vector
126 * @param f function
127 * @return FTensor::Tensor2_symmetric<double, 3>
128 */
129template <typename A, typename B>
130auto inline getMat(A &&t_val, B &&t_vec, Fun<double> f) {
131 return getMatSpecial(std::forward<A>(t_val), std::forward<B>(t_vec), f);
132}
133
134/**
135 * @copydoc EigenMatrix::getDiffMat
136 */
138 Vec<double, 3> &t_vec,
139 Fun<double> f, Fun<double> d_f,
140 const int nb);
141/**
142 * @copydoc EigenMatrix::getDiffMat
143 */
146 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
147 Fun<double> d_f, const int nb);
151 Fun<double> f, Fun<double> d_f, const int nb);
155 Fun<double> f, Fun<double> d_f, const int nb);
156
157/**
158 * @copydoc EigenMatrix::getDiffMat
159 */
161 Vec<double, 2> &t_vec,
162 Fun<double> f, Fun<double> d_f,
163 const int nb);
164
165/**
166 * @copydoc EigenMatrix::getDiffMat
167 */
170 Vec<FTensor::PackPtr<double *, 4>, 2> &t_vec, Fun<double> f,
171 Fun<double> d_f, const int nb);
175 Fun<double> f, Fun<double> d_f, const int nb);
179 Fun<double> f, Fun<double> d_f, const int nb);
180
181/**
182 * @brief Get the Diff Mat object
183 *
184 * \f[
185 * P_{ijkl} = \frac{\partial B_{ij}}{\partial A_{kl}}
186 * \f]
187 *
188 * \note Eigen vector are in rows.
189 *
190 * @param t_val eigen values
191 * @param t_vec eigen vector
192 * @param f function
193 * @param d_f directive of function
194 * @param nb number of nonequal eigen valuse
195 * @return FTensor::Ddg<double, 3, 3>
196 */
197template <typename A, typename B>
198inline auto getDiffMat(A &&t_val, B &&t_vec, Fun<double> f, Fun<double> d_f,
199 const int nb) {
200 return getDiffMatSpecial(std::forward<A>(t_val), std::forward<B>(t_vec), f,
201 d_f, nb);
202}
203
204/**
205 * @copydoc EigenMatrix::getDiffDiffMat
206 */
208getDiffDiffMatSpecial(Val<double, 3> &t_val, Vec<double, 3> &t_vec,
209 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
210 FTensor::Tensor2_symmetric<double, 3> &t_S, const int nb);
211
212/**
213 * @copydoc EigenMatrix::getDiffDiffMat
214 */
217 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
218 Fun<double> d_f, Fun<double> dd_f,
219 FTensor::Tensor2_symmetric<double, 3> &t_S, const int nb);
223 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
225 const int nb);
229 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
231 const int nb);
232
233/**
234 * @copydoc EigenMatrix::getDiffDiffMat
235 */
237getDiffDiffMatSpecial(Val<double, 3> &t_val, Vec<double, 3> &t_vec,
238 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
239 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
240/**
241 * @copydoc EigenMatrix::getDiffDiffMat
242 */
245 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
246 Fun<double> d_f, Fun<double> dd_f,
247 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
251 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
252 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
256 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
257 FTensor::Tensor2<double, 3, 3> &t_S, const int nb);
258
259/**
260 * @copydoc EigenMatrix::getDiffDiffMat
261 */
264 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
265 Fun<double> d_f, Fun<double> dd_f,
267 const int nb);
270 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
271 Fun<double> d_f, Fun<double> dd_f,
273 const int nb);
276 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
277 Fun<double> d_f, Fun<double> dd_f,
279 const int nb);
282 Vec<FTensor::PackPtr<double *, 9>, 3> &t_vec, Fun<double> f,
283 Fun<double> d_f, Fun<double> dd_f,
285 const int nb);
288 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
289 Fun<double> d_f, Fun<double> dd_f,
291 const int nb);
294 Vec<FTensor::CursorPtr<double *, 9>, 3> &t_vec, Fun<double> f,
295 Fun<double> d_f, Fun<double> dd_f,
297 const int nb);
298
299/**
300 * @copydoc EigenMatrix::getDiffDiffMat
301 */
303getDiffDiffMatSpecial(Val<double, 2> &t_val, Vec<double, 2> &t_vec,
304 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
305 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
306
307/**
308 * @copydoc EigenMatrix::getDiffDiffMat
309 */
311getDiffDiffMatSpecial(Val<double, 2> &t_val, Vec<double, 2> &t_vec,
312 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
313 FTensor::Tensor2_symmetric<double, 2> &t_S, const int nb);
314
315/**
316 * @copydoc EigenMatrix::getDiffDiffMat
317 */
321 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
322 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
326 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
327 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
331 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
332 FTensor::Tensor2<double, 2, 2> &t_S, const int nb);
333
334/**
335 * @copydoc EigenMatrix::getDiffDiffMat
336 */
340 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
341 FTensor::Tensor2_symmetric<double, 2> &t_S, const int nb);
345 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
347 const int nb);
351 Fun<double> f, Fun<double> d_f, Fun<double> dd_f,
353 const int nb);
354
355/**
356 * @copydoc EigenMatrix::getDiffDiffMat
357 */
360 Vec<FTensor::PackPtr<double *, 4>, 2> &t_vec, Fun<double> f,
361 Fun<double> d_f, Fun<double> dd_f,
363 const int nb);
366 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
367 Fun<double> d_f, Fun<double> dd_f,
369 const int nb);
372 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
373 Fun<double> d_f, Fun<double> dd_f,
375 const int nb);
378 Vec<FTensor::PackPtr<double *, 4>, 2> &t_vec, Fun<double> f,
379 Fun<double> d_f, Fun<double> dd_f,
381 const int nb);
384 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
385 Fun<double> d_f, Fun<double> dd_f,
387 const int nb);
390 Vec<FTensor::CursorPtr<double *, 4>, 2> &t_vec, Fun<double> f,
391 Fun<double> d_f, Fun<double> dd_f,
393 const int nb);
394
395/**
396 * @brief Get the Diff Diff Mat object
397 *
398 * \f[
399 * LS_{klmn} =
400 * S_{ij} \frac{\partial^2 B_{ij}}{\partial A_{kl} \partial A_{mn} }
401 * \f]
402 *
403 * \note Eigen vector are in rows.
404 *
405 * @param t_val eigen values
406 * @param t_vec eigen vectors
407 * @param f function
408 * @param d_f directive of function
409 * @param dd_f second directive of function
410 * @param t_S S tensor
411 * @param nb number of nonzero eigen values
412 * @return FTensor::Ddg<double, 3, 3>
413 */
414template <typename A, typename B, typename C>
415inline auto getDiffDiffMat(A &&t_val, B &&t_vec, Fun<double> f, Fun<double> d_f,
416 Fun<double> dd_f, C &&t_S, const int nb) {
417 return getDiffDiffMatSpecial(std::forward<A>(t_val), std::forward<B>(t_vec),
418 f, d_f, dd_f, std::forward<C>(t_S), nb);
419}
420
421} // 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