43 int argc,
char* argv[])
59 char recomputeOffline;
70 std::cout <<
"\nOffline FOUND with parameter:\n" <<
71 "Number of thermocouples = " << metaData.
numberTC <<
72 "\nNumber of basis functions = " << metaData.
numberBasis <<
73 "\nType of basis functions = " << metaData.
basisType <<
75 "\n\nShould I recompute it? [y/n]" << std::endl;
76 std::cin >> recomputeOffline;
78 while ( !cin.fail() && recomputeOffline !=
'y' && recomputeOffline !=
'n' );
81 if (recomputeOffline ==
'y')
88 Info <<
"\nOffline already computed." << endl;
89 Info <<
"Check that the basis used for the parameterized BC are correct (RBF, POD, etc.)\n";
94 volScalarField&
T(
_T());
101 Info <<
"\nComputing offline" << endl;
115 int Nbasis =
Theta.cols();
119 for (label j = 0; j < Nbasis; j++)
124 Info <<
"Solving for j = " << j << endl;
127 volScalarField&
T =
_T();
131 for (label
i = 0;
i <
Theta.rows();
i++)
142 for (label baseI = 0; baseI < Nbasis; baseI++)
144 for (label baseJ = 0; baseJ < Nbasis; baseJ++)
146 Phi(baseI, baseJ) =
phi(baseI) *
phi(baseJ);
154 Info <<
"\nOffline part ENDED\n" << endl;
158 Eigen::JacobiSVD<Eigen::MatrixXd>
svd(
A,
159 Eigen::ComputeThinU | Eigen::ComputeThinV);
177 Info << endl <<
"Using quasilinearity of direct problem" << endl;
178 List<Eigen::MatrixXd> linSys;
180 Info <<
"debug: Theta size = " <<
Theta.rows() <<
", " <<
Theta.cols() << endl;
184 Eigen::VectorXd weigths;
188 if (linSys_solver ==
"fullPivLU")
190 weigths = linSys[0].fullPivLu().solve(linSys[1]);
192 else if (linSys_solver ==
"jacobiSvd")
194 Eigen::JacobiSVD<Eigen::MatrixXd>
svd(linSys[0],
195 Eigen::ComputeThinU | Eigen::ComputeThinV);
196 weigths =
svd.solve(linSys[1]);
198 else if (linSys_solver ==
"householderQr")
200 weigths = linSys[0].householderQr().solve(linSys[1]);
202 else if (linSys_solver ==
"ldlt")
204 weigths = linSys[0].ldlt().solve(linSys[1]);
206 else if (linSys_solver ==
"inverse")
208 weigths = linSys[0].inverse() * linSys[1];
210 else if (linSys_solver ==
"TSVD")
214 else if (linSys_solver ==
"Tikhonov")
220 Info <<
"Select a linear system solver in this list:" << endl
221 <<
"fullPivLU, jacobiSvd, householderQr, ldlt, inverse, TSVD" << endl;
#define M_Assert(Expr, Msg)
void parameterizedBCoffline(bool force=0)
Performs offline computation for the parameterized BC method, if the offline directory "".
inverseLaplacianProblemTotalHeatMeasure_paramBC()
Eigen::VectorXd parameterizedBC(word linSys_solver="fullPivLU", double regPar=0)
Implementation of a parameterization method to solve inverse Laplacian problems.
void update_gParametrized(List< scalar > weigths)
Update the boundary heat flux.
Eigen::VectorXd addSol
Solution of the additional problem at the thermocouples positions.
Eigen::MatrixXd Theta
Theta matrix of the lynear system.
virtual void solveAdditional()
Set BC the additional problem and solves it.
void parameterizedBCpostProcess(Eigen::VectorXd weigths)
Reconstruct the temperature field and compute the cost function J.
word baseFuncType
Type of basis functions used for the parameterization of the heat flux.
PtrList< volScalarField > Tbasis
Solutions of the direct problem with the basis of the parameterization as boundary heat flux.
List< scalar > gWeights
Weights of the heat flux parameterization.
double shapeParameter
RBF shape parameter.
word folderOffline
Folder where the offline solutions and matrices are saved.
PtrList< volScalarField > Tad_base
Solution of the additional problem.
List< scalar > g
Heat flux at hotSide [W/m2].
Eigen::VectorXd Tdirect
Vector of computed temperatures at the thermocouples locations [K].
volScalarField list2Field(List< scalar > list, scalar innerField=0.0)
Create a field with the hotSide boundary heat flux at the hotSide bounday cells for visualization.
Eigen::VectorXd Tmeas
Vector of measured temperatures at the thermocouples locations [K].
autoPtr< fvMesh > _mesh
Mesh.
Eigen::VectorXd fieldValueAtThermocouples(volScalarField &field)
Interpolates the field value at the thermocouples points.
void solveDirect()
Solve direct problem.
autoPtr< volScalarField > _T
Temperature field.
Header file of the inverseLaplacianProblemTotalHeatMeasure_paramBC class.
Eigen::VectorXd Tikhonov(Eigen::MatrixXd A, Eigen::MatrixXd b, double regularizationParameter)
Truncated Singular Value regularization.
Eigen::VectorXd TSVD(Eigen::MatrixXd A, Eigen::MatrixXd b, int filter)
Truncated Singular Value regularization.
void exportFields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &field, word folder, word fieldname)
Function to export a scalar of vector field.
void exportSolution(GeometricField< Type, PatchField, GeoMesh > &s, fileName subfolder, fileName folder, word fieldName)
Export a field to file in a certain folder and subfolder.
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.
void read_fields(PtrList< GeometricField< Type, PatchField, GeoMesh > > &Lfield, word Name, fileName casename, int first_snap, int n_snap)
Function to read a list of fields from the name of the field and casename.
double integralOnPatch(fvMesh &mesh, volScalarField &field, word patch)
Evaluate the integral on a patch.
bool check_file(std::string fileName)
Function that returns true if a file exists.
Info<< endl;Info<< "*********************************************************"<< endl;Info<< "Performing test for the parameterized BC inverse solver"<< endl;Info<< endl;word outputFolder="./ITHACAoutput/parameterizedBCtest_RBFparameter/";volScalarField gTrueField=example_paramBC.list2Field(example_paramBC.gTrue);ITHACAstream::exportSolution(gTrueField, "1", outputFolder, "gTrue");Eigen::VectorXd rbfWidth=EigenFunctions::ExpSpaced(0.001, 100, rbfWidthTest_size);ITHACAstream::exportMatrix(rbfWidth, "rbfShapeParameters", "eigen", outputFolder);Eigen::VectorXd residualNorms;residualNorms.resize(rbfWidthTest_size);Eigen::VectorXd heatFluxL2norm(rbfWidthTest_size);Eigen::VectorXd heatFluxLinfNorm=heatFluxL2norm;Eigen::VectorXd condNumber=heatFluxL2norm;Eigen::MatrixXd singVal;for(int i=0;i< rbfWidthTest_size;i++){ Info<< "*********************************************************"<< endl;Info<< "RBF parameter "<< rbfWidth(i)<< endl;Info<< "Test "<< i+1<< endl;Info<< endl;example_paramBC.set_gParametrized("rbf", rbfWidth(i));example_paramBC.parameterizedBCoffline(1);example_paramBC.parameterizedBC("fullPivLU");volScalarField gParametrizedField=example_paramBC.list2Field(example_paramBC.g);ITHACAstream::exportSolution(gParametrizedField, std::to_string(i+1), outputFolder, "gParametrized");volScalarField &T(example_paramBC._T());ITHACAstream::exportSolution(T, std::to_string(i+1), outputFolder, "T");residualNorms(i)=Foam::sqrt(example_paramBC.residual.squaredNorm());Eigen::MatrixXd A=example_paramBC.Theta.transpose() *example_paramBC.Theta;Eigen::JacobiSVD< Eigen::MatrixXd > svd(A, Eigen::ComputeThinU|Eigen::ComputeThinV)
Eigen::MatrixXd singularValues