1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 \*---------------------------------------------------------------------------*/
32 #include "PODEigenBase.H"
33 #include "volFields.H"
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 void Foam::PODEigenBase::calcEigenBase(const scalarSquareMatrix& orthMatrix)
40 // Calculate eigen-values
42 EigenSolver<scalar> eigenSolver(orthMatrix);
46 SortableList<scalar> sortedList(orthMatrix.n());
48 forAll (sortedList, i)
50 sortedList[i] = eigenSolver.eigenValue(i);
53 // Sort will sort the values in descending order and insert values
57 forAllReverse(sortedList, i)
59 eigenValues_[n] = sortedList[i];
63 new scalarField(eigenSolver.eigenVector(sortedList.indices()[i]))
69 // Assemble cumulative relative eigen-values
70 cumEigenValues_[0] = eigenValues_[0];
72 // Assemble accumulated normalised eigenvalues
73 for (label i = 1; i < cumEigenValues_.size(); i++)
75 cumEigenValues_[i] = cumEigenValues_[i - 1] + eigenValues_[i];
79 cumEigenValues_ /= sum(eigenValues_);
82 // for (label i = 0; i < orthMatrix.m(); i++)
84 // const scalarField& eVector = eigenVectors_[i];
86 // Info<< "Scalar product: "
87 // << eigenValues_[i]*eVector
90 // scalarField vp(orthMatrix.m(), 0);
96 // vp[i] += orthMatrix[i][j]*eVector[j];
100 // Info << "Vector product: " << vp << nl << endl;
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 // Construct given a list of fields
108 Foam::PODEigenBase::PODEigenBase(const PtrList<volScalarField>& snapshots)
110 eigenValues_(snapshots.size()),
111 cumEigenValues_(snapshots.size()),
112 eigenVectors_(snapshots.size())
114 // Calculate the snapshot of the field with all available fields
115 label nSnapshots = snapshots.size();
117 scalarSquareMatrix orthMatrix(nSnapshots);
119 for (label snapI = 0; snapI < nSnapshots; snapI++)
121 for (label snapJ = 0; snapJ <= snapI; snapJ++)
123 // Calculate the inner product and insert it into the matrix
124 orthMatrix[snapI][snapJ] =
133 orthMatrix[snapJ][snapI] = orthMatrix[snapI][snapJ];
135 // Info << "Product: " << orthMatrix[snapI][snapJ]
138 // orthMatrix[snapI][snapJ]/
140 // Foam::sqrt(sumSqr(snapshots[snapI]))*
141 // Foam::sqrt(sumSqr(snapshots[snapJ]))
148 calcEigenBase(orthMatrix);
152 // ************************************************************************* //