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++)
70int newtonSteadyNSTurbSUP::operator()(
const Eigen::VectorXd& x,
71 Eigen::VectorXd& fvec)
const
73 Eigen::VectorXd aTmp(Nphi_u);
74 Eigen::VectorXd bTmp(Nphi_p);
75 aTmp = x.head(Nphi_u);
76 bTmp = x.tail(Nphi_p);
78 Eigen::MatrixXd cc(1, 1);
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);
91 for (
int l = 0; l < N_BC; l++)
98 for (
int i = 0; i < Nphi_u; i++)
100 cc = aTmp.transpose() * Eigen::SliceFromTensor(problem->C_tensor, 0,
101 i) * aTmp - gNut.transpose() *
102 Eigen::SliceFromTensor(problem->cTotalTensor, 0, i) * aTmp;
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);
128int newtonSteadyNSTurbPPE::operator()(
const Eigen::VectorXd& x,
129 Eigen::VectorXd& fvec)
const
131 Eigen::VectorXd aTmp(Nphi_u);
132 Eigen::VectorXd bTmp(Nphi_p);
133 aTmp = x.head(Nphi_u);
134 bTmp = x.tail(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++)
155 penaltyU.col(l) = bc(l) * problem->bcVelVec[l] - problem->bcVelMat[l] *
160 for (
int i = 0; i < Nphi_u; i++)
162 cc = aTmp.transpose() * Eigen::SliceFromTensor(problem->C_tensor, 0,
163 i) * aTmp - gNut.transpose() *
164 Eigen::SliceFromTensor(problem->cTotalTensor, 0, i) * aTmp;
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++)
176 gg = aTmp.transpose() * Eigen::SliceFromTensor(problem->gTensor, 0,
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);
194int newtonSteadyNSTurbSUP::df(
const Eigen::VectorXd& x,
195 Eigen::MatrixXd& fjac)
const
197 Eigen::NumericalDiff<newtonSteadyNSTurbSUP> numDiff(*
this);
202int newtonSteadyNSTurbPPE::df(
const Eigen::VectorXd& x,
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++)
248 Eigen::VectorXd vel_vec =
vel_now.col(0);
249 for (
int i = 0; i <
nphiNut; i++)
257 Eigen::VectorXd res(
y);
260 " ##################" << endl;
261 Info <<
"Solving for the parameter: " <<
vel_now << endl;
263 if (res.norm() < 1e-5)
265 Info << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
266 hnls.iter <<
" iterations " << def << endl << endl;
270 Info << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
271 hnls.iter <<
" iterations " << def << endl << endl;
279 if (
problem->bcMethod ==
"lift")
283 else if (
problem->bcMethod ==
"penalty")
292 if (
problem->bcMethod ==
"lift")
294 for (
int j = 0; j <
N_BC; j++)
303 Eigen::HybridNonLinearSolver<newtonSteadyNSTurbPPE> hnls(
newtonObjectPPE);
307 for (
int j = 0; j <
N_BC; j++)
313 Eigen::VectorXd vel_vec =
vel_now.col(0);
314 for (
int i = 0; i <
nphiNut; i++)
322 Eigen::VectorXd res(
y);
325 " ##################" << endl;
326 Info <<
"Solving for the parameter: " <<
vel_now << endl;
328 if (res.norm() < 1e-5)
330 Info << green <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
331 hnls.iter <<
" iterations " << def << endl << endl;
335 Info << red <<
"|F(x)| = " << res.norm() <<
" - Minimun reached in " <<
336 hnls.iter <<
" iterations " << def << endl << endl;
353 List <Eigen::MatrixXd> CoeffU;
354 List <Eigen::MatrixXd> CoeffP;
355 List <Eigen::MatrixXd> CoeffNut;
362 if (counter == nextWrite)
364 Eigen::MatrixXd currentUCoeff;
365 Eigen::MatrixXd currentPCoeff;
366 Eigen::MatrixXd currentNutCoeff;
370 CoeffU.append(currentUCoeff);
371 CoeffP.append(currentPCoeff);
372 CoeffNut.append(currentNutCoeff);
373 nextWrite += printevery;
379 volVectorField uRec(
"uRec",
Umodes[0]);
380 volScalarField pRec(
"pRec",
problem->Pmodes[0]);
381 volScalarField nutRec(
"nutRec",
problem->nutModes[0]);
399 assert(
problem->inletIndex.rows() == vel.rows()
400 &&
"Imposed boundary conditions dimensions do not match given values matrix dimensions");
401 Eigen::MatrixXd vel_scal;
402 vel_scal.resize(vel.rows(), vel.cols());
404 for (
int k = 0; k <
problem->inletIndex.rows(); k++)
406 int p =
problem->inletIndex(k, 0);
407 int l =
problem->inletIndex(k, 1);
408 scalar area = gSum(
problem->liftfield[0].mesh().magSf().boundaryField()[p]);
409 scalar u_lf = gSum(
problem->liftfield[k].mesh().magSf().boundaryField()[p] *
410 problem->liftfield[k].boundaryField()[p]).component(l) / area;
411 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::MatrixXd bTotalMatrix
Total B Matrix.
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.
List< Eigen::MatrixXd > bcVelVec
Boundary term for penalty method - vector.
Eigen::MatrixXd K_matrix
Gradient of pressure matrix.
List< Eigen::MatrixXd > bcVelMat
Boundary term for penalty method - matrix.
Eigen::MatrixXd P_matrix
Div of velocity.
word bcMethod
Boundary Method.
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.
Structure to implement a newton object for a stationary NS problem.