Loading...
Searching...
No Matches
parameterizedBCtest_RBFwidth.H
Go to the documentation of this file.
1Info << endl;
2Info << "*********************************************************" << endl;
3Info << "Performing test for the parameterized BC inverse solver" << endl;
4Info << endl;
5word outputFolder = "./ITHACAoutput/parameterizedBCtest_RBFparameter/";
6volScalarField gTrueField = example_paramBC.list2Field(example_paramBC.gTrue);
8 "1", outputFolder,
9 "gTrue");
10
11Eigen::VectorXd rbfWidth = EigenFunctions::ExpSpaced(0.001, 100,
12 rbfWidthTest_size);
13ITHACAstream::exportMatrix(rbfWidth, "rbfShapeParameters", "eigen",
14 outputFolder);
15
16Eigen::VectorXd residualNorms;
17residualNorms.resize(rbfWidthTest_size);
18Eigen::VectorXd heatFluxL2norm(rbfWidthTest_size);
19Eigen::VectorXd heatFluxLinfNorm = heatFluxL2norm;
20Eigen::VectorXd condNumber = heatFluxL2norm;
21Eigen::MatrixXd singVal;
22
23for (int i = 0; i < rbfWidthTest_size; i++)
24{
25 Info << "*********************************************************" << endl;
26 Info << "RBF parameter " << rbfWidth(i) << endl;
27 Info << "Test " << i + 1 << endl;
28 Info << endl;
29 example_paramBC.set_gParametrized("rbf", rbfWidth(i));
30 example_paramBC.parameterizedBCoffline(1);
31 example_paramBC.parameterizedBC("fullPivLU");
32 volScalarField gParametrizedField = example_paramBC.list2Field(
33 example_paramBC.g);
34 ITHACAstream::exportSolution(gParametrizedField,
35 std::to_string(i + 1),
36 outputFolder,
37 "gParametrized");
38 volScalarField& T(example_paramBC._T());
40 std::to_string(i + 1),
41 outputFolder,
42 "T");
43 residualNorms(i) = Foam::sqrt(
44 example_paramBC.residual.squaredNorm());
45 Eigen::MatrixXd A = example_paramBC.Theta.transpose() * example_paramBC.Theta;
46 Eigen::JacobiSVD<Eigen::MatrixXd> svd(A,
47 Eigen::ComputeThinU | Eigen::ComputeThinV);
48 Eigen::MatrixXd singularValues = svd.singularValues();
49 singVal.conservativeResize(singularValues.rows(), singVal.cols() + 1);
50 singVal.col(i) = singularValues;
52
53 if (singularValues.minCoeff() > 0)
54 {
55 conditionNumber = singularValues.maxCoeff() / singularValues.minCoeff();
56 }
57 else
58 {
59 conditionNumber = DBL_MAX;
60 }
61
62 Info << "Condition number = " << conditionNumber << endl;
64 volScalarField gDiffField = (gParametrizedField - gTrueField).ref();
65 scalar EPS = 1e-6;
66 volScalarField relativeErrorField(gTrueField);
67
68 for (label i = 0; i < relativeErrorField.internalField().size(); i++)
69 {
70 if (std::abs(gTrueField.ref()[i]) < EPS)
71 {
72 relativeErrorField.ref()[i] = (std::abs(gDiffField.ref()[i])) / EPS;
73 }
74 else
75 {
76 relativeErrorField.ref()[i] = (std::abs(gDiffField.ref()[i])) /
77 gTrueField.ref()[i];
78 }
79 }
80
81 ITHACAstream::exportSolution(relativeErrorField,
82 std::to_string(i + 1), outputFolder,
83 "relativeErrorField");
84 heatFluxL2norm(i) = ITHACAutilities::L2normOnPatch(mesh, relativeErrorField,
85 "hotSide");
86 heatFluxLinfNorm(i) = ITHACAutilities::LinfNormOnPatch(mesh, relativeErrorField,
87 "hotSide");
88}
89
90ITHACAstream::exportMatrix(condNumber, "condNumber", "eigen",
91 outputFolder);
92ITHACAstream::exportMatrix(heatFluxL2norm, "relError_L2norm", "eigen",
93 outputFolder);
94ITHACAstream::exportMatrix(heatFluxLinfNorm, "relError_LinfNorm", "eigen",
95 outputFolder);
96ITHACAstream::exportMatrix(singVal, "singularValues", "eigen",
97 outputFolder);
98ITHACAstream::exportMatrix(residualNorms, "residuals2norm", "eigen",
99 outputFolder);
100example_paramBC.postProcess(outputFolder, "gParametrized");
101Info << "*********************************************************" << endl;
102Info << "*********************************************************" << endl;
103Info << endl;
Foam::fvMesh & mesh
Definition createMesh.H:47
volScalarField & T
Definition createT.H:46
volScalarField & A
Eigen::VectorXd ExpSpaced(double first, double last, int n)
Returns exponentially spaced vector.
T condNumber(Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &A)
Conditioning number of a dense matrix.
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 ...
double LinfNormOnPatch(fvMesh &mesh, volScalarField &field, word patch)
Evaluate the Linf norm of a field on a boundary patch.
double L2normOnPatch(fvMesh &mesh, volScalarField &field, word patch)
Evaluate the L2 norm of a field on a boundary patch.
Eigen::VectorXd residualNorms
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
double conditionNumber
label i
Definition pEqn.H:46