From c77afff48f8a475034c6ecb21ddd285f94b272d6 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 27 Jul 2020 07:20:24 +0200 Subject: [PATCH] COMP: fix sloppy (and now ambiguous) use of PtrList::set() - constructs such as the following will no longer worked, but that is also a good thing. ptrlist.set(i, scalarField(nFaces, Zero)); this called set(.., const tmp&), which meant under the hood: - create local temporary const scalarField& - wrap as const tmp& - use tmp::ptr(), to clone the const-ref This implies an additional allocation (for the const scalarField&) which is immediately discarded. Doubtful that compiler optimization would do anything. --- .../adjoint/optimisation/updateMethod/LBFGS/LBFGS.C | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C index b782371105..2aa335053f 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C @@ -58,8 +58,8 @@ void Foam::LBFGS::allocateMatrices() label nVars(activeDesignVars_.size()); for (label i = 0; i < nPrevSteps_; i++) { - y_.set(i, scalarField(nVars, Zero)); - s_.set(i, scalarField(nVars, Zero)); + y_.set(i, new scalarField(nVars, Zero)); + s_.set(i, new scalarField(nVars, Zero)); } } @@ -120,8 +120,8 @@ void Foam::LBFGS::LBFGSUpdate() label nSteps(min(counter_, nPrevSteps_)); label nLast(nSteps - 1); scalarField q(objectiveDerivatives_, activeDesignVars_); - scalarField a(nSteps, 0.); - scalarField r(nSteps, 0.); + scalarField a(nSteps, Zero); + scalarField r(nSteps, Zero); for (label i = nLast; i > -1; --i) { r[i] = 1./globalSum(y_[i]*s_[i]);