From 254d38d772175284a7ac34eadba54598fa3fdffe Mon Sep 17 00:00:00 2001 From: Vaggelis Papoutsis <vaggelisp@gmail.com> Date: Tue, 31 Dec 2019 20:03:22 +0200 Subject: [PATCH] BUG: continuation of updateMethods with empty activeDesignVariables When activeDesignVariables are not set explicitly, all design variables are treated as active. These were allocated properly when starting from 0 but not when starting from an intermediate optimisation cycle (e.g. running 5 optimisation cycles, stopping and restarting). TUT: added a new tutorial including the restart of an optimisation run to help identify future regression --- .../optimisation/updateMethod/BFGS/BFGS.C | 13 +- .../optimisation/updateMethod/DBFGS/DBFGS.C | 11 +- .../optimisation/updateMethod/LBFGS/LBFGS.C | 11 +- .../optimisation/updateMethod/SQP/SQP.C | 11 +- .../optimisation/updateMethod/SR1/SR1.C | 13 +- .../conjugateGradient/conjugateGradient.C | 11 +- .../sbend/turbulent/opt/BFGS-continuation/0/U | 55 +++++++ .../turbulent/opt/BFGS-continuation/0/Ua | 56 ++++++++ .../turbulent/opt/BFGS-continuation/0/nuTilda | 55 +++++++ .../opt/BFGS-continuation/0/nuaTilda | 60 ++++++++ .../turbulent/opt/BFGS-continuation/0/nut | 55 +++++++ .../sbend/turbulent/opt/BFGS-continuation/0/p | 52 +++++++ .../turbulent/opt/BFGS-continuation/0/pa | 52 +++++++ .../turbulent/opt/BFGS-continuation/Allclean | 10 ++ .../turbulent/opt/BFGS-continuation/Allrun | 17 +++ .../constant/adjointRASProperties | 21 +++ .../constant/dynamicMeshDict | 47 ++++++ .../constant/transportProperties | 21 +++ .../constant/turbulenceProperties | 28 ++++ .../opt/BFGS-continuation/system/controlDict | 57 ++++++++ .../BFGS-continuation/system/decomposeParDict | 26 ++++ .../opt/BFGS-continuation/system/fvSchemes | 71 +++++++++ .../opt/BFGS-continuation/system/fvSolution | 65 +++++++++ .../BFGS-continuation/system/optimisationDict | 136 ++++++++++++++++++ 24 files changed, 922 insertions(+), 32 deletions(-) create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/U create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/Ua create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuTilda create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuaTilda create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nut create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/p create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/pa create mode 100755 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allclean create mode 100755 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allrun create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/adjointRASProperties create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/dynamicMeshDict create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/transportProperties create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/turbulenceProperties create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/controlDict create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/decomposeParDict create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSchemes create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSolution create mode 100644 tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/optimisationDict diff --git a/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/BFGS/BFGS.C b/src/optimisation/adjointOptimisation/adjoint/optimisation/updateMethod/BFGS/BFGS.C index 26b80e1803d..9cd0671d9da 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<scalar>(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 0e5f0fe06c8..fb38d03d126 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<scalar>(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 c60d094b9fb..5478281842a 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 8f91c5e2272..9d988abe83c 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 69c98a54cbc..b582b57a249 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<scalar>(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 629ba8221e5..3e8ca3747ad 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<label>("nDVs"); correction_ = scalarField(nDVs, Zero); + + if (activeDesignVars_.empty()) + { + activeDesignVars_ = identity(nDVs); + } } } diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/U b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/U new file mode 100644 index 00000000000..07d059bcacf --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/U @@ -0,0 +1,55 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volVectorField; + location "0"; + object U; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 1 -1 0 0 0 0 ]; + +internalField uniform ( 3.95 0 0 ); + +boundaryField +{ + frontBack + { + type empty; + } + sideWall + { + type fixedValue; + value uniform ( 0 0 0 ); + } + lower + { + type fixedValue; + value uniform ( 0 0 0 ); + } + upper + { + type fixedValue; + value uniform ( 0 0 0 ); + } + Inlet + { + type fixedValue; + value uniform ( 3.95 0 0 ); + } + Outlet + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/Ua b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/Ua new file mode 100644 index 00000000000..465d3a935b6 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/Ua @@ -0,0 +1,56 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volVectorField; + location "0"; + object Ua; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 1 -1 0 0 0 0 ]; + +internalField uniform ( 0 0 0 ); + +boundaryField +{ + frontBack + { + type empty; + } + sideWall + { + type adjointWallVelocity; + value uniform ( 0 0 0 ); + } + upper + { + type adjointWallVelocity; + value uniform ( 0 0 0 ); + } + Inlet + { + type adjointInletVelocity; + value uniform ( 0 0 0 ); + } + Outlet + { + type adjointOutletVelocity; + value uniform ( 0 0 0 ); + } + lower + { + type adjointWallVelocity; + value uniform ( 0 0 0 ); + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuTilda b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuTilda new file mode 100644 index 00000000000..a7f8dfed2e4 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuTilda @@ -0,0 +1,55 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object nuTilda; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -1 0 0 0 0 ]; + +internalField uniform 4.5e-05; + +boundaryField +{ + frontBack + { + type empty; + } + sideWall + { + type fixedValue; + value uniform 0; + } + upper + { + type fixedValue; + value uniform 0; + } + lower + { + type fixedValue; + value uniform 0; + } + Inlet + { + type fixedValue; + value uniform 4.5e-05; + } + Outlet + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuaTilda b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuaTilda new file mode 100644 index 00000000000..24b5f41f45b --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nuaTilda @@ -0,0 +1,60 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object nuaTilda; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 0 -1 0 0 0 0 ]; + +internalField uniform 0; + +boundaryField +{ + frontBack + { + type empty; + } + sideWall + { + type fixedValue; + value uniform 0; + } + upper + { + type fixedValue; + value uniform 0; + } + lower + { + type fixedValue; + value uniform 0; + } + Inlet + { + type adjointInletNuaTilda; + value uniform 0; + } + Outlet + { + type adjointOutletNuaTilda; + value uniform 0; + } + defaultFaces + { + type empty; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nut b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nut new file mode 100644 index 00000000000..206a8db7631 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/nut @@ -0,0 +1,55 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object nut; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -1 0 0 0 0 ]; + +internalField uniform 3.15e-06; + +boundaryField +{ + frontBack + { + type empty; + } + sideWall + { + type nutLowReWallFunction; + value uniform 0; + } + upper + { + type nutLowReWallFunction; + value uniform 0; + } + lower + { + type nutLowReWallFunction; + value uniform 0; + } + Inlet + { + type fixedValue; + value uniform 3.15e-06; + } + Outlet + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/p b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/p new file mode 100644 index 00000000000..7c186dde34e --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/p @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object p; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -2 0 0 0 0 ]; + +internalField uniform 0; + +boundaryField +{ + frontBack + { + type empty; + } + lower + { + type zeroGradient; + } + upper + { + type zeroGradient; + } + sideWall + { + type zeroGradient; + } + Inlet + { + type zeroGradient; + } + Outlet + { + type fixedValue; + value uniform 0; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/pa b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/pa new file mode 100644 index 00000000000..59938b12cd7 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/0/pa @@ -0,0 +1,52 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class volScalarField; + location "0"; + object pa; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [ 0 2 -2 0 0 0 0 ]; + +internalField uniform 0; + +boundaryField +{ + frontBack + { + type empty; + } + sideWall + { + type zeroGradient; + } + upper + { + type zeroGradient; + } + Inlet + { + type zeroGradient; + } + Outlet + { + type adjointOutletPressure; + value uniform 0; + } + lower + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allclean b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allclean new file mode 100755 index 00000000000..dbf18a2bf75 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allclean @@ -0,0 +1,10 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions +#------------------------------------------------------------------------------ + +cleanCase +sed -i 's/endTime 10/endTime 5/g' system/controlDict +sed -i 's/fromFile/axisAligned/g' constant/dynamicMeshDict + +#------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allrun b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allrun new file mode 100755 index 00000000000..5fe5d93d734 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/Allrun @@ -0,0 +1,17 @@ +#!/bin/sh +cd "${0%/*}" || exit # Run from this directory +. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions +#------------------------------------------------------------------------------ + +resourcesDir=$FOAM_TUTORIALS/incompressible/adjointOptimisationFoam/resources + +\cp -r $resourcesDir/meshes/sbend/polyMesh constant +runApplication decomposePar +runParallel $(getApplication) +mv log.adjointOptimisationFoam log.adjointOptimisationFoamFirstPhase +sed -i 's/endTime 5/endTime 10/g' system/controlDict +sed -i 's/axisAligned/fromFile/g' constant/dynamicMeshDict +runParallel $(getApplication) +runParallel cumulativeDisplacement + +#------------------------------------------------------------------------------ diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/adjointRASProperties b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/adjointRASProperties new file mode 100644 index 00000000000..290360691b9 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/adjointRASProperties @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object adjointTurbulenceProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +adjointRASModel adjointSpalartAllmaras; + +adjointTurbulence on; + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/dynamicMeshDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/dynamicMeshDict new file mode 100644 index 00000000000..2fb565e7979 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/dynamicMeshDict @@ -0,0 +1,47 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object dynamicMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solver volumetricBSplinesMotionSolver; + +volumetricBSplinesMotionSolverCoeffs +{ + duct + { + type cartesian; + nCPsU 9; + nCPsV 5; + nCPsW 3; + degreeU 3; + degreeV 3; + degreeW 2; + + controlPointsDefinition axisAligned; + lowerCpBounds (-1.1 -0.21 -0.05); + upperCpBounds ( 1.1 0.39 0.15); + + confineX1movement false; + confineX2movement false; + confineX3movement true; + confineBoundaryControlPoints false; + + boundUMinCPs ( (true true true) (true true true) ); + boundUMaxCPs ( (true true true) (true true true) ); + boundWMinCPs ( (true true true) ); + boundWMaxCPs ( (true true true) ); + } +} + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/transportProperties b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/transportProperties new file mode 100644 index 00000000000..d0211f908ee --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/transportProperties @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object transportProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +transportModel Newtonian; + +nu nu [0 2 -1 0 0 0 0] 1.5e-05; + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/turbulenceProperties b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/turbulenceProperties new file mode 100644 index 00000000000..2dfe5cd0e9b --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/constant/turbulenceProperties @@ -0,0 +1,28 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object turbulenceProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +simulationType RAS; + +RAS +{ + RASModel SpalartAllmaras; + + turbulence on; + + printCoeffs on; +} + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/controlDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/controlDict new file mode 100644 index 00000000000..d72b1e2f212 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/controlDict @@ -0,0 +1,57 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application adjointOptimisationFoam; + +startFrom latestTime; + +startTime 0; + +stopAt endTime; + +endTime 5; + +deltaT 1; + +writeControl timeStep; + +writeInterval 1; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 16; + +writeCompression true; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable yes; + +functions +{ + yPlus + { + type yPlus; + libs ("libfieldFunctionObjects.so"); + writeControl writeTime; + } +} + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/decomposeParDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/decomposeParDict new file mode 100644 index 00000000000..614d8914884 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/decomposeParDict @@ -0,0 +1,26 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object decomposeParDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +numberOfSubdomains 4; + +method hierarchical; + +coeffs +{ + n (4 1 1); +} + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSchemes b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSchemes new file mode 100644 index 00000000000..ed618ddb426 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSchemes @@ -0,0 +1,71 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default steadyState; +} + +gradSchemes +{ + default Gauss linear; + gradDConv cellLimited Gauss linear 1; +} + +divSchemes +{ + default Gauss linear; + + div(phi,U) bounded Gauss linearUpwind gradUConv; + div(phi,nuTilda) bounded Gauss linearUpwind gradNuTildaConv; + div(yPhi,yWall) Gauss linearUpwind gradDConv; + div(-phi,Ua) bounded Gauss linearUpwind gradUaConv; + div(-phi,nuaTilda) bounded Gauss linearUpwind gradNuaTildaConv; + div(-yPhi,da) Gauss linearUpwind gradDaConv; + + div((nuEff*dev(grad(U).T()))) Gauss linear; + div((nuEff*dev(grad(Ua).T()))) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear limited 0.333; + +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +wallDist +{ + method advectionDiffusion; + advectionDiffusionCoeffs + { + method meshWave; + tolerance 3.e-6; + maxIter 1000; + epsilon 0.1; + } +} + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSolution b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSolution new file mode 100644 index 00000000000..6e36a45a344 --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/fvSolution @@ -0,0 +1,65 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +SIMPLE +{ + nNonOrthogonalCorrectors 0; +} + +solvers +{ + "p|pa" + { + solver PCG; + preconditioner DIC; + tolerance 1e-9; + relTol 0.01; + }; + "m|ma" + { + solver PCG; + preconditioner DIC; + tolerance 1e-9; + relTol 0.01; + }; + "U|Ua|nuTilda|nuaTilda|yWall|da" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-9; + relTol 0.1; + }; +} + +relaxationFactors +{ + fields + { + p 0.5; + pa 0.5; + } + equations + { + U 0.7; + Ua 0.7; + nuTilda 0.7; + nuaTilda 0.7; + yWall 0.7; + da 0.7; + } +} + +// ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/optimisationDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/optimisationDict new file mode 100644 index 00000000000..dd37fade2ad --- /dev/null +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/opt/BFGS-continuation/system/optimisationDict @@ -0,0 +1,136 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v1912 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object optimisationDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +optimisationManager steadyOptimisation; + +primalSolvers +{ + p1 + { + active true; + type incompressible; + solver simple; + solutionControls + { + nIters 3000; + residualControl + { + "p.*" 1.e-7; + "U.*" 1.e-7; + "nuTilda.*" 1.e-7; + } + } + } +} + +adjointManagers +{ + am1 + { + primalSolver p1; + adjointSolvers + { + as1 + { + // choose adjoint solver + //---------------------- + active true; + type incompressible; + solver adjointSimple; + + // manage objectives + //------------------ + objectives + { + type incompressible; + objectiveNames + { + losses + { + weight 1; + type PtLosses; + patches (Inlet Outlet); + } + } + } + + // ATC treatment + //-------------- + ATCModel + { + ATCModel standard; + } + + // solution control + //------------------ + solutionControls + { + nIters 3000; + residualControl + { + "pa.*" 1.e-7; + "Ua.*" 1.e-7; + } + } + } + } + } +} + +optimisation +{ + optimisationType + { + type shapeOptimisation; + writeEachMesh true; + } + + sensitivities + { + type volumetricBSplinesFI; + patches (lower upper); + } + updateMethod + { + method BFGS; + BFGS + { + etaHessian 0.8; + scaleFirstHessian true; + /* + activeDesignVariables + ( + 141 142 144 145 147 148 + 150 151 153 154 168 169 + 171 172 174 175 177 178 + 180 181 195 196 198 199 + 201 202 204 205 207 208 + 222 223 225 226 228 229 + 231 232 234 235 249 250 + 252 253 255 256 258 259 + 261 262 + ); + */ + } + } + meshMovement + { + type volumetricBSplines; + maxAllowedDisplacement 2.e-3; + } +} + +// ************************************************************************* // -- GitLab