diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/BFGS/BFGS.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/BFGS/BFGS.C index 26b80e1803..9cd0671d9d 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/BFGS/BFGS.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/BFGS/BFGS.C @@ -51,11 +51,7 @@ void Foam::BFGS::allocateMatrices() // Set active design variables, if necessary if (activeDesignVars_.empty()) { - activeDesignVars_.setSize(correction_.size()); - forAll(activeDesignVars_, dvI) - { - activeDesignVars_[dvI] = dvI; - } + activeDesignVars_ = identity(objectiveDerivatives_.size()); } // Set previous HessianInv to be a diagonal matrix @@ -155,9 +151,14 @@ void Foam::BFGS::readFromDict() optMethodIODict_.readEntry("counter", counter_); optMethodIODict_.readEntry("eta", eta_); - label n = HessianInvOld_.n(); + const label n(HessianInvOld_.n()); HessianInv_ = SquareMatrix(n, Zero); correction_ = scalarField(correctionOld_.size(), Zero); + + if (activeDesignVars_.empty()) + { + activeDesignVars_ = identity(n); + } } } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/DBFGS/DBFGS.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/DBFGS/DBFGS.C index 0e5f0fe06c..fb38d03d12 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/DBFGS/DBFGS.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/DBFGS/DBFGS.C @@ -51,11 +51,7 @@ void Foam::DBFGS::allocateMatrices() // Set active design variables, if necessary if (activeDesignVars_.empty()) { - activeDesignVars_.setSize(correction_.size()); - forAll(activeDesignVars_, dvI) - { - activeDesignVars_[dvI] = dvI; - } + activeDesignVars_ = identity(objectiveDerivatives_.size()); } // Set previous Hessian to be a diagonal matrix @@ -162,6 +158,11 @@ void Foam::DBFGS::readFromDict() label n = HessianOld_.n(); Hessian_ = SquareMatrix(n, Zero); correction_ = scalarField(correctionOld_.size(), Zero); + + if (activeDesignVars_.empty()) + { + activeDesignVars_ = identity(n); + } } } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C index c60d094b9f..5478281842 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/LBFGS/LBFGS.C @@ -51,11 +51,7 @@ void Foam::LBFGS::allocateMatrices() // Set active design variables, if necessary if (activeDesignVars_.empty()) { - activeDesignVars_.setSize(objectiveDerivatives_.size()); - forAll(activeDesignVars_, dvI) - { - activeDesignVars_[dvI] = dvI; - } + activeDesignVars_ = identity(objectiveDerivatives_.size()); } // Allocate vectors @@ -184,6 +180,11 @@ void Foam::LBFGS::readFromDict() optMethodIODict_.readEntry("correctionOld", correctionOld_); correction_ = scalarField(correctionOld_.size(), Zero); + + if (activeDesignVars_.empty()) + { + activeDesignVars_ = identity(derivativesOld_.size()); + } } } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SQP/SQP.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SQP/SQP.C index 8f91c5e227..9d988abe83 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SQP/SQP.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SQP/SQP.C @@ -58,11 +58,7 @@ void Foam::SQP::allocateMatrices() // Set active design variables, if necessary if (activeDesignVars_.empty()) { - activeDesignVars_.setSize(correction_.size()); - forAll(activeDesignVars_, dvI) - { - activeDesignVars_[dvI] = dvI; - } + activeDesignVars_ = identity(objectiveDerivatives_.size()); } // Set previous Hessian to be a diagonal matrix @@ -269,6 +265,11 @@ void Foam::SQP::readFromDict() optMethodIODict_.readEntry("eta", eta_); correction_ = scalarField(correctionOld_.size(), Zero); + + if (activeDesignVars_.empty()) + { + activeDesignVars_ = identity(correction_.size()); + } } } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SR1/SR1.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SR1/SR1.C index 69c98a54cb..b582b57a24 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SR1/SR1.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/SR1/SR1.C @@ -51,11 +51,7 @@ void Foam::SR1::allocateMatrices() // Set active design variables, if necessary if (activeDesignVars_.empty()) { - activeDesignVars_.setSize(correction_.size()); - forAll(activeDesignVars_, dvI) - { - activeDesignVars_[dvI] = dvI; - } + activeDesignVars_ = identity(objectiveDerivatives_.size()); } // Set previous HessianInv to be a diagonal matrix @@ -146,9 +142,14 @@ void Foam::SR1::readFromDict() optMethodIODict_.readEntry("counter", counter_); optMethodIODict_.readEntry("eta", eta_); - label n = HessianInvOld_.n(); + const label n(HessianInvOld_.n()); HessianInv_ = SquareMatrix(n, Zero); correction_ = scalarField(correctionOld_.size(), Zero); + + if (activeDesignVars_.empty()) + { + activeDesignVars_ = identity(n); + } } } diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/conjugateGradient/conjugateGradient.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/conjugateGradient/conjugateGradient.C index 629ba8221e..3e8ca3747a 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/conjugateGradient/conjugateGradient.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/conjugateGradient/conjugateGradient.C @@ -51,11 +51,7 @@ void Foam::conjugateGradient::allocateFields() // Set active design variables, if necessary if (activeDesignVars_.empty()) { - activeDesignVars_.setSize(objectiveDerivatives_.size()); - forAll(activeDesignVars_, dvI) - { - activeDesignVars_[dvI] = dvI; - } + activeDesignVars_ = identity(objectiveDerivatives_.size()); } // Allocate old fields @@ -75,6 +71,11 @@ void Foam::conjugateGradient::readFromDict() label nDVs = optMethodIODict_.get