58 for (label k = 0; k <
Pnumber; k++)
60 for (label n = 0; n <
Tnumber; ++n)
62 mu(k, n) =
mu_range(k, 0) +
static_cast <float> (rand()) /
static_cast <float>
71 std::srand(std::time(0));
72 auto rand = Eigen::MatrixXd::Random(Tsize,
Pnumber);
75 k = (rand.array() +
double(1)) / 2;
90 for (label k = 0; k <
Pnumber; k++)
99 Info <<
"reductionProblem::truthSolve() is a Method to be overridden -> Exiting the code"
107 if (s.boundaryField()[BC_ind].type() ==
"fixedValue"
108 || s.boundaryField()[BC_ind].type() ==
"processor")
110 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
112 s.boundaryFieldRef()[BC_ind][
i] = value;
115 else if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
117 fixedGradientFvPatchScalarField& Tpatch =
118 refCast<fixedGradientFvPatchScalarField>(s.boundaryFieldRef()[BC_ind]);
119 scalarField& gradTpatch = Tpatch.gradient();
122 gradTpatch[faceI] = value;
125 else if (s.boundaryField()[BC_ind].type() ==
"fixedFluxPressure")
127 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
129 s.boundaryFieldRef()[BC_ind][
i] = value;
132 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
134 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
136 s.boundaryFieldRef()[BC_ind][
i] = value;
139 freestreamFvPatchField<scalar>& Tpatch =
140 refCast<freestreamFvPatchField<scalar >> (s.boundaryFieldRef()[BC_ind]);
141 scalarField& gradTpatch = Tpatch.freestreamValue();
144 gradTpatch[faceI] = value;
148 else if (s.boundaryField()[BC_ind].type() ==
"calculated")
150 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
152 s.boundaryFieldRef()[BC_ind][
i] = value;
156 else if (s.boundaryField()[BC_ind].type() ==
"empty")
163 Vector<double>& value)
165 if (s.boundaryField()[BC_ind].type() ==
"fixedValue")
167 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
169 s.boundaryFieldRef()[BC_ind][
i] = value;
172 else if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
174 Info <<
"This Feature is not implemented for this boundary condition" << endl;
177 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
179 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
181 s.boundaryFieldRef()[BC_ind][
i] = value;
184 freestreamFvPatchField<vector>& Tpatch =
185 refCast<freestreamFvPatchField<vector >> (s.boundaryFieldRef()[BC_ind]);
186 vectorField& gradTpatch = Tpatch.freestreamValue();
189 gradTpatch[faceI] = value;
196 rec_field2, PtrList<volVectorField>& modes, label Nmodes,
197 Eigen::MatrixXd coeff_matrix)
199 for (label k = 0; k < coeff_matrix.cols(); k++)
201 for (label
i = 0;
i < Nmodes;
i++)
205 rec_field2.append(coeff_matrix(
i, k) * modes[
i]);
209 rec_field2[k] += coeff_matrix(
i, k) * modes[
i];
218 rec_field2, PtrList<volScalarField>& modes, label Nmodes,
219 Eigen::MatrixXd coeff_matrix)
221 for (label k = 0; k < coeff_matrix.cols(); k++)
223 for (label
i = 0;
i < Nmodes;
i++)
227 rec_field2.append(coeff_matrix(
i, k) * modes[
i]);
231 rec_field2[k] += coeff_matrix(
i, k) * modes[
i];
239 Info <<
"reductionProblem::project is a function to be overridden exiting the code"
246 mkDir(
"./ITHACAoutput/Parameters");
248 ofs.open (
"./ITHACAoutput/Parameters/par",
249 std::ofstream::out | std::ofstream::app);
252 ofs << mu_now[
i] <<
' ';
261 Info <<
"reductionProblem::liftSolve is a virtual function it must be overridden"
268 Info <<
"reductionProblem::liftSolveT is a virtual function it must be overridden"
274 PtrList<volVectorField> snapshots, PtrList<volVectorField>& modes,
279 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
280 std::vector<SPLINTER::RBFSpline> rbfsplines;
281 rbfsplines.reserve(coeff.rows());
284 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
289 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
294 muSampRefined.conservativeResize(muSampRefined.rows(),
295 muSampRefined.cols() + 1);
296 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
301 for (label
i = 0;
i < coeff.rows();
i++)
303 SPLINTER::DataTable samples;
308 SPLINTER::DenseVector x(muSampRefined.cols());
311 for (label k = 0; k < muSampRefined.cols(); k++)
313 x(k) = muSampRefined(j, k);
316 samples.addSample(x, coeff(
i, j));
319 if (rbfBasis ==
"GAUSSIAN")
321 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
322 SPLINTER::RadialBasisFunctionType::GAUSSIAN));
324 else if (rbfBasis ==
"THIN_PLATE")
326 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
327 SPLINTER::RadialBasisFunctionType::THIN_PLATE_SPLINE));
329 else if (rbfBasis ==
"MULTI_QUADRIC")
331 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
332 SPLINTER::RadialBasisFunctionType::MULTIQUADRIC));
334 else if (rbfBasis ==
"INVERSE_QUADRIC")
336 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
337 SPLINTER::RadialBasisFunctionType::INVERSE_QUADRIC));
339 else if (rbfBasis ==
"INVERSE_MULTI_QUADRIC")
341 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
342 SPLINTER::RadialBasisFunctionType::INVERSE_MULTIQUADRIC));
347 "Unknown string for rbfBasis. Valid types are 'GAUSSIAN', 'THIN_PLATE', 'MULTI_QUADRIC', 'INVERSE_QUADRIC', 'INVERSE_MULTI_QUADRIC'"
358 PtrList<volScalarField> snapshots, PtrList<volScalarField>& modes,
363 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
364 std::vector<SPLINTER::RBFSpline> rbfsplines;
365 rbfsplines.reserve(coeff.rows());
368 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
373 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
378 muSampRefined.conservativeResize(muSampRefined.rows(),
379 muSampRefined.cols() + 1);
380 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
385 for (label
i = 0;
i < coeff.rows();
i++)
387 SPLINTER::DataTable samples;
392 SPLINTER::DenseVector x(muSampRefined.cols());
395 for (label k = 0; k < muSampRefined.cols(); k++)
397 x(k) = muSampRefined(j, k);
400 samples.addSample(x, coeff(
i, j));
403 if (rbfBasis ==
"GAUSSIAN")
405 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
406 SPLINTER::RadialBasisFunctionType::GAUSSIAN));
408 else if (rbfBasis ==
"THIN_PLATE")
410 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
411 SPLINTER::RadialBasisFunctionType::THIN_PLATE_SPLINE));
413 else if (rbfBasis ==
"MULTI_QUADRIC")
415 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
416 SPLINTER::RadialBasisFunctionType::MULTIQUADRIC));
418 else if (rbfBasis ==
"INVERSE_QUADRIC")
420 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
421 SPLINTER::RadialBasisFunctionType::INVERSE_QUADRIC));
423 else if (rbfBasis ==
"INVERSE_MULTI_QUADRIC")
425 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
426 SPLINTER::RadialBasisFunctionType::INVERSE_MULTIQUADRIC));
431 "Unknown string for rbfBasis. Valid types are 'GAUSSIAN', 'THIN_PLATE', 'MULTI_QUADRIC', 'INVERSE_QUADRIC', 'INVERSE_MULTI_QUADRIC'"
442 PtrList<volVectorField> snapshots, PtrList<volVectorField>& modes,
447 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
448 std::vector<SPLINTER::BSpline> bsplines;
449 bsplines.reserve(coeff.rows());
452 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
457 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
462 muSampRefined.conservativeResize(muSampRefined.rows(),
463 muSampRefined.cols() + 1);
464 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
469 for (label
i = 0;
i < coeff.rows();
i++)
471 SPLINTER::DataTable samples;
476 SPLINTER::DenseVector x(muSampRefined.cols());
479 for (label k = 0; k < muSampRefined.cols(); k++)
481 x(k) = muSampRefined(j, k);
484 samples.addSample(x, coeff(
i, j));
487 SPLINTER::BSpline bspline = SPLINTER::BSpline::Builder(samples).degree(
489 bsplines.push_back(bspline);
497 PtrList<volScalarField> snapshots, PtrList<volScalarField>& modes,
502 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
503 std::vector<SPLINTER::BSpline> bsplines;
504 bsplines.reserve(coeff.rows());
507 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
512 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
517 muSampRefined.conservativeResize(muSampRefined.rows(),
518 muSampRefined.cols() + 1);
519 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
524 for (label
i = 0;
i < coeff.rows();
i++)
526 SPLINTER::DataTable samples;
531 SPLINTER::DenseVector x(muSampRefined.cols());
534 for (label k = 0; k < muSampRefined.cols(); k++)
536 x(k) = muSampRefined(j, k);
539 samples.addSample(x, coeff(
i, j));
542 SPLINTER::BSpline bspline = SPLINTER::BSpline::Builder(samples).degree(
544 bsplines.push_back(bspline);
forAll(example_CG.gList, solutionI)
#define M_Assert(Expr, Msg)
void project()
General projection operation.
void writeMu(List< scalar > mu_now)
Write out a list of scalar corresponding to the parameters used in the truthSolve.
label Pnumber
Number of parameters.
void reconstructFromMatrix(PtrList< volVectorField > &rec_field2, PtrList< volVectorField > &modes, label Nmodes, Eigen::MatrixXd coeff_matrix)
Exact reconstruction using a certain number of modes for vector list of fields and the projection coe...
Eigen::MatrixXd mu_samples
Matrix of parameters to be used for PODI, where each row corresponds to a sample point....
reductionProblem()
Construct Null.
void assignBC(volVectorField &s, label BC_ind, Vector< double > &value)
Assign Boundary Condition to a volVectorField.
label Tnumber
Dimension of the training set (used only when gerating parameters without input)
void genRandPar()
Generate Random Numbers.
Eigen::MatrixXd mu
Row matrix of parameters.
Eigen::MatrixXd mu_range
Range of the parameter spaces.
void setParameters()
Set Parameters Problems.
void liftSolve()
Virtual function to compute the lifting function for scalar field.
void truthSolve()
Perform a TruthSolve.
std::vector< SPLINTER::BSpline > getCoeffManifoldSPL(PtrList< volVectorField > snapshots, PtrList< volVectorField > &modes, label splDeg=3)
Constructs the parameters-coefficients manifold for vector fields, based on the B-spline model.
std::vector< SPLINTER::RBFSpline > getCoeffManifoldRBF(PtrList< volVectorField > snapshots, PtrList< volVectorField > &modes, word rbfBasis="GAUSSIAN")
Constructs the parameters-coefficients manifold for vector fields, based on RBF-spline model.
void genEquiPar()
Generate Equidistributed Numbers.
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.
Header file of the reductionProblem class.