Loading...
Searching...
No Matches
sequentialIHTP.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ██╗████████╗██╗ ██╗ █████╗ ██████╗ █████╗ ███████╗██╗ ██╗
3 ██║╚══██╔══╝██║ ██║██╔══██╗██╔════╝██╔══██╗ ██╔════╝██║ ██║
4 ██║ ██║ ███████║███████║██║ ███████║█████╗█████╗ ██║ ██║
5 ██║ ██║ ██╔══██║██╔══██║██║ ██╔══██║╚════╝██╔══╝ ╚██╗ ██╔╝
6 ██║ ██║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ╚████╔╝
7 ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═══╝
8 * In real Time Highly Advanced Computational Applications for Finite Volumes
9 * Copyright (C) 2017 by the ITHACA-FV authors
10-------------------------------------------------------------------------------
11License
12 This file is part of ITHACA-FV
13 ITHACA-FV is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17 ITHACA-FV is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public License
22 along with ITHACA-FV. If not, see <http://www.gnu.org/licenses/>.
23Class
24 sequentialIHTP
25Description
26 A general full order implementation of an inverse problem
27SourceFiles
28 sequentialIHTP.C
29\*---------------------------------------------------------------------------*/
30
35#ifndef sequentialIHTP_H
36#define sequentialIHTP_H
37#include <iostream>
38#include "fvCFD.H"
39#include "interpolation.H"
40#include "fvOptions.H"
41#include "simpleControl.H"
42#include "IOmanip.H"
43#include "Time.H"
44#include "laplacianProblem.H"
45// #include "reducedLaplacian.H"
46#include "ITHACAutilities.H"
47#include <Eigen/Dense>
48#include <cmath>
49#include "Foam2Eigen.H"
50#include "cnpy.H"
51#include "mixedFvPatchFields.H"
52#include "cellDistFuncs.H"
54
55#define _USE_MATH_DEFINES
56
57using namespace SPLINTER;
58
60class sequentialIHTP: public laplacianProblem
61{
62
63 public:
64 // Constructors
65 sequentialIHTP();
67 sequentialIHTP(int argc, char* argv[]);
68 //sequentialIHTP(int argc, char* argv[], scalar _diffusivity);
69 virtual ~sequentialIHTP() {};
70
71 ITHACAparameters* para;
72
73 // Dummy variables to transform inverseLaplacianFoam into a class
75 autoPtr<volScalarField> _T;
76 PtrList<volScalarField> Ttime;
77 List<PtrList<volScalarField>> Tbasis;
78
80 autoPtr<volScalarField> _Tad;
81 PtrList<volScalarField> Tad_time;
82 PtrList<volScalarField> T0_time;
83
85 mutable autoPtr<fvMesh> _mesh;
86
88 autoPtr<simpleControl> _simple;
89
91 autoPtr<fv::options> _fvOptions;
92
94 autoPtr<Time> _runTime;
95 autoPtr<Time> _runTimeShort;
96
98 dimensionedScalar DT;
99
101 scalar diffusivity = 0.0;
102
104 PtrList<volScalarField> T0field;
105
107 volScalarModes T0modes;
108
110 Eigen::MatrixXd T0explicitMatrix_red;
111
113 Eigen::MatrixXd T0implicitMatrix_red;
114
116 Eigen::MatrixXd Tbasis_projectionMat;
117
119 Eigen::VectorXd Tad_projected;
120
122 List<label> magicPoints;
123
125 Eigen::MatrixXd pointsReconstructMatrix;
126
129
131 Eigen::VectorXd pointTad_reconstructed;
132
134 PtrList<volScalarField> projectionErrorTbasis;
135
137 //double projectionErrorTad;
138 PtrList<volScalarField> projectionErrorTad;
139
141 int NmodesT0 = 0;
142
144 scalar startTime;
145 scalar deltaTime;
146 scalar endTime;
147 label Ntimes;
148 List<scalar> timeSteps;
149
152 List<scalar> samplingTime;
153
156
159
162
165
168
171
173 List<label> samplingSteps;
174
177
180
183
185 double J;
186
188 Eigen::VectorXd Jlist;
189
192
194 double HTC;
195
197 double density;
198
201
203 word folderOffline = "./ITHACAoutput/offlineParamBC/";
204
207
209 scalar offlineEndTime = 0.0;
210
211 bool offlineFlag = 0;
212 bool interpolationFlag = 0;
213
216
217 scalar homogeneousBC = 0.0;
218 List<scalar> homogeneousBCcoldSide;
219 List<scalar> Tf; //temperature at coldSide [K]
220 List<scalar> refGrad;
221 List<scalar> valueFraction;
222
225
228
230 List<List<scalar>> g;
231
233 List<List<scalar>> heatFluxSpaceBasis;
234
236 List<List<List<scalar>>> gBaseFunctions;
237
239 label Nbasis = 0;
240
242 label NbasisInTime = 0;
243
245 label NbasisInSpace = 0;
246
248 label NsamplesWindow = 0;
249
251 List<scalar> gWeights;
252
254 List<scalar> gWeightsOld;
255
257 List<List<scalar>> gTrue;
258
260 Eigen::VectorXd residual;
261 Eigen::VectorXd addSol;
262 Eigen::VectorXd T0_vector;
263 Eigen::VectorXd Tcomp;
264 Eigen::MatrixXd Theta;
265 word timeBasisType = "None";
266
267 word linSys_solver;
268 label TSVD_filter;
269 scalar Tikhonov_filter;
270 label CG_Nsteps;
271
272 List<vector> thermocouplesPos;
273 List<int> thermocouplesCellID;
274 List<int> thermocouplesCellProc;
275 List<Foam::vector> thermocouplesCellC;
276 Eigen::VectorXd Tmeas; //Temperature at the thermocouples locations [K]
277 Eigen::VectorXd
278 TmeasShort; //Temperature at the thermocouples locations in only two sampling times [K]
279 Eigen::VectorXd Tdirect;
280 Eigen::VectorXd Tdiff;
281
282 // Functions
283
284 //--------------------------------------------------------------------------
285
287 void setDiffusivity(scalar _diff);
288
289 //--------------------------------------------------------------------------
290
292 void setSpaceBasis(word type, scalar shapeParameter, label Npod = 0);
293
294
295 //--------------------------------------------------------------------------
296
298 void set_gParametrized(word spaceBaseFuncType,
299 scalar shapeParameter_space);
300
301 //--------------------------------------------------------------------------
302
304 volScalarField list2Field(List<scalar> list, scalar innerField = 0.0);
305
306 //--------------------------------------------------------------------------
307
312 List<List<scalar>> interpolateWeights(List<scalar> Wold, List<scalar> Wnew);
313
314 //--------------------------------------------------------------------------
315
320 void update_gParametrized(List<scalar> weights);
321
322 //--------------------------------------------------------------------------
323
330 void parameterizedBCoffline(bool force = 0);
331
332 //--------------------------------------------------------------------------
333
336 void reconstrucT(word outputFolder);
337
338 //--------------------------------------------------------------------------
339
345 Eigen::VectorXd reconstrucT(Eigen::VectorXi cells);
346
347 //--------------------------------------------------------------------------
348
351 void parameterizedBC(word folder, volScalarField initialField);
352
353 //--------------------------------------------------------------------------
354
356 void set_valueFraction();
357
358 //--------------------------------------------------------------------------
359
361 virtual void assignDirectBC(label timeI);
362
363 //--------------------------------------------------------------------------
364
367 virtual void assignT0_IF(volScalarField& T0_init) = 0;
368
369 //--------------------------------------------------------------------------
370
373 virtual void solveT0(volScalarField initialField);
374
375 //--------------------------------------------------------------------------
376
379 void getT0modes();
380
381 //--------------------------------------------------------------------------
382
385 void projectT0();
386
387 //--------------------------------------------------------------------------
388
391 void projectDirectOntoT0();
392
393 //--------------------------------------------------------------------------
394
399
400 //--------------------------------------------------------------------------
401
405
406 //--------------------------------------------------------------------------
407
410 void T0offline(int NmagicPoints);
411
412
413 //--------------------------------------------------------------------------
414
417 void solveAdditional();
418
419 //--------------------------------------------------------------------------
420
423 void solveDirect();
424
425 //--------------------------------------------------------------------------
426
430 virtual void readThermocouples();
431
432 //--------------------------------------------------------------------------
433
441 Eigen::VectorXd fieldValueAtThermocouples(volScalarField& field);
442
443 //--------------------------------------------------------------------------
444
452 Eigen::VectorXd fieldValueAtThermocouples(PtrList<volScalarField> fieldList,
453 label fieldI);
454
455 //--------------------------------------------------------------------------
456
463 Eigen::VectorXd fieldValueAtThermocouples(PtrList<volScalarField> fieldList);
464
465 //--------------------------------------------------------------------------
466
469 void restart();
470
471 //--------------------------------------------------------------------------
472
475 void restartOffline();
476
477 //--------------------------------------------------------------------------
478
481 void restartT0();
482
483 //--------------------------------------------------------------------------
484
488
489 //--------------------------------------------------------------------------
490
493 void parameterizedBC_postProcess(List<Eigen::MatrixXd> linSys,
494 Eigen::VectorXd weigths, word outputFolder, label verbose = 0);
495
496 //--------------------------------------------------------------------------
497
500 void findMagicPoints(int NmagicPoints);
501
502};
503
504#endif
Header file of the Foam2Eigen class.
Header file of the ITHACAregularization class, it contains the implementation of several methods for ...
Header file of the ITHACAutilities namespace.
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
virtual void readThermocouples()
Identifies in the mesh the cells corresponding to the termocouples locations.
void parameterizedBCoffline(bool force=0)
Performs offline computation for the parameterized BC method, if the offline directory "".
Eigen::MatrixXd T0explicitMatrix_red
T0 reduced explicit matrix.
label timeSamplesNum
Number of time samples (filled in createThermocouples.H).
label NbasisInTime
Number of basis in time.
label coldSide_ind
Index of the coldSide patch.
Eigen::VectorXd pointTad_reconstructed
Reconstruction of Tsd at the magic points.
scalar diffusivity
Diffusivity value.
virtual void assignT0_IF(volScalarField &T0_init)=0
Set IF of the T0 problem.
double HTC
Heat transfer coefficient [W/(m2 K)].
scalar timeSamplesDeltaT
Time interval in between samples (read from thermocouplesDict).
double specificHeat
Specific heat capacity [J/kg/K].
void restartT0()
Restart fields.
int NmodesT0
Number of POD modes.
void restartOffline()
Restart fields.
int thermocouplesNum
Number of thermocouples.
void T0offline(int NmagicPoints)
Assemble all the matrices required in the online phase.
dimensionedScalar DT
Dummy thermal diffusivity with unitary value.
volScalarModes T0modes
List of POD modes.
Eigen::VectorXd Jlist
List of cost funtions [K^2].
label hotSide_ind
Index of the hotSide patch.
Eigen::MatrixXd Tbasis_projectionMat
Projection of the Tbasis on the reduced space.
int gBasisSize
Number of heat flux bases (both in time and space).
label timeSampleI
Time sample index.
Eigen::VectorXd Tad_projected
Projection of Tad on the reduced space.
Eigen::MatrixXd pointsReconstructMatrix
Matrix that reconstruct some points into the full order space.
List< List< scalar > > gTrue
True heat flux at hotSide [W/m2].
label NtimestepsInSequence
Number of timesteps considered in each acquisition sequence.
List< scalar > gWeightsOld
Weights of the parameterization.
void reconstrucT(word outputFolder)
Reconstructs the temperature field using superposition of effects.
PtrList< volScalarField > projectionErrorTad
L2 norm of the projection error of Tad on the T0 modes.
Eigen::MatrixXd T0implicitMatrix_red
T0 reduced implicit matrix.
List< List< scalar > > interpolateWeights(List< scalar > Wold, List< scalar > Wnew)
double thermalCond
Thermal conductivity [W/(m K)].
PtrList< volScalarField > projectionErrorTbasis
L2 norm of the projection error of Tbasis on the T0 modes.
void findMagicPoints(int NmagicPoints)
Find the points at with the projection error is computed.
List< List< scalar > > heatFluxSpaceBasis
Heat flux space basis.
PtrList< volScalarField > T0field
List of snapshots for the T0 solutions.
word folderOffline
Folder where the offline solutions are saved.
List< List< List< scalar > > > gBaseFunctions
Bases of the heat flux.
scalar startTime
Time discretization (filled in the constructor).
void solveAdditional()
Set BC and IF of the additional problem for the parameterized heat flux.
void projectionErrorOffline()
Compute the L2 norm of the projection error for each Tbasis and Tad.
autoPtr< volScalarField > _T
Temperature field.
List< label > magicPoints
Magic points for the T0 projection error estimation.
void update_gParametrized(List< scalar > weights)
Update the boundary condition g when g is parameterized.
virtual void solveT0(volScalarField initialField)
Solve the T0 problem.
void sampling2symulationTime()
Fills the vector samplingSteps which contains the timesteps at which the measurements are taken.
label NbasisInSpace
Number of basis in space.
List< scalar > samplingTime
List of times at which the measurements are acquired (this List is filled by readThermocouples()).
bool thermocouplesRead
1 if readThermocouples() was called, 0 elsewise
autoPtr< volScalarField > _Tad
Additional temperature field.
double J
Cost funtion [K^2].
label basisDeltaSample
Number of sampling steps to consider when computing offline phase.
autoPtr< Time > _runTime
Time.
void set_gParametrized(word spaceBaseFuncType, scalar shapeParameter_space)
Set parameterized heat flux defining the basis.
Eigen::VectorXd residual
Parametrized BC.
volScalarField list2Field(List< scalar > list, scalar innerField=0.0)
Convert list of boundary heat flux into field.
scalar offlineEndTime
End time for the ofline computation.
void setDiffusivity(scalar _diff)
Set diffusivity.
void projectT0()
Project T0 matrices onto the reduced spaced.
void projectDirectOntoT0()
Assemble the matrices to go from the gWeights to the T0 reduced space.
autoPtr< fvMesh > _mesh
Mesh.
scalar timeSamplesT0
First sampling time (read from thermocouplesDict).
List< List< scalar > > g
Heat flux at hotSide.
List< label > samplingSteps
List of timesteps at which measurements are available.
Eigen::VectorXd fieldValueAtThermocouples(volScalarField &field)
Interpolates the field value at the thermocouples points NOTE: do NOT call whe field is an element of...
label NtimeStepsBetweenSamples
Number of timesteps between two samples.
label offlineTimestepsSize
Number of timestep to solve for during offline phase.
autoPtr< simpleControl > _simple
simpleControl
label Nbasis
Number of basis.
autoPtr< fv::options > _fvOptions
fvOptions
virtual void assignDirectBC(label timeI)
Set BC of the direct problem.
Eigen::MatrixXd pointTbasis_reconstructionMat
Matrix that reconstructs the Tbasis at the magic points.
void solveDirect()
Solve direct problem.
label NsamplesWindow
Number of samples considered in the offline phase.
void set_valueFraction()
Set valueFraction list values for Robin condition.
double density
Density [kg /m3].
void pointProjectionOffline()
Assemble the matrix pointsProjectionMatrix to project some points on the reduced basis space.
List< scalar > gWeights
Weights of the parameterization.
void setSpaceBasis(word type, scalar shapeParameter, label Npod=0)
Define the base functions used for the parametrization of g.
void getT0modes()
Compute T0 modes prome snapshots.
void restart()
Restart temperature field.
Header file of the laplacianProblem class.