40inverseLaplacianProblemTotalHeatMeasure_paramBC::inverseLaplacianProblemTotalHeatMeasure_paramBC() {}
42inverseLaplacianProblemTotalHeatMeasure_paramBC::inverseLaplacianProblemTotalHeatMeasure_paramBC(
43 int argc,
char* argv[])
56 fvMesh& mesh =
_mesh();
59 char recomputeOffline;
67 fin >> metaData.numberTC >> metaData.numberBasis >>
68 metaData.basisType >> metaData.shapeParameter;
70 Info <<
"\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 <<
74 "\nRBF shape parameters = " << metaData.shapeParameter <<
75 "\n\nShould I recompute it? [y/n]" << 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;
104 M_Assert(
Tmeas.size() > 0,
"Initialize Tmeas");
105 M_Assert(
gWeights.size() > 0,
"Initialize gWeights");
110 fout << metaData.numberTC <<
' ' <<
111 metaData.numberBasis <<
' ' <<
112 metaData.basisType <<
' ' <<
113 metaData.shapeParameter <<
' ';
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;
157 Eigen::MatrixXd A =
Theta.transpose() *
Theta + gIntegralWeight * Phi;
158 Eigen::JacobiSVD<Eigen::MatrixXd> svd(A,
159 Eigen::ComputeThinU | Eigen::ComputeThinV);
160 Eigen::MatrixXd singularValues = svd.singularValues();
162 if (singularValues.minCoeff() > 0)
164 double conditionNumber = singularValues.maxCoeff() / singularValues.minCoeff();
165 Info <<
"Condition number = " << conditionNumber << endl;
173inverseLaplacianProblemTotalHeatMeasure_paramBC::parameterizedBC(
177 Info << endl <<
"Using quasilinearity of direct problem" << endl;
178 List<Eigen::MatrixXd> linSys;
180 Info <<
"debug: Theta size = " <<
Theta.rows() <<
", " <<
Theta.cols() << endl;
181 linSys[0] =
Theta.transpose() *
Theta + gIntegralWeight * Phi;
182 linSys[1] = gIntegralWeight * gIntegral_meas * phi +
Theta.transpose() *
184 Eigen::VectorXd weigths;
185 M_Assert(std::abs(gIntegral_meas) > 1e-16,
"First set up gIntegral_meas");
186 M_Assert(std::abs(gIntegralWeight) > 1e-16,
"First set up gIntegralWeight");
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;
void parameterizedBCoffline(bool force=0)
Performs offline computation for the parameterized BC method, if the offline directory "".
void update_gParametrized(List< scalar > weigths)
Update the boundary heat flux.
Eigen::VectorXd addSol
Solution of the additional problem at the thermocouples positions.
inverseLaplacianProblem_paramBC()
Null constructor.
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.