@@ -599,6 +599,13 @@ class DAOPTION(object):
599
599
## The max number of correctBoundaryConditions calls in the updateOFField function.
600
600
maxCorrectBCCalls = 10
601
601
602
+ ## Whether to write the primal solutions for minor iterations (i.e., line search).
603
+ ## The default is False. If set it to True, it will write flow fields (and the deformed geometry)
604
+ ## for each primal solution. This will significantly increases the IO runtime, so it should never
605
+ ## be True for production runs. However, it is useful for debugging purpose (e.g., to find out
606
+ ## the poor quality mesh during line search)
607
+ writeMinorIterations = False
608
+
602
609
def __init__ (self ):
603
610
"""
604
611
Nothing needs to be done for initializing DAOPTION
@@ -679,8 +686,8 @@ def __init__(self, comm=None, options=None):
679
686
self ._initSolver ()
680
687
681
688
# initialize the number of primal and adjoint calls
682
- self .nSolvePrimals = 0
683
- self .nSolveAdjoints = 0
689
+ self .nSolvePrimals = 1
690
+ self .nSolveAdjoints = 1
684
691
685
692
# flags for primal and adjoint failure
686
693
self .primalFail = 0
@@ -1099,7 +1106,7 @@ def writeDesignVariable(self, fileName, xDV):
1099
1106
"""
1100
1107
# Write the design variable history to files
1101
1108
if self .comm .rank == 0 :
1102
- if self .nSolveAdjoints == 0 :
1109
+ if self .nSolveAdjoints == 1 :
1103
1110
f = open (fileName , "w" )
1104
1111
else :
1105
1112
f = open (fileName , "a" )
@@ -1144,7 +1151,7 @@ def writeTotalDeriv(self, fileName, sens, evalFuncs):
1144
1151
"""
1145
1152
# Write the sens history to files
1146
1153
if self .comm .rank == 0 :
1147
- if self .nSolveAdjoints == 1 :
1154
+ if self .nSolveAdjoints == 2 :
1148
1155
f = open (fileName , "w" )
1149
1156
else :
1150
1157
f = open (fileName , "a" )
@@ -1855,6 +1862,9 @@ def solvePrimal(self):
1855
1862
else :
1856
1863
self .primalFail = self .solver .solvePrimal (self .xvVec , self .wVec )
1857
1864
1865
+ if self .getOption ("writeMinorIterations" ):
1866
+ self .renameSolution (self .nSolvePrimals )
1867
+
1858
1868
self .nSolvePrimals += 1
1859
1869
1860
1870
return
@@ -1889,7 +1899,8 @@ def solveAdjoint(self):
1889
1899
if self .getOption ("useAD" )["mode" ] == "forward" :
1890
1900
raise Error ("solveAdjoint only supports useAD->mode=reverse|fd" )
1891
1901
1892
- solutionTime = self .renameSolution (self .nSolveAdjoints )
1902
+ if not self .getOption ("writeMinorIterations" ):
1903
+ solutionTime = self .renameSolution (self .nSolveAdjoints )
1893
1904
1894
1905
Info ("Running adjoint Solver %03d" % self .nSolveAdjoints )
1895
1906
@@ -1912,7 +1923,7 @@ def solveAdjoint(self):
1912
1923
1913
1924
# calculate dRdWTPC
1914
1925
adjPCLag = self .getOption ("adjPCLag" )
1915
- if self .nSolveAdjoints == 0 or self .nSolveAdjoints % adjPCLag == 0 :
1926
+ if self .nSolveAdjoints == 1 or ( self .nSolveAdjoints - 1 ) % adjPCLag == 0 :
1916
1927
self .dRdWTPC = PETSc .Mat ().create (PETSc .COMM_WORLD )
1917
1928
self .solver .calcdRdWT (self .xvVec , self .wVec , 1 , self .dRdWTPC )
1918
1929
@@ -2334,7 +2345,7 @@ def solveAdjoint(self):
2334
2345
self .nSolveAdjoints += 1
2335
2346
2336
2347
# we destroy dRdWTPC only when we need to recompute it next time
2337
- if self .nSolveAdjoints % adjPCLag == 0 :
2348
+ if ( self .nSolveAdjoints - 1 ) % adjPCLag == 0 :
2338
2349
self .dRdWTPC .destroy ()
2339
2350
2340
2351
return
@@ -2714,7 +2725,7 @@ def renameSolution(self, solIndex):
2714
2725
Info ("Solution time %g less than 1e-6, not moved." % float (solutionTime ))
2715
2726
return solutionTime
2716
2727
2717
- distTime = "%.8f" % (( solIndex + 1 ) / 1e8 )
2728
+ distTime = "%.8f" % (solIndex / 1e8 )
2718
2729
2719
2730
src = os .path .join (checkPath , solutionTime )
2720
2731
dst = os .path .join (checkPath , distTime )
0 commit comments