ENH: replace autoPtr<bool> with Switch (#2777)

- initialise with Switch::INVALID and then test if good() to
  trigger the initial update.

  This avoids some overhead, but primarily avoids ambiguity with
  implicit casting to a 'bool' that autoPtr<bool> has.
This commit is contained in:
Mark Olesen
2023-05-11 14:14:35 +02:00
parent 687a9528b0
commit 521043094e
2 changed files with 10 additions and 10 deletions

View File

@ -172,11 +172,11 @@ adjointBoundaryCondition<Type>::computePatchGrad(word name)
template<class Type>
bool adjointBoundaryCondition<Type>::addATCUaGradUTerm()
{
if (!addATCUaGradUTerm_)
if (!addATCUaGradUTerm_.good())
{
addATCUaGradUTerm_.reset(new bool(isA<ATCUaGradU>(getATC())));
addATCUaGradUTerm_ = bool(isA<ATCUaGradU>(getATC()));
}
return addATCUaGradUTerm_();
return addATCUaGradUTerm_;
}
@ -202,7 +202,7 @@ adjointBoundaryCondition<Type>::adjointBoundaryCondition
adjointBC.patch_
)
),
addATCUaGradUTerm_(adjointBC.addATCUaGradUTerm_)
addATCUaGradUTerm_(Switch::INVALID)
{}
@ -221,7 +221,7 @@ adjointBoundaryCondition<Type>::adjointBoundaryCondition
adjointSolverName_(solverName),
simulationType_("incompressible"),
boundaryContrPtr_(nullptr),
addATCUaGradUTerm_(nullptr)
addATCUaGradUTerm_(Switch::INVALID)
{
// Set the boundaryContribution pointer
setBoundaryContributionPtr();

View File

@ -39,6 +39,7 @@ Description
#include "boundaryAdjointContribution.H"
#include "ATCModel.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -73,11 +74,10 @@ protected:
//- to the adjoint boundary conditions
autoPtr<boundaryAdjointContribution> boundaryContrPtr_;
//- Whether to add the extra term from the UaGradU formulation
// autoPtr since ATCModel has not been allocated at the time
// adjointBoundaryConditions are constructed
autoPtr<bool> addATCUaGradUTerm_;
//- Whether to add the extra term from the UaGradU formulation.
// As a Switch with delayed evaluation since ATCModel
// has not been allocated at the time of construction
Switch addATCUaGradUTerm_;
// Protected Member Functions