18 explicit msr(
int argc,
char* argv[])
67 int NUproj =
para->ITHACAdict->lookupOrDefault<
int>(
"NUproj", 2);
68 int NPproj =
para->ITHACAdict->lookupOrDefault<
int>(
"NPproj", 2);
78 int NTproj =
para->ITHACAdict->lookupOrDefault<
int>(
"NTproj", 2);
82 int NCproj =
para->ITHACAdict->lookupOrDefault<
int>(
"NCproj", 2);
97 List<scalar> mu_now(3);
99 for (
int i = 0;
i <
mu.cols();
i++)
113 mu_now[0] =
mu(0,
i);
114 mu_now[1] =
mu(1,
i);
115 mu_now[2] =
mu(2,
i);
131 explicit Tmlocal(
int argc,
char* argv[],
int Nsampled)
133 Tm(argc, argv, Nsampled),
143 explicit Ploct(
int argc,
char* argv[],
int Nsampled)
155 explicit Plocal(
int argc,
char* argv[],
int Nsampled)
157 Ptot(argc, argv, Nsampled),
167 explicit Tmloct(
int argc,
char* argv[],
int Nsampled)
176int main(
int argc,
char* argv[])
179 msr prova(argc, argv);
193 int central =
static_cast<int>(prova.
Tnumber / 2);
194 double nu0 = 2.46E-06;
195 double betatot0 = 321.8E-05;
196 double dlam30 = 3.58e-04;
200 prova.
mu_range(1, 0) = 1.1 * betatot0;
201 prova.
mu_range(1, 1) = 0.9 * betatot0;
202 prova.
mu_range(2, 0) = 1.1 * dlam30;
203 prova.
mu_range(2, 1) = 0.9 * dlam30;
206 prova.
mu(0, central) = nu0;
207 prova.
mu(1, central) = betatot0;
208 prova.
mu(2, central) = dlam30;
209 double tstart = std::time(0);
210 Eigen::MatrixXd arange(prova.
Pnumber, 2);
211 Eigen::MatrixXd mu_f = prova.
mu;
217 arange(
i, 0) = prova.
mu.row(
i).minCoeff();
218 arange(
i, 1) = prova.
mu.row(
i).maxCoeff();
232 prova.
_nu().value() = nu0;
234 double tend = std::time(0);
235 double deltat_offline;
236 deltat_offline = difftime(tend, tstart);
241 std::ofstream diff_t(
"./ITHACAoutput/t_offline=" + name(deltat_offline));
244 std::cout <<
"Offline stage time= " << deltat_offline << std::endl;
256 Eigen::VectorXi NPrec(8);
265 Eigen::VectorXi NDec(3);
272 double umedio = 2.46E-03;
274 Eigen::MatrixXd Twall(4, 2);
286 Eigen::MatrixXd vel_now(1, 1);
287 vel_now(0, 0) = umedio;
289 Eigen::MatrixXd temp_now = Twall;
291 Eigen::VectorXd mu_on(3);
292 ridotto.
nu = mu_f(0, central);
293 ridotto.
btot = mu_f(1, central);
294 ridotto.
b1 = prova.
r1 * ridotto.
btot;
295 ridotto.
b2 = prova.
r2 * ridotto.
btot;
296 ridotto.
b3 = prova.
r3 * ridotto.
btot;
297 ridotto.
b4 = prova.
r4 * ridotto.
btot;
298 ridotto.
b5 = prova.
r5 * ridotto.
btot;
299 ridotto.
b6 = prova.
r6 * ridotto.
btot;
300 ridotto.
b7 = prova.
r7 * ridotto.
btot;
301 ridotto.
b8 = prova.
r8 * ridotto.
btot;
302 ridotto.
dl3 = mu_f(2, central);
305 mu_on(0) = ridotto.
nu;
306 mu_on(1) = ridotto.
btot;
307 mu_on(2) = ridotto.
dl3;
308 ridotto.
solveOnline(vel_now, temp_now, mu_on, ref_start);
316 Eigen::MatrixXd err(10, tf);
317 Eigen::MatrixXd TmFOM(prova.
Tnumber, tf);
318 Eigen::MatrixXd PtotFOM(prova.
Tnumber, tf);
319 Eigen::MatrixXd TmROM(prova.
Tnumber, tf);
320 Eigen::MatrixXd PtotROM(prova.
Tnumber, tf);
321 std::cout <<
"Computing errors on reference case..." << std::endl;
323 for (
int i = ref_start;
i < ref_start + tf;
i++)
346 std::cout <<
"End" << std::endl;
349 std::cout <<
"computing FOM output..." << std::endl;
355 for (
int i = 0;
i < prova.
Tfield.size();
i++)
357 tmpt = prova.
Tfield[
i].weightedAverage(prova.
_mesh().V()).value();
362 TmFOM(rig,
col) = tmpt;
363 PtotFOM(rig,
col) = tmpp;
366 else if (
col == tf_fom)
377 std::cout <<
"End" << std::endl;
383 std::string folder = {
"./ITHACAoutput/ROMOutput/"};
387 ridotto.
nu = mu_f(0,
i);
388 ridotto.
btot = mu_f(1,
i);
389 ridotto.
b1 = prova.
r1 * ridotto.
btot;
390 ridotto.
b2 = prova.
r2 * ridotto.
btot;
391 ridotto.
b3 = prova.
r3 * ridotto.
btot;
392 ridotto.
b4 = prova.
r4 * ridotto.
btot;
393 ridotto.
b5 = prova.
r5 * ridotto.
btot;
394 ridotto.
b6 = prova.
r6 * ridotto.
btot;
395 ridotto.
b7 = prova.
r7 * ridotto.
btot;
396 ridotto.
b8 = prova.
r8 * ridotto.
btot;
397 ridotto.
dl3 = mu_f(2,
i);
398 mu_on(0) = ridotto.
nu;
399 mu_on(1) = ridotto.
btot;
400 mu_on(2) = ridotto.
dl3;
401 folder.append(std::to_string(
i));
402 ridotto.
solveOnline(vel_now, temp_now, mu_on, ref_start);
404 folder = {
"./ITHACAoutput/ROMOutput/"};
413 for (
int i = 0;
i < tf;
i++)
429 folder = {
"./ITHACAoutput/Sensitivity/ModelOutput/"};
430 int Nparameters = prova.
Pnumber;
431 std::vector<std::string> pdflist = {
"normal",
"normal",
"normal"};
432 int samplingPoints = 1000;
437 Eigen::MatrixXd Mp(Nparameters, 2);
439 Mp(0, 1) = nu0 * 0.1 / 3;
441 Mp(1, 1) = betatot0 * 0.1 / 3;
443 Mp(2, 1) = dlam30 * 0.1 / 3;
451 tstart = std::time(0);
454 for (
int j = 0; j < samplingPoints; j++)
456 ridotto.
nu = analisi.
MatX(j, 0);
458 ridotto.
b1 = prova.
r1 * ridotto.
btot;
459 ridotto.
b2 = prova.
r2 * ridotto.
btot;
460 ridotto.
b3 = prova.
r3 * ridotto.
btot;
461 ridotto.
b4 = prova.
r4 * ridotto.
btot;
462 ridotto.
b5 = prova.
r5 * ridotto.
btot;
463 ridotto.
b6 = prova.
r6 * ridotto.
btot;
464 ridotto.
b7 = prova.
r7 * ridotto.
btot;
465 ridotto.
b8 = prova.
r8 * ridotto.
btot;
466 ridotto.
dl3 = analisi.
MatX(j, 2);
467 mu_on(0) = ridotto.
nu;
468 mu_on(1) = ridotto.
btot;
469 mu_on(2) = ridotto.
dl3;
470 folder.append(std::to_string(counter));
471 ridotto.
solveOnline(vel_now, temp_now, mu_on, ref_start);
473 folder = {
"./ITHACAoutput/Sensitivity/ModelOutput/"};
479 int Ntot = samplingPoints;
480 double deltat_online = difftime(tend, tstart);
482 std::ofstream diff_ton(
"./ITHACAoutput/t_onlineSA_" + name(Ntot) +
"=" + name(
485 Tmlocal TmediaSA(argc, argv, Ntot);
486 Plocal PtotSA(argc, argv, Ntot);
491 analisi.
M = autoPtr<FofM>(& TmediaSA);
496 std::cout <<
"Mean value and variance of the output:" << std::endl;
497 std::cout << analisi.
Ey <<
"\t" << analisi.
Vy << std::endl;
498 std::cout <<
"-------------" << std::endl;
501 std::cout <<
"analisi regression coefficients:" << std::endl;
502 std::cout << analisi.
betas << std::endl;
503 std::cout <<
"-------------" << std::endl;
506 std::cout <<
"quality: " << analisi.
QI << std::endl;
508 Eigen::MatrixXd saveyout(samplingPoints, 1);
509 Eigen::MatrixXd saveymodel(samplingPoints, 1);
510 saveyout.col(0) = analisi.
y;
511 saveymodel.col(0) = analisi.
ylin;
514 Eigen::MatrixXd coeffsT(4, 3);
516 coeffsT(0, 0) = analisi.
Ey;
517 coeffsT(0, 1) = analisi.
Vy;
518 coeffsT(0, 2) = analisi.
QI;
519 coeffsT.row(1) = analisi.
EX;
520 coeffsT.row(2) = analisi.
VX;
521 coeffsT.row(3) = analisi.
betas;
524 analisi.
M = autoPtr<FofM>(& PtotSA);
529 std::cout <<
"Mean value and variance of the output:" << std::endl;
530 std::cout << analisi.
Ey <<
"\t" << analisi.
Vy << std::endl;
531 std::cout <<
"-------------" << std::endl;
533 std::cout <<
"analisi regression coefficients:" << std::endl;
534 std::cout << analisi.
betas << std::endl;
535 std::cout <<
"-------------" << std::endl;
537 std::cout <<
"quality: " << analisi.
QI << std::endl;
538 Eigen::MatrixXd saveyoutP(samplingPoints, 1);
539 Eigen::MatrixXd saveymodelP(samplingPoints, 1);
540 saveyoutP.col(0) = analisi.
y;
541 saveymodelP.col(0) = analisi.
ylin;
544 Eigen::MatrixXd coeffsP(4, 3);
546 coeffsP(0, 0) = analisi.
Ey;
547 coeffsP(0, 1) = analisi.
Vy;
548 coeffsP(0, 2) = analisi.
QI;
549 coeffsP.row(1) = analisi.
EX;
550 coeffsP.row(2) = analisi.
VX;
551 coeffsP.row(3) = analisi.
betas;
int main(int argc, char *argv[])
Header file of the ITHACAstream class, it contains the implementation of several methods for input ou...
Eigen::VectorXd modelOutput
Vector to store the desired output of the model, i.e. the figure of merit.
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
void getYstat()
Method to compute Ey and Vy, it sets Ydone=true.
void getXstats()
Method to compute EX and VX, it sets Xdone=true.
double Vy
Variance of the output.
Eigen::VectorXd y
Vectors to store the output of the model.
double QI
double to quantify the goodness of linear regression from 0 (no linearity) to 1 (perfect linearity) a...
Eigen::MatrixXd MatX
Matrices storing the independent variables' values.
Eigen::VectorXd VX
Vector to store the variances of the parameters.
double Ey
Mean value of the output.
void getBetas()
Method to compute SRCs, it sets bdone=true.
void load_output()
Method to load the output of FOM/ROM inside member LRsensitivity member y.
Eigen::VectorXd ylin
Vector to store the result of linear approximation.
Eigen::MatrixXd trainingRange
Matrix to store the range used in training/offline stage.
Eigen::VectorXd betas
Vector to store the standardized regression coefficient (SRC)
void assessQuality()
Method to compute the quality of linear regression approximation.
void buildSamplingSet(std::vector< std::string > &pdflist, Eigen::MatrixXd plist)
Method to build MatX, it internally calls ITHACAsampling::samplingMC pdflist is the list with the nam...
Eigen::VectorXd EX
Vector to store the meanvalues of the parameters.
autoPtr< FofM > M
Figure of merit object.
volScalarField & powerDens
Plocal(int argc, char *argv[], int Nsampled)
Ploct(int argc, char *argv[], int Nsampled)
volScalarField & powerDens
autoPtr< volScalarField > _powerDens
List of pointers to power density field.
void buildMO(std::string dir, label t)
Method that computes the total power for the snapshot number t (starting from 0), output are sought i...
void buildMO(std::string dir)
Method that computes the total power at the last time instant of the simulation, output are sought in...
autoPtr< volScalarField > _powerDens
List of pointers to power density field.
autoPtr< volScalarField > _T
List of pointers to temperature field.
void buildMO(std::string dir, label t)
Method that computes the average temperature (integral average) for the snapshot number t (starting f...
void buildMO(std::string dir)
Method that computes the average temperature (integral average) at the last time instant of the simul...
autoPtr< volScalarField > _T
List of pointers to temperature field.
Tmlocal(int argc, char *argv[], int Nsampled)
Tmloct(int argc, char *argv[], int Nsampled)
autoPtr< dimensionedScalar > _betaTot
autoPtr< volScalarField > _NSF
void homogenizeT()
Method to compute the homogenized temperature field, it also sets homboolT=true.
autoPtr< volScalarField > _prec8
autoPtr< volScalarField > _dec3
autoPtr< volScalarField > _SP
autoPtr< volScalarField > _T
PtrList< volScalarField > Prec8field
List of pointers used to form the prec8 snapshots matrix.
autoPtr< dimensionedScalar > _beta8
autoPtr< volScalarField > _dec2
autoPtr< dimensionedScalar > _beta5
autoPtr< volScalarField > _prec2
PtrList< volScalarField > Fluxfield
List of pointers used to form the flux snapshots matrix.
autoPtr< volScalarField > _prec4
autoPtr< dimensionedScalar > _beta2
PtrList< volScalarField > Prec4field
List of pointers used to form the prec4 snapshots matrix.
void change_viscosity(double mu)
method to change the viscosity in UEqn
autoPtr< dimensionedScalar > _beta3
void readMSRfields()
Method to read all the fieds of the MSR problem in the offline folder, it also reads mu_samples matri...
PtrList< volScalarField > Dec3field
List of pointers used to form the dec3 snapshots matrix.
void liftSolve()
Perform a lift solve for the velocity field.
autoPtr< volVectorField > _U
autoPtr< dimensionedScalar > _beta7
void liftSolveT()
Perform a lift solve for the temperature.
autoPtr< dimensionedScalar > _beta1
autoPtr< dimensionedScalar > _decLam3
autoPtr< volScalarField > _prec5
autoPtr< volScalarField > _v
autoPtr< dimensionedScalar > _beta4
PtrList< volScalarField > Dec1field
List of pointers used to form the dec1 snapshots matrix.
autoPtr< volScalarField > _prec3
PtrList< volScalarField > PowerDensfield
List of pointers used to form the powerDens snapshots matrix.
autoPtr< volScalarField > _prec6
autoPtr< volScalarField > _D
autoPtr< volScalarField > _prec7
autoPtr< dimensionedScalar > _nu
autoPtr< volScalarField > _TXS
autoPtr< volScalarField > _p
void restart()
method to set all fields back to values in 0 folder
PtrList< volScalarField > Tfield
List of pointers used to form the temperature snapshots matrix.
PtrList< volVectorField > Ufield
List of pointers used to form the velocity snapshots matrix.
PtrList< volScalarField > Prec1field
List of pointers used to form the prec1 snapshots matrix.
autoPtr< volScalarField > _prec1
void homogenizeU()
Method to compute the homogenized velocity field, it also sets homboolU=true.
void projectPPE(fileName folder, label NUmodes, label NPmodes, label NFluxmodes, Eigen::VectorXi Nprecmodes, label NTmodes, Eigen::VectorXi Ndecmodes, label NCmodes)
Project using the Poisson Equation for pressure.
PtrList< volScalarField > TXSFields
List of pointers used to form the SP snapshosts matrix.
void msrgetModesEVD()
Method to compute the modes for all the fields in the MSR problem, if hombool==false the velocity mod...
autoPtr< volScalarField > _flux
autoPtr< volScalarField > _A
autoPtr< dimensionedScalar > _beta6
autoPtr< volScalarField > _dec1
msr(int argc, char *argv[])
PtrList< volScalarField > DEC3REC
PtrList< volScalarField > FLUXREC
scalar nu
characteristic constants of the problem
PtrList< volScalarField > TXSREC
PtrList< volScalarField > PREC4REC
PtrList< volVectorField > UREC
Recontructed fields.
PtrList< volScalarField > DEC1REC
PtrList< volScalarField > PREC1REC
PtrList< volScalarField > POWERDENSREC
PtrList< volScalarField > TREC
void clearFields()
Method to clear all the fields of MSR (sets the size to zero)
PtrList< volScalarField > PREC8REC
void solveOnline(Eigen::MatrixXd vel_now, Eigen::MatrixXd temp_now, Eigen::VectorXd mu_online, int startSnap=0)
void reconstructAP(fileName folder="./ITHACAOutput/online_rec", int printevery=1)
Eigen::MatrixXi inletIndexT
label Pnumber
Number of parameters.
label Tnumber
Dimension of the training set (used only when gerating parameters without input)
bool offline
Boolean variable, it is 1 if the Offline phase has already been computed, else 0.
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.
Eigen::MatrixXi inletIndex
Matrix that contains informations about the inlet boundaries.
void truthSolve()
Perform a TruthSolve.
usmsrProblem()
Construct Null.
void exportMatrix(Eigen::Matrix< T, -1, dim > &matrix, word Name, word type, word folder)
Export the reduced matrices in numpy (type=python), matlab (type=matlab) and txt (type=eigen) format ...
List< Eigen::MatrixXd > readMatrix(word folder, word mat_name)
Read a three dimensional matrix from a txt file in Eigen format.
double errorL2Rel(GeometricField< T, fvPatchField, volMesh > &field1, GeometricField< T, fvPatchField, volMesh > &field2, List< label > *labels)
Computes the relative error between two geometric Fields in L2 norm.