95 Eigen::VectorXd& fvec)
const
97 Eigen::VectorXd a_dot(
Nphi_u);
98 Eigen::VectorXd a_tmp(
Nphi_u);
100 Eigen::VectorXd c_dot(
Nphi_t);
101 Eigen::VectorXd c_tmp(
Nphi_t);
108 Eigen::MatrixXd cc(1, 1);
120 Eigen::MatrixXd qq(1, 1);
130 fvec(
i) = - M5(
i) + M1(
i) - cc(0, 0) - M10(
i) - M2(
i);
139 for (
int j = 0; j <
Nphi_t; j++)
143 fvec(k) = -M8(j) + M6(j) - qq(0, 0);
146 for (
int j = 0; j <
N_BC; j++)
148 fvec(j) = x(j) -
BC(j);
151 for (
int j = 0; j <
N_BC_t; j++)
154 fvec(k) = x(k) -
BC_t(j);
162 Eigen::MatrixXd& fjac)
const
164 Eigen::NumericalDiff<newton_unsteadyBB_sup> numDiff(*
this);
173 Eigen::VectorXd& fvec)
const
175 Eigen::VectorXd a_dot(
Nphi_u);
176 Eigen::VectorXd a_tmp(
Nphi_u);
178 Eigen::VectorXd c_dot(
Nphi_t);
179 Eigen::VectorXd c_tmp(
Nphi_t);
186 Eigen::MatrixXd cc(1, 1);
187 Eigen::MatrixXd gg(1, 1);
188 Eigen::MatrixXd bb(1, 1);
190 Eigen::MatrixXd qq(1, 1);
216 fvec(
i) = - M5(
i) + M1(
i) - cc(0, 0) - M10(
i) - M2(
i);
225 fvec(k) = M3(j, 0) + gg(0, 0) + M11(j, 0) - M7(j, 0);
228 for (
int j = 0; j <
Nphi_t; j++)
232 fvec(k) = -M8(j) + M9(j) - qq(0, 0);
244 Eigen::MatrixXd& fjac)
const
246 Eigen::NumericalDiff<newton_unsteadyBB_PPE> numDiff(*
this);
253 Eigen::MatrixXd& vel_now_BC,
int NParaSet,
int startSnap)
255 std::cout <<
"################## Online solve N° " << NParaSet <<
256 " ##################" << std::endl;
257 std::cout <<
"Solving for the parameter: " << temp_now_BC << std::endl;
268 std::cerr <<
"File: ReducedUnsteadyBB.C, Line: 264" << std::endl;
273 Info << T_IC.boundaryField() << endl;
275 for (
int j = 0; j < T_IC.boundaryField().size(); j++)
282 std::cerr <<
"File: ReducedUnsteadyBB.C, Line: 277" << std::endl;
290 std::cerr <<
"File: ReducedUnsteadyBB.C, Line: 284" << std::endl;
305 std::cerr <<
"File: ReducedUnsteadyBB.C, Line: 299" << std::endl;
307 std::cerr <<
"File: ReducedUnsteadyBB.C, Line: 302" << std::endl;
317 for (
int j = 0; j <
N_BC_t; j++)
322 for (
int j = 0; j <
N_BC; j++)
332 tmp_sol.col(0).tail(
y.rows()) =
y;
345 Eigen::VectorXd res(
y);
349 for (
int j = 0; j <
N_BC; j++)
351 y(j) = vel_now_BC(j, 0);
354 for (
int j = 0; j <
N_BC_t; j++)
357 y(k) = temp_now_BC(j, 0);
362 Info <<
"Time = " <<
time << endl;
364 if (res.norm() < 1e-5)
366 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
367 hnls.iter <<
" iterations " << def << std::endl << std::endl;
371 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
372 hnls.iter <<
" iterations " << def << std::endl << std::endl;
376 tmp_sol.col(0).tail(
y.rows()) =
y;
382 "./ITHACAoutput/red_coeff/" + name(NParaSet) +
"/");
384 "./ITHACAoutput/red_coeff/" + name(NParaSet) +
"/");
386 "./ITHACAoutput/red_coeff/" + name(NParaSet) +
"/");
393 Eigen::MatrixXd& vel_now_BC,
int NParaSet,
int startSnap)
395 std::cout <<
"################## Online solve N° " << NParaSet <<
396 " ##################" << std::endl;
397 std::cout <<
"Solving for the parameter: " << temp_now_BC << std::endl;
433 for (
int j = 0; j < T_IC.boundaryField().size(); j++)
481 for (
int j = 0; j <
N_BC_t; j++)
486 for (
int j = 0; j <
N_BC; j++)
496 tmp_sol.col(0).tail(
y.rows()) =
y;
509 Eigen::VectorXd res(
y);
518 for (
int j = 0; j <
N_BC; j++)
520 y(j) = vel_now_BC(j, 0);
523 for (
int j = 0; j <
N_BC_t; j++)
526 y(k) = temp_now_BC(j, 0);
531 Info <<
"Time = " <<
time << endl;
533 if (res.norm() < 1e-5)
535 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
536 hnls.iter <<
" iterations " << def << std::endl << std::endl;
540 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
541 hnls.iter <<
" iterations " << def << std::endl << std::endl;
545 tmp_sol.col(0).tail(
y.rows()) =
y;
551 "./ITHACAoutput/red_coeff/" + name(NParaSet) +
"/");
555 "./ITHACAoutput/red_coeff/" + name(NParaSet) +
"/");
557 "./ITHACAoutput/red_coeff/" + name(NParaSet) +
"/");
574 int counter2 = 1 +
TREC.size();
578 if (counter == nextwrite)
580 volVectorField U_rec(
"U_rec",
LUmodes[0] * 0);
582 for (
int j = 0; j <
Nphi_u; j++)
599 PREC.append((P_rec).clone());
602 volScalarField T_rec(
"T_rec",
LTmodes[0] * 0);
604 for (
int j = 0; j <
Nphi_t; j++)
610 nextwrite += printevery;
612 std::ofstream of(folder + name(counter2) +
"/" + name(timenow));
614 UREC.append((U_rec).clone());
615 TREC.append((T_rec).clone());
Header file of the ReducedUnsteadyBB class.
Class to change color to the output stream.
int Nphi_t
Number of temperature modes.
int N_BC_t
Number of parametrized boundary conditions related to temperature field.
PtrList< volScalarField > PREC
void reconstruct_sup(fileName folder="./ITHACAOutput/online_rec", int printevery=1)
Method to reconstruct a solution from an online solve with a supremizer stabilisation technique.
newton_unsteadyBB_PPE newton_object_PPE
Function object to call the non linear solver PPE approach.
scalar Pr
DimensionedScalar Pr;.
PtrList< volVectorField > LUmodes
List of pointers to store the modes for velocity including lift field modes.
Eigen::MatrixXd online_solutiont
List of Eigen matrices to store current online solution for temperature equation.
Eigen::MatrixXd solveOnline_sup(Eigen::MatrixXd &temp_now_BC, Eigen::MatrixXd &vel_now_BC, int NParaSet=0, int startSnap=0)
Method to perform an online solve using a supremizer stabilisation method.
PtrList< volScalarField > LTmodes
List of pointers to store the modes for temperature including lift field modes.
int Nphi_prgh
Number of shifted pressure modes.
PtrList< volScalarField > TREC
Reconstructed temperature field.
Eigen::MatrixXd solveOnline_PPE(Eigen::MatrixXd &temp_now_BC, Eigen::MatrixXd &vel_now_BC, int NParaSet=0, int startSnap=0)
Method to perform an online solve using a PPE stabilisation method.
newton_unsteadyBB_sup newton_object_sup
Function object to call the non linear solver sup approach.
ReducedUnsteadyBB()
Construct Null.
UnsteadyBB * problem
Pointer to the FOM problem.
Implementation of a parametrized full order unsteady Boussinesq problem and preparation of the the ...
Eigen::MatrixXd HP_matrix
Buoyancy term - PPE equation.
Eigen::MatrixXd Y_matrix
Diffusive term - energy equation.
PtrList< volScalarField > Prghmodes
List of pointers used to form the shifted pressure modes.
Eigen::MatrixXd W_matrix
Mass Matrix - energy equation.
PtrList< volScalarField > Prghfield
List of pointers used to form the shifted pressure snapshots matrix.
Eigen::MatrixXd H_matrix
Buoyancy term - momentum equation.
List< Eigen::MatrixXd > Q_matrix
Non linear convective term - energy equation.
PtrList< volScalarField > Tmodes
List of pointers used to form the temperature modes.
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.
label NTmodes
Number of temperature modes used for the projection.
Eigen::VectorXd y
Vector to store the solution during the Newton procedure.
scalar nu
Reduced viscosity in case of parametrized viscosity.
int N_BC
Number of parametrized boundary conditions.
PtrList< volVectorField > UREC
Recontructed velocity field.
int Nphi_u
Number of velocity modes.
scalar finalTime
Scalar to store the final time if the online simulation.
scalar tstart
Scalar to store the initial time if the online simulation.
scalar time
Scalar to store the current time.
double dt
Scalar to store the time increment.
Eigen::MatrixXi inletIndexT
Eigen::MatrixXi inletIndex
Matrix that contains informations about the inlet boundaries.
Eigen::MatrixXd BC1_matrix
PPE BC1.
Eigen::MatrixXd BC3_matrix
PPE BC3.
Eigen::Tensor< double, 3 > C_tensor
Diffusion term.
volVectorModes supmodes
List of pointers used to form the supremizer modes.
volVectorModes Umodes
List of pointers used to form the velocity modes.
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
List< Eigen::MatrixXd > G_matrix
Divergence of momentum PPE.
label NUmodes
Number of velocity modes used for the projection.
PtrList< volVectorField > liftfield
List of pointers used to form the list of lifting functions.
Eigen::MatrixXd B_matrix
Diffusion term.
Eigen::MatrixXd D_matrix
Laplacian term PPE.
label NSUPmodes
Number of supremizer modes used for the projection.
Eigen::MatrixXd K_matrix
Gradient of pressure matrix.
Eigen::MatrixXd P_matrix
Div of velocity.
Eigen::MatrixXd M_matrix
Mass Matrix.
List< Eigen::MatrixXd > BC2_matrix
PPE BC2.
Matrix< VectorType, Dynamic, Dynamic > SliceFromTensor(Eigen::Tensor< VectorType, 3 > &tensor, label dim, label index1)
void exportSolution(GeometricField< Type, PatchField, GeoMesh > &s, fileName subfolder, fileName folder, word fieldName)
Export a field to file in a certain folder and subfolder.
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 ...
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.
bool check_folder(word folder)
Checks if a folder exists.
void createSymLink(word folder)
Creates symbolic links to 0, system and constant.
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) const
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
Newton object for the resolution of the reduced problem using a supremizer approach.
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) const