MaMiCo 1.2
Loading...
Searching...
No Matches
POD.h
1// This file is part of the Mamico project. For conditions of distribution
2// and use, please see the copyright notice in Mamico's main folder, or at
3// www5.in.tum.de/mamico
4
5#pragma once
6#include <Eigen/Dense>
7#include <Eigen/Eigenvalues>
8#include <string>
9#include <vector>
10
11// #define DEBUG_POD
12#include "coupling/filtering/interfaces/FilterInterface.h"
13
14namespace coupling {
15namespace filtering {
16template <unsigned int dim> class POD;
17}
18} // namespace coupling
19
24template <unsigned int dim> class coupling::filtering::POD : public coupling::filtering::FilterInterface<dim> {
25public:
26 POD(const std::vector<coupling::datastructures::CouplingCell<dim>*>& inputCellVector,
27 const std::vector<coupling::datastructures::CouplingCell<dim>*>& outputCellVector,
28#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
29 MPI_Comm comm,
30#endif
31 const std::array<bool, 7> filteredValues, int tws, int kmax)
32 : coupling::filtering::FilterInterface<dim>(inputCellVector, outputCellVector, filteredValues, "POD"), _timeWindowSize(tws), _kMax(kmax),
33 _cycleCounter(0), _spatialIndex(0), _t(0), _data(NULL), _C(NULL), _A(NULL), _A_T(NULL) {
34 int spatialSize = inputCellVector.size();
35 _data = new Eigen::MatrixXd[dim + 1]; // separate data matrices for: mass,
36 // momentum0, momentum1, momentum2
37 _C = new Eigen::MatrixXd[dim + 1];
38 _A = new Eigen::MatrixXd[dim + 1];
39 _A_T = new Eigen::MatrixXd[dim + 1];
40 for (unsigned int i = 0; i < dim + 1; i++) {
41 _data[i] = Eigen::MatrixXd::Constant(_timeWindowSize, spatialSize, (i == 0) ? 1 : 0);
42 }
43
44#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
45 // get MPI parameters
46 _comm = comm;
47 MPI_Comm_rank(comm, (int*)&_rank);
48 MPI_Comm_size(comm, (int*)&_commSize);
49#endif
50
51#ifdef DEBUG_POD
52 std::cout << " POD: Created Proper Orthogonal Decomposition instance." << std::endl;
53 // TODO selection of filtered properties
54 std::cout << " WARNING: Regardless of configuration, "
55 "POD always filters macroscopic mass and momentum."
56 << std::endl;
57#endif
58 }
59
60 ~POD() {
61 if (_data != NULL) {
62 delete[] _data;
63 _data = NULL;
64 }
65 if (_C != NULL) {
66 delete[] _C;
67 _C = NULL;
68 }
69 if (_A != NULL) {
70 delete[] _A;
71 _A = NULL;
72 }
73 if (_A_T != NULL) {
74 delete[] _A_T;
75 _A_T = NULL;
76 }
77
78#ifdef DEBUG_POD
79 std::cout << " POD: Deleted Proper Orthogonal Decomposition instance." << std::endl;
80#endif
81 }
82
83 void operator()();
84
85private:
86 unsigned int _timeWindowSize; // number of snapshots / coupling cycles taken
87 // into consideration for noise reduction
88 const unsigned int _kMax; // number of dominant eigenvalues
89 unsigned int _cycleCounter; // coupling cycle counter, indicates how many data
90 // snapshots are available already
91 unsigned int _spatialIndex; // cell counter, should run from zero to
92 // getLocalNumberCouplingCells()-1 within an
93 // iteration of ProcessInnerCouplingCell
94 unsigned int _t; // active temporal index, iterates cyclic between zero and
95 // _timeWindowSize
96 Eigen::MatrixXd* _data; // set of snapshots (sampled by transferStrategy)
97 Eigen::MatrixXd* _C; // temporal auto-correlation covariance matrix of _data
98 Eigen::MatrixXd* _A; // POD temporal modes / eigenvectors of C
99 Eigen::MatrixXd* _A_T; // Transpose of A
100
101#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
102 MPI_Comm _comm;
103 unsigned int _rank;
104 unsigned int _commSize;
105#endif
106};
107
108// include implementation of header
109#include "POD.cpph"
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
Definition FilterInterface.h:32
Definition POD.h:24
Definition FilterPipeline.h:21
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15