59 Eigen::VectorXd faceCellDist =
63 scalar faceDist = faceCellDist(faceI);
74 volScalarField& lambda =
_lambda();
78 if (patchI ==
mesh.boundaryMesh().findPatchID(
"coldSide"))
83 else if (patchI ==
mesh.boundaryMesh().findPatchID(
"hotSide"))
97 volScalarField& lambda =
_lambda();
100 dimensionedScalar sourceDim(
"sourceDim", dimensionSet(1, -1, -3, -1, 0, 0, 0),
102 autoPtr<volScalarField> f_
104 new volScalarField(
"f", lambda)
106 volScalarField& f = f_();
125 return (f * sourceDim).ref();
131 volScalarField& deltaT =
_deltaT();
135 if (patchI ==
mesh.boundaryMesh().findPatchID(
"coldSide"))
140 else if (patchI ==
mesh.boundaryMesh().findPatchID(
"hotSide"))
154 volScalarField& lambda =
_lambda();
158#if defined(OFVER) && (OFVER == 6)
166 while (
simple.correctNonOrthogonal())
170 fvm::laplacian(
DT, lambda) == - f
182 solve(
"sensitivity");
187 volScalarField&
T =
_T();
188 volScalarField& deltaT =
_deltaT();
192 if (strcmp( problemID,
"direct") == 0)
196 else if (strcmp( problemID,
"sensitivity") == 0)
202 Info <<
"Problem name should be direct or sensitivity" << endl;
206#if defined(OFVER) && (OFVER == 6)
213 while (
simple.correctNonOrthogonal())
215 if (strcmp( problemID,
"direct") == 0)
219 fvm::laplacian(
DT,
T)
223 else if (strcmp( problemID,
"sensitivity") == 0)
227 fvm::laplacian(
DT, deltaT)
237 Info <<
"Defining the plane for measurements interpolation" << endl;
287 volScalarField& deltaT =
_deltaT();
321 Info <<
"Iteration " <<
cgIter + 1 << endl;
330 volScalarField&
T =
_T();
346 volScalarField& lambda =
_lambda();
352 volScalarField& deltaT =
_deltaT();
361 volScalarField&
T =
_T();
362 volScalarField& lambda =
_lambda();
363 volScalarField& deltaT =
_deltaT();
380 volScalarField& lambda =
_lambda();
403 Info <<
"gamma = " <<
gamma << endl;
424 scalar betaDiv = 0.0;
442 Info <<
"beta = " <<
beta << endl;
457 List<scalar> sqTdiff;
472 Info <<
"J = " <<
J << endl;
476 Info <<
"Convergence reached in " <<
cgIter <<
" iterations" << endl;
479 else if (Foam::mag((Jold -
J) /
J) <=
JtolRel)
481 Info <<
"Relative tolerance criteria meet in " <<
cgIter <<
" iterations" <<
483 Info <<
"|Jold - J| / |J| = " << Foam::mag((Jold -
J) /
J) << endl;
495 Foam::vector thermocoupleCellDim)
510 volScalarField&
T =
_T();
511 volScalarField& lambda =
_lambda();
512 volScalarField& deltaT =
_deltaT();
513 autoPtr<volScalarField> gVolField_
515 new volScalarField(
"g",
T)
517 volScalarField& gVolField = gVolField_();
522 const labelUList& faceCells = cPatch.faceCells();
526 label faceOwner = faceCells[faceI] ;
527 gVolField[faceOwner] =
g[faceI];
543 volScalarField&
T =
_T();
544 DataTable thermocouplesSamples;
556 if ( Pstream::master() ==
true )
565 pointField pLocal(pLabels.size(), Foam::vector::zero);
602 thermocouplesSamples.addSample(x,
Tmeas(thermocoupleI));
604 std::cout <<
Tmeas << std::endl;
605 RBFSpline rbfspline(thermocouplesSamples, RadialBasisFunctionType::GAUSSIAN);
606 auto inPlaneCellID = 0;
607 forAll(
T.internalField(), cellI)
609 auto cx =
mesh.C()[cellI].component(Foam::vector::X);
610 auto cy =
mesh.C()[cellI].component(Foam::vector::Y);
611 auto cz =
mesh.C()[cellI].component(Foam::vector::Z);
650 DenseMatrix& RBFweights, DenseMatrix& RBFbasis)
653 volScalarField&
T =
_T();
654 DataTable thermocouplesSamples;
666 if ( Pstream::master() ==
true )
675 pointField pLocal(pLabels.size(), Foam::vector::zero);
712 thermocouplesSamples.addSample(x,
Tmeas(thermocoupleI));
714 std::cout <<
Tmeas << std::endl;
715 RBFSpline rbfspline(thermocouplesSamples, RadialBasisFunctionType::GAUSSIAN);
716 auto inPlaneCellID = 0;
717 forAll(
T.internalField(), cellI)
719 auto cx =
mesh.C()[cellI].component(Foam::vector::X);
720 auto cy =
mesh.C()[cellI].component(Foam::vector::Y);
721 auto cz =
mesh.C()[cellI].component(Foam::vector::Z);
760 volScalarField&
T =
_T();
781 Info <<
"\nResetting time, mesh and fields: " << fieldName <<
"\n" << endl;
784 if (fieldName ==
"T" || fieldName ==
"all")
789 if (fieldName ==
"lambda" || fieldName ==
"all")
794 if (fieldName ==
"deltaT" || fieldName ==
"all")
799 argList& args =
_args();
802 instantList Times =
runTime.times();
805 _simple = autoPtr<simpleControl>
813 if (fieldName ==
"T" || fieldName ==
"all")
816 _T = autoPtr<volScalarField>
833 if (fieldName ==
"deltaT" || fieldName ==
"all")
836 _deltaT = autoPtr<volScalarField>
853 if (fieldName ==
"lambda" || fieldName ==
"all")
856 _lambda = autoPtr<volScalarField>
873 Info <<
"Ready for new computation" << endl;
forAll(example_CG.gList, solutionI)
int cgIterMax
Maximum CG iterations.
Eigen::VectorXd Tsens
Vector of solutions of the sensitivity problem at the thermocouples points.
Eigen::MatrixXd Jlist
Vector to store the const function J.
void set_valueFraction()
Set valueFraction list values for Robin condition.
PtrList< volScalarField > lambdaField
List of adjoint solutions.
double gamma
Conjugate coefficient.
bool interpolationPlaneDefined
Flag for definition of interpolation plane.
bool saveSolInLists
Flag to save solutions in lists.
double Jtol
Absolute stopping criterion for the CG.
void defineThermocouplesPlane()
Identifies the plane defined by the thermocouples.
void assignSensitivityBC()
Set BC and IF of the sensitivity problem.
thermocouplesPlane interpolationPlane
Interpolation plane.
void thermocouplesInterpolation()
Interpolates the thermocouples measurements in the plane defined in readThermocouples() using radial ...
int isInPlane(double cx, double cy, double cz, Foam::vector thermocoupleCellDim)
Checks if a cell crosses the interpolation plane.
int cgIter
Conjugate Gradient (CG) interations counter.
double gamma_den
Denoinator of the conjugate coefficient.
void sensibilitySolAtThermocouplesLocations()
Fill the Foam::vector containing the values of the sensitivity solution at the thermocouples location...
void assignAdjointBC()
Set BC of the adjoint problem.
double beta
CG search step size.
void updateHeatFlux()
Updates the heat flux in the conjugate gradient iterations.
int conjugateGradient()
Conjugate gradient method.
inverseLaplacianProblem_CG()
Null constructor.
void writeFields(label folderNumber, const char *folder)
Writes fields to file.
List< scalar > gradJ
Gradient of the cost function.
void solve(const char *problemID)
Solve for direct and sensitivity.
bool interpolation
Flag for interpolation of the temperature measurements.
List< scalar > P
Search direction.
void solveSensitivity()
Solve sensibility problem.
double gradJ_L2norm
L2 norm of the gradient of J.
PtrList< volScalarField > Tfield
List of temperature solutions.
double JtolRel
Relative stopping criterion for the CG.
autoPtr< volScalarField > _deltaT
Sensibility temperature field.
void computeGradJ()
Computes the gradient of cost function J and its L2 norm.
void solveAdjoint()
Solve adjoint problem.
void computeSearchStep()
Compute the search step beta.
PtrList< volScalarField > deltaTfield
List of sensitivity solutions.
volScalarField assignAdjointBCandSource()
Assign the BC for the adjoint problem and returs the source field.
List< scalar > valueFractionAdj
Value fraction for the adjoint Robin BC.
autoPtr< volScalarField > _lambda
Adjoint field.
void searchDirection()
Computes the search direction P.
void differenceBetweenDirectAndMeasure()
Computes the difference between direct problem solution and measure.
int conjugateGradientConvergenceCheck()
Convergence cher for the conjugate gradient method.
Implementation of a inverse Laplacian problem .
Eigen::VectorXd Tdiff
Difference between computed and measured temperatures at the thermocouples.
label hotSide_ind
Index of the hotSide patch.
dimensionedScalar DT
Dummy thermal conductivity with unitary value.
double H
Heat transfer coefficient [W/(m2 K)].
autoPtr< simpleControl > _simple
simpleControl
List< scalar > g
Heat flux at hotSide [W/m2].
double J
Cost funtion [K^2].
Eigen::VectorXd Tdirect
Vector of computed temperatures at the thermocouples locations [K].
void restart()
Restart fields.
List< scalar > homogeneousBCcoldSide
List of zeros of the size of coldSide patch.
List< scalar > valueFraction
Value fraction for the Robin BC.
autoPtr< Time > _runTime
Time.
scalar homogeneousBC
Homogenerous BC.
Eigen::VectorXd Tmeas
Vector of measured temperatures at the thermocouples locations [K].
List< List< scalar > > gList
List of boundary heat fluxes.
Foam::vector cellDim(const faceList &ff, const pointField &pp, const cell &cc, labelList pLabels, pointField pLocal)
Compute maximum cell dimension in x, y and z.
void set_g()
Set the right g size and fills it with zeros.
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 > refGrad
Reference gradient for the Robin BC.
List< int > thermocouplesCellProc
List of incedes of the processors contining each thermocouple.
int thermocouplesNum
Number of thermocouples.
double k
Thermal diffusivity [W/(m K)].
void solveDirect()
Solve direct problem.
autoPtr< volScalarField > _T
Temperature field.
List< int > thermocouplesCellID
List of cells indices containing a thermocouple.
autoPtr< argList > _args
argList
Header file of the inverseLaplacianProblem_CG class.
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 ...
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 assignIF(GeometricField< Type, fvPatchField, volMesh > &s, Type value)
Assign internal field.
void assignBC(GeometricField< scalar, fvPatchField, volMesh > &s, label BC_ind, double value)
Assign uniform Boundary Condition to a volScalarField.
Eigen::VectorXd boudaryFaceToCellDistance(fvMesh &mesh, label BC_ind)
Compute the distance between the boundary face center and the boundary cell center.
simpleControl simple(mesh)
List< scalar > thermocoupleZ
List< scalar > thermocoupleX
Foam::vector thermocoupleCellDim