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->NPmodes; k++)
78 for (
int k = 0; k <
problem->liftfieldT.size(); k++)
84 for (
int k = 0; k <
problem->NTmodes; k++)
90 for (
int k = 0; k <
problem->Ufield.size(); k++)
96 for (
int k = 0; k <
problem->Tfield.size(); k++)
110 Eigen::VectorXd& fvec)
const
112 Eigen::VectorXd a_dot(
Nphi_u);
113 Eigen::VectorXd a_tmp(
Nphi_u);
114 Eigen::VectorXd b_tmp(
Nphi_p);
119 Eigen::MatrixXd cc(1, 1);
121 Eigen::VectorXd M1 =
problem->B_matrix * a_tmp *
nu;
123 Eigen::VectorXd M2 =
problem->K_matrix * b_tmp;
125 Eigen::VectorXd M5 =
problem->M_matrix * a_dot;
127 Eigen::VectorXd M3 =
problem->P_matrix * a_tmp;
131 cc = a_tmp.transpose() *
problem->C_matrix[
i] * a_tmp;
132 fvec(
i) = - M5(
i) + M1(
i) - cc(0, 0) - M2(
i);
135 for (
int j = 0; j <
Nphi_p; j++)
141 for (
int j = 0; j <
N_BC; j++)
143 fvec(j) = x(j) -
BC(j);
151 Eigen::MatrixXd& fjac)
const
153 Eigen::NumericalDiff<newton_unsteadyNST_sup> numDiff(*
this);
159 Eigen::VectorXd& fvect)
const
161 Eigen::VectorXd c_dot(
Nphi_t);
162 Eigen::VectorXd c_tmp(
Nphi_t);
166 Eigen::MatrixXd qq(1, 1);
168 Eigen::VectorXd M6 =
problem->Y_matrix * c_tmp *
DT;
170 Eigen::VectorXd M8 =
problem->MT_matrix * c_dot;
175 fvect(
i) = -M8(
i) + M6(
i) - qq(0, 0);
178 for (
int j = 0; j <
N_BC_t; j++)
180 fvect(j) = t(j) -
BC_t(j);
187 Eigen::MatrixXd& fjact)
const
189 Eigen::NumericalDiff<newton_unsteadyNST_sup_t> numDiff(*
this);
190 numDiff.df(t, fjact);
196 Eigen::MatrixXd& temp_now,
int startSnap)
209 for (
int j = 0; j <
N_BC; j++)
214 for (
int j = 0; j <
N_BC_t; j++)
216 z(j) = temp_now(j, 0);
229 for (
int j = 0; j <
N_BC_t; j++)
234 for (
int j = 0; j <
N_BC; j++)
250 tmp_sol.col(0).tail(
y.rows()) =
y;
252 Eigen::MatrixXd tmp_solt(
Nphi_t + 1, 1);
254 tmp_solt.col(0).tail(
z.rows()) =
z;
259 Eigen::HybridNonLinearSolver<newton_unsteadyNST_sup_t> hnlst(
270 Eigen::VectorXd res(
y);
271 Eigen::VectorXd rest(
z);
276 for (
int j = 0; j <
N_BC; j++)
286 for (
int j = 0; j <
N_BC_t; j++)
288 z(j) = temp_now(j, 0);
296 " ##################" << std::endl;
297 Info <<
"Time = " <<
time << endl;
298 std::cout <<
"Solving for the parameter: " <<
vel_now << std::endl;
299 std::cout <<
"Solving for the parameter: " << temp_now << std::endl;
301 if (res.norm() < 1e-5)
303 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
304 hnls.iter <<
" iterations " << def << std::endl << std::endl;
308 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
309 hnls.iter <<
" iterations " << def << std::endl << std::endl;
312 if (rest.norm() < 1e-5)
314 std::cout << green <<
"|F(x)| = " << rest.norm() <<
" - Minimun reached in " <<
315 hnlst.iter <<
" iterations " << def << std::endl << std::endl;
319 std::cout << red <<
"|F(x)| = " << rest.norm() <<
" - Minimun reached in " <<
320 hnlst.iter <<
" iterations " << def << std::endl << std::endl;
325 tmp_sol.col(0).tail(
y.rows()) =
y;
337 tmp_solt.col(0).tail(
z.rows()) =
z;
353 "./ITHACAoutput/red_coeff");
355 "./ITHACAoutput/red_coeff");
357 "./ITHACAoutput/red_coeff_t");
359 "./ITHACAoutput/red_coeff_t");
374 if (counter == nextwrite)
376 volVectorField U_rec(
"U_rec",
Umodes[0] * 0);
378 for (
int j = 0; j <
Nphi_u; j++)
385 volScalarField P_rec(
"P_rec",
Pmodes[0] * 0);
387 for (
int j = 0; j <
Nphi_p; j++)
394 nextwrite += printevery;
396 UREC.append((U_rec).clone());
397 PREC.append((P_rec).clone());
416 if (counter == nextwrite)
420 for (
int j = 0; j <
Nphi_t; j++)
426 nextwrite += printevery;
Header file of the reducedUnsteadyNST class.
Class to change color to the output stream.
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.
scalar finalTime
Scalar to store the final time if the online simulation.
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.
void reconstruct_supt(fileName folder="./ITHACAOutput/online_rec", int printevery=1)
Method to reconstruct a solution from an online solve with a supremizer stabilisation technique for t...
PtrList< volScalarField > T_rec
Reconstructed temperature field.
reducedUnsteadyNST()
Construct Null.
List< Eigen::MatrixXd > online_solutiont
List of Eigen matrices to store the online solution for temperature equation.
newton_unsteadyNST_sup_t newton_object_sup_t
Functor object to call the non linear solver sup. approach for temperature case.
scalar tstart
Scalar to store the final time if the online simulation.
unsteadyNST * problem
pointer to the FOM problem
int Nphi_t
Number of temperature modes.
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.
scalar dt
Scalar to store the time increment.
newton_unsteadyNST_sup newton_object_sup
Functor object to call the non linear solver sup. approach for velocity case.
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.
scalar time
Scalar to store the current time.
void solveOnline_sup(Eigen::MatrixXd &vel_now, Eigen::MatrixXd &temp_now, int startSnap=0)
Method to perform an online solve using a supremizer stabilisation method.
Implementation of a parametrized full order unsteady NS problem weakly coupled with the energy equat...
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.
void createSymLink(word folder)
Creates symbolic links to 0, system and constant.
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) 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