38 explicit tutorial11(
int argc,
char* argv[])
50 volScalarField& p_rgh;
53 void offlineSolve(Eigen::MatrixXd par_BC)
55 List<scalar> mu_now(1);
66 for (label k = 0; k < par_BC.rows(); k++)
68 for (label j = 0; j < par_BC.cols(); j++)
70 for (label i = 0; i <
mu.cols(); i++)
75 assignBC(T, inletIndexT(j, 0), par_BC(k, j));
84 void onlineSolveFull(Eigen::MatrixXd par_BC, label para_set_BC, fileName folder)
92 label i = para_set_BC;
94 for (label j = 0; j < par_BC.cols(); j++)
96 assignBC(T, inletIndexT(j, 0), par_BC(i, j));
103 void onlineSolveRead(fileName folder)
119 for (label k = 0; k < inletIndexT.rows(); k++)
122 fvMesh& mesh =
_mesh();
123 volScalarField& T =
_T();
124 volVectorField& U =
_U();
125 surfaceScalarField& phi =
_phi();
126 phi = linearInterpolate(U) & mesh.Sf();
127 simpleControl simple(mesh);
131 volScalarField& alphat =
_alphat();
133 dimensionedScalar& Pr =
_Pr();
134 dimensionedScalar& Prt =
_Prt();
135 label BCind = inletIndexT(k, 0);
136 volScalarField Tlift(
"Tlift" + name(k), T);
137 instantList Times = runTime.times();
138 runTime.setTime(Times[1], 1);
139 Info <<
"Solving a lifting Problem" << endl;
143 alphat.correctBoundaryConditions();
144 volScalarField alphaEff(
"alphaEff",
turbulence->nu() / Pr + alphat);
146 for (label j = 0; j < T.boundaryField().size(); j++)
153 else if (T.boundaryField()[BCind].type() ==
"fixedValue")
163 while (simple.correctNonOrthogonal())
168 - fvm::laplacian(alphaEff, Tlift)
171 Info <<
"ExecutionTime = " << runTime.elapsedCpuTime() <<
" s"
172 <<
" ClockTime = " << runTime.elapsedClockTime() <<
" s"
187int main(
int argc,
char* argv[])
192 word par_offline_BC(
"./par_offline_BC");
194 word par_online_BC(
"./par_online_BC");
200 word stabilization = para->ITHACAdict->lookupOrDefault<word>(
"Stabilization",
202 int NmodesUproj = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesUproj", 5);
203 int NmodesPproj = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesPproj", 5);
204 int NmodesPrghproj = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesPrghproj",
206 int NmodesTproj = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesTproj", 5);
207 int NmodesSUPproj = 0;
209 if (stabilization ==
"supremizer")
211 NmodesSUPproj = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesSUPproj", 5);
214 int NmodesOut = para->ITHACAdict->lookupOrDefault<
int>(
"NmodesOut", 15);
220 example.setParameters();
222 example.mu_range(0, 0) = 0.00001;
223 example.mu_range(0, 1) = 0.00001;
225 example.genEquiPar();
227 example.inletIndexT.resize(3, 1);
228 example.inletIndexT << 1, 2, 3;
230 example.inletIndex.resize(1, 2);
231 example.inletIndex << 3, 0;
233 example.startTime = 0.0;
234 example.finalTime = 5.0;
235 example.timeStep = 0.002;
236 example.writeEvery = 0.01;
238 example.offlineSolve(par_off_BC);
242 example.liftSolveT();
244 example.computeLift(example.Ufield, example.liftfield, example.Uomfield);
246 example.computeLiftT(example.Tfield, example.liftfieldT, example.Tomfield);
249 example.Uomfield, example.Umodes, example._U().name(),
250 example.podex, 0, 0, NmodesOut,
false);
252 example.Pfield, example.Pmodes, example._p().name(),
253 example.podex, 0, 0, NmodesOut,
false);
255 example.Prghfield, example.Prghmodes, example._p_rgh().name(),
256 example.podex, 0, 0, NmodesOut,
false);
258 example.Tomfield, example.Tmodes, example._T().name(),
259 example.podex, 0, 0, NmodesOut,
false);
262 if (stabilization ==
"supremizer")
264 example.solvesupremizer(
"modes");
268 Eigen::MatrixXd List_of_modes(NmodesOut - 5, 1);
270 for (
int i = 0; i < List_of_modes.rows(); i++)
272 List_of_modes(i, 0) = i + 1;
277 "./ITHACAoutput/l2error");
279 PtrList<volScalarField> TLmodes;
281 for (label k = 0; k < example.liftfieldT.size(); k++)
283 TLmodes.append((example.liftfieldT[k]).clone());
286 for (label k = 0; k < List_of_modes.size(); k++)
288 TLmodes.append((example.Tmodes[k]).clone());
292 PtrList<volVectorField> ULmodes;
294 for (label k = 0; k < example.liftfield.size(); k++)
296 ULmodes.append((example.liftfield[k]).clone());
299 for (label k = 0; k < List_of_modes.size(); k++)
301 ULmodes.append((example.Umodes[k]).clone());
304 if (stabilization ==
"supremizer")
306 for (label k = 0; k < NmodesSUPproj; k++)
308 ULmodes.append((example.supmodes[k]).clone());
313 Eigen::MatrixXd L2errorProjMatrixU(example.Ufield.size(), List_of_modes.rows());
314 Eigen::MatrixXd L2errorProjMatrixT(example.Tfield.size(), List_of_modes.rows());
317 for (
int i = 0; i < List_of_modes.rows(); i++)
320 List_of_modes(i, 0) + example.liftfield.size() + NmodesSUPproj);
322 List_of_modes(i, 0) + example.liftfieldT.size());
324 ULmodes, coeffU, List_of_modes(i,
325 0) + example.liftfield.size() + NmodesSUPproj);
327 TLmodes, coeffT, List_of_modes(i, 0) + example.liftfieldT.size());
332 L2errorProjMatrixU.col(i) = L2errorProjU;
333 L2errorProjMatrixT.col(i) = L2errorProjT;
338 "./ITHACAoutput/l2error");
340 "./ITHACAoutput/l2error");
343 if (stabilization ==
"supremizer")
345 example.projectSUP(
"./Matrices", NmodesUproj, NmodesPrghproj, NmodesTproj,
348 else if (stabilization ==
"PPE")
350 example.projectPPE(
"./Matrices", NmodesUproj, NmodesPrghproj, NmodesTproj,
359 example.Tmodes.resize(NmodesTproj);
360 example.Umodes.resize(NmodesUproj);
361 example.Pmodes.resize(NmodesPproj);
362 example.Prghmodes.resize(NmodesPrghproj);
366 reduced.nu = 0.00001;
368 reduced.tstart = 0.0;
369 reduced.finalTime = 5.0;
372 Eigen::MatrixXd vel_now_BC(1, 1);
373 vel_now_BC(0, 0) = 0.0157;
376 for (label k = 0; k < par_on_BC.rows(); k++)
378 Eigen::MatrixXd temp_now_BC(3, 1);
379 temp_now_BC(0, 0) = par_on_BC(k, 0);
380 temp_now_BC(1, 0) = par_on_BC(k, 1);
381 temp_now_BC(2, 0) = par_on_BC(k, 2);
383 if (stabilization ==
"supremizer")
385 reduced.solveOnline_sup(temp_now_BC, vel_now_BC, k, par_on_BC.rows());
386 reduced.reconstruct_sup(
"./ITHACAoutput/ReconstructionSUP/", 5);
388 else if (stabilization ==
"PPE")
390 reduced.solveOnline_PPE(temp_now_BC, vel_now_BC, k, par_on_BC.rows());
391 reduced.reconstruct_PPE(
"./ITHACAoutput/ReconstructionPPE/", 5);
397 HFonline2.Pnumber = 1;
398 HFonline2.Tnumber = 1;
399 HFonline2.setParameters();
400 HFonline2.mu_range(0, 0) = 0.00001;
401 HFonline2.mu_range(0, 1) = 0.00001;
402 HFonline2.genEquiPar();
403 HFonline2.inletIndexT.resize(3, 1);
404 HFonline2.inletIndexT << 1, 2, 3;
405 HFonline2.inletIndex.resize(1, 2);
406 HFonline2.inletIndex << 3, 0;
407 HFonline2.startTime = 0.0;
408 HFonline2.finalTime = 5.0;
409 HFonline2.timeStep = 0.002;
410 HFonline2.writeEvery = 0.01;
412 HFonline2.onlineSolveFull(par_on_BC, 1,
413 "./ITHACAoutput/high_fidelity_online2");
416 example.onlineSolveRead(
"./ITHACAoutput/Offline/");
418 example.onlineSolveRead(
"./ITHACAoutput/high_fidelity_online2/");
421 example.Ufield_on, reduced.UREC);
423 example.Tfield_on, reduced.TREC);
426 "./ITHACAoutput/l2error");
428 "./ITHACAoutput/l2error");
Header file of the ITHACAPOD class.
Header file of the ITHACAstream class, it contains the implementation of several methods for input ou...
Header file of the ReducedUnsteadyBB class.
Header file of the UnsteadyBB class.
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.
Class where it is implemented a reduced problem for the unsteady Navier-stokes problem.
autoPtr< volScalarField > _p_rgh
Shifted Pressure field.
void liftSolveT()
Perform a lift solve for temperature.
autoPtr< volScalarField > _T
Temperature field.
autoPtr< dimensionedScalar > _Prt
dimensionedScalar Prt;
autoPtr< dimensionedScalar > _Pr
dimensionedScalar Pr;
PtrList< volScalarField > Prghfield
List of pointers used to form the shifted pressure snapshots matrix.
UnsteadyBB()
Null constructor.
PtrList< volVectorField > Ufield_on
List of pointers used to form the temperature snapshots matrix.
autoPtr< fvMesh > _mesh
Mesh.
autoPtr< volScalarField > _alphat
dimensionedScalar alphat;
PtrList< volScalarField > Tfield_on
List of pointers used to form the temperature snapshots matrix.
PtrList< volScalarField > liftfieldT
List of pointers used to form the list of lifting functions.
PtrList< volScalarField > Tfield
List of pointers used to form the temperature snapshots matrix.
void assignBC(volVectorField &s, label BC_ind, Vector< double > &value)
Assign Boundary Condition to a volVectorField.
void assignIF(T &s, G &value)
Assign internal field condition.
bool offline
Boolean variable, it is 1 if the Offline phase has already been computed, else 0.
Eigen::MatrixXd mu
Row matrix of parameters.
void truthSolve()
Perform a TruthSolve.
autoPtr< surfaceScalarField > _phi
Flux.
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
autoPtr< Time > _runTime
Time.
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
autoPtr< volVectorField > _U
Velocity field.
autoPtr< volScalarField > _p
Pressure field.
autoPtr< incompressible::turbulenceModel > turbulence
Turbulence model.
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.
void exportMatrix(Eigen::Matrix< T, -1, dim > &matrix, word Name, word type, word folder)
Export the reduced matrices in numpy (type=python), matlab (type=matlab) and txt (type=eigen) format ...
List< Eigen::MatrixXd > readMatrix(word folder, word mat_name)
Read a three dimensional matrix from a txt file in Eigen format.
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.
Eigen::VectorXd getCoeffs(GeometricField< Type, PatchField, GeoMesh > &snapshot, PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, label Nmodes, bool consider_volumes)
Projects a snapshot on a basis function and gets the coefficients of the projection.
PtrList< GeometricField< Type, PatchField, GeoMesh > > reconstructFromCoeff(PtrList< GeometricField< Type, PatchField, GeoMesh > > &modes, Eigen::MatrixXd &coeff_matrix, label Nmodes)
Exact reconstruction using a certain number of modes for a list of fields and the projection coeffici...
double errorL2Rel(GeometricField< T, fvPatchField, volMesh > &field1, GeometricField< T, fvPatchField, volMesh > &field2, List< label > *labels)
Computes the relative error between two geometric Fields in L2 norm.
bool check_folder(word folder)
Checks if a folder exists.
void createSymLink(word folder)
Creates symbolic links to 0, system and constant.