Skip to content

Commit

Permalink
Fixed pimpleFoam's adjoint (#517)
Browse files Browse the repository at this point in the history
* Deactivated dRdWOld.

* Added a template for solveAdjointUnsteady.

* DAPimpleFoam working.

* Added the option to use backward ddtScheme.

* Added shape derivs. Changed the pimple solver a bit.

* Added printToScreen to the turb.correct() call. Fixed an issue for the obj update for pimple.

* Fixed an issue for the calcSensFD func.

* Fixed a bug for the readStateVars by setting the proper oldTime level before the adjoint solve.

* Added betaFI to origional safv3

* Added a new obj func for variance calculation.

* Enabled totals for all derivs.

* Added the variance obj to Makefile.

* Added the test for pimple.

* Fixed a few bugs.

* updated test script for scalarTransport

* Fixed the scalarTransport test.

* Added an option to use part of the runtime for unsteady obj.

* Fixed a bug for the steady.g

* Added the pimple field test.

* Added the test to Allrun.

* Added the missing ref.
  • Loading branch information
friedenhe authored Nov 18, 2023
1 parent 767274c commit 6f44401
Show file tree
Hide file tree
Showing 75 changed files with 1,929 additions and 875 deletions.
18 changes: 11 additions & 7 deletions dafoam/optFuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ def calcObjFuncSens(xDV, funcs):
DVCon.evalFunctionsSens(funcsSens)

# Solve the adjoint
DASolver.solveAdjoint()
if DASolver.getOption("unsteadyAdjoint")["mode"] == "timeAccurate":
DASolver.solveAdjointUnsteady()
else:
DASolver.solveAdjoint()

# Evaluate the CFD derivatives
DASolver.evalFunctionsSens(funcsSens, evalFuncs=evalFuncs)
Expand Down Expand Up @@ -334,9 +337,9 @@ def calcObjFuncSensUnsteady(xDV, funcs):

mode = DASolver.getOption("unsteadyAdjoint")["mode"]
nTimeInstances = DASolver.getOption("unsteadyAdjoint")["nTimeInstances"]
if mode == "hybridAdjoint":
if mode == "hybrid":
iEnd = -1
elif mode == "timeAccurateAdjoint":
elif mode == "timeAccurate":
iEnd = 0

# NOTE: calling calcRes here is critical because it will setup the correct
Expand All @@ -346,9 +349,6 @@ def calcObjFuncSensUnsteady(xDV, funcs):
# this will create issues for the setTimeInstanceField call (nOldTimes)
DASolver.calcPrimalResidualStatistics("calc")

# set these vectors zeros
DASolver.zeroTimeAccurateAdjointVectors()

for i in range(nTimeInstances - 1, iEnd, -1):

Info("--Solving Adjoint for Time Instance %d--" % i)
Expand Down Expand Up @@ -502,7 +502,11 @@ def calcFDSens(objFun=calcObjFuncValues, fileName=None):
for funcName in evalFuncs:
gradFD[funcName] = {}
for shapeVar in xDV:
gradFD[funcName][shapeVar] = np.zeros(len(xDV[shapeVar]))
try:
nDVs = len(xDV[shapeVar])
except Exception:
nDVs = 1
gradFD[funcName][shapeVar] = np.zeros(nDVs)
if gcomm.rank == 0:
print("-------FD----------", deltaX, flush=True)

Expand Down
Loading

0 comments on commit 6f44401

Please sign in to comment.