Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added inverseRadius for location obj. #654

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading