Loading...
Searching...
No Matches
incrementalPOD.H
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-------------------------------------------------------------------------------
12License
13 This file is part of ITHACA-FV
14 ITHACA-FV is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Lesser General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18 ITHACA-FV is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 You should have received a copy of the GNU Lesser General Public License
23 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
24Class
25 incrementalPOD
26Description
27 Implementation of a incremental POD decomposition of a general field
28SourceFiles
29 incrementalPOD.C
30\*---------------------------------------------------------------------------*/
31
36
37#ifndef INCREMENTALPOD_H
38#define INCREMENTALPOD_H
39
40#include "fvCFD.H"
41#include "ITHACAutilities.H"
42#include "ITHACAstream.H"
43#include "ITHACAparameters.H"
44#include "Foam2Eigen.H"
45#include "EigenFunctions.H"
46#include "Modes.H"
47#pragma GCC diagnostic push
48#pragma GCC diagnostic ignored "-Wold-style-cast"
49#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
50#include <Spectra/GenEigsSolver.h>
51#include <Spectra/SymEigsSolver.h>
52#include <Eigen/Eigen>
53#include <unsupported/Eigen/SparseExtra>
54#pragma GCC diagnostic pop
55
56/*---------------------------------------------------------------------------*\
57 Class incrementalPOD Declaration
58\*---------------------------------------------------------------------------*/
59
63
64template<class Type, template<class> class PatchField, class GeoMesh>
65class incrementalPOD : public Modes<Type, PatchField, GeoMesh>
66{
67 public:
68
70 double tolleranceSVD = 0;
71
73 int rank = 0;
74
76 word PODnorm;
77
79 Eigen::VectorXd massVector;
80
82 Eigen::VectorXd singularValues;
83
85 word outputFolder = "./ITHACAoutput/incrementalPOD/";
86
88
91
92 //--------------------------------------------------------------------------
99 incrementalPOD(GeometricField<Type, PatchField, GeoMesh>& snapshot,
100 double _tol, word _PODnorm);
101
104
105 //--------------------------------------------------------------------------
110 void initialize(GeometricField<Type, PatchField, GeoMesh>& snapshot);
111
112 //--------------------------------------------------------------------------
117 void addSnapshot(GeometricField<Type, PatchField, GeoMesh>& snapshot);
118
119 //--------------------------------------------------------------------------
122 void fillPtrList();
123
124 //--------------------------------------------------------------------------
131 Eigen::VectorXd project(
132 GeometricField<Type, PatchField, GeoMesh>& inputField,
133 label numberOfModes = 0);
134
135 //--------------------------------------------------------------------------
144 GeometricField<Type, PatchField, GeoMesh> reconstruct(
145 GeometricField<Type, PatchField, GeoMesh>& inputField,
146 Eigen::MatrixXd Coeff,
147 word Name);
148
149 //--------------------------------------------------------------------------
157 GeometricField<Type, PatchField, GeoMesh> projectSnapshot(
158 GeometricField<Type, PatchField, GeoMesh>& snapshot,
159 label numberOfModes = 0);
160
161 //--------------------------------------------------------------------------
168 void projectSnapshots(
169 PtrList<GeometricField<Type, PatchField, GeoMesh>> snapshots,
170 PtrList<GeometricField<Type, PatchField, GeoMesh>>& projSnapshots,
171 label numberOfModes = 0);
172
173 //--------------------------------------------------------------------------
176 void writeModes();
177};
178
181
182namespace ITHACAPOD
183{
184//--------------------------------------------------------------------------
191 Eigen::MatrixXd& matrix,
192 Eigen::VectorXd& weights)
193{
194 M_Assert(matrix.rows() == weights.rows(),
195 "Matrix and weights must have the same number of rows");
196 Eigen::MatrixXd Ortho = matrix;
197 Ortho = matrix;
198
199 for (label i = 0; i < matrix.cols(); i++)
200 {
201 for (label k = 0; k < i; k++)
202 {
203 double num = Ortho.col(k).transpose() * weights.asDiagonal()
204 * matrix.col(i);
205 double den = (Ortho.col(k).transpose() * weights.asDiagonal()
206 * Ortho.col(k));
207 double fact = num / den;
208 Ortho.col(i) -= fact * Ortho.col(k) ;
209 }
210
211 Ortho.col(i).normalize();
212 }
213
214 matrix = Ortho;
215};
216}
217// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218
219#endif
Header file of the EigenFunctions class.
Header file of the Foam2Eigen class.
#define M_Assert(Expr, Msg)
Header file of the ITHACAstream class, it contains the implementation of several methods for input ou...
Header file of the ITHACAutilities namespace.
Header file of the Modes class.
Implementation of a container class derived from PtrList.
Definition Modes.H:69
Implementation of a incremental POD algorithm according to Oxberry et al.
void addSnapshot(GeometricField< Type, PatchField, GeoMesh > &snapshot)
Add a snapshot to the POD space.
void initialize(GeometricField< Type, PatchField, GeoMesh > &snapshot)
Initialize the incremental POD algorithm.
void fillPtrList()
Fill the POD modes prtList from the Eigen matrix.
Eigen::VectorXd singularValues
Vector of the singular values.
void writeModes()
Write to modes to file.
void projectSnapshots(PtrList< GeometricField< Type, PatchField, GeoMesh > > snapshots, PtrList< GeometricField< Type, PatchField, GeoMesh > > &projSnapshots, label numberOfModes=0)
Project a list of snapshots onto the reduced space.
Eigen::VectorXd project(GeometricField< Type, PatchField, GeoMesh > &inputField, label numberOfModes=0)
Project a field into the reduced space.
GeometricField< Type, PatchField, GeoMesh > reconstruct(GeometricField< Type, PatchField, GeoMesh > &inputField, Eigen::MatrixXd Coeff, word Name)
Reconstruct a field from the reduced coefficients.
word outputFolder
Folder where the modes and singular values are saved.
incrementalPOD()
Constructors.
~incrementalPOD()
Destructor.
double tolleranceSVD
Tollerance for the incremental SVD.
Eigen::VectorXd massVector
Vector of the cells volumes.
int rank
Rank of the reduced space.
GeometricField< Type, PatchField, GeoMesh > projectSnapshot(GeometricField< Type, PatchField, GeoMesh > &snapshot, label numberOfModes=0)
Project a snapshot onto the POD space.
word PODnorm
POD norm used for projection. It can be L2 or Frobenius.
incrementalPOD< vector, fvPatchField, volMesh > vectorIncrementalPOD
incrementalPOD< scalar, fvPatchField, volMesh > scalarIncrementalPOD
namespace for the computation of the POD, it exploits bot the method of snapshots and SVD.
void weightedGramSchmidt(Eigen::MatrixXd &matrix, Eigen::VectorXd &weights)
Weighted Gram-Schmidt orthogonalization.
label i
Definition pEqn.H:46