ENH: replace List<objective*> with UPtrList in incompressiblePrimalSolver (fixes #2946)

This commit is contained in:
Vaggelis Papoutsis
2023-07-18 19:14:05 +03:00
committed by Andrew Heather
parent b435feffde
commit e0ea0973b1
4 changed files with 14 additions and 18 deletions

View File

@ -119,17 +119,13 @@ bool Foam::incompressiblePrimalSolver::readDict(const dictionary& dict)
}
Foam::List<Foam::objective*>
Foam::UPtrList<Foam::objective>
Foam::incompressiblePrimalSolver::getObjectiveFunctions() const
{
DynamicList<objective*> objectives(10);
DynamicList<objective*> objectives;
auto adjointSolvers = mesh_.lookupClass<adjointSolver>();
for (adjointSolver* adjointPtr : adjointSolvers)
for (auto& adjoint : mesh_.sorted<adjointSolver>())
{
adjointSolver& adjoint = *adjointPtr;
if (adjoint.primalSolverName() == solverName_)
{
PtrList<objective>& managerObjectives =
@ -137,12 +133,12 @@ Foam::incompressiblePrimalSolver::getObjectiveFunctions() const
for (objective& obj : managerObjectives)
{
objectives.append(&obj);
objectives.push_back(&obj);
}
}
}
return objectives;
return UPtrList<objective>(objectives);
}

View File

@ -139,7 +139,7 @@ public:
// Access
//- Return the list of objectives assodicated with this solver
List<objective*> getObjectiveFunctions() const;
UPtrList<objective> getObjectiveFunctions() const;
//- Access to the incompressible variables set
const incompressibleVars& getIncoVars() const;

View File

@ -107,7 +107,7 @@ Foam::simple::simple
incoVars_(allocateVars()),
MRF_(mesh, word(useSolverNameForFields() ? solverName_ : word::null)),
cumulativeContErr_(Zero),
objectives_(0)
objectives_()
{
addExtraSchemes();
setRefCell
@ -248,11 +248,11 @@ void Foam::simple::postIter()
// Print objective values to screen and compute mean value
Info<< endl;
for (objective* obj : objectives_)
for (auto& obj : objectives_)
{
Info<< obj->objectiveName() << " : " << obj->J() << endl;
obj->accumulateJMean(solverControl_());
obj->writeInstantaneousValue();
Info<< obj.objectiveName() << " : " << obj.J() << endl;
obj.accumulateJMean(solverControl_());
obj.writeInstantaneousValue();
}
// Average fields if necessary
@ -309,9 +309,9 @@ void Foam::simple::preLoop()
void Foam::simple::postLoop()
{
for (objective* obj : objectives_)
for (auto& obj : objectives_)
{
obj->writeInstantaneousSeparator();
obj.writeInstantaneousSeparator();
}
// Safety

View File

@ -84,7 +84,7 @@ protected:
scalar cumulativeContErr_;
//- List of objectives related to this primal solver
List<objective*> objectives_;
UPtrList<objective> objectives_;
//- Protected Member Functions