From eb6d1b346e7eb741894ec5b02c2ee95cf9c911b1 Mon Sep 17 00:00:00 2001 From: Ping He Date: Wed, 29 May 2024 13:11:59 -0500 Subject: [PATCH] Added an option to use latest fields for unsteady solvers. (#644) --- dafoam/pyDAFoam.py | 1 + src/adjoint/DASolver/DAPimpleFoam/DAPimpleFoam.C | 12 ++++++++---- .../DASolver/DARhoPimpleFoam/DARhoPimpleFoam.C | 12 ++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/dafoam/pyDAFoam.py b/dafoam/pyDAFoam.py index 6c2ba427..f8e74910 100755 --- a/dafoam/pyDAFoam.py +++ b/dafoam/pyDAFoam.py @@ -474,6 +474,7 @@ def __init__(self): "PCMatUpdateInterval": 1, "reduceIO": True, "additionalOutput": ["None"], + "readZeroFields": True, } ## At which iteration should we start the averaging of objective functions. diff --git a/src/adjoint/DASolver/DAPimpleFoam/DAPimpleFoam.C b/src/adjoint/DASolver/DAPimpleFoam/DAPimpleFoam.C index 1186bf99..ee510683 100755 --- a/src/adjoint/DASolver/DAPimpleFoam/DAPimpleFoam.C +++ b/src/adjoint/DASolver/DAPimpleFoam/DAPimpleFoam.C @@ -121,11 +121,15 @@ label DAPimpleFoam::solvePrimal( // change the run status daOptionPtr_->setOption("runStatus", "solvePrimal"); - // we need to read in the states from the 0 folder every time we start the primal - // here we read in all time levels runTime.setTime(0.0, 0); - this->readStateVars(0.0, 0); - this->readStateVars(0.0, 1); + // if readZeroFields, we need to read in the states from the 0 folder every time + // we start the primal here we read in all time levels + label readZeroFields = daOptionPtr_->getAllOptions().subDict("unsteadyAdjoint").getLabel("readZeroFields"); + if (readZeroFields) + { + this->readStateVars(0.0, 0); + this->readStateVars(0.0, 1); + } // call correctNut, this is equivalent to turbulence->validate(); daTurbulenceModelPtr_->updateIntermediateVariables(); diff --git a/src/adjoint/DASolver/DARhoPimpleFoam/DARhoPimpleFoam.C b/src/adjoint/DASolver/DARhoPimpleFoam/DARhoPimpleFoam.C index b53f1fad..b3a8eeb8 100755 --- a/src/adjoint/DASolver/DARhoPimpleFoam/DARhoPimpleFoam.C +++ b/src/adjoint/DASolver/DARhoPimpleFoam/DARhoPimpleFoam.C @@ -126,11 +126,15 @@ label DARhoPimpleFoam::solvePrimal( // change the run status daOptionPtr_->setOption("runStatus", "solvePrimal"); - // we need to read in the states from the 0 folder every time we start the primal - // here we read in all time levels runTime.setTime(0.0, 0); - this->readStateVars(0.0, 0); - this->readStateVars(0.0, 1); + // if readZeroFields, we need to read in the states from the 0 folder every time + // we start the primal here we read in all time levels + label readZeroFields = daOptionPtr_->getAllOptions().subDict("unsteadyAdjoint").getLabel("readZeroFields"); + if (readZeroFields) + { + this->readStateVars(0.0, 0); + this->readStateVars(0.0, 1); + } // call correctNut, this is equivalent to turbulence->validate(); daTurbulenceModelPtr_->updateIntermediateVariables();