54 for (
int k = 0; k <
Nphi_u; k++)
60 for (
int k = 0; k <
Nphi_p; k++)
66 for (
int k = 0; k <
Nphi_u; k++)
88 Eigen::VectorXd& fvec)
const
90 Eigen::VectorXd a_dot(
Nphi_u);
91 Eigen::VectorXd aTmp(
Nphi_u);
105 Eigen::MatrixXd cc(1, 1);
111 Eigen::MatrixXd penaltyU = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
116 for (
int l = 0; l <
N_BC; l++)
127 fvec(
i) = - a_dot(
i) + m1(
i) - cc(0, 0) - m2(
i);
131 fvec(
i) += ((penaltyU *
tauU)(
i, 0));
137 for (
int j = 0; j <
N_BC; j++)
139 fvec(j) = x(j) -
bc(j);
148 Eigen::MatrixXd& fjac)
const
150 Eigen::NumericalDiff<newtonUnsteadyNSTurbIntrusive> numDiff(*
this);
159 Eigen::VectorXd& fvec)
const
161 Eigen::VectorXd a_dot(
Nphi_u);
162 Eigen::VectorXd aTmp(
Nphi_u);
163 Eigen::VectorXd bTmp(
Nphi_p);
179 Eigen::MatrixXd cc(1, 1);
180 Eigen::MatrixXd gg(1, 1);
181 Eigen::MatrixXd bb(1, 1);
182 Eigen::MatrixXd nn(1, 1);
194 Eigen::MatrixXd penaltyU = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
199 for (
int l = 0; l <
N_BC; l++)
210 fvec(
i) = - a_dot(
i) + m1(
i) - cc(0, 0) - m2(
i);
214 fvec(
i) += ((penaltyU *
tauU)(
i, 0));
218 for (
int j = 0; j <
Nphi_p; j++)
227 fvec(k) = m3(j, 0) + gg(0, 0) - m7(j, 0) - nn(0, 0);
232 for (
int j = 0; j <
N_BC; j++)
234 fvec(j) = x(j) -
bc(j);
243 Eigen::MatrixXd& fjac)
const
245 Eigen::NumericalDiff<newtonUnsteadyNSTurbIntrusivePPE> numDiff(*
this);
256 "The time step dt must be smaller than exportEvery.");
258 "The time step dt must be smaller than storeEvery.");
260 "The variable storeEvery must be an integer multiple of the time step dt.");
262 "The variable exportEvery must be an integer multiple of the time step dt.");
264 "The variable exportEvery must be an integer multiple of the variable storeEvery.");
286 for (
int j = 0; j <
N_BC; j++)
300 for (
int j = 0; j <
N_BC; j++)
307 int onlineSize =
static_cast<int>(Ntsteps / numberOfStores);
314 Eigen::MatrixXd tmp_sol(
Nphi_u + 1, 1);
316 tmp_sol.col(0).tail(
y.rows()) =
y;
323 nextStore += numberOfStores;
327 Eigen::HybridNonLinearSolver<newtonUnsteadyNSTurbIntrusive> hnls(
338 Eigen::VectorXd res(
y);
345 for (
int j = 0; j <
N_BC; j++)
355 " ##################" << std::endl;
356 Info <<
"Time = " <<
time << endl;
357 std::cout <<
"Solving for the parameter: " <<
vel_now << std::endl;
359 if (res.norm() < 1e-5)
361 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
362 hnls.iter <<
" iterations " << def << std::endl << std::endl;
366 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
367 hnls.iter <<
" iterations " << def << std::endl << std::endl;
372 tmp_sol.col(0).tail(
y.rows()) =
y;
374 if (counter == nextStore)
385 nextStore += numberOfStores;
394 "./ITHACAoutput/red_coeff");
396 "./ITHACAoutput/red_coeff");
403 "The time step dt must be smaller than exportEvery.");
405 "The time step dt must be smaller than storeEvery.");
407 "The variable storeEvery must be an integer multiple of the time step dt.");
409 "The variable exportEvery must be an integer multiple of the time step dt.");
411 "The variable exportEvery must be an integer multiple of the variable storeEvery.");
434 for (
int j = 0; j <
N_BC; j++)
448 for (
int j = 0; j <
N_BC; j++)
455 int onlineSize =
static_cast<int>(Ntsteps / numberOfStores);
464 tmp_sol.col(0).tail(
y.rows()) =
y;
471 nextStore += numberOfStores;
475 Eigen::HybridNonLinearSolver<newtonUnsteadyNSTurbIntrusivePPE> hnls(
486 Eigen::VectorXd res(
y);
493 for (
int j = 0; j <
N_BC; j++)
503 " ##################" << std::endl;
504 Info <<
"Time = " <<
time << endl;
505 std::cout <<
"Solving for the parameter: " <<
vel_now << std::endl;
507 if (res.norm() < 1e-5)
509 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
510 hnls.iter <<
" iterations " << def << std::endl << std::endl;
514 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
515 hnls.iter <<
" iterations " << def << std::endl << std::endl;
520 tmp_sol.col(0).tail(
y.rows()) =
y;
522 if (counter == nextStore)
533 nextStore += numberOfStores;
542 "./ITHACAoutput/red_coeff");
544 "./ITHACAoutput/red_coeff");
561 volScalarField nutAveNow(
"nutAveNow",
nutModes[0] * 0);
562 List < Eigen::MatrixXd> CoeffU;
563 List < Eigen::MatrixXd> CoeffP;
564 List < Eigen::MatrixXd> CoeffNut;
571 if (counter == nextWrite)
573 Eigen::MatrixXd currentUCoeff;
574 Eigen::MatrixXd currentPCoeff;
575 Eigen::MatrixXd currentNutCoeff;
579 CoeffU.append(currentUCoeff);
580 CoeffP.append(currentPCoeff);
581 CoeffNut.append(currentNutCoeff);
582 nextWrite += exportEveryIndex;
588 volVectorField uRec(
"uRec",
Umodes[0]);
619 volScalarField nutAveNow(
"nutAveNow",
nutModes[0] * 0);
620 List < Eigen::MatrixXd> CoeffU;
621 List < Eigen::MatrixXd> CoeffP;
622 List < Eigen::MatrixXd> CoeffNut;
629 if (counter == nextWrite)
631 Eigen::MatrixXd currentUCoeff;
632 Eigen::MatrixXd currentPCoeff;
633 Eigen::MatrixXd currentNutCoeff;
637 CoeffU.append(currentUCoeff);
638 CoeffP.append(currentPCoeff);
639 CoeffNut.append(currentNutCoeff);
640 nextWrite += exportEveryIndex;
646 volVectorField uRec(
"uRec",
Umodes[0]);
668 &&
"Imposed boundary conditions dimensions do not match given values matrix dimensions");
669 Eigen::MatrixXd vel_scal;
670 vel_scal.resize(vel.rows(), vel.cols());
679 vel_scal(k, 0) = vel(k, 0) / u_lf;
690 system(
"ln -s ../../constant " + folder +
"/constant");
691 system(
"ln -s ../../0 " + folder +
"/0");
692 system(
"ln -s ../../system " + folder +
"/system");
694 IOdictionary FORCESdict
710 for (
int j = 0; j <
Nphi_u; j++)
717 for (
int j = 0; j <
Nphi_u; j++)
724 for (
int j = 0; j <
Nphi_p; j++)
#define M_Assert(Expr, Msg)
Header file of the ReducedUnsteadyNSTurbIntrusive class.
Class to change color to the output stream.
GeometricField< Type, PatchField, GeoMesh > reconstruct(GeometricField< Type, PatchField, GeoMesh > &inputField, Eigen::MatrixXd Coeff, word Name)
Function to reconstruct the solution starting from the coefficients, in this case the field is passed...
void reconstructLiftAndDrag(UnsteadyNSTurbIntrusive &problem, fileName folder)
Method to compute the reduced order forces for same number of modes of velocity and pressure.
ReducedUnsteadyNSTurbIntrusive()
Construct Null.
Eigen::MatrixXd initCond
Tha matrix containing the initial conditions for the reduced variables, in case of PPE approach it mu...
PtrList< volScalarField > nutRecFields
Reconstructed eddy viscosity fields list.
newtonUnsteadyNSTurbIntrusive newtonObject
Function object to call the non linear solver sup approach.
PtrList< volScalarField > nutModes
List of pointers to store the modes for the eddy viscosity.
UnsteadyNSTurbIntrusive * problem
Pointer to the FOM problem.
Eigen::MatrixXd setOnlineVelocity(Eigen::MatrixXd vel)
Sets the online velocity.
void solveOnlinePPE(Eigen::MatrixXd vel)
Method to perform an online solve using an intrusive approach with the usage of PPE.
void reconstructPPE(bool exportFields=false, fileName folder="./online_rec")
Method to reconstruct the solutions from an online solve with a PPE semi-uniform approach.
void reconstruct(bool exportFields=false, fileName folder="./online_rec")
Method to reconstruct the solutions from an online solve with a fully uniform approach.
newtonUnsteadyNSTurbIntrusivePPE newtonObjectPPE
Function object to call the non linear solver sup approach.
Implementation of a parametrized full order unsteady NS problem and preparation of the the reduced ...
Eigen::MatrixXd kMatrix
Pressure Gradient matrix.
Eigen::Tensor< double, 3 > cTotalTensor
Total Turbulent tensor.
Eigen::Tensor< double, 3 > cTotalPPETensor
Total Turbulent tensor PPE approach.
Eigen::MatrixXd bTotalMatrix
Total B Matrix.
Eigen::MatrixXd bMatrix
Diffusive matrix.
volScalarModes nutModes
List of POD modes for eddy viscosity.
virtual void solveOnline()
Virtual Method to perform and online Solve.
Eigen::VectorXd y
Vector to store the solution during the Newton procedure.
ITHACAparameters * para
parameters to be read from the ITHACAdict file
Eigen::MatrixXd fTau
Reduced matrix for tangent forces.
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.
Eigen::MatrixXd tauU
Penalty Factor.
PtrList< volScalarField > pRecFields
Reconstructed pressure fields list.
int count_online_solve
Counter to count the online solutions.
Eigen::MatrixXd vel_now
Online inlet velocity vector.
Eigen::MatrixXd fN
Reduced matrix for normal forces.
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.
PtrList< volVectorField > uRecFields
Recontructed velocity fields list.
int N_BC
Number of parametrized boundary conditions.
int Nphi_u
Number of velocity modes.
bool startFromZero
A variable for starting solving the reduced system from zero or not.
double exportEvery
A variable for exporting the fields.
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.
double storeEvery
A variable for storing the reduced coefficients.
Eigen::MatrixXi inletIndex
Matrix that contains informations about the inlet boundaries.
List< Eigen::MatrixXd > bcVelVec
Boundary term for penalty method - vector.
Eigen::MatrixXd nMatrix
Pressure forces.
Eigen::MatrixXd BC1_matrix
PPE BC1.
Eigen::MatrixXd tauMatrix
Viscous forces.
Eigen::MatrixXd BC3_matrix
PPE BC3.
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
volVectorModes Umodes
List of pointers used to form the velocity modes.
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
PtrList< volVectorField > liftfield
List of pointers used to form the list of lifting functions.
volVectorModes L_U_SUPmodes
List of pointers containing the total number of lift, supremizer and velocity modes.
Eigen::MatrixXd D_matrix
Laplacian term PPE.
Eigen::Tensor< double, 3 > gTensor
Divergence of momentum PPE.
List< Eigen::MatrixXd > bcVelMat
Boundary term for penalty method - matrix.
Eigen::Tensor< double, 3 > bc2Tensor
PPE BC2.
volScalarModes Pmodes
List of pointers used to form the pressure modes.
word bcMethod
Boundary Method.
word timeDerivativeSchemeOrder
Matrix< VectorType, Dynamic, Dynamic > SliceFromTensor(Eigen::Tensor< VectorType, 3 > &tensor, label dim, label index1)
void exportFields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &field, word folder, word fieldname)
Function to export a scalar of vector 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 ...
bool isInteger(double ratio)
This function checks if ratio is an integer.
void createSymLink(word folder)
Creates symbolic links to 0, system and constant.
UnsteadyNSTurbIntrusive * problem
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) const
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) const
UnsteadyNSTurbIntrusive * problem
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const