From d5661b50de0e9ddc6e6b4188455ca668e6f7c1bb Mon Sep 17 00:00:00 2001 From: Vaggelis Papoutsis Date: Thu, 21 Dec 2023 10:56:40 +0200 Subject: [PATCH 1/2] FIX: roll-back of the execution of function objects in optimisation In steadyOptimisation mode, each time-step corresponds to an optimisation cycle and is sub-cycled, to allow for iterating the flow and adjoint equations. This sub-cycling does not allow the execution of function objects. This was circumvented in 8947735b1d, by explicitly calling the execution of the function objects in the simple solver of adjointOptimisationFoam. However, each sub-cycled iteration is a writeTime, if the current optimisation cycle corresponds to a writeTime. This means that function objects with a writeControl write; will be executed in each iteration of the flow equations, within this specific optimisation cycle, leading to a lot of disc space and file clutter, if the function object outputs fields (e.g. yPlus). 8947735b1d is partially rolled back, by protecting the call to the execution of the function objects with a bool that defaults to false. --- .../solvers/primalSolvers/incompressible/simple/simple.C | 5 +++-- .../solvers/primalSolvers/incompressible/simple/simple.H | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.C b/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.C index d7bab37b8e..dd600099e9 100644 --- a/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.C +++ b/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.C @@ -107,7 +107,8 @@ Foam::simple::simple incoVars_(allocateVars()), MRF_(mesh, word(useSolverNameForFields() ? solverName_ : word::null)), cumulativeContErr_(Zero), - objectives_() + objectives_(), + allowFunctionObjects_(dict.getOrDefault("allowFunctionObjects", false)) { addExtraSchemes(); setRefCell @@ -246,7 +247,7 @@ void Foam::simple::postIter() { // Execute function objects in optimisation cases // Disabled in Time since we are subsycling - if (managerType_ == "steadyOptimisation") + if (managerType_ == "steadyOptimisation" && allowFunctionObjects_) { const_cast(mesh_.time()).functionObjects().execute(false); } diff --git a/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.H b/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.H index 7f2b68cac9..38cd61d648 100644 --- a/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.H +++ b/src/optimisation/adjointOptimisation/adjoint/solvers/primalSolvers/incompressible/simple/simple.H @@ -86,6 +86,12 @@ protected: //- List of objectives related to this primal solver UPtrList objectives_; + //- Allow the execution of function objects in optimisation mode. + // Depending on the functions used and the setup, this might lead + // to a high amount of data written to the hard drive. + // WIP + bool allowFunctionObjects_; + //- Protected Member Functions From e5a62a0bdd0d4523a22f44ea7778e97ea60baf6f Mon Sep 17 00:00:00 2001 From: Vaggelis Papoutsis Date: Thu, 21 Dec 2023 11:23:46 +0200 Subject: [PATCH 2/2] TUT: removed unnecessary computations of yPlus in shape optimisation tutorials --- .../opt/losses/BFGS-continuation/system/controlDict | 11 ----------- .../SA/opt/losses/BFGS-oneGo/system/controlDict | 11 ----------- .../SA/opt/losses/BFGS/op1/system/controlDict | 11 ----------- .../sbend/turbulent/SA/opt/nutSqr/system/controlDict | 10 ---------- .../SA/opt/powerDissipation/system/controlDict | 10 ---------- .../sbend/turbulent/kOmegaSST/opt/system/controlDict | 10 ---------- 6 files changed, 63 deletions(-) diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-continuation/system/controlDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-continuation/system/controlDict index 80267a160a..8ac263eda1 100644 --- a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-continuation/system/controlDict +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-continuation/system/controlDict @@ -44,16 +44,5 @@ timePrecision 6; runTimeModifiable yes; -functions -{ - yPlus - { - type yPlus; - libs ( fieldFunctionObjects ); - writeFields yes; - writeControl writeTime; - } -} - // ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-oneGo/system/controlDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-oneGo/system/controlDict index 027ec157e9..a676be50dd 100644 --- a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-oneGo/system/controlDict +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS-oneGo/system/controlDict @@ -44,16 +44,5 @@ timePrecision 6; runTimeModifiable yes; -functions -{ - yPlus - { - type yPlus; - libs (fieldFunctionObjects); - writeFields yes; - writeControl writeTime; - } -} - // ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS/op1/system/controlDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS/op1/system/controlDict index 7f096db2e9..41e8757f2e 100644 --- a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS/op1/system/controlDict +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/losses/BFGS/op1/system/controlDict @@ -44,16 +44,5 @@ timePrecision 6; runTimeModifiable yes; -functions -{ - yPlus - { - type yPlus; - libs (fieldFunctionObjects); - writeFields yes; - writeControl writeTime; - } -} - // ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/nutSqr/system/controlDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/nutSqr/system/controlDict index f6230cff5f..41e8757f2e 100644 --- a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/nutSqr/system/controlDict +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/nutSqr/system/controlDict @@ -44,15 +44,5 @@ timePrecision 6; runTimeModifiable yes; -functions -{ - yPlus - { - type yPlus; - libs (fieldFunctionObjects); - writeFields yes; - writeControl writeTime; - } -} // ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/powerDissipation/system/controlDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/powerDissipation/system/controlDict index f6230cff5f..41e8757f2e 100644 --- a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/powerDissipation/system/controlDict +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/SA/opt/powerDissipation/system/controlDict @@ -44,15 +44,5 @@ timePrecision 6; runTimeModifiable yes; -functions -{ - yPlus - { - type yPlus; - libs (fieldFunctionObjects); - writeFields yes; - writeControl writeTime; - } -} // ************************************************************************* // diff --git a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/kOmegaSST/opt/system/controlDict b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/kOmegaSST/opt/system/controlDict index 564840935a..41e8757f2e 100644 --- a/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/kOmegaSST/opt/system/controlDict +++ b/tutorials/incompressible/adjointOptimisationFoam/shapeOptimisation/sbend/turbulent/kOmegaSST/opt/system/controlDict @@ -44,15 +44,5 @@ timePrecision 6; runTimeModifiable yes; -functions -{ -// yPlus -// { -// type yPlus; -// libs ("libfieldFunctionObjects.so"); -// writeFields yes; -// writeControl writeTime; -// } -} // ************************************************************************* //