From 1649d8f41146d1fa9c3108bf8e50a5fce78e4daa Mon Sep 17 00:00:00 2001 From: Psenica Date: Thu, 14 Nov 2024 10:27:56 -0600 Subject: [PATCH] Adding in flag for calculating the heat flux per unit area or for total surface --- src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.C | 50 +++++++++++++++---- src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.H | 3 ++ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.C b/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.C index 80affbf2..8f529834 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.C +++ b/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.C @@ -74,11 +74,23 @@ DAObjFuncWallHeatFlux::DAObjFuncWallHeatFlux( "calculated") #endif { + // Assign type, this is common for all objectives objFuncDict_.readEntry("type", objFuncType_); objFuncDict_.readEntry("scale", scale_); + // Heat flux can be calculated by either per unit area or over entire surface. Default value is byUnitArea + if (objFuncDict_.found("scheme")) + { + objFuncDict_.readEntry("scheme", calcMode_); + } + else + { + calcMode_ = "byUnitArea"; + } + + #ifdef CompressibleFlow // setup the connectivity for heat flux, this is needed in Foam::DAJacCondFdW @@ -162,17 +174,20 @@ void DAObjFuncWallHeatFlux::calcObjFunc( objFuncValue: the sum of objective, reduced across all processors and scaled by "scale" */ - // always calculate the area of all the heat flux patches - areaSum_ = 0.0; - forAll(objFuncFaceSources, idxI) + // if calcMode is per unit area then calculate the area of all the heat flux patches + if (calcMode_ == "byUnitArea") { - const label& objFuncFaceI = objFuncFaceSources[idxI]; - label bFaceI = objFuncFaceI - daIndex_.nLocalInternalFaces; - const label patchI = daIndex_.bFacePatchI[bFaceI]; - const label faceI = daIndex_.bFaceFaceI[bFaceI]; - areaSum_ += mesh_.magSf().boundaryField()[patchI][faceI]; + areaSum_ = 0.0; + forAll(objFuncFaceSources, idxI) + { + const label& objFuncFaceI = objFuncFaceSources[idxI]; + label bFaceI = objFuncFaceI - daIndex_.nLocalInternalFaces; + const label patchI = daIndex_.bFacePatchI[bFaceI]; + const label faceI = daIndex_.bFaceFaceI[bFaceI]; + areaSum_ += mesh_.magSf().boundaryField()[patchI][faceI]; + } + reduce(areaSum_, sumOp()); } - reduce(areaSum_, sumOp()); // initialize faceValues to zero forAll(objFuncFaceValues, idxI) @@ -238,7 +253,22 @@ void DAObjFuncWallHeatFlux::calcObjFunc( const label faceI = daIndex_.bFaceFaceI[bFaceI]; scalar area = mesh_.magSf().boundaryField()[patchI][faceI]; - objFuncFaceValues[idxI] = scale_ * wallHeatFluxBf[patchI][faceI] * area / areaSum_; + + if (calcMode_ == "byUnitArea") + { + objFuncFaceValues[idxI] = scale_ * wallHeatFluxBf[patchI][faceI] * area / areaSum_; + } + else if (calcMode_ == "total") + { + objFuncFaceValues[idxI] = scale_ * wallHeatFluxBf[patchI][faceI] * area; + } + else + { + FatalErrorIn(" ") << "mode for " + << objFuncName_ << " " << objFuncPart_ << " not valid!" + << "Options: byUnitArea (default value), total." + << abort(FatalError); + } objFuncValue += objFuncFaceValues[idxI]; } diff --git a/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.H b/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.H index 53d208ef..de33ab1b 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.H +++ b/src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.H @@ -50,6 +50,9 @@ protected: /// the area of all heat flux patches scalar areaSum_ = -9999.0; + /// if calculating flux per unit area or total, which mode to use + word calcMode_; + public: TypeName("wallHeatFlux"); // Constructors