From 50ce904f072fb946125ea7b2e00d78ada5e32465 Mon Sep 17 00:00:00 2001 From: Eirikur Jonsson <36180221+eirikurj@users.noreply.github.com> Date: Thu, 10 Feb 2022 21:00:44 +0000 Subject: [PATCH 1/2] Convergence history is now written to the cgns volume file (#189) --- src/f2py/adflow.pyf | 9 ++++----- src/modules/monitor.f90 | 5 ----- src/output/writeCGNSVolume.F90 | 11 ++++++----- src/solver/solvers.F90 | 4 ++-- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/f2py/adflow.pyf b/src/f2py/adflow.pyf index 9f319ba0e..686023c8c 100644 --- a/src/f2py/adflow.pyf +++ b/src/f2py/adflow.pyf @@ -677,17 +677,17 @@ python module libadflow integer(kind=inttype) dimension(:,:) :: bcdatafamlists logical intent(in) :: bcvarsempty end subroutine computematrixfreeproductbwd - - + + subroutine computematrixfreeproductbwdfast(dwbar, wbar, statesize)! in :test:adjointapi.f90:adjointapi real(kind=realtype) dimension(:),intent(in) :: dwbar real(kind=realtype) dimension(statesize),intent(out),depend(statesize) :: wbar integer(kind=inttype) intent(in) :: statesize - end subroutine computematrixfreeproductbwdfast + end subroutine computematrixfreeproductbwdfast #endif end module adjointapi module adjointdebug - + #ifndef USE_COMPLEX subroutine computematrixfreeproductfwdfd(xvdot,extradot,wdot,bcdatavaluesdot,usespatial,usestate,famlists,bcdatanames,bcdatavalues,bcdatafamlists,bcvarsempty,dwdot,funcsdot,fdot,costsize,fsize,ntime,h) ! in :test:adjointAPI.F90:adjointdebug real(kind=realtype) dimension(:),intent(in) :: xvdot @@ -1309,7 +1309,6 @@ python module libadflow logical :: showcpu logical :: monmasssliding logical :: monmassfamilies - integer :: nitercur real(kind=realtype) allocatable,dimension(:,:,:) :: convarray integer(kind=inttype) :: ntimestepsrestart integer(kind=inttype) :: timestepunsteady diff --git a/src/modules/monitor.f90 b/src/modules/monitor.f90 index 744f43d4a..67635f875 100644 --- a/src/modules/monitor.f90 +++ b/src/modules/monitor.f90 @@ -65,11 +65,6 @@ module monitor ! ! Variables to store the convergence info. ! - ! nIterCur: Current number of iterations. Also niterCur is an - ! integer, because of cgns. - - integer :: nIterCur - ! convArray(0:nIterMax,nsps,nmon): 3D array to store the ! convergence histories. diff --git a/src/output/writeCGNSVolume.F90 b/src/output/writeCGNSVolume.F90 index 04a825801..10a56aeb6 100644 --- a/src/output/writeCGNSVolume.F90 +++ b/src/output/writeCGNSVolume.F90 @@ -490,7 +490,8 @@ subroutine writeCGNSConvInfo ! use inputIO use inputPhysics - use monitor + use monitor, only : nMon, monNames, convArray + use iteration, only : iterTot use su_cgns use outputMod use utils, only : terminate @@ -510,9 +511,9 @@ subroutine writeCGNSConvInfo if(.not. storeConvInnerIter) return ! Store the number of iterations to be written in nn. - ! This is nIterCur + 1, because the array starts at 0. + ! This is iterTot + 1, because the array starts at 0. - nn = nIterCur + 1 + nn = iterTot + 1 ! Depending on the input option, set the CGNS type and allocate ! the memory for either buf4 or buf8. @@ -521,7 +522,7 @@ subroutine writeCGNSConvInfo ! that's what Tecplot needs realTypeCGNS = RealDouble - allocate(buf8(0:nIterCur), stat=ierr) + allocate(buf8(0:iterTot), stat=ierr) if(ierr /= 0) & @@ -585,7 +586,7 @@ subroutine writeCGNSConvInfo ! Copy the convergence info to either buf4 or buf8 and write ! it to file. - do mm=0,nIterCur + do mm=0,iterTot buf8(mm) = convArray(mm,conv,i) enddo diff --git a/src/solver/solvers.F90 b/src/solver/solvers.F90 index bb80a58c8..de07895e0 100644 --- a/src/solver/solvers.F90 +++ b/src/solver/solvers.F90 @@ -959,7 +959,7 @@ subroutine solveState nMGCycles = nCycles if(groundLevel > 1) nMGCycles = nCyclesCoarse - ! Allocate (or reallocate) the convergence arry for this solveState. + ! Allocate (or reallocate) the convergence array for this solveState. call allocConvArrays(nMGCycles) ! Allocate space for storing hisotry of function evaluations for NK @@ -1283,7 +1283,7 @@ subroutine convergenceInfo ! Determine whether or not the iterations must be written. writeIterations = .true. - if(equationMode == unsteady .and. & + if(equationMode == unsteady .and. & timeIntegrationScheme == explicitRK) writeIterations = .false. ! Initializations From 9bfbeb2380819aab63ce4973d2e7f8ce158b80c8 Mon Sep 17 00:00:00 2001 From: Sabet Seraj <48863473+sseraj@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:53:49 -0500 Subject: [PATCH 2/2] Implemented restartAdjoint option (#188) * removed unused restartAdjoint from Fortran * implemented restartAdjoint in Python --- adflow/pyADflow.py | 15 ++++++++++----- src/f2py/adflow.pyf | 1 - src/modules/inputParam.F90 | 4 +--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/adflow/pyADflow.py b/adflow/pyADflow.py index d7bd1251a..ac129598e 100644 --- a/adflow/pyADflow.py +++ b/adflow/pyADflow.py @@ -3405,11 +3405,16 @@ def solveAdjoint(self, aeroProblem, objective, forcePoints=None, structAdjoint=N # on this AP, there is no point in solving the reset, so continue # with psi set as zero if not (self.curAP.adjointFailed and self.getOption("skipafterfailedadjoint")): - # Extract the psi: - psi = self.curAP.adflowData.adjoints[objective] - # Actually Solve the adjoint system...psi is updated with the - # new solution. + if self.getOption("restartAdjoint"): + # Use the previous solution as the initial guess + psi = self.curAP.adflowData.adjoints[objective] + else: + # Use a zero initial guess + psi = numpy.zeros_like(self.curAP.adflowData.adjoints[objective]) + + # Actually solve the adjoint system + # psi is updated with the new solution self.adflow.adjointapi.solveadjoint(RHS, psi, True) # Now set the flags and possibly reset adjoint @@ -5301,7 +5306,6 @@ def _getOptionMap(self): "viscpc": ["adjoint", "viscpc"], "frozenturbulence": ["adjoint", "frozenturbulence"], "usediagtspc": ["adjoint", "usediagtspc"], - "restartadjoint": ["adjoint", "restartadjoint"], "adjointsolver": { "gmres": "gmres", "tfqmr": "tfqmr", @@ -5369,6 +5373,7 @@ def _getSpecialOptionLists(self): "outputsurfacefamily", "cutcallback", "infchangecorrection", + "restartadjoint", "skipafterfailedadjoint", "useexternaldynamicmesh", } diff --git a/src/f2py/adflow.pyf b/src/f2py/adflow.pyf index 686023c8c..a65bb2d2b 100644 --- a/src/f2py/adflow.pyf +++ b/src/f2py/adflow.pyf @@ -1219,7 +1219,6 @@ python module libadflow logical :: viscpc logical :: frozenturbulence logical :: usediagtspc - logical :: restartadjoint logical :: setmonitor logical :: printtiming logical :: firstrun diff --git a/src/modules/inputParam.F90 b/src/modules/inputParam.F90 index 565e7398f..70b8f7b56 100644 --- a/src/modules/inputParam.F90 +++ b/src/modules/inputParam.F90 @@ -761,11 +761,9 @@ module inputADjoint ! viscPC : Whether or not to keep cross derivative terms ! in viscous preconditioner. ! FrozenTurbulence: Whether to use frozen turbulence assumption - ! restartADjoint: Whether or not we want to restart the adjoint - ! from the previous solution ! useDiagTSPC : Whether or not the off time instance terms are ! included in the TS preconditioner. - logical :: setMonitor, ApproxPC, restartADjoint, useDiagTSPC + logical :: setMonitor, ApproxPC, useDiagTSPC logical :: frozenTurbulence, viscPC, ADPC ! ADjointSolverType: Type of linear solver for the ADjoint