Skip to content

Commit

Permalink
Renamed RefDifference to RefVar (#612)
Browse files Browse the repository at this point in the history
* Added sqrt for calcRefDiff.

* Renamed RefDiff to RefStd

* Updated tests for the refStd.

* Renamed RefStd to RefVar.
  • Loading branch information
friedenhe authored Mar 26, 2024
1 parent 7570ed7 commit fed0263
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 42 deletions.
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

0 comments on commit fed0263

Please sign in to comment.