18 explicit msr(
int argc,
char* argv[])
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)
154 explicit Plocal(
int argc,
char* argv[],
int Nsampled)
156 Ptot(argc, argv, Nsampled),
165 explicit Tmloct(
int argc,
char* argv[],
int Nsampled)
174int main(
int argc,
char* argv[])
177 msr prova(argc, argv);
191 int central =
static_cast<int>(prova.
Tnumber / 2);
192 double nu0 = 2.46E-06;
193 double betatot0 = 321.8E-05;
194 double dlam30 = 3.58e-04;
198 prova.
mu_range(1, 0) = 1.1 * betatot0;
199 prova.
mu_range(1, 1) = 0.9 * betatot0;
200 prova.
mu_range(2, 0) = 1.1 * dlam30;
201 prova.
mu_range(2, 1) = 0.9 * dlam30;
204 prova.
mu(0, central) = nu0;
205 prova.
mu(1, central) = betatot0;
206 prova.
mu(2, central) = dlam30;
207 double tstart = std::time(0);
208 Eigen::MatrixXd arange(prova.
Pnumber, 2);
209 Eigen::MatrixXd mu_f = prova.
mu;
215 arange(
i, 0) = prova.
mu.row(
i).minCoeff();
216 arange(
i, 1) = prova.
mu.row(
i).maxCoeff();
230 prova.
_nu().value() = nu0;
232 double tend = std::time(0);
233 double deltat_offline;
234 deltat_offline = difftime(tend, tstart);
239 std::ofstream diff_t(
"./ITHACAoutput/t_offline=" + name(deltat_offline));
242 std::cout <<
"Offline stage time= " << deltat_offline << std::endl;
254 Eigen::VectorXi NPrec(8);
263 Eigen::VectorXi NDec(3);
270 double umedio = 2.46E-03;
272 Eigen::MatrixXd Twall(4, 2);
284 Eigen::MatrixXd vel_now(1, 1);
285 vel_now(0, 0) = umedio;
287 Eigen::MatrixXd temp_now = Twall;
289 Eigen::VectorXd mu_on(3);
290 ridotto.
nu = mu_f(0, central);
291 ridotto.
btot = mu_f(1, central);
292 ridotto.
b1 = prova.
r1 * ridotto.
btot;
293 ridotto.
b2 = prova.
r2 * ridotto.
btot;
294 ridotto.
b3 = prova.
r3 * ridotto.
btot;
295 ridotto.
b4 = prova.
r4 * ridotto.
btot;
296 ridotto.
b5 = prova.
r5 * ridotto.
btot;
297 ridotto.
b6 = prova.
r6 * ridotto.
btot;
298 ridotto.
b7 = prova.
r7 * ridotto.
btot;
299 ridotto.
b8 = prova.
r8 * ridotto.
btot;
300 ridotto.
dl3 = mu_f(2, central);
303 mu_on(0) = ridotto.
nu;
304 mu_on(1) = ridotto.
btot;
305 mu_on(2) = ridotto.
dl3;
306 ridotto.
solveOnline(vel_now, temp_now, mu_on, ref_start);
314 Eigen::MatrixXd err(10, tf);
315 Eigen::MatrixXd TmFOM(prova.
Tnumber, tf);
316 Eigen::MatrixXd PtotFOM(prova.
Tnumber, tf);
317 Eigen::MatrixXd TmROM(prova.
Tnumber, tf);
318 Eigen::MatrixXd PtotROM(prova.
Tnumber, tf);
319 std::cout <<
"Computing errors on reference case..." << std::endl;
321 for (
int i = ref_start;
i < ref_start + tf;
i++)
344 std::cout <<
"End" << std::endl;
347 std::cout <<
"computing FOM output..." << std::endl;
353 for (
int i = 0;
i < prova.
Tfield.size();
i++)
355 tmpt = prova.
Tfield[
i].weightedAverage(prova.
_mesh().V()).value();
360 TmFOM(rig,
col) = tmpt;
361 PtotFOM(rig,
col) = tmpp;
364 else if (
col == tf_fom)
375 std::cout <<
"End" << std::endl;
381 std::string folder = {
"./ITHACAoutput/ROMOutput/"};
385 ridotto.
nu = mu_f(0,
i);
386 ridotto.
btot = mu_f(1,
i);
387 ridotto.
b1 = prova.
r1 * ridotto.
btot;
388 ridotto.
b2 = prova.
r2 * ridotto.
btot;
389 ridotto.
b3 = prova.
r3 * ridotto.
btot;
390 ridotto.
b4 = prova.
r4 * ridotto.
btot;
391 ridotto.
b5 = prova.
r5 * ridotto.
btot;
392 ridotto.
b6 = prova.
r6 * ridotto.
btot;
393 ridotto.
b7 = prova.
r7 * ridotto.
btot;
394 ridotto.
b8 = prova.
r8 * ridotto.
btot;
395 ridotto.
dl3 = mu_f(2,
i);
396 mu_on(0) = ridotto.
nu;
397 mu_on(1) = ridotto.
btot;
398 mu_on(2) = ridotto.
dl3;
399 folder.append(std::to_string(
i));
400 ridotto.
solveOnline(vel_now, temp_now, mu_on, ref_start);
402 folder = {
"./ITHACAoutput/ROMOutput/"};
411 for (
int i = 0;
i < tf;
i++)
427 folder = {
"./ITHACAoutput/Sensitivity/ModelOutput/"};
428 int Nparameters = prova.
Pnumber;
429 std::vector<std::string> pdflist = {
"normal",
"normal",
"normal"};
430 int samplingPoints = 1000;
435 Eigen::MatrixXd Mp(Nparameters, 2);
437 Mp(0, 1) = nu0 * 0.1 / 3;
439 Mp(1, 1) = betatot0 * 0.1 / 3;
441 Mp(2, 1) = dlam30 * 0.1 / 3;
449 tstart = std::time(0);
452 for (
int j = 0; j < samplingPoints; j++)
454 ridotto.
nu = analisi.
MatX(j, 0);
456 ridotto.
b1 = prova.
r1 * ridotto.
btot;
457 ridotto.
b2 = prova.
r2 * ridotto.
btot;
458 ridotto.
b3 = prova.
r3 * ridotto.
btot;
459 ridotto.
b4 = prova.
r4 * ridotto.
btot;
460 ridotto.
b5 = prova.
r5 * ridotto.
btot;
461 ridotto.
b6 = prova.
r6 * ridotto.
btot;
462 ridotto.
b7 = prova.
r7 * ridotto.
btot;
463 ridotto.
b8 = prova.
r8 * ridotto.
btot;
464 ridotto.
dl3 = analisi.
MatX(j, 2);
465 mu_on(0) = ridotto.
nu;
466 mu_on(1) = ridotto.
btot;
467 mu_on(2) = ridotto.
dl3;
468 folder.append(std::to_string(counter));
469 ridotto.
solveOnline(vel_now, temp_now, mu_on, ref_start);
471 folder = {
"./ITHACAoutput/Sensitivity/ModelOutput/"};
477 int Ntot = samplingPoints;
478 double deltat_online = difftime(tend, tstart);
480 std::ofstream diff_ton(
"./ITHACAoutput/t_onlineSA_" + name(Ntot) +
"=" + name(
483 Tmlocal TmediaSA(argc, argv, Ntot);
484 Plocal PtotSA(argc, argv, Ntot);
489 analisi.
M = autoPtr<FofM>(&TmediaSA);
494 std::cout <<
"Mean value and variance of the output:" << std::endl;
495 std::cout << analisi.
Ey <<
"\t" << analisi.
Vy << std::endl;
496 std::cout <<
"-------------" << std::endl;
499 std::cout <<
"analisi regression coefficients:" << std::endl;
500 std::cout << analisi.
betas << std::endl;
501 std::cout <<
"-------------" << std::endl;
504 std::cout <<
"quality: " << analisi.
QI << std::endl;
506 Eigen::MatrixXd saveyout(samplingPoints, 1);
507 Eigen::MatrixXd saveymodel(samplingPoints, 1);
508 saveyout.col(0) = analisi.
y;
509 saveymodel.col(0) = analisi.
ylin;
512 Eigen::MatrixXd coeffsT(4, 3);
514 coeffsT(0, 0) = analisi.
Ey;
515 coeffsT(0, 1) = analisi.
Vy;
516 coeffsT(0, 2) = analisi.
QI;
517 coeffsT.row(1) = analisi.
EX;
518 coeffsT.row(2) = analisi.
VX;
519 coeffsT.row(3) = analisi.
betas;
522 analisi.
M = autoPtr<FofM>(&PtotSA);
527 std::cout <<
"Mean value and variance of the output:" << std::endl;
528 std::cout << analisi.
Ey <<
"\t" << analisi.
Vy << std::endl;
529 std::cout <<
"-------------" << std::endl;
531 std::cout <<
"analisi regression coefficients:" << std::endl;
532 std::cout << analisi.
betas << std::endl;
533 std::cout <<
"-------------" << std::endl;
535 std::cout <<
"quality: " << analisi.
QI << std::endl;
536 Eigen::MatrixXd saveyoutP(samplingPoints, 1);
537 Eigen::MatrixXd saveymodelP(samplingPoints, 1);
538 saveyoutP.col(0) = analisi.
y;
539 saveymodelP.col(0) = analisi.
ylin;
542 Eigen::MatrixXd coeffsP(4, 3);
544 coeffsP(0, 0) = analisi.
Ey;
545 coeffsP(0, 1) = analisi.
Vy;
546 coeffsP(0, 2) = analisi.
QI;
547 coeffsP.row(1) = analisi.
EX;
548 coeffsP.row(2) = analisi.
VX;
549 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...
IOdictionary * ITHACAdict
Dictionary for input objects from file.
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.
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.