POD basis computation using voloctree.
POD basis computation using voloctree.This example computes the POD basis starting from a database of simulations defined on the same mesh and reconstructs the first mode as a PODField object using the buildFieldWithCoeff function. Following the computation, both the POD Field with the mode and POD Mode object corresponding to the first mode are written on file in the example folder.
#include <array>
#if BITPIT_ENABLE_MPI
#include <mpi.h>
#endif
#include "pod.hpp"
using namespace bitpit;
{
std::vector<std::array<std::string,3>> vectorNames= pod.
getVectorNames();
int N = scalarNames.size();
for (int i=0; i<N; i++) {
std::cout << "L2 norm of " << field_name << " " << scalarNames[i] << " is "<< vecL2[i] << std::endl;
}
int M = vectorNames.size();
for (int i=N; i<N+M; i++) {
std::cout << "L2 norm of " << field_name << " " << vectorNames[i-N][0].substr(0,vectorNames[i-N][0].size()-2) << " is "<< vecL2[i] << std::endl;
}
}
void printMat (std::vector < std::vector<double>> mat)
{
std::cout << "mat = " << std::endl;
size_t M = mat.size();
size_t N = mat[0].size();
for (size_t i=0; i<M; i++) {
for (size_t j=0; j<N; j++) {
if (j == 0) {
std::cout << "[ "<< mat[i][j] ;
}
else if (j==(N-1)) {
std::cout << " , " << mat[i][j] << " ]" << std::endl;
}
else {
std::cout << " , " << mat[i][j] ;
}
if (N==1) {
std::cout << " ]" << std::endl;
}
}
}
}
void run()
{
for (int i=0; i<6; i++) {
pod.
addSnapshot(
"./data",
"test_set2."+std::to_string(i));
}
std::cout <<
"the number of modes is = " << pod.
getModeCount() << std::endl;
std::size_t N_sfields = names.size();
std::size_t N_vfiedls = namev.size();
std::size_t N_fields = N_sfields+N_vfiedls;
std::vector < std::vector<double>> recostructionCoeffs;
recostructionCoeffs.clear();
recostructionCoeffs.resize(N_fields, std::vector<double>(N_modes, 0.0));
for (std::size_t i = 0; i < N_fields; i++) {
recostructionCoeffs[i][0] = 1;
}
printL2norm(mode1_recon, pod, "mode 1");
std::vector < std::vector<double>> test_mat = pod.
projectField(mode1_recon);
std::cout << "the coefficient matrix of the projection on the first mode is " << std::endl;
printMat(test_mat);
pod.
write(mode1_recon,
"mode1_recon");
}
int main(int argc, char *argv[])
{
#if BITPIT_ENABLE_MPI
MPI_Init(&argc,&argv);
#endif
try {
run();
} catch (const std::exception &exception) {
log::cout() << exception.what();
exit(1);
}
#if BITPIT_ENABLE_MPI
MPI_Finalize();
#endif
}
The POD (Proper Orthogonal Decomposition) class provides an interface for defining POD object.
std::size_t getModeCount()
std::vector< std::array< std::string, 3 > > getVectorNames()
std::vector< std::string > getScalarNames()
void setMeshType(MeshType type)
void setStaticMesh(bool flag)
std::vector< double > fieldsl2norm(pod::PODField &snap)
void setMemoryMode(MemoryMode mode)
void write(const pod::PODField &snap, std::string file_name) const
void setDirectory(const std::string &directory)
void reconstructFields(pod::PODField &field, pod::PODField &recon)
void setUseMean(bool flag)
std::vector< std::vector< double > > projectField(pod::PODField &field)
void setWriteMode(WriteMode mode)
void setEnergyLevel(double energy)
void setName(const std::string &name)
void setErrorMode(ErrorMode mode)
void addSnapshot(const std::string &directory, const std::string &name)
The PODfield structure is used to store the fields inside POD classes.