Skip to content

Commit

Permalink
Added inverseRadius for localtion obj. (mdolab#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
friedenhe authored Jun 24, 2024
1 parent 7b3f157 commit aa2d351
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/adjoint/DAObjFunc/DAObjFuncLocation.C
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ DAObjFuncLocation::DAObjFuncLocation(
maxRFaceI_ = maxRFaceI;
}
}

}

/// calculate the value of objective function
Expand Down Expand Up @@ -185,8 +184,48 @@ void DAObjFuncLocation::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objValTmp, sumOp<scalar>());

// expSumKS stores sum[exp(coeffKS*x_i)], it will be used to scale dFdW
expSumKS = objValTmp;
objFuncValue = log(objValTmp) / coeffKS_;
}
else if (mode_ == "maxInverseRadiusKS")
{
// this is essentially minimal radius using KS

// calculate Location
scalar objValTmp = 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];

vector faceC = mesh_.Cf().boundaryField()[patchI][faceI] - center_;

tensor faceCTensor(tensor::zero);
faceCTensor.xx() = faceC.x();
faceCTensor.yy() = faceC.y();
faceCTensor.zz() = faceC.z();

vector faceCAxial = faceCTensor & axis_;
vector faceCRadial = faceC - faceCAxial;

scalar radius = mag(faceCRadial);
scalar iRadius = 1.0 / (radius + 1e-12);

objFuncFaceValues[idxI] = exp(coeffKS_ * iRadius);

objValTmp += objFuncFaceValues[idxI];

if (objValTmp > 1e200)
{
FatalErrorIn(" ") << "KS function summation term too large! "
<< "Reduce coeffKS! " << abort(FatalError);
}
}

// need to reduce the sum of force across all processors
reduce(objValTmp, sumOp<scalar>());

objFuncValue = log(objValTmp) / coeffKS_;
}
Expand Down
1 change: 1 addition & 0 deletions src/adjoint/Make/files_Solid
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ DAObjFunc/DAObjFuncVariableVolSum.C
DAObjFunc/DAObjFuncMeshQualityKS.C
DAObjFunc/DAObjFuncWallHeatFlux.C
DAObjFunc/DAObjFuncPatchMean.C
DAObjFunc/DAObjFuncLocation.C

DAFvSource/DAFvSource.C
DAFvSource/DAFvSourceHeatSource.C
Expand Down

0 comments on commit aa2d351

Please sign in to comment.