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

Renamed RefDifference to RefVar #612

Merged
merged 4 commits into from
Mar 26, 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
11 changes: 5 additions & 6 deletions src/adjoint/DAObjFunc/DAObjFunc.C
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ DAObjFunc::DAObjFunc(
objFuncCellValues_[idxI] = 0.0;
}

calcRefDiffSquare_ = objFuncDict_.lookupOrDefault<label>("calcRefDiffSquare", 0);
if (calcRefDiffSquare_)
calcRefVar_ = objFuncDict_.lookupOrDefault<label>("calcRefVar", 0);
if (calcRefVar_)
{
objFuncDict_.readEntry<scalarList>("ref", ref_);
}
Expand Down Expand Up @@ -318,15 +318,15 @@ scalar DAObjFunc::getObjFuncValue()
return objFuncValue_;
}

void DAObjFunc::calcRefDiffSquare(scalar& objFuncValue)
void DAObjFunc::calcRefVar(scalar& objFuncValue)
{
/*
Description:
Call the variable difference with respect to a given reference and take a square of it.
This can be used in FIML. This function is for calcRefDiffSquare_ == 1
This can be used in FIML. This function is for calcRefVar == 1
*/

if (calcRefDiffSquare_)
if (calcRefVar_)
{
if (ref_.size() == 1)
{
Expand All @@ -338,7 +338,6 @@ void DAObjFunc::calcRefDiffSquare(scalar& objFuncValue)
objFuncValue = (objFuncValue - ref_[idxI]) * (objFuncValue - ref_[idxI]);
}
}

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Expand Down
8 changes: 4 additions & 4 deletions src/adjoint/DAObjFunc/DAObjFunc.H
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ protected:
List<List<word>> objFuncConInfo_;

/// whether to calculate (obj-ref)^2
label calcRefDiffSquare_;
label calcRefVar_;

/// if calcRefDiffSquare_ is True, set the reference value list
/// if calcRefVar_ is True, set the reference value list
scalarList ref_;

public:
Expand Down Expand Up @@ -243,8 +243,8 @@ public:
/// whether to compute reference coefficients for special objFunc treatment such as totalPressureRatio
label calcRefCoeffs = 1;

/// calculate the varDiffSquare
void calcRefDiffSquare(scalar& objFuncValue);
/// calculate (var-ref)^2
void calcRefVar(scalar& objFuncValue);
};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncCenterOfPressure.C
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void DAObjFuncCenterOfPressure::calcObjFunc(

objFuncValue = scale_ * (weightedPressure / totalPressure + (center_ & axis_));

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncForce.C
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ void DAObjFuncForce::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncLocation.C
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ void DAObjFuncLocation::calcObjFunc(
<< abort(FatalError);
}

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncMass.C
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ void DAObjFuncMass::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncMassFlowRate.C
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ void DAObjFuncMassFlowRate::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncMeshQualityKS.C
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ void DAObjFuncMeshQualityKS::calcObjFunc(

objFuncValue = log(objFuncValue) / coeffKS_;

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncMoment.C
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void DAObjFuncMoment::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncPatchMean.C
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ void DAObjFuncPatchMean::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncPower.C
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ void DAObjFuncPower::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncTotalPressure.C
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ void DAObjFuncTotalPressure::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncTotalPressureRatio.C
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ void DAObjFuncTotalPressureRatio::calcObjFunc(
}
}

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncTotalTemperatureRatio.C
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ void DAObjFuncTotalTemperatureRatio::calcObjFunc(
}
}

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncVariableVolSum.C
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ void DAObjFuncVariableVolSum::calcObjFunc(

objFuncValue /= totalVol;

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncVonMisesStressKS.C
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ void DAObjFuncVonMisesStressKS::calcObjFunc(

objFuncValue = log(objValTmp) / coeffKS_;

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.C
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ void DAObjFuncWallHeatFlux::calcObjFunc(
// need to reduce the sum of force across all processors
reduce(objFuncValue, sumOp<scalar>());

// check if we need to calculate refDiffSquare.
this->calcRefDiffSquare(objFuncValue);
// check if we need to calculate refDiff.
this->calcRefVar(objFuncValue);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DAPimpleFoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"center": [0.25, 0.0, 0.05],
"scale": 1.0,
"addToAdjoint": True,
"calcRefDiffSquare": True,
"calcRefVar": True,
"ref": [0.1, 0.05, 0.04, 0.02, 0.02, 0.01, 0.0, -0.01, -0.01, -0.02]
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/runTests_DASimpleFoamAD.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"center": [0.25, 0.0, 0.05],
"scale": 1.0 / (0.5 * U0 * U0 * A0 * 1.0),
"addToAdjoint": True,
"calcRefDiffSquare": True,
"calcRefVar": True,
"ref": [0.1]
}
},
Expand Down
Loading