From f6ec5c676e9d8fe0fb5496f8e82a2ce6b1fb5854 Mon Sep 17 00:00:00 2001 From: Vaggelis Papoutsis Date: Mon, 8 Jan 2024 18:28:48 +0200 Subject: [PATCH] BUG: ISQP crashing with the ShermanMorrison preconditiooner (fixes #3077) ISQP crashed during the first update of the design variables, if the latter had no bounds and the ShermanMorrison preconditiooner was used. --- .../adjoint/optimisation/updateMethod/ISQP/ISQP.C | 10 +++++----- .../adjoint/optimisation/updateMethod/ISQP/ISQP.H | 2 +- .../adjoint/optimisation/updateMethod/LBFGS/LBFGS.C | 2 +- .../adjoint/optimisation/updateMethod/LBFGS/LBFGS.H | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.C index f6ab3de548..08893cbc49 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.C @@ -429,12 +429,12 @@ Foam::tmp Foam::ISQP::ShermanMorrisonPrecon // process, the diagonal matrix related to bound constraints is treated as // the initial matrix of the L-BFGS update. - // Constribution from bound constraints, treated as the seed of the + // Contribution from bound constraints, treated as the seed of the // L-BFGS inverse - tmp tdiag(nullptr); + refPtr tdiag(nullptr); if (includeBoundConstraints_) { - tdiag.reset(lTilda_()/ls_() + uTilda_()/us_()); + tdiag.reset((lTilda_()/ls_() + uTilda_()/us_()).ptr()); } // List of vectors to be used in the rank-1 updates related to the flow @@ -462,7 +462,7 @@ Foam::tmp Foam::ISQP::ShermanMorrisonRank1Update ( const PtrList& r1Updates, const scalarField& p, - const tmp& diag, + const refPtr& diag, const scalarField& mult, label n ) @@ -472,7 +472,7 @@ Foam::tmp Foam::ISQP::ShermanMorrisonRank1Update if (n == 0) { - Ap = invHessianVectorProduct(p, counter_, diag); + Ap = invHessianVectorProduct(p, counter_, diag.shallowClone()); return tAp; } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.H index d94f444ded..537e0b43a0 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/ISQP/ISQP.H @@ -248,7 +248,7 @@ protected: ( const PtrList& r1Updates, const scalarField& p, - const tmp& diag, + const refPtr& diag, const scalarField& mult, label n ); diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C index 3617635957..654e857912 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C @@ -175,7 +175,7 @@ Foam::LBFGS::invHessianVectorProduct ( const scalarField& vector, const label counter, - tmp diag + const refPtr diag ) { // Sanity checks diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.H b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.H index e785e7997a..384e997d4e 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.H +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.H @@ -131,7 +131,7 @@ protected: ( const scalarField& vector, const label counter, - tmp diag = nullptr + const refPtr diag = nullptr ); //- Compute the Hessian - vector product