1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
29 \*---------------------------------------------------------------------------*/
31 #include "PODEigenBase.H"
32 #include "volFields.H"
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 void Foam::PODEigenBase::calcEigenBase(const scalarSquareMatrix& orthMatrix)
39 // Calculate eigen-values
41 EigenSolver<scalar> eigenSolver(orthMatrix);
45 SortableList<scalar> sortedList(orthMatrix.n());
47 forAll (sortedList, i)
49 sortedList[i] = eigenSolver.eigenValue(i);
52 // Sort will sort the values in descending order and insert values
56 forAllReverse(sortedList, i)
58 eigenValues_[n] = sortedList[i];
62 new scalarField(eigenSolver.eigenVector(sortedList.indices()[i]))
68 // Assemble cumulative relative eigen-values
69 cumEigenValues_[0] = eigenValues_[0];
71 // Assemble accumulated normalised eigenvalues
72 for (label i = 1; i < cumEigenValues_.size(); i++)
74 cumEigenValues_[i] = cumEigenValues_[i - 1] + eigenValues_[i];
78 cumEigenValues_ /= sum(eigenValues_);
81 // for (label i = 0; i < orthMatrix.m(); i++)
83 // const scalarField& eVector = eigenVectors_[i];
85 // Info<< "Scalar product: "
86 // << eigenValues_[i]*eVector
89 // scalarField vp(orthMatrix.m(), 0);
95 // vp[i] += orthMatrix[i][j]*eVector[j];
99 // Info << "Vector product: " << vp << nl << endl;
104 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 // Construct given a list of fields
107 Foam::PODEigenBase::PODEigenBase(const PtrList<volScalarField>& snapshots)
109 eigenValues_(snapshots.size()),
110 cumEigenValues_(snapshots.size()),
111 eigenVectors_(snapshots.size())
113 // Calculate the snapshot of the field with all available fields
114 label nSnapshots = snapshots.size();
116 scalarSquareMatrix orthMatrix(nSnapshots);
118 for (label snapI = 0; snapI < nSnapshots; snapI++)
120 for (label snapJ = 0; snapJ <= snapI; snapJ++)
122 // Calculate the inner product and insert it into the matrix
123 orthMatrix[snapI][snapJ] =
132 orthMatrix[snapJ][snapI] = orthMatrix[snapI][snapJ];
134 // Info << "Product: " << orthMatrix[snapI][snapJ]
137 // orthMatrix[snapI][snapJ]/
139 // Foam::sqrt(sumSqr(snapshots[snapI]))*
140 // Foam::sqrt(sumSqr(snapshots[snapJ]))
147 calcEigenBase(orthMatrix);
151 // ************************************************************************* //