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;
147 else if (s.boundaryField()[BC_ind].type() ==
"calculated")
149 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
151 s.boundaryFieldRef()[BC_ind][
i] = value;
154 else if (s.boundaryField()[BC_ind].type() ==
"empty")
161 Vector<double>& value)
163 if (s.boundaryField()[BC_ind].type() ==
"fixedValue")
165 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
167 s.boundaryFieldRef()[BC_ind][
i] = value;
170 else if (s.boundaryField()[BC_ind].type() ==
"fixedGradient")
172 Info <<
"This Feature is not implemented for this boundary condition" << endl;
175 else if (s.boundaryField()[BC_ind].type() ==
"freestream")
177 for (label
i = 0;
i < s.boundaryField()[BC_ind].size();
i++)
179 s.boundaryFieldRef()[BC_ind][
i] = value;
182 freestreamFvPatchField<vector>& Tpatch =
183 refCast<freestreamFvPatchField<vector>>(s.boundaryFieldRef()[BC_ind]);
184 vectorField& gradTpatch = Tpatch.freestreamValue();
187 gradTpatch[faceI] = value;
194 rec_field2, PtrList<volVectorField>& modes, label Nmodes,
195 Eigen::MatrixXd coeff_matrix)
197 for (label k = 0; k < coeff_matrix.cols(); k++)
199 for (label
i = 0;
i < Nmodes;
i++)
203 rec_field2.append(coeff_matrix(
i, k)*modes[
i]);
207 rec_field2[k] += coeff_matrix(
i, k) * modes[
i];
216 rec_field2, PtrList<volScalarField>& modes, label Nmodes,
217 Eigen::MatrixXd coeff_matrix)
219 for (label k = 0; k < coeff_matrix.cols(); k++)
221 for (label
i = 0;
i < Nmodes;
i++)
225 rec_field2.append(coeff_matrix(
i, k)*modes[
i]);
229 rec_field2[k] += coeff_matrix(
i, k) * modes[
i];
237 Info <<
"reductionProblem::project is a function to be overridden exiting the code"
244 mkDir(
"./ITHACAoutput/Parameters");
246 ofs.open (
"./ITHACAoutput/Parameters/par",
247 std::ofstream::out | std::ofstream::app);
250 ofs << mu_now[
i] <<
' ';
258 Info <<
"reductionProblem::liftSolve is a virtual function it must be overridden"
265 Info <<
"reductionProblem::liftSolveT is a virtual function it must be overridden"
271 PtrList<volVectorField> snapshots, PtrList<volVectorField>& modes,
276 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
277 std::vector<SPLINTER::RBFSpline> rbfsplines;
278 rbfsplines.reserve(coeff.rows());
281 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
286 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
291 muSampRefined.conservativeResize(muSampRefined.rows(),
292 muSampRefined.cols() + 1);
293 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
298 for (label
i = 0;
i < coeff.rows();
i++)
300 SPLINTER::DataTable samples;
305 SPLINTER::DenseVector x(muSampRefined.cols());
308 for (label k = 0; k < muSampRefined.cols(); k++)
310 x(k) = muSampRefined(j, k);
313 samples.addSample(x, coeff(
i, j));
316 if (rbfBasis ==
"GAUSSIAN")
318 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
319 SPLINTER::RadialBasisFunctionType::GAUSSIAN));
321 else if (rbfBasis ==
"THIN_PLATE")
323 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
324 SPLINTER::RadialBasisFunctionType::THIN_PLATE_SPLINE));
326 else if (rbfBasis ==
"MULTI_QUADRIC")
328 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
329 SPLINTER::RadialBasisFunctionType::MULTIQUADRIC));
331 else if (rbfBasis ==
"INVERSE_QUADRIC")
333 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
334 SPLINTER::RadialBasisFunctionType::INVERSE_QUADRIC));
336 else if (rbfBasis ==
"INVERSE_MULTI_QUADRIC")
338 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
339 SPLINTER::RadialBasisFunctionType::INVERSE_MULTIQUADRIC));
344 "Unknown string for rbfBasis. Valid types are 'GAUSSIAN', 'THIN_PLATE', 'MULTI_QUADRIC', 'INVERSE_QUADRIC', 'INVERSE_MULTI_QUADRIC'"
355 PtrList<volScalarField> snapshots, PtrList<volScalarField>& modes,
360 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
361 std::vector<SPLINTER::RBFSpline> rbfsplines;
362 rbfsplines.reserve(coeff.rows());
365 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
370 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
375 muSampRefined.conservativeResize(muSampRefined.rows(),
376 muSampRefined.cols() + 1);
377 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
382 for (label
i = 0;
i < coeff.rows();
i++)
384 SPLINTER::DataTable samples;
389 SPLINTER::DenseVector x(muSampRefined.cols());
392 for (label k = 0; k < muSampRefined.cols(); k++)
394 x(k) = muSampRefined(j, k);
397 samples.addSample(x, coeff(
i, j));
400 if (rbfBasis ==
"GAUSSIAN")
402 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
403 SPLINTER::RadialBasisFunctionType::GAUSSIAN));
405 else if (rbfBasis ==
"THIN_PLATE")
407 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
408 SPLINTER::RadialBasisFunctionType::THIN_PLATE_SPLINE));
410 else if (rbfBasis ==
"MULTI_QUADRIC")
412 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
413 SPLINTER::RadialBasisFunctionType::MULTIQUADRIC));
415 else if (rbfBasis ==
"INVERSE_QUADRIC")
417 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
418 SPLINTER::RadialBasisFunctionType::INVERSE_QUADRIC));
420 else if (rbfBasis ==
"INVERSE_MULTI_QUADRIC")
422 rbfsplines.push_back(SPLINTER::RBFSpline(samples,
423 SPLINTER::RadialBasisFunctionType::INVERSE_MULTIQUADRIC));
428 "Unknown string for rbfBasis. Valid types are 'GAUSSIAN', 'THIN_PLATE', 'MULTI_QUADRIC', 'INVERSE_QUADRIC', 'INVERSE_MULTI_QUADRIC'"
439 PtrList<volVectorField> snapshots, PtrList<volVectorField>& modes, label splDeg)
443 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
444 std::vector<SPLINTER::BSpline> bsplines;
445 bsplines.reserve(coeff.rows());
448 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
453 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
458 muSampRefined.conservativeResize(muSampRefined.rows(),
459 muSampRefined.cols() + 1);
460 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
465 for (label
i = 0;
i < coeff.rows();
i++)
467 SPLINTER::DataTable samples;
472 SPLINTER::DenseVector x(muSampRefined.cols());
475 for (label k = 0; k < muSampRefined.cols(); k++)
477 x(k) = muSampRefined(j, k);
480 samples.addSample(x, coeff(
i, j));
483 SPLINTER::BSpline bspline = SPLINTER::BSpline::Builder(samples).degree(
485 bsplines.push_back(bspline);
493 PtrList<volScalarField> snapshots, PtrList<volScalarField>& modes, label splDeg)
497 "The dimension of the coefficient matrix must correspond to the constructed parameter matrix 'mu_samples'");
498 std::vector<SPLINTER::BSpline> bsplines;
499 bsplines.reserve(coeff.rows());
502 Eigen::MatrixXd muSampRefined(
mu_samples.rows(), 0);
507 bool isConst = (
mu_samples.col(
i).array() == firstVal).all();
512 muSampRefined.conservativeResize(muSampRefined.rows(),
513 muSampRefined.cols() + 1);
514 muSampRefined.col(muSampRefined.cols() - 1) =
mu_samples.col(
i);
519 for (label
i = 0;
i < coeff.rows();
i++)
521 SPLINTER::DataTable samples;
526 SPLINTER::DenseVector x(muSampRefined.cols());
529 for (label k = 0; k < muSampRefined.cols(); k++)
531 x(k) = muSampRefined(j, k);
534 samples.addSample(x, coeff(
i, j));
537 SPLINTER::BSpline bspline = SPLINTER::BSpline::Builder(samples).degree(
539 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.