49 for (
int k = 0; k <
problem->liftfield.size(); k++)
54 for (
int k = 0; k <
problem->NUmodes; k++)
59 for (
int k = 0; k <
problem->NSUPmodes; k++)
71 Eigen::VectorXd& fvec)
const
73 Eigen::VectorXd aTmp(
Nphi_u);
74 Eigen::VectorXd bTmp(
Nphi_p);
78 Eigen::MatrixXd cc(1, 1);
80 Eigen::VectorXd m1 =
problem->bTotalMatrix * aTmp *
nu;
82 Eigen::VectorXd m2 =
problem->K_matrix * bTmp;
84 Eigen::VectorXd m3 =
problem->P_matrix * aTmp;
86 Eigen::MatrixXd penaltyU = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
89 if (
problem->bcMethod ==
"penalty")
91 for (
int l = 0; l <
N_BC; l++)
101 i) * aTmp -
gNut.transpose() *
103 fvec(
i) = m1(
i) - cc(0, 0) - m2(
i);
105 if (
problem->bcMethod ==
"penalty")
107 fvec(
i) += ((penaltyU *
tauU)(
i, 0));
111 for (
int j = 0; j <
Nphi_p; j++)
117 if (
problem->bcMethod ==
"lift")
119 for (
int j = 0; j <
N_BC; j++)
121 fvec(j) = x(j) -
bc(j);
129 Eigen::VectorXd& fvec)
const
131 Eigen::VectorXd aTmp(
Nphi_u);
132 Eigen::VectorXd bTmp(
Nphi_p);
136 Eigen::MatrixXd cc(1, 1);
137 Eigen::MatrixXd gg(1, 1);
138 Eigen::MatrixXd bb(1, 1);
140 Eigen::VectorXd m1 =
problem->bTotalMatrix * aTmp *
nu;
142 Eigen::VectorXd m2 =
problem->K_matrix * bTmp;
144 Eigen::VectorXd m3 =
problem->D_matrix * bTmp;
146 Eigen::VectorXd m7 =
problem->BC3_matrix * aTmp *
nu;
148 Eigen::MatrixXd penaltyU = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
151 if (
problem->bcMethod ==
"penalty")
153 for (
int l = 0; l <
N_BC; l++)
163 i) * aTmp -
gNut.transpose() *
165 fvec(
i) = m1(
i) - cc(0, 0) - m2(
i);
167 if (
problem->bcMethod ==
"penalty")
169 fvec(
i) += ((penaltyU *
tauU)(
i, 0));
173 for (
int j = 0; j <
Nphi_p; j++)
179 fvec(k) = m3(j, 0) + gg(0, 0) - m7(j, 0);
182 if (
problem->bcMethod ==
"lift")
184 for (
int j = 0; j <
N_BC; j++)
186 fvec(j) = x(j) -
bc(j);
195 Eigen::MatrixXd& fjac)
const
197 Eigen::NumericalDiff<newtonSteadyNSTurbSUP> numDiff(*
this);
203 Eigen::MatrixXd& fjac)
const
205 Eigen::NumericalDiff<newtonSteadyNSTurbPPE> numDiff(*
this);
214 if (
problem->bcMethod ==
"lift")
218 else if (
problem->bcMethod ==
"penalty")
227 if (
problem->bcMethod ==
"lift")
229 for (
int j = 0; j <
N_BC; j++)
238 Eigen::HybridNonLinearSolver<newtonSteadyNSTurbSUP> hnls(
newtonObjectSUP);
242 for (
int j = 0; j <
N_BC; j++)
247 if (
problem->viscCoeff ==
"L2")
254 else if (
problem->viscCoeff ==
"RBF")
264 Info <<
"The way to compute the eddy viscosity coefficients has to be either L2 or RBF"
271 Eigen::VectorXd res(
y);
274 " ##################" << std::endl;
275 std::cout <<
"Solving for the parameter: " <<
vel_now << std::endl;
277 if (res.norm() < 1e-5)
279 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
280 hnls.iter <<
" iterations " << def << std::endl << std::endl;
284 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
285 hnls.iter <<
" iterations " << def << std::endl << std::endl;
293 if (
problem->bcMethod ==
"lift")
297 else if (
problem->bcMethod ==
"penalty")
306 if (
problem->bcMethod ==
"lift")
308 for (
int j = 0; j <
N_BC; j++)
317 Eigen::HybridNonLinearSolver<newtonSteadyNSTurbPPE> hnls(
newtonObjectPPE);
321 for (
int j = 0; j <
N_BC; j++)
326 if (
problem->viscCoeff ==
"L2")
333 else if (
problem->viscCoeff ==
"RBF")
343 Info <<
"The way to compute the eddy viscosity coefficients has to be either L2 or RBF"
350 Eigen::VectorXd res(
y);
353 " ##################" << std::endl;
354 std::cout <<
"Solving for the parameter: " <<
vel_now << std::endl;
356 if (res.norm() < 1e-5)
358 std::cout << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
359 hnls.iter <<
" iterations " << def << std::endl << std::endl;
363 std::cout << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
364 hnls.iter <<
" iterations " << def << std::endl << std::endl;
381 List <Eigen::MatrixXd> CoeffU;
382 List <Eigen::MatrixXd> CoeffP;
383 List <Eigen::MatrixXd> CoeffNut;
390 if (counter == nextWrite)
392 Eigen::MatrixXd currentUCoeff;
393 Eigen::MatrixXd currentPCoeff;
394 Eigen::MatrixXd currentNutCoeff;
398 CoeffU.append(currentUCoeff);
399 CoeffP.append(currentPCoeff);
400 CoeffNut.append(currentNutCoeff);
401 nextWrite += printevery;
407 volVectorField uRec(
"uRec",
Umodes[0]);
408 volScalarField pRec(
"pRec",
problem->Pmodes[0]);
409 volScalarField nutRec(
"nutRec",
problem->nutModes[0]);
427 assert(
problem->inletIndex.rows() == vel.rows()
428 &&
"Imposed boundary conditions dimensions do not match given values matrix dimensions");
429 Eigen::MatrixXd vel_scal;
430 vel_scal.resize(vel.rows(), vel.cols());
432 for (
int k = 0; k <
problem->inletIndex.rows(); k++)
435 int l =
problem->inletIndex(k, 1);
436 scalar area = gSum(
problem->liftfield[0].mesh().magSf().boundaryField()[
p]);
437 scalar u_lf = gSum(
problem->liftfield[k].mesh().magSf().boundaryField()[
p] *
438 problem->liftfield[k].boundaryField()[
p]).component(l) / area;
439 vel_scal(k, 0) = vel(k, 0) / u_lf;
Header file of the ReducedSteadyNSTurb class.
Class to change color to the output stream.
PtrList< volScalarField > nutRecFields
Reconstructed eddy viscosity fields list.
newtonSteadyNSTurbSUP newtonObjectSUP
Newton Object to solve the nonlinear problem sup approach.
newtonSteadyNSTurbPPE newtonObjectPPE
Newton Object to solve the nonlinear problem PPE approach.
void solveOnlinePPE(Eigen::MatrixXd velNow)
Method to perform an online solve using a PPE stabilisation method.
ReducedSteadyNSTurb()
Construct Null.
int nphiNut
Number of viscosity modes.
Eigen::MatrixXd rbfCoeffMat
The matrix of the eddy viscosity RBF interoplated coefficients.
void solveOnlineSUP(Eigen::MatrixXd velNow)
Method to perform an online solve using a supremizer stabilisation method.
SteadyNSTurb * problem
Pointer to the FOM problem.
void reconstruct(bool exportFields=false, fileName folder="./ITHACAoutput/online_rec", int printevery=1)
Method to reconstruct the solutions from an online solve.
Eigen::VectorXd rbfCoeff
Vector of eddy viscosity RBF interoplated coefficients.
Eigen::MatrixXd setOnlineVelocity(Eigen::MatrixXd vel)
Sets the online velocity.
Implementation of a parametrized full order steady turbulent Navier Stokes problem and preparation ...
Eigen::VectorXd y
Vector to store the solution during the Newton procedure.
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.
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.
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 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
Structure to implement a newton object for a stationary NS problem.
int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const
int df(const Eigen::VectorXd &x, Eigen::MatrixXd &fjac) const