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++)
72 for (
int k = 0; k <
problem->Ufield.size(); k++)
88 Eigen::VectorXd& fvec)
const
90 Eigen::VectorXd a_dot(
Nphi_u);
91 Eigen::VectorXd aTmp(
Nphi_u);
95 if (
problem->timeDerivativeSchemeOrder ==
"first")
105 Eigen::MatrixXd cc(1, 1);
107 Eigen::VectorXd m1 =
problem->bTotalMatrix * aTmp *
nu;
109 Eigen::VectorXd m2 =
problem->kMatrix * aTmp;
111 Eigen::MatrixXd penaltyU = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
114 if (
problem->bcMethod ==
"penalty")
116 for (
int l = 0; l <
N_BC; l++)
127 fvec(
i) = - a_dot(
i) + m1(
i) - cc(0, 0) - m2(
i);
129 if (
problem->bcMethod ==
"penalty")
131 fvec(
i) += ((penaltyU *
tauU)(
i, 0));
135 if (
problem->bcMethod ==
"lift")
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);
168 if (
problem->timeDerivativeSchemeOrder ==
"first")
179 Eigen::MatrixXd cc(1, 1);
180 Eigen::MatrixXd gg(1, 1);
181 Eigen::MatrixXd bb(1, 1);
182 Eigen::MatrixXd nn(1, 1);
184 Eigen::VectorXd m1 =
problem->bTotalMatrix * aTmp *
nu;
186 Eigen::VectorXd m2 =
problem->kMatrix * bTmp;
188 Eigen::VectorXd m3 =
problem->D_matrix * bTmp;
190 Eigen::VectorXd m6 =
problem->BC1_matrix * aTmp *
nu;
192 Eigen::VectorXd m7 =
problem->BC3_matrix * aTmp *
nu;
194 Eigen::MatrixXd penaltyU = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
197 if (
problem->bcMethod ==
"penalty")
199 for (
int l = 0; l <
N_BC; l++)
210 fvec(
i) = - a_dot(
i) + m1(
i) - cc(0, 0) - m2(
i);
212 if (
problem->bcMethod ==
"penalty")
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);
230 if (
problem->bcMethod ==
"lift")
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.");
267 if (
problem->bcMethod ==
"lift")
271 else if (
problem->bcMethod ==
"penalty")
284 if (
problem->bcMethod ==
"lift")
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);
343 if (
problem->bcMethod ==
"lift")
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.");
414 if (
problem->bcMethod ==
"lift")
418 else if (
problem->bcMethod ==
"penalty")
432 if (
problem->bcMethod ==
"lift")
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);
491 if (
problem->bcMethod ==
"lift")
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]);
589 volScalarField pRec(
"pRec",
problem->Pmodes[0]);
590 volScalarField nutRec(
"nutRec",
problem->nutModes[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]);
647 volScalarField pRec(
"pRec",
problem->Pmodes[0]);
648 volScalarField nutRec(
"nutRec",
problem->nutModes[0]);
667 assert(
problem->inletIndex.rows() == vel.rows()
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());
672 for (
int k = 0; k <
problem->inletIndex.rows(); k++)
675 int l =
problem->inletIndex(k, 1);
676 scalar area = gSum(
problem->liftfield[0].mesh().magSf().boundaryField()[
p]);
677 scalar u_lf = gSum(
problem->liftfield[k].mesh().magSf().boundaryField()[
p] *
678 problem->liftfield[k].boundaryField()[
p]).component(l) / area;
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++)
732 if (
para->exportPython)
738 if (
para->exportMatlab)
#define M_Assert(Expr, Msg)
Header file of the ReducedUnsteadyNSTurbIntrusive class.
Class to change color to the output stream.
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 ...
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.
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