From bab4fd32e02945daadea288f94b8bb383bc36f1f Mon Sep 17 00:00:00 2001 From: Ping He Date: Wed, 6 Dec 2023 19:47:05 -0600 Subject: [PATCH 1/2] Fixed a bug to allow mulitple parts for unsteady objs. --- dafoam/pyDAFoam.py | 3 +- src/adjoint/DAObjFunc/DAObjFunc.H | 8 -- .../DAObjFunc/DAObjFuncCenterOfPressure.C | 2 - .../DAObjFunc/DAObjFuncFieldInversion.C | 2 - src/adjoint/DAObjFunc/DAObjFuncForce.C | 1 - src/adjoint/DAObjFunc/DAObjFuncLocation.C | 1 - src/adjoint/DAObjFunc/DAObjFuncMass.C | 1 - src/adjoint/DAObjFunc/DAObjFuncMassFlowRate.C | 1 - .../DAObjFunc/DAObjFuncMeshQualityKS.C | 1 - src/adjoint/DAObjFunc/DAObjFuncMoment.C | 1 - src/adjoint/DAObjFunc/DAObjFuncPatchMean.C | 2 - src/adjoint/DAObjFunc/DAObjFuncPower.C | 2 - .../DAObjFunc/DAObjFuncTotalPressure.C | 2 - .../DAObjFunc/DAObjFuncTotalPressureRatio.C | 1 - .../DAObjFuncTotalTemperatureRatio.C | 1 - .../DAObjFunc/DAObjFuncVariableVolSum.C | 2 - src/adjoint/DAObjFunc/DAObjFuncVariance.C | 2 - .../DAObjFunc/DAObjFuncVonMisesStressKS.C | 1 - src/adjoint/DAObjFunc/DAObjFuncWallHeatFlux.C | 2 - src/adjoint/DASolver/DASolver.C | 84 +++++++++++++++---- src/adjoint/DASolver/DASolver.H | 15 ++-- src/pyDASolvers/DASolvers.H | 4 +- src/pyDASolvers/pyDASolvers.pyx | 6 +- .../refs/DAFoam_Test_DAPimpleFoamFieldRef.txt | 13 +-- tests/runTests_DAPimpleFoamField.py | 41 ++++----- 25 files changed, 100 insertions(+), 99 deletions(-) diff --git a/dafoam/pyDAFoam.py b/dafoam/pyDAFoam.py index aef5f423..7dc2ccbc 100755 --- a/dafoam/pyDAFoam.py +++ b/dafoam/pyDAFoam.py @@ -465,6 +465,7 @@ def __init__(self): "periodicity": -1.0, "objFuncStartTime": -1.0, "objFuncEndTime": -1.0, + "objFuncTimeOperator": "None", "PCMatPrecomputeInterval": 100, "PCMatUpdateInterval": 1, "reduceIO": True, @@ -2415,7 +2416,7 @@ def solveAdjointUnsteady(self): # on the state at this time index dFScaling = 1.0 if n >= objFuncStartTimeIndex and n <= objFuncEndTimeIndex: - dFScaling = self.solver.getObjFuncUnsteadyScaling(objFuncName.encode()) + dFScaling = self.solver.getObjFuncUnsteadyScaling() else: dFScaling = 0.0 diff --git a/src/adjoint/DAObjFunc/DAObjFunc.H b/src/adjoint/DAObjFunc/DAObjFunc.H index 4ea3893c..b75a31f6 100755 --- a/src/adjoint/DAObjFunc/DAObjFunc.H +++ b/src/adjoint/DAObjFunc/DAObjFunc.H @@ -92,9 +92,6 @@ protected: /// the connectivity information for the objective function List> objFuncConInfo_; - /// the unsteady objective function type like sum or average - word timeOperator_ = "None"; - public: /// Runtime type information TypeName("DAObjFunc"); @@ -234,11 +231,6 @@ public: return objFuncConInfo_; } - const word& getObjFuncTimeOperator() const - { - return timeOperator_; - } - /// expSumKS stores sum[exp(coeffKS*x_i)] for KS function which will be used to scale dFdW scalar expSumKS = 1.0; diff --git a/src/adjoint/DAObjFunc/DAObjFuncCenterOfPressure.C b/src/adjoint/DAObjFunc/DAObjFuncCenterOfPressure.C index 84111595..792f928e 100644 --- a/src/adjoint/DAObjFunc/DAObjFuncCenterOfPressure.C +++ b/src/adjoint/DAObjFunc/DAObjFuncCenterOfPressure.C @@ -71,8 +71,6 @@ DAObjFuncCenterOfPressure::DAObjFuncCenterOfPressure( center_[2] = centerList[2]; objFuncDict_.readEntry("scale", scale_); - - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncFieldInversion.C b/src/adjoint/DAObjFunc/DAObjFuncFieldInversion.C index 8b1412f5..b8608271 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncFieldInversion.C +++ b/src/adjoint/DAObjFunc/DAObjFuncFieldInversion.C @@ -74,8 +74,6 @@ DAObjFuncFieldInversion::DAObjFuncFieldInversion( { objFuncConInfo_ = {{}}; // level 0 } - - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncForce.C b/src/adjoint/DAObjFunc/DAObjFuncForce.C index cee9494b..244c645f 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncForce.C +++ b/src/adjoint/DAObjFunc/DAObjFuncForce.C @@ -115,7 +115,6 @@ DAObjFuncForce::DAObjFuncForce( // now replace nut with the corrected name for the selected turbulence model daModel.correctModelStates(objFuncConInfo_[0]); - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncLocation.C b/src/adjoint/DAObjFunc/DAObjFuncLocation.C index 86a51de4..2baa0c0d 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncLocation.C +++ b/src/adjoint/DAObjFunc/DAObjFuncLocation.C @@ -110,7 +110,6 @@ DAObjFuncLocation::DAObjFuncLocation( } } - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncMass.C b/src/adjoint/DAObjFunc/DAObjFuncMass.C index 2ac773a4..782fe4fb 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncMass.C +++ b/src/adjoint/DAObjFunc/DAObjFuncMass.C @@ -44,7 +44,6 @@ DAObjFuncMass::DAObjFuncMass( objFuncDict_.readEntry("scale", scale_); - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncMassFlowRate.C b/src/adjoint/DAObjFunc/DAObjFuncMassFlowRate.C index e99e1801..841071e9 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncMassFlowRate.C +++ b/src/adjoint/DAObjFunc/DAObjFuncMassFlowRate.C @@ -57,7 +57,6 @@ DAObjFuncMassFlowRate::DAObjFuncMassFlowRate( objFuncDict_.readEntry("scale", scale_); - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncMeshQualityKS.C b/src/adjoint/DAObjFunc/DAObjFuncMeshQualityKS.C index 0bc84f25..efe5bb58 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncMeshQualityKS.C +++ b/src/adjoint/DAObjFunc/DAObjFuncMeshQualityKS.C @@ -77,7 +77,6 @@ DAObjFuncMeshQualityKS::DAObjFuncMeshQualityKS( Info << "includeFaceList " << includeFaceList_ << endl; } - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncMoment.C b/src/adjoint/DAObjFunc/DAObjFuncMoment.C index e0d47ffa..0fe5da0f 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncMoment.C +++ b/src/adjoint/DAObjFunc/DAObjFuncMoment.C @@ -91,7 +91,6 @@ DAObjFuncMoment::DAObjFuncMoment( // now replace nut with the corrected name for the selected turbulence model daModel.correctModelStates(objFuncConInfo_[0]); - timeOperator_ = objFuncDict.lookupOrDefault("timeOperator", "None"); } /// calculate the value of objective function diff --git a/src/adjoint/DAObjFunc/DAObjFuncPatchMean.C b/src/adjoint/DAObjFunc/DAObjFuncPatchMean.C index 6e5fb538..4980f665 100755 --- a/src/adjoint/DAObjFunc/DAObjFuncPatchMean.C +++ b/src/adjoint/DAObjFunc/DAObjFuncPatchMean.C @@ -45,8 +45,6 @@ DAObjFuncPatchMean::DAObjFuncPatchMean( objFuncDict_.readEntry("varType", varType_); objFuncDict_.readEntry