Loading...
Searching...
No Matches
CompressibleUnSteadyPimpleTutorial.C
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/>.
24Description
25Tutorial of compressible and unsteady flow around a moving airfoil
26\*---------------------------------------------------------------------------*/
27
29#include "ITHACAPOD.H"
30#include "ITHACAstream.H"
31#include "Foam2Eigen.H"
32#include "DEIM.H"
33//#include "ReducedProblem.H"
34#include <chrono>
36
37template<typename O>
38class HROM : public DEIM<O>
39{
40 public:
41 using DEIM<O>::DEIM;
42 PtrList<O> fields;
43 autoPtr<O> subField;
44
45};
46
47
48class tutorial26: public CompressibleUnSteadyRhoPimple
49{
50 public:
51 tutorial26(int argc, char* argv[])
53 U(_U()),
54 p(_p()),
55 E(_E())
56 //,pd(_pointDisplacement())
57 {
58 //point0 = meshPtr().points();
59 }
61 volVectorField& U;
63 volScalarField& p;
65 volScalarField& E;
67 //autoPtr<HROM<O>> DeimObject;
69 //pointVectorField& pd;
71 void offlineSolve(word folder = "./ITHACAoutput/Offline/")
72 {
73 //List<scalar> mu_now(1);
74 if (offline)
75 {
79 }
80 else
81 {
82 truthSolve(folder);
83 //restart();
84 }
85 }
86
87};
88/*----------------------------------------------------------------------------------------------------------*\
89 Starting the MAIN
90\*-----------------------------------------------------------------------------------------------------------*/
91int main(int argc, char* argv[])
92{
93 // Construct the tutorial object
94 tutorial26 example(argc, argv);
95 std::clock_t startOff;
96 double durationOff;
97 // Read some parameters from file
98 ITHACAparameters* para = ITHACAparameters::getInstance(example.meshPtr(),
99 example._runTime());
100 // Read the par file where the parameters are stored
101 int NmodesUout = readInt(para->ITHACAdict->lookup("NmodesUout"));
102 int NmodesPout = readInt(para->ITHACAdict->lookup("NmodesPout"));
103 int NmodesEout = readInt(para->ITHACAdict->lookup("NmodesEout"));
104 int NmodesUproj = readInt(para->ITHACAdict->lookup("NmodesUproj"));
105 int NmodesPproj = readInt(para->ITHACAdict->lookup("NmodesPproj"));
106 int NmodesEproj = readInt(para->ITHACAdict->lookup("NmodesEproj"));
107 // word filename("./par");
108 // example.mu = ITHACAstream::readMatrix(filename);
109 // Time parameters: We can use Ioodictionnary to access time parameters
110 example.startTime = 0;
111 example.finalTime = 0.15;
112 example.timeStep = 2e-06;
113 example.writeEvery = 4e-04;
114 // //Perform the offline solve
115 startOff = std::clock();
116 example.offlineSolve();
117 //exit(0);
118 durationOff = (std::clock() - startOff);
119 Info << "The Offline phase duration is equal to " << durationOff <<
120 endl;
121
122 if (example.podex == 0 )
123 {
124 ITHACAPOD::getModes(example.Ufield, example.Umodes, example._U().name(),
125 example.podex, 0, 0, NmodesUout);
126 ITHACAPOD::getModes(example.Pfield, example.Pmodes, example._p().name(),
127 example.podex, 0, 0, NmodesPout);
128 ITHACAPOD::getModes(example.Efield, example.Emodes, example.E().name(),
129 example.podex, 0, 0, NmodesEout);
130 }
131 else
132 {
133 ITHACAstream::read_fields(example.Umodes, example._U(), "./ITHACAoutput/POD/");
134 ITHACAstream::read_fields(example.Pmodes, example._p(), "./ITHACAoutput/POD/");
135 ITHACAstream::read_fields(example.Emodes, example._E(), "./ITHACAoutput/POD/");
136 }
137
138 HyperReducedCompressibleUnSteadyNS hyperreduced(example);
139 // Info << hyperreduced.Umodes.size() << endl;
140 // Info << hyperreduced.Pmodes.size() << endl;
141 // Info << hyperreduced.Emodes.size() << endl;
142 hyperreduced.startTime = example.startTime;
143 hyperreduced.finalTime = example.finalTime;
144 hyperreduced.timeStep = example.timeStep;
145 hyperreduced.writeEvery = example.writeEvery;
147 hyperreduced.SolveHyperReducedSys(NmodesUproj, NmodesPproj, NmodesEproj);
148 return 0;
149 // online.coeffL2 = ITHACAutilities::getCoeffs(example.Dfield, online.Dmodes, NmodesDproj, false);
150 // if( (!ITHACAutilities::check_folder("./ITHACAoutput/Matrices/")) )
151 // {
152 // mkDir("ITHACAoutput/Matrices");
153 // Eigen::MatrixXd CoeffsPd = ITHACAutilities::getCoeffs(example.Dfield, online.Dmodes, NmodesDproj, false);
154 // Eigen::MatrixXd CoeffsP = ITHACAutilities::getCoeffs(example.Pfield, online.Pmodes, NmodesPproj, true);
155 // Eigen::MatrixXd CoeffsU = ITHACAutilities::getCoeffs(example.Ufield, online.Umodes, NmodesUproj, true);
156 // /// Export the matrix coefficient of pointDisplacement Field
157 // cnpy::save(CoeffsPd, "./ITHACAoutput/Matrices/CoeffsPd.npy");
158 // cnpy::save(CoeffsP, "./ITHACAoutput/Matrices/CoeffsP.npy");
159 // cnpy::save(CoeffsU, "./ITHACAoutput/Matrices/CoeffsU.npy");
160 // }
161 // /// ############### contruct the reduced the class object ###################
162 // ReducedFsi reduced(online);
163 // reduced.startTime = example.startTime;
164 // reduced.finalTime = example.finalTime;
165 // reduced.timeStep = example.timeStep;
166 // reduced.writeEvery = example.writeEvery;
167 // //Perform the online solutions
168 // scalar mu_now = example.mu(0, 0);
169 // std::clock_t startOn;
170 // double durationOn;
171 // startOn = std::clock();
172 // reduced.solveOnline_Pimple(mu_now, NmodesUproj, NmodesPproj, NmodesDproj);
173 // durationOn = (std::clock() - startOn);
174 // Info << "The Online phase duration is equal to " << durationOn << endl;
175 // Info << "======================= ONLINE PHASE COMPLETED ================================" << "\n";
176 // if (!ITHACAutilities::check_folder("./ITHACAoutput/DataFromRom"))
177 // {
178 // mkDir("ITHACAoutput/DataFromRom");
179 // Eigen::VectorXd RedCentersOfMassy = Foam2Eigen::field2Eigen(reduced.centerofmassy);
180 // cnpy::save(RedCentersOfMassy, "./ITHACAoutput/DataFromRom/RedCentersOfMassy_" + name(NmodesUproj) + "_" + name(NmodesPproj) + ".npy");
181 // Eigen::VectorXd romforcey = Foam2Eigen::field2Eigen(reduced.romforcey);
182 // cnpy::save(romforcey, "./ITHACAoutput/DataFromRom/romforcey_" + name(NmodesUproj) + "_" + name(NmodesPproj) + ".npy");
183 // Eigen::VectorXd romforcex = Foam2Eigen::field2Eigen(reduced.romforcex);
184 // cnpy::save(romforcex, "./ITHACAoutput/DataFromRom/romforcex_" + name(NmodesUproj) + "_" + name(NmodesPproj) + ".npy");
185 // Eigen::VectorXd pdcoeffrbf = Foam2Eigen::field2Eigen(reduced.pdcoeffrbf);
186 // ITHACAstream::exportMatrix(pdcoeffrbf, "CoeffsRbf", "python","./ITHACAoutput/DataFromRom/RedPdCoeff/");
187 // /// Export reduced coefficients vectors
188 // ITHACAstream::exportMatrix(reduced.CoeffP,"CoeffsP", "python", "./ITHACAoutput/DataFromRom/ReducedCoeffs/");
189 // ITHACAstream::exportMatrix(reduced.CoeffU,"CoeffsU", "python", "./ITHACAoutput/DataFromRom/ReducedCoeffs/");
190 // }
191 // Eigen::MatrixXd errL2U = ITHACAutilities::errorL2Rel(example.Ufield, reduced.UredFields);
192 // Info << "======================= errL2U completed================================" << "\n";
193 // Eigen::MatrixXd errL2P = ITHACAutilities::errorL2Rel(example.Pfield, reduced.PredFields);
194 // cnpy::save(errL2U, "./ITHACAoutput/DataFromRom/errL2U_" + name(NmodesUproj) + "_" + name(NmodesPproj) + ".npy");
195 // cnpy::save(errL2P, "./ITHACAoutput/DataFromRom/errL2P_" + name(NmodesUproj) + "_" + name(NmodesPproj) + ".npy");
196 return 0;
197}
198
199
Header file of the CompressibleUnSteadyPimple class.
Header file of the Foam2Eigen class.
Header file of the reducedSteadyNS class.
Header file of the ITHACAPOD class.
Header file of the ITHACAstream class, it contains the implementation of several methods for input ou...
PtrList< volScalarField > Efield
List of pointers used to store the energy solutions.
DEIM(PtrList< O > &SnapShotsMatrix, label MaxModes, word FunctionName, word FieldName)
Definition DEIM.C:34
Class where it is implemented a reduced problem for the UnSteady RhoPimple problem.
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
bool offline
Boolean variable, it is 1 if the Offline phase has already been computed, else 0.
void truthSolve()
Perform a TruthSolve.
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
Definition steadyNS.H:86
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
Definition steadyNS.H:89
autoPtr< volVectorField > _U
Velocity field.
Definition steadyNS.H:272
autoPtr< volScalarField > _p
Pressure field.
Definition steadyNS.H:269
void offlineSolve(word folder="./ITHACAoutput/Offline/")
Hyper-reduced object.
volScalarField & p
Pressure field.
volVectorField & U
Velocity field.
volScalarField & E
Energy field.
void getModes(PtrList< GeometricField< Type, PatchField, GeoMesh > > &snapshots, PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, word fieldName, bool podex, bool supex, bool sup, label nmodes, bool correctBC)
Computes the bases or reads them for a field.
Definition ITHACAPOD.C:93
void read_fields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &Lfield, word Name, fileName casename, int first_snap, int n_snap)
Function to read a list of fields from the name of the field and casename.