59 Eigen::VectorXd faceCellDist =
63 scalar faceDist = faceCellDist(faceI);
75 volScalarField& lambda =
_lambda();
79 if (patchI ==
mesh.boundaryMesh().findPatchID(
"coldSide"))
84 else if (patchI ==
mesh.boundaryMesh().findPatchID(
"hotSide"))
99 volScalarField& lambda =
_lambda();
102 dimensionedScalar sourceDim(
"sourceDim", dimensionSet(1, -1, -3, -1, 0, 0, 0),
104 autoPtr<volScalarField> f_
106 new volScalarField(
"f", lambda)
108 volScalarField& f = f_();
127 return (f * sourceDim).ref();
133 volScalarField& deltaT =
_deltaT();
137 if (patchI ==
mesh.boundaryMesh().findPatchID(
"coldSide"))
142 else if (patchI ==
mesh.boundaryMesh().findPatchID(
"hotSide"))
156 volScalarField& lambda =
_lambda();
160#if defined(OFVER) && (OFVER == 6)
168 while (
simple.correctNonOrthogonal())
172 fvm::laplacian(
DT, lambda) == - f
184 solve(
"sensitivity");
189 volScalarField&
T =
_T();
190 volScalarField& deltaT =
_deltaT();
194 if (strcmp( problemID,
"direct") == 0)
198 else if (strcmp( problemID,
"sensitivity") == 0)
204 Info <<
"Problem name should be direct or sensitivity" << endl;
208#if defined(OFVER) && (OFVER == 6)
215 while (
simple.correctNonOrthogonal())
217 if (strcmp( problemID,
"direct") == 0)
221 fvm::laplacian(
DT,
T)
225 else if (strcmp( problemID,
"sensitivity") == 0)
229 fvm::laplacian(
DT, deltaT)
239 Info <<
"Defining the plane for measurements interpolation" << endl;
289 volScalarField& deltaT =
_deltaT();
323 Info <<
"Iteration " <<
cgIter + 1 << endl;
332 volScalarField&
T =
_T();
348 volScalarField& lambda =
_lambda();
354 volScalarField& deltaT =
_deltaT();
363 volScalarField&
T =
_T();
364 volScalarField& lambda =
_lambda();
365 volScalarField& deltaT =
_deltaT();
382 volScalarField& lambda =
_lambda();
406 Info <<
"gamma = " <<
gamma << endl;
428 scalar betaDiv = 0.0;
447 Info <<
"beta = " <<
beta << endl;
462 List<scalar> sqTdiff;
478 Info <<
"J = " <<
J << endl;
482 Info <<
"Convergence reached in " <<
cgIter <<
" iterations" << endl;
485 else if (Foam::mag((Jold -
J) /
J) <=
JtolRel)
487 Info <<
"Relative tolerance criteria meet in " <<
cgIter <<
" iterations" <<
489 Info <<
"|Jold - J| / |J| = " << Foam::mag((Jold -
J) /
J) << endl;
501 Foam::vector thermocoupleCellDim)
516 volScalarField&
T =
_T();
517 volScalarField& lambda =
_lambda();
518 volScalarField& deltaT =
_deltaT();
519 autoPtr<volScalarField> gVolField_
521 new volScalarField(
"g",
T)
523 volScalarField& gVolField = gVolField_();
528 const labelUList& faceCells = cPatch.faceCells();
532 label faceOwner = faceCells[faceI] ;
533 gVolField[faceOwner] =
g[faceI];
550 volScalarField&
T =
_T();
551 DataTable thermocouplesSamples;
563 if ( Pstream::master() ==
true )
572 pointField pLocal(pLabels.size(), Foam::vector::zero);
610 thermocouplesSamples.addSample(x,
Tmeas(thermocoupleI));
613 std::cout <<
Tmeas << std::endl;
614 RBFSpline rbfspline(thermocouplesSamples, RadialBasisFunctionType::GAUSSIAN);
615 auto inPlaneCellID = 0;
616 forAll(
T.internalField(), cellI)
618 auto cx =
mesh.C()[cellI].component(Foam::vector::X);
619 auto cy =
mesh.C()[cellI].component(Foam::vector::Y);
620 auto cz =
mesh.C()[cellI].component(Foam::vector::Z);
660 DenseMatrix& RBFweights, DenseMatrix& RBFbasis)
663 volScalarField&
T =
_T();
664 DataTable thermocouplesSamples;
676 if ( Pstream::master() ==
true )
685 pointField pLocal(pLabels.size(), Foam::vector::zero);
723 thermocouplesSamples.addSample(x,
Tmeas(thermocoupleI));
726 std::cout <<
Tmeas << std::endl;
727 RBFSpline rbfspline(thermocouplesSamples, RadialBasisFunctionType::GAUSSIAN);
728 auto inPlaneCellID = 0;
729 forAll(
T.internalField(), cellI)
731 auto cx =
mesh.C()[cellI].component(Foam::vector::X);
732 auto cy =
mesh.C()[cellI].component(Foam::vector::Y);
733 auto cz =
mesh.C()[cellI].component(Foam::vector::Z);
773 volScalarField&
T =
_T();
795 Info <<
"\nResetting time, mesh and fields: " << fieldName <<
"\n" << endl;
798 if (fieldName ==
"T" || fieldName ==
"all")
803 if (fieldName ==
"lambda" || fieldName ==
"all")
808 if (fieldName ==
"deltaT" || fieldName ==
"all")
813 argList& args =
_args();
816 instantList Times =
runTime.times();
819 _simple = autoPtr<simpleControl>
827 if (fieldName ==
"T" || fieldName ==
"all")
830 _T = autoPtr<volScalarField>
847 if (fieldName ==
"deltaT" || fieldName ==
"all")
850 _deltaT = autoPtr<volScalarField>
867 if (fieldName ==
"lambda" || fieldName ==
"all")
870 _lambda = autoPtr<volScalarField>
887 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.
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< List< scalar > > gList
List of boundary heat fluxes.
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].
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.
inverseLaplacianProblem()
Null constructor.
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)