Loading...
Searching...
No Matches
IHTP01inverseLaplacian.H
Go to the documentation of this file.
1#ifndef IHTP01inverseLaplacian_H
2#define IHTP01inverseLaplacian_H
3
10{
11 public:
12 explicit IHTP01inverseLaplacian_paramBC(int argc, char* argv[])
13 :
15 T(_T()),
16 mesh(_mesh()),
18 {
19 hotSide_ind = mesh.boundaryMesh().findPatchID("hotSide");
20 coldSide_ind = mesh.boundaryMesh().findPatchID("coldSide");
22 }
23
25 volScalarField& T;
26
28 fvMesh& mesh;
29
31 Time& runTime;
32
34 double a;
35
37 double b;
38
40 double c;
41
43 double d;
44
46 List<scalar> heatFlux_gammaEx1;
47
49 List<scalar> heatFlux_gammaEx2;
50
52 List<scalar> heatFlux_gammaEx3;
53
55 List<scalar> heatFlux_gammaEx4;
56
59
62
65
68
70 PtrList<volScalarField> gField;
71
72
73 //--------------------------------------------------------------------------
77 {
78 restart();
79 fvMesh& mesh = _mesh();
80 simpleControl& simple = _simple();
81 volScalarField Tad(_T());
82 Foam::Time& runTime = _runTime();
84 List<scalar> RobinBC = - Tf;
85 forAll(mesh.boundaryMesh(), patchI)
86 {
87 if (patchI == mesh.boundaryMesh().findPatchID("coldSide"))
88 {
90 }
91 else if (patchI == mesh.boundaryMesh().findPatchID("hotSide"))
92 {
94 }
95 else if (patchI == mesh.boundaryMesh().findPatchID("gammaEx1"))
96 {
98 }
99 else if (patchI == mesh.boundaryMesh().findPatchID("gammaEx2"))
100 {
102 }
103 else if (patchI == mesh.boundaryMesh().findPatchID("gammaEx3"))
104 {
106 }
107 else if (patchI == mesh.boundaryMesh().findPatchID("gammaEx4"))
108 {
110 }
111 }
112
113#if defined(OFVER) && (OFVER == 6)
114
115 while (simple.loop(runTime))
116#else
117 while (simple.loop())
118#endif
119 {
120 while (simple.correctNonOrthogonal())
121 {
122 fvScalarMatrix TEqn
123 (
124 fvm::laplacian(DT, Tad)
125 );
126 TEqn.solve();
127 }
128 }
129
130 Tad_base.append(Tad.clone());
131 //Reinitializing runTime
132 instantList Times = runTime.times();
133 runTime.setTime(Times[1], 1);
137 "Tad");
138 }
139
140 //--------------------------------------------------------------------------
149 void postProcess(word folder, word heatFluxFieldName, scalar innerField = 0.0)
150 {
151#include"postProcess.H"
152 }
153
154
155 //--------------------------------------------------------------------------
159 {
160#include"directBC.H"
161 }
162
163 //--------------------------------------------------------------------------
167 {
168 word outputFolder = "./ITHACAoutput/true/";
169#include"solveTrue.H"
170 }
171
172 //--------------------------------------------------------------------------
177 Eigen::VectorXd bestApproximator()
178 {
179 fvMesh& mesh = _mesh();
180 int Nbasis = gBaseFunctions.size();
181 Eigen::MatrixXd mass(Nbasis, Nbasis);
182 Eigen::VectorXd source(Nbasis);
183 forAll(gBaseFunctions, baseI)
184 {
185 forAll(gBaseFunctions, baseJ)
186 {
187 mass(baseI, baseJ) = ITHACAutilities::L2productOnPatch(mesh,
188 gBaseFunctions[baseI], gBaseFunctions[baseJ], "hotSide");
189 }
190
192 gTrue, "hotSide");
193 }
194
195 return mass.fullPivLu().solve(source); //Vector of coefficients
196 }
197
198
199 //--------------------------------------------------------------------------
204 Eigen::VectorXd bestInterpolation()
205 {
206 int Nbasis = gBaseFunctions.size();
207 Eigen::VectorXd coeff(Nbasis);
208 Eigen::MatrixXd Phi = Eigen::MatrixXd::Zero(Nbasis, Nbasis);
209 forAll(gBaseFunctions, baseI)
210 {
211 scalar centerX = thermocouplesPos[baseI].x();
212 scalar centerZ = thermocouplesPos[baseI].z();
214 {
215 scalar tcX = thermocouplesPos[TCi].x();
216 scalar tcZ = thermocouplesPos[TCi].z();
217 double radius = Foam::sqrt((tcX - centerX) * (tcX - centerX) +
218 (tcZ - centerZ) * (tcZ - centerZ));
219 Phi(TCi, baseI) = Foam::exp(- (shapeParameter *
221 * radius * radius));
222 }
223
224 coeff(baseI) = k * (b * thermocouplesPos[baseI].x() + c);
225 }
226
227 return Phi.fullPivLu().solve(coeff);
228 }
229
230};
231
232
233
240{
241 public:
242 explicit IHTP01inverseLaplacian_CG(int argc, char* argv[])
243 :
244 inverseLaplacianProblem_CG(argc, argv),
245 T(_T()),
246 lambda(_lambda()),
247 deltaT(_deltaT()),
248 mesh(_mesh()),
250 {
251 hotSide_ind = mesh.boundaryMesh().findPatchID("hotSide");
252 coldSide_ind = mesh.boundaryMesh().findPatchID("coldSide");
254 cgIter = 0;
256 }
257
259 volScalarField& T;
260
262 volScalarField& lambda;
263
265 volScalarField& deltaT;
266
268 fvMesh& mesh;
269
271 Time& runTime;
272
274 double a;
275
277 double b;
278
280 double c;
281
283 double d;
284
286 List<scalar> heatFlux_gammaEx1;
287
289 List<scalar> heatFlux_gammaEx2;
290
292 List<scalar> heatFlux_gammaEx3;
293
295 List<scalar> heatFlux_gammaEx4;
296
299
302
305
308
310 PtrList<volScalarField> gField;
311
312 //--------------------------------------------------------------------------
321 void postProcess(word folder, word heatFluxFieldName, scalar innerField = 0.0)
322 {
323#include"postProcess.H"
324 }
325
326
327 //--------------------------------------------------------------------------
331 {
332#include"directBC.H"
333 }
334
335 //--------------------------------------------------------------------------
339 {
340 word outputFolder = "./ITHACAoutput/true/";
341#include"solveTrue.H"
342 }
343};
344
345#endif
forAll(example_CG.gList, solutionI)
Definition CGtest.H:21
label gammaEx3_ind
gammaEx3 boundary patches label
label gammaEx4_ind
gammaEx4 boundary patches label
IHTP01inverseLaplacian_CG(int argc, char *argv[])
double a
Constant to define boundary conditions.
volScalarField & deltaT
Sensitivity field.
PtrList< volScalarField > gField
List of estimated heat fluxes used for post processing.
volScalarField & T
Temperature field.
double b
Constant to define boundary conditions.
List< scalar > heatFlux_gammaEx1
Boundary heat flux at the gammaEx1 patch.
void assignDirectBC()
Assign the correct boundary condition to direct problem and assign -g/k to the hotSide patch.
void postProcess(word folder, word heatFluxFieldName, scalar innerField=0.0)
Post process all the estimated heat fluxes heatFluxFieldName inside folder computing the relative err...
label gammaEx2_ind
gammaEx2 boundary patches label
double d
Constant to define boundary conditions.
double c
Constant to define boundary conditions.
List< scalar > heatFlux_gammaEx4
Boundary heat flux at the gammaEx4 patch.
label gammaEx1_ind
gammaEx1 boundary patches label
volScalarField & lambda
Adjoint field.
List< scalar > heatFlux_gammaEx2
Boundary heat flux at the gammaEx2 patch.
void solveTrue()
Perform a solution of the direct problem with the correct boundary conditions.
List< scalar > heatFlux_gammaEx3
Boundary heat flux at the gammaEx3 patch.
double a
Constant to define boundary conditions.
double c
Constant to define boundary conditions.
volScalarField & T
Temperature field.
IHTP01inverseLaplacian_paramBC(int argc, char *argv[])
label gammaEx3_ind
gammaEx3 boundary patches label
label gammaEx1_ind
gammaEx1 boundary patches label
void solveTrue()
Perform a solution of the direct problem with the correct boundary conditions.
label gammaEx2_ind
gammaEx2 boundary patches label
void assignDirectBC()
Assign the correct boundary condition to direct problem and assign -g/k to the hotSide patch.
Eigen::VectorXd bestInterpolation()
Compute the best interpolation of the true heat flux gTrue in the parameterized space.
double d
Constant to define boundary conditions.
void postProcess(word folder, word heatFluxFieldName, scalar innerField=0.0)
Post process all the estimated heat fluxes heatFluxFieldName inside folder computing the relative err...
List< scalar > heatFlux_gammaEx2
Boundary heat flux at the gammaEx2 patch.
List< scalar > heatFlux_gammaEx4
Boundary heat flux at the gammaEx4 patch.
Eigen::VectorXd bestApproximator()
Compute the best approximation of the true heat flux gTrue in the parameterized space.
label gammaEx4_ind
gammaEx4 boundary patches label
List< scalar > heatFlux_gammaEx3
Boundary heat flux at the gammaEx3 patch.
PtrList< volScalarField > gField
List of estimated heat fluxes used for post processing.
List< scalar > heatFlux_gammaEx1
Boundary heat flux at the gammaEx1 patch.
double b
Constant to define boundary conditions.
void solveAdditional()
Solve the additional problem.
bool interpolationPlaneDefined
Flag for definition of interpolation plane.
int cgIter
Conjugate Gradient (CG) interations counter.
autoPtr< volScalarField > _deltaT
Sensibility temperature field.
autoPtr< volScalarField > _lambda
Adjoint field.
Eigen::VectorXd addSol
Solution of the additional problem at the thermocouples positions.
List< List< scalar > > gBaseFunctions
Basis of the heat flux parameterization.
word folderOffline
Folder where the offline solutions and matrices are saved.
PtrList< volScalarField > Tad_base
Solution of the additional problem.
label hotSide_ind
Index of the hotSide patch.
dimensionedScalar DT
Dummy thermal conductivity with unitary value.
List< vector > thermocouplesPos
List containing the positions of the thermocouples.
List< scalar > Tf
Temperature at coldSide [K].
autoPtr< simpleControl > _simple
simpleControl
bool thermocouplesRead
Flag to know if thermocouples file was read.
List< scalar > valueFraction
Value fraction for the Robin BC.
scalar homogeneousBC
Homogenerous BC.
void set_valueFraction()
Set valueFraction list values for Robin condition.
label coldSide_ind
Index of the coldSide patch.
autoPtr< fvMesh > _mesh
Mesh.
Eigen::VectorXd fieldValueAtThermocouples(volScalarField &field)
Interpolates the field value at the thermocouples points.
List< scalar > gTrue
True heat flux at hotSide [w/m2].
List< scalar > refGrad
Reference gradient for the Robin BC.
double k
Thermal diffusivity [W/(m K)].
autoPtr< volScalarField > _T
Temperature field.
Eigen::MatrixXd source
Source vector.
fvScalarMatrix & TEqn
Definition TEqn.H:15
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 assignMixedBC(GeometricField< Type, fvPatchField, volMesh > &field, label BC_ind, List< Type > &value, List< Type > &grad, List< scalar > &valueFrac)
Assign value of a boundary condition of type "mixed".
void assignBC(GeometricField< scalar, fvPatchField, volMesh > &s, label BC_ind, double value)
Assign uniform Boundary Condition to a volScalarField.
double L2productOnPatch(fvMesh &mesh, List< scalar > &field1, List< scalar > &field2, word patch)
Evaluate the L2 inner product between two scalarLists.
simpleControl simple(mesh)