diff --git a/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C b/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C index 2b70f30568..4729ac3bf3 100644 --- a/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C +++ b/applications/utilities/preProcessing/optimisation/writeMorpherCPs/writeMorpherCPs.C @@ -45,33 +45,37 @@ int main(int argc, char *argv[]) #include "createTime.H" #include "createMesh.H" - IOdictionary dict + const dictionary NURBSdict ( - IOobject + IOdictionary ( - "dynamicMeshDict", - mesh.time().constant(), - mesh, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) + IOobject + ( + "dynamicMeshDict", + mesh.time().constant(), + mesh, + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE, + false + ) + ).subDict("volumetricBSplinesMotionSolverCoeffs") ); + // Read box names and allocate size + wordList controlBoxes(NURBSdict.toc()); - const dictionary& coeffDict = - dict.subDict("volumetricBSplinesMotionSolverCoeffs"); - - wordList controlBoxes(coeffDict.get("controlBoxes")); - - forAll(controlBoxes, iNURB) + for (const word& boxName : controlBoxes) { - // Creating an object writes the control points in the - // constructor - NURBS3DVolume::New - ( - coeffDict.subDict(controlBoxes[iNURB]), - mesh, - false // do not compute parametric coordinates - ); + if (NURBSdict.isDict(boxName)) + { + // Creating an object writes the control points in the + // constructor + NURBS3DVolume::New + ( + NURBSdict.subDict(boxName), + mesh, + false // do not compute parametric coordinates + ); + } } Info<< "End\n" << endl; diff --git a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethod/displacementMethod.C b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethod/displacementMethod.C index db9a456531..9ac5a2812c 100644 --- a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethod/displacementMethod.C +++ b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethod/displacementMethod.C @@ -75,12 +75,11 @@ Foam::autoPtr Foam::displacementMethod::New false ) ); - word motionSolverName(dynamicMeshDict.get("solver")); - word modelType("displacementMethod" + motionSolverName); + word solverType(dynamicMeshDict.get("solver")); - Info<< "displacementMethod type : " << modelType << endl; + Info<< "displacementMethod type : " << solverType << endl; - auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType); + auto cstrIter = dictionaryConstructorTablePtr_->cfind(solverType); if (!cstrIter.found()) { @@ -88,9 +87,9 @@ Foam::autoPtr Foam::displacementMethod::New ( dynamicMeshDict, "solver", - modelType, + solverType, *dictionaryConstructorTablePtr_ - ) << exit(FatalError); + ) << exit(FatalIOError); } return autoPtr(cstrIter()(mesh, patchIDs)); } diff --git a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethoddisplacementLaplacian/displacementMethoddisplacementLaplacian.H b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethoddisplacementLaplacian/displacementMethoddisplacementLaplacian.H index 2a4c30245b..d9f2f3faef 100644 --- a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethoddisplacementLaplacian/displacementMethoddisplacementLaplacian.H +++ b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethoddisplacementLaplacian/displacementMethoddisplacementLaplacian.H @@ -82,7 +82,7 @@ private: public: //- Runtime type information - TypeName("displacementMethoddisplacementLaplacian"); + TypeName("displacementLaplacian"); // Constructors diff --git a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodelasticityMotionSolver/displacementMethodelasticityMotionSolver.H b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodelasticityMotionSolver/displacementMethodelasticityMotionSolver.H index a412364160..50b8ec4df8 100644 --- a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodelasticityMotionSolver/displacementMethodelasticityMotionSolver.H +++ b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodelasticityMotionSolver/displacementMethodelasticityMotionSolver.H @@ -86,7 +86,7 @@ private: public: //- Runtime type information - TypeName("displacementMethodelasticityMotionSolver"); + TypeName("elasticityMotionSolver"); // Constructors diff --git a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodlaplacianMotionSolver/displacementMethodlaplacianMotionSolver.H b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodlaplacianMotionSolver/displacementMethodlaplacianMotionSolver.H index 294c0ddd22..083ab09589 100644 --- a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodlaplacianMotionSolver/displacementMethodlaplacianMotionSolver.H +++ b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodlaplacianMotionSolver/displacementMethodlaplacianMotionSolver.H @@ -83,7 +83,7 @@ private: public: //- Runtime type information - TypeName("displacementMethodlaplacianMotionSolver"); + TypeName("laplacianMotionSolver"); // Constructors diff --git a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvelocityLaplacian/displacementMethodvelocityLaplacian.H b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvelocityLaplacian/displacementMethodvelocityLaplacian.H index 1f109009e0..d2bea03b43 100644 --- a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvelocityLaplacian/displacementMethodvelocityLaplacian.H +++ b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvelocityLaplacian/displacementMethodvelocityLaplacian.H @@ -84,7 +84,7 @@ private: public: //- Runtime type information - TypeName("displacementMethodvelocityLaplacian"); + TypeName("velocityLaplacian"); // Constructors diff --git a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvolumetricBSplinesMotionSolver/displacementMethodvolumetricBSplinesMotionSolver.H b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvolumetricBSplinesMotionSolver/displacementMethodvolumetricBSplinesMotionSolver.H index e82a17dd0f..283769544f 100644 --- a/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvolumetricBSplinesMotionSolver/displacementMethodvolumetricBSplinesMotionSolver.H +++ b/src/optimisation/adjointOptimisation/adjoint/displacementMethod/displacementMethodvolumetricBSplinesMotionSolver/displacementMethodvolumetricBSplinesMotionSolver.H @@ -77,7 +77,7 @@ private: public: //- Runtime type information - TypeName("displacementMethodvolumetricBSplinesMotionSolver"); + TypeName("volumetricBSplinesMotionSolver"); // Constructors diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/optMeshMovement/optMeshMovement/optMeshMovement.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/optMeshMovement/optMeshMovement/optMeshMovement.C index 794ad1b04e..e217065b30 100644 --- a/src/optimisation/adjointOptimisation/adjoint/optimisation/optMeshMovement/optMeshMovement/optMeshMovement.C +++ b/src/optimisation/adjointOptimisation/adjoint/optimisation/optMeshMovement/optMeshMovement/optMeshMovement.C @@ -110,7 +110,7 @@ Foam::autoPtr Foam::optMeshMovement::New "type", modelType, *dictionaryConstructorTablePtr_ - ) << exit(FatalError); + ) << exit(FatalIOError); } return autoPtr(cstrIter()(mesh, dict, patchIDs)); @@ -156,9 +156,10 @@ void Foam::optMeshMovement::writeMeshQualityMetrics() if (writeMeshQualityMetrics_) { cellQuality cellQualityEngine(mesh_); - tmp cellNonOrtho = cellQualityEngine.nonOrthogonality(); - tmp cellSkewness = cellQualityEngine.skewness(); - Info<< "Average, Max cell non - orthogonality " << gAverage(cellNonOrtho()) + tmp cellNonOrtho(cellQualityEngine.nonOrthogonality()); + tmp cellSkewness(cellQualityEngine.skewness()); + Info<< "Average, Max cell non - orthogonality " + << gAverage(cellNonOrtho()) << " " << gMax(cellNonOrtho()) << endl; Info<< "Average, Max cell skewness " << gAverage(cellSkewness()) << " " << gMax(cellSkewness()) << endl; 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