57 for (
int k = 0; k <
problem->liftfield.size(); k++)
62 for (
int k = 0; k <
problem->NUmodes; k++)
67 for (
int k = 0; k <
problem->NSUPmodes; k++)
73 for (
int k = 0; k <
problem->liftfieldT.size(); k++)
78 for (
int k = 0; k <
problem->NTmodes; k++)
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);
110 Eigen::VectorXd M1 =
problem->B_matrix * a_tmp *
nu;
112 Eigen::VectorXd M5 =
problem->M_matrix * a_dot;
114 Eigen::VectorXd M2 =
problem->K_matrix * b_tmp;
116 Eigen::VectorXd M3 =
problem->P_matrix * a_tmp;
118 Eigen::VectorXd M10 =
problem->H_matrix * c_tmp;
120 Eigen::MatrixXd qq(1, 1);
122 Eigen::VectorXd M6 =
problem->Y_matrix * c_tmp * (
nu /
Pr);
124 Eigen::VectorXd M8 =
problem->W_matrix * c_dot;
130 fvec(
i) = - M5(
i) + M1(
i) - cc(0, 0) - M10(
i) - M2(
i);
139 for (
int j = 0; j <
Nphi_t; j++)
142 qq = a_tmp.transpose() *
problem->Q_matrix[j] * c_tmp;
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);
193 Eigen::VectorXd M1 =
problem->B_matrix * a_tmp *
nu;
195 Eigen::VectorXd M2 =
problem->K_matrix * b_tmp;
197 Eigen::VectorXd M5 =
problem->M_matrix * a_dot;
199 Eigen::VectorXd M3 =
problem->D_matrix * b_tmp;
201 Eigen::VectorXd M6 =
problem->BC1_matrix * a_tmp *
nu;
204 Eigen::VectorXd M10 =
problem->H_matrix * c_tmp;
205 Eigen::VectorXd M11 =
problem->HP_matrix * c_tmp;
206 Eigen::VectorXd M7 =
problem->BC3_matrix * a_tmp *
nu;
208 Eigen::VectorXd M9 =
problem->Y_matrix * c_tmp * (
nu /
Pr);
210 Eigen::VectorXd M8 =
problem->W_matrix * c_dot;
216 fvec(
i) = - M5(
i) + M1(
i) - cc(0, 0) - M10(
i) - M2(
i);
222 gg = a_tmp.transpose() *
problem->G_matrix[j] * a_tmp;
223 bb = a_tmp.transpose() *
problem->BC2_matrix[j] * a_tmp;
225 fvec(k) = M3(j, 0) + gg(0, 0) + M11(j, 0) - M7(j, 0);
228 for (
int j = 0; j <
Nphi_t; j++)
231 qq = a_tmp.transpose() *
problem->Q_matrix[j] * c_tmp;
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;
272 volScalarField T_IC(
"T_IC",
problem->Tfield[0].clone());
273 Info << T_IC.boundaryField() << endl;
275 for (
int j = 0; j < T_IC.boundaryField().size(); j++)
279 if (j ==
problem->inletIndexT(
i, 0))
281 T_IC.boundaryFieldRef()[
problem->inletIndexT(
i, 0)][j] = temp_now_BC(
i, 0);
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;
431 volScalarField T_IC(
"T_IC",
problem->Tfield[0]);
433 for (
int j = 0; j < T_IC.boundaryField().size(); j++)
437 if (j ==
problem->inletIndexT(
i, 0))
439 T_IC.boundaryFieldRef()[
problem->inletIndexT(
i, 0)][j] = temp_now_BC(
i, 0);
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++)
591 volScalarField P_rec(
"P_rec",
problem->Prghmodes[0] * 0);
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::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.
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