60 if (
problem->fluxMethod ==
"inconsistent")
63 Eigen::VectorXd a_o = Eigen::VectorXd::Zero(
Nphi_u);
64 Eigen::VectorXd a_n = a_o;
65 Eigen::MatrixXd b = Eigen::VectorXd::Zero(
Nphi_p);
66 Eigen::MatrixXd x = Eigen::VectorXd::Zero(
Nphi_p);
68 Eigen::VectorXd RHS = Eigen::VectorXd::Zero(
Nphi_p);
93 tmp_sol.col(0).segment(1,
Nphi_u) = a_o;
94 tmp_sol.col(0).tail(b.rows()) = b;
100 std::cout <<
" ################## time = " <<
time <<
101 " ##################" << std::endl;
104 Eigen::VectorXd M1 =
problem->BP_matrix * a_o *
nu ;
106 Eigen::MatrixXd cf(1, 1);
108 Eigen::MatrixXd M2 =
problem->P_matrix * a_o;
110 for (label l = 0; l <
Nphi_p; l++)
114 RHS(l) = (1 /
dt) * M2(l, 0) - cf(0, 0) + M1(l, 0);
118 List<Eigen::MatrixXd> RedLinSysP =
problem->LinSysDiv;
121 for (label
i = 0;
i <
N_BC;
i++)
123 RedLinSysP[1] += vel(
i, 0) * ((1 /
dt) *
problem->LinSysDiv[
i + 1] +
131 Eigen::MatrixXd cc(1, 1);
133 Eigen::VectorXd M5 =
problem->B_matrix * a_o *
nu ;
135 Eigen::VectorXd M3 =
problem->K_matrix * b;
137 Eigen::MatrixXd boundaryTerm = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
139 for (label l = 0; l <
N_BC; l++)
141 boundaryTerm.col(l) = (vel(l, 0) * (
problem->RD_matrix[l] *
nu +
142 vel(l, 0) *
problem->RC_matrix[l]));
145 for (label l = 0; l <
Nphi_u; l++)
149 a_n(l) = a_o(l) + (M5(l) - cc(0, 0) - M3(l)) *
dt;
151 for (label j = 0; j <
N_BC; j++)
153 a_n(l) += boundaryTerm(l, j) *
dt;
158 tmp_sol.col(0).segment(1,
Nphi_u) = a_n;
159 tmp_sol.col(0).tail(b.rows()) = b;
164 else if (
problem->fluxMethod ==
"consistent")
167 Eigen::VectorXd a_o = Eigen::VectorXd::Zero(
Nphi_u);
168 Eigen::VectorXd a_n = a_o;
169 Eigen::MatrixXd b = Eigen::VectorXd::Zero(
Nphi_p);
170 Eigen::VectorXd c_o = Eigen::VectorXd::Zero(
Nphi_u);
171 Eigen::VectorXd c_n = Eigen::VectorXd::Zero(
Nphi_u);
172 Eigen::MatrixXd x = Eigen::VectorXd::Zero(
Nphi_p);
174 Eigen::VectorXd RHS = Eigen::VectorXd::Zero(
Nphi_p);
201 tmp_sol.col(0).segment(1,
Nphi_u) = a_o;
203 tmp_sol.col(0).tail(
Nphi_u) = c_o;
209 std::cout <<
" ################## time = " <<
time <<
210 " ##################" << std::endl;
214 Eigen::VectorXd M1 =
problem->BP_matrix * a_o *
nu ;
216 Eigen::MatrixXd cf(1, 1);
218 Eigen::MatrixXd M2 =
problem->P_matrix * a_o;
220 for (label l = 0; l <
Nphi_p; l++)
224 RHS(l) = (1 /
dt) * M2(l, 0) - cf(0, 0) + M1(l, 0);
228 List<Eigen::MatrixXd> RedLinSysP =
problem->LinSysDiv;
231 for (label l = 0; l <
N_BC; l++)
233 RedLinSysP[1] += vel(l, 0) * ((1 /
dt) *
problem->LinSysDiv[l + 1] +
235 vel(l, 0) *
problem->LinSysConv[l + 1]);
241 Eigen::MatrixXd cc(1, 1);
243 Eigen::VectorXd M5 =
problem->B_matrix * a_o *
nu ;
245 Eigen::VectorXd M3 =
problem->K_matrix * b;
247 Eigen::MatrixXd boundaryTerm = Eigen::MatrixXd::Zero(
Nphi_u,
N_BC);
249 for (label l = 0; l <
N_BC; l++)
251 boundaryTerm.col(l) = (vel(l, 0) * (
problem->RD_matrix[l] *
nu +
252 vel(l, 0) *
problem->RC_matrix[l]));
255 for (label k = 0; k <
Nphi_u; k++)
259 a_n(k) = a_o(k) + (M5(k) - cc(0, 0) - M3(k)) *
dt;
261 for (label l = 0; l <
N_BC; l++)
263 a_n(k) += boundaryTerm(k, l) *
dt;
269 Eigen::MatrixXd M6 =
problem->I_matrix * a_o;
271 Eigen::MatrixXd M7 =
problem->DF_matrix * a_o *
nu;
273 Eigen::MatrixXd M8 =
problem->KF_matrix * b.col(0);
275 Eigen::MatrixXd M9 = Eigen::VectorXd::Zero(
Nphi_u);
277 for (label k = 0; k <
Nphi_u; k++)
284 Eigen::VectorXd boundaryTermFlux = Eigen::VectorXd::Zero(
Nphi_u);
286 for (label l = 0; l <
N_BC; l++)
288 boundaryTermFlux += (vel(l, 0) * (
problem->SD_matrix[l] *
nu +
289 vel(l, 0) *
problem->SC_matrix[l]));
292 c_n =
problem->W_matrix.colPivHouseholderQr().solve(M6 - M9 +
dt * (-M8 + M7
293 + boundaryTermFlux));
295 tmp_sol.col(0).segment(1,
Nphi_u) = a_n;
297 tmp_sol.col(0).tail(
Nphi_u) = c_n;
306 "Only the inconsistent flux method and consistent flux method are implemented."
323 List < Eigen::MatrixXd> CoeffU;
324 List < Eigen::MatrixXd> CoeffP;
325 List <double> tValues;
333 if (counter == nextwrite)
335 Eigen::MatrixXd currentUCoeff;
336 Eigen::MatrixXd currentPCoeff;
339 CoeffU.append(currentUCoeff);
340 CoeffP.append(currentPCoeff);
341 nextwrite += exportEveryIndex;
343 tValues.append(timeNow);
349 volVectorField uRec(
"uRec",
problem->Umodes[0]);
350 volScalarField pRec(
"pRec",
problem->Pmodes[0]);
static Eigen::MatrixXd solveLinearSys(List< Eigen::MatrixXd > LinSys, Eigen::MatrixXd x, Eigen::VectorXd &residual, const Eigen::MatrixXd &bc=Eigen::MatrixXd::Zero(0, 0), const std::string solverType="fullPivLu")
Linear system solver for the online problem.
void exportFields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &field, word folder, word fieldname)
Function to export a scalar of vector field.
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.