58 for (
int k = 0; k <
problem->liftfield.size(); k++)
63 for (
int k = 0; k <
problem->NUmodes; k++)
68 for (
int k = 0; k <
problem->NSUPmodes; k++)
74 for (
int k = 0; k <
problem->NPmodes; k++)
79 for (
int k = 0; k <
problem->liftfieldT.size(); k++)
85 for (
int k = 0; k <
problem->NTmodes; k++)
91 for (
int k = 0; k <
problem->Ufield.size(); k++)
97 for (
int k = 0; k <
problem->Tfield.size(); k++)
111 Eigen::VectorXd& fvec)
const
113 Eigen::VectorXd a_dot(
Nphi_u);
114 Eigen::VectorXd a_tmp(
Nphi_u);
115 Eigen::VectorXd b_tmp(
Nphi_p);
120 Eigen::MatrixXd cc(1, 1);
122 Eigen::VectorXd M1 =
problem ->B_total_matrix * a_tmp *
nu;
124 Eigen::VectorXd M2 =
problem->K_matrix * b_tmp;
126 Eigen::VectorXd M5 =
problem->M_matrix * a_dot;
128 Eigen::VectorXd M3 =
problem->P_matrix * a_tmp;
133 cc = a_tmp.transpose() *
problem->C_matrix[
i] * a_tmp -
nu_c.transpose() *
135 fvec(
i) = - M5(
i) + M1(
i) - cc(0, 0) - M2(
i);
139 for (
int j = 0; j <
Nphi_p; j++)
145 for (
int j = 0; j <
N_BC; j++)
147 fvec(j) = x(j) -
BC(j);
155 Eigen::MatrixXd& fjac)
const
157 Eigen::NumericalDiff<newton_unsteadyNSTTurb_sup> numDiff(*
this);
164 Eigen::VectorXd& fvect)
const
167 Eigen::VectorXd c_dot(
Nphi_t);
168 Eigen::VectorXd c_tmp(
Nphi_t);
172 Eigen::MatrixXd qq(1, 1);
173 Eigen::MatrixXd st(1, 1);
175 Eigen::VectorXd M6 =
problem->Y_matrix * c_tmp *
nu /
Pr;
177 Eigen::VectorXd M8 =
problem->MT_matrix * c_dot;
183 fvect(
i) = -M8(
i) + M6(
i) - qq(0, 0) + st(0, 0) /
Prt;
186 for (
int j = 0; j <
N_BC_t; j++)
188 fvect(j) = t(j) -
BC_t(j);
195 Eigen::MatrixXd& fjact)
const
197 Eigen::NumericalDiff<newton_unsteadyNSTTurb_sup_t> numDiff(*
this);
198 numDiff.df(t, fjact);
205 Eigen::MatrixXd& temp_now,
int startSnap)
212 volScalarField T_IC(
"T_IC",
problem->Tfield[0]);
214 for (
int j = 0; j < T_IC.boundaryField().size(); j++)
218 if (j ==
problem->inletIndexT(
i, 0))
220 T_IC.boundaryFieldRef()[
problem->inletIndexT(
i, 0)][j] = temp_now(
i, 0);
233 for (
int j = 0; j <
N_BC; j++)
238 for (
int j = 0; j <
N_BC_t; j++)
240 z(j) = temp_now(j, 0);
255 for (
int j = 0; j <
N_BC; j++)
260 for (
int j = 0; j <
N_BC_t; j++)
276 tmp_sol.col(0).tail(
y.rows()) =
y;
278 Eigen::MatrixXd tmp_solt(
Nphi_t + 1, 1);
280 tmp_solt.col(0).tail(
z.rows()) =
z;
283 Eigen::HybridNonLinearSolver<newton_unsteadyNSTTurb_sup> hnls(
285 Eigen::HybridNonLinearSolver<newton_unsteadyNSTTurb_sup_t> hnlst(
296 std::vector<double> tv;
300 for (
int i = 1;
i < tv.size();
i++)
310 volScalarField nut_rec(
"nut_rec",
problem->nuTmodes[0] * 0);
317 nutREC.append((nut_rec).clone());
319 Eigen::VectorXd res(
y);
320 Eigen::VectorXd rest(
z);
325 for (
int j = 0; j <
N_BC; j++)
333 for (
int j = 0; j <
N_BC_t; j++)
335 z(j) = temp_now(j, 0);
343 " ##################" << std::endl;
344 Info <<
"Time = " <<
time << endl;
345 std::cout <<
"Solving for the parameter: " <<
vel_now << std::endl;
347 if (res.norm() < 1e-5)
349 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
350 hnls.iter <<
" iterations " << def << std::endl << std::endl;
354 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
355 hnls.iter <<
" iterations " << def << std::endl << std::endl;
360 tmp_sol.col(0).tail(
y.rows()) =
y;
372 tmp_solt.col(0).tail(
z.rows()) =
z;
388 "./ITHACAoutput/red_coeff");
390 "./ITHACAoutput/red_coeff");
392 "./ITHACAoutput/red_coeff_t");
394 "./ITHACAoutput/red_coeff_t");
404 system(
"ln -s ../../constant " + folder +
"/constant");
405 system(
"ln -s ../../0 " + folder +
"/0");
406 system(
"ln -s ../../system " + folder +
"/system");
413 if (counter == nextwrite)
415 volVectorField U_rec(
"U_rec",
Umodes[0] * 0);
417 for (
int j = 0; j <
Nphi_u; j++)
423 volScalarField P_rec(
"P_rec",
Pmodes[0] * 0);
425 for (
int j = 0; j <
Nphi_p; j++)
432 nextwrite += printevery;
434 UREC.append((U_rec).clone());
435 PREC.append((P_rec).clone());
445 system(
"ln -s ../../constant " + folder +
"/constant");
446 system(
"ln -s ../../0 " + folder +
"/0");
447 system(
"ln -s ../../system " + folder +
"/system");
454 if (counter == nextwrite)
458 for (
int j = 0; j <
Nphi_t; j++)
464 nextwrite += printevery;
Header file of the reducedUnsteadyNSTTurb class.
Class to change color to the output stream.
ReducedUnsteadyNSTTurb()
Construct Null.
void solveOnlineSup(Eigen::MatrixXd &vel_now, Eigen::MatrixXd &temp_now, int startSnap=0)
Method to perform an online solve using a supremizer stabilisation method.
double time
Scalar to store the current time.
newton_unsteadyNSTTurb_sup_t newton_object_sup_t
Functor object to call the non linear solver sup. approach for temperature field.
double dt
Scalar to store the time increment.
newton_unsteadyNSTTurb_sup newton_object_sup
Functor object to call the non linear solver sup. approach.
scalar Prt
Scalar to store the turbulent Prandtl number.
int Nphi_nut
Number of nut field modes.
UnsteadyNSTTurb * problem
Pointer to the FOM problem.
void reconstructSup(fileName folder="./ITHACAOutput/online_rec", int printevery=1)
Method to reconstruct a solution for velocity and pressure from an online solve with a supremizer sta...
PtrList< volScalarField > nutREC
Reconstructed eddy viscosity field.
double finalTime
Scalar to store the final time if the online simulation.
void reconstructSupt(fileName folder="./ITHACAOutput/online_rec", int printevery=1)
Method to reconstruct a solution for temperature from an online solve with a supremizer stabilisation...
scalar Pr
Scalar to store the Prandtl number.
double tstart
Scalar to store the final time if the online simulation.
Implementation of a parametrized full order unsteady NST problem weakly coupled with the energy equa...
PtrList< volScalarField > PREC
Reconstructed pressure field.
Eigen::VectorXd y
Vector to store the solution during the Newton procedure.
PtrList< volScalarField > Pmodes
List of pointers to store the modes for pressure.
List< Eigen::MatrixXd > online_solution
List of Eigen matrices to store the online solution.
int Nphi_p
Number of pressure modes.
scalar nu
Reduced viscosity in case of parametrized viscosity.
int count_online_solve
Counter to count the online solutions.
Eigen::MatrixXd vel_now
Online inlet velocity vector.
PtrList< volScalarField > Psnapshots
List of pointers to store the snapshots for pressure.
PtrList< volVectorField > Usnapshots
List of pointers to store the snapshots for velocity.
PtrList< volVectorField > Umodes
List of pointers to store the modes for velocity.
int N_BC
Number of parametrized boundary conditions.
PtrList< volVectorField > UREC
Recontructed velocity field.
int Nphi_u
Number of velocity modes.
PtrList< volScalarField > TREC
Reconstructed temperature field.
int N_BC_t
Number of parametrized boundary conditions related to temperature field.
PtrList< volScalarField > Tmodes
List of pointers to store the modes for temperature.
PtrList< volScalarField > T_rec
Reconstructed temperature field.
List< Eigen::MatrixXd > online_solutiont
List of Eigen matrices to store the online solution for temperature equation.
int Nphi_t
Number of temperature modes.
Eigen::VectorXd z
Vector to store the temperature solution during the Newton procedure.
PtrList< volScalarField > Tsnapshots
List of pointers to store the snapshots for temperature.
void exportFields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &field, word folder, word fieldname)
Function to export a scalar of vector field.
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.
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
UnsteadyNSTTurb * problem
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) const
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) const
UnsteadyNSTTurb * problem
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const