Loading...
Searching...
No Matches
EigenFunctions.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ██╗████████╗██╗ ██╗ █████╗ ██████╗ █████╗ ███████╗██╗ ██╗
3 ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██║ ██║
4 ██║ ██║ ███████║███████║██║ ███████║█████╗█████╗ ██║ ██║
5 ██║ ██║ ██╔══██║██╔══██║██║ ██╔══██║╚════╝██╔══╝ ╚██╗ ██╔╝
6 ██║ ██║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ╚████╔╝
7 ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝
8
9 * In real Time Highly Advanced Computational Applications for Finite Volumes
10 * Copyright (C) 2017 by the ITHACA-FV authors
11-------------------------------------------------------------------------------
12
13License
14 This file is part of ITHACA-FV
15
16 ITHACA-FV is free software: you can redistribute it and/or modify
17 it under the terms of the GNU Lesser General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
20
21 ITHACA-FV is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU Lesser General Public License for more details.
25
26 You should have received a copy of the GNU Lesser General Public License
27 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
28
29\*---------------------------------------------------------------------------*/
30
31#include "EigenFunctions.H"
32
33// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * * //
34
35// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36
38{
39void sortEigenvalues(Eigen::VectorXd& eigenvalues,
40 Eigen::MatrixXd& eigenvectors)
41{
42 labelList order;
43 scalarField eigenValues(eigenvalues.size());
44
45 for (label i = 0; i < eigenvalues.size(); i++)
46 {
47 eigenValues[i] = eigenvalues(i);
48 }
49
50 sortedOrder(eigenValues, order);
51 scalarField eigenValues2(eigenValues);
52
53 for (label i = 0; i < order.size(); i++)
54 {
55 eigenvalues(i) = eigenValues[order[order.size() - i - 1]];
56 }
57
58 Eigen::MatrixXd eigenvectors2 = eigenvectors;
59
60 for (label i = 0; i < eigenvalues.size(); i++)
61 {
62 for (label k = 0; k < eigenvalues.size(); k++)
63 {
64 eigenvectors2(i, k) = eigenvectors(k, order[order.size() - i - 1]);
65 }
66 }
67
68 eigenvectors = eigenvectors2;
69}
70
71
72Eigen::VectorXd ExpSpaced(double first, double last, int n)
73{
74 Eigen::VectorXd vector(n);
75 double m = (double) 1 / (n * 1.0 - 1);
76 double quotient = std::pow(last / first, m);
77 vector(0) = first;
78
79 for (int i = 1; i < n; i++)
80 {
81 vector(i) = vector(i - 1) * quotient;
82 }
83
84 return vector;
85}
86
87template <typename T>
88Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
89vectorTensorProduct(const Eigen::Matrix<T, Eigen::Dynamic, 1>&
90 g,
91 const Eigen::Tensor<T, 3 >& c,
92 const Eigen::Matrix<T, Eigen::Dynamic, 1>& a)
93{
94 int prodDim = c.dimension(0);
95 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> prod;
96 prod.resize(prodDim, 1);
97
98 for (int i = 0; i < prodDim; i++)
99 {
100 prod(i, 0) = g.transpose() *
101 SliceFromTensor(c, 0, i) * a;
102 }
103
104 return prod;
105}
106
107template Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>
109 const Eigen::Matrix<double, Eigen::Dynamic, 1>& g,
110 const Eigen::Tensor<double, 3 >& c,
111 const Eigen::Matrix<double, Eigen::Dynamic, 1>& a);
112
113template Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic>
115 const Eigen::Matrix<int, Eigen::Dynamic, 1>& g, const Eigen::Tensor<int, 3 >& c,
116 const Eigen::Matrix<int, Eigen::Dynamic, 1>& a);
117
118template Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic>
120 const Eigen::Matrix<float, Eigen::Dynamic, 1>& g,
121 const Eigen::Tensor<float, 3 >& c,
122 const Eigen::Matrix<float, Eigen::Dynamic, 1>& a);
123}
Header file of the EigenFunctions class.
Namespace to perform operation on Eigen objects.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > vectorTensorProduct(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &g, const Eigen::Tensor< T, 3 > &c, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &a)
A function that computes the product of g.T c a, where c is a third dim tensor.
Eigen::VectorXd ExpSpaced(double first, double last, int n)
Returns exponentially spaced vector.
void sortEigenvalues(Eigen::VectorXd &eigenvalues, Eigen::MatrixXd &eigenvectors)
sort eigenvalues
dimensionedVector & g
label i
Definition pEqn.H:46