Use UPtrList for managing objective functions
Stumbled across these when examining other code...
The incompressiblePrimalSolver uses a List of pointers for the objective functions. I think that a UPtrList would make more sense. The primary reason being to encapsulate the pointer dereference, as well as other methods (eg, test(), get(), ...).
The code that may need to be modified in any case is the use of lookupClass. This is usually OK, but there is no absolute guarantee about the iteration order.
Here's a code snippet using sorted
instead, which generates a UPtrList as an intermediate type (a couple of allocations fewer than sending back a HashTable).
Foam::UPtrList<Foam::objective>
Foam::incompressiblePrimalSolver::getObjectiveFunctions() const
{
DynamicList<objective*> objectives;
for (auto& adjoint : mesh_.sorted<adjointSolver>())
{
if (adjoint.primalSolverName() == solverName_)
{
PtrList<objective>& managerObjectives =
adjoint.getObjectiveManager().getObjectiveFunctions();
for (objective& obj : managerObjectives)
{
objectives.push_back(&obj);
}
}
}
return UPtrList<objective>(objectives);
}