Skip to content

Commit

Permalink
Added option to toggle convergence printout (#30)
Browse files Browse the repository at this point in the history
* added option to toggle convergence printout

* added docs

* turn off print outs in tests

* fixed complex conv print

* updated real conv print for consistency

* added option to print complex convergence

* added more imaginary units

* Bump patch version so we get a new conda release

---------

Co-authored-by: Eytan Adler <[email protected]>
  • Loading branch information
sseraj and eytanadler authored Aug 13, 2024
1 parent 3ea3b9b commit 9272199
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 54 deletions.
4 changes: 4 additions & 0 deletions cmplxfoil/CMPLXFOIL.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,13 @@ def __call__(self, aeroProblem, useComplex=False, deriv=False):
xfoil = self.xfoil_cs
funcs = self.funcsComplex
sliceData = self.sliceDataComplex
xfoil.cl01.printconv = self.getOption("printComplexConvergence")
else:
dtype = float
xfoil = self.xfoil
funcs = self.funcs
sliceData = self.sliceData
xfoil.cl01.printconv = self.getOption("printRealConvergence")

self.setAeroProblem(aeroProblem)

Expand Down Expand Up @@ -1068,6 +1070,8 @@ def _setCoordinates(self, x, y, setComplex=False):
def _getDefaultOptions():
return {
"maxIters": [int, 100], # maximum iterations for XFOIL solver
"printRealConvergence": [bool, True],
"printComplexConvergence": [bool, False],
"writeCoordinates": [bool, True], # whether to write coordinates to .dat file when `writeSolution` called
"writeSliceFile": [bool, True], # whether or not to save chordwise data
"writeSolution": [bool, False], # whether or not to call writeSolution after each call to XFOIL
Expand Down
2 changes: 1 addition & 1 deletion cmplxfoil/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.1.0"
__version__ = "2.1.1"

from .CMPLXFOIL import CMPLXFOIL

Expand Down
6 changes: 6 additions & 0 deletions doc/options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ maxIters:
desc: >
The maximum iterations for XFOIL solver.
By default 100.
printRealConvergence:
desc: >
Whether or not to print out the convergence history in real mode.
printComplexConvergence:
desc: >
Whether or not to print out the convergence history in complex mode.
numberSolutions:
desc: >
If True, will add call counter to output file names.
Expand Down
4 changes: 2 additions & 2 deletions src/XFOIL.INC
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
& LCPGRD,LBLGRD, LBLSYM, LCMINP, LHMOMP
LOGICAL LPLOT,LSYM,LIQSET,LCLIP,LVLAB,LCURS,LLAND
LOGICAL LPGRID, LPCDW, LPLIST, LPLEGN
LOGICAL TFORCE, LEXITFLAG
LOGICAL TFORCE, LEXITFLAG, PRINTCONV
REAL NX, NY, MASS, MINF1, MINF, MINF_CL, MVISC, MACHP1
INTEGER RETYP, MATYP, AIJPIV
CHARACTER*1 VMXBL
Expand Down Expand Up @@ -101,7 +101,7 @@
& LCPGRD,LBLGRD,LBLSYM,
& LPLOT,LSYM,LIQSET,LCLIP,LVLAB,LCURS,LLAND,
& LPGRID,LPCDW,LPLIST,LPLEGN,
& LCMINP, LHMOMP, LEXITFLAG
& LCMINP, LHMOMP, LEXITFLAG, PRINTCONV
COMMON/CR14/ XB(IBX),YB(IBX),
& XBP(IBX),YBP(IBX),SB(IBX),SNEW(4*IBX),
& XBF,YBF,XOF,YOF,HMOM,HFX,HFY,
Expand Down
2 changes: 1 addition & 1 deletion src/f2py/libcmplxfoil.pyf
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ python module libcmplxfoil ! in
real*8 dimension(3,2,322) :: vdel
real*8 dimension(3,322,322) :: vm
real*8 dimension(3,2) :: vz
common /cl01/ ok,limage,sharp,lgamu,lqinu,lvisc,lalfa,lwake,lpacc,lblini,lipan,lqaij,ladij,lwdij,lcpxx,lqvdes,lqrefl,lqspec,lvconv,lcpref,lclock,lpfile,lpfilx,lppsho,lbflap,lflap,leiw,lscini,lforef,lnorm,lgsame,lplcam,lqsym,lgsym,lqgrid,lggrid,lgtick,lqslop,lgslop,lcslop,lqsppl,lgeopl,lgparm,lcpgrd,lblgrd,lblsym,lplot,lsym,liqset,lclip,lvlab,lcurs,lland,lpgrid,lpcdw,lplist,lplegn,lcminp,lhmomp,lexitflag
common /cl01/ ok,limage,sharp,lgamu,lqinu,lvisc,lalfa,lwake,lpacc,lblini,lipan,lqaij,ladij,lwdij,lcpxx,lqvdes,lqrefl,lqspec,lvconv,lcpref,lclock,lpfile,lpfilx,lppsho,lbflap,lflap,leiw,lscini,lforef,lnorm,lgsame,lplcam,lqsym,lgsym,lqgrid,lggrid,lgtick,lqslop,lgslop,lcslop,lqsppl,lgeopl,lgparm,lcpgrd,lblgrd,lblsym,lplot,lsym,liqset,lclip,lvlab,lcurs,lland,lpgrid,lpcdw,lplist,lplegn,lcminp,lhmomp,lexitflag,printconv
common /cl02/ tforce
common /cr07/ ssple,sspec,xspoc,yspoc,qgamm,qspec,qspecp,algam,clgam,cmgam,alqsp,clqsp,cmqsp,qf0,qf1,qf2,qf3,qdof0,qdof1,qdof2,qdof3,clspec,ffilt
common /cr06/ gam,gamu,gam_a,sig,nx,ny,apanel,sst,sst_go,sst_gp,gamte,gamte_a,sigte,sigte_a,dste,ante,aste
Expand Down
25 changes: 14 additions & 11 deletions src/xoper.f
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,14 @@ SUBROUTINE VISCAL(NITER1)
CALL CDCALC
C
C------ display changes and test for convergence
IF(RLX.LT.1.0)
& WRITE(*,2000) ITER, RMSBL, RMXBL, VMXBL,IMXBL,ISMXBL,RLX
IF(RLX.EQ.1.0)
& WRITE(*,2010) ITER, RMSBL, RMXBL, VMXBL,IMXBL,ISMXBL
CDP = CD - CDF
WRITE(*,2020) ALFA/DTOR, CL, CM, CD, CDF, CDP
IF (PRINTCONV) THEN
IF(RLX.LT.1.0)
& WRITE(*,2000) ITER, RMSBL, RMXBL, VMXBL,IMXBL,ISMXBL,RLX
IF(RLX.EQ.1.0)
& WRITE(*,2010) ITER, RMSBL, RMXBL, VMXBL,IMXBL,ISMXBL
CDP = CD - CDF
WRITE(*,2020) ALFA/DTOR, CL, CM, CD, CDF, CDP
ENDIF
C
IF(RMSBL .LT. EPS1) THEN
LVCONV = .TRUE.
Expand All @@ -942,13 +944,14 @@ SUBROUTINE VISCAL(NITER1)
RETURN
C....................................................................
2000 FORMAT
& (/1X,I3,' rms: ',E10.4,' max: ',E10.4,3X,A1,' at ',I4,I3,
& ' RLX:',F6.3)
& (/1X,I3,' rms: ',ES10.4E2,' max: ',ES11.4E2,
& 3X,A1,' at ',I4,I3, ' RLX:',F6.3)
2010 FORMAT
& (/1X,I3,' rms: ',E10.4,' max: ',E10.4,3X,A1,' at ',I4,I3)
& (/1X,I3,' rms: ',ES10.4E2,' max: ',ES11.4E2,
& 3X,A1,' at ',I4,I3)
2020 FORMAT
& ( 1X,3X,' a =', F7.3,' CL =',F8.4 /
& 1X,3X,' Cm =', F8.4, ' CD =',F9.5,
& ( 1X,3X,' a =', F9.5,' CL =',F9.5 /
& 1X,3X,' Cm =', F9.5,' CD =',F9.5,
& ' => CDf =',F9.5,' CDp =',F9.5)
END ! VISCAL

Expand Down
4 changes: 2 additions & 2 deletions src_cs/c_XFOIL.INC
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ C PARAMETER (IVX=IQX/2 + IWX + 50)
& LCPGRD,LBLGRD, LBLSYM, LCMINP, LHMOMP
LOGICAL LPLOT,LSYM,LIQSET,LCLIP,LVLAB,LCURS,LLAND
LOGICAL LPGRID, LPCDW, LPLIST, LPLEGN
LOGICAL TFORCE, LEXITFLAG
LOGICAL TFORCE, LEXITFLAG, PRINTCONV
complex NX, NY, MASS, MINF1, MINF, MINF_CL, MVISC, MACHP1
INTEGER RETYP, MATYP, AIJPIV
CHARACTER*1 VMXBL
Expand Down Expand Up @@ -139,7 +139,7 @@ C
& LCPGRD,LBLGRD,LBLSYM,
& LPLOT,LSYM,LIQSET,LCLIP,LVLAB,LCURS,LLAND,
& LPGRID,LPCDW,LPLIST,LPLEGN,
& LCMINP, LHMOMP, LEXITFLAG
& LCMINP, LHMOMP, LEXITFLAG, PRINTCONV
COMMON/CR14/ XB(IBX),YB(IBX),
& XBP(IBX),YBP(IBX),SB(IBX),SNEW(4*IBX),
& XBF,YBF,XOF,YOF,HMOM,HFX,HFY,
Expand Down
37 changes: 21 additions & 16 deletions src_cs/c_xoper.f
Original file line number Diff line number Diff line change
Expand Up @@ -949,16 +949,15 @@ SUBROUTINE VISCAL(NITER1)
CALL CDCALC
C
C------ display changes and test for convergence
c IF(RLX.LT.1.0)
c & WRITE(*,2000) ITER, real(RMSBL), real(RMXBL),VMXBL,
c & real(IMXBL),real(ISMXBL),real(RLX)
c IF(RLX.CEQ.1.0)
c & WRITE(*,2010)ITER, real(RMSBL), real(RMXBL), VMXBL,
c & real(IMXBL),real(ISMXBL),real(RLX)
c CDP = CD - CDF
c WRITE(*,2020) real(ALFA/DTOR), real(CL), real(CM), real(CD),
c & real(CDF), real(CDP)
C
IF (PRINTCONV) THEN
IF(RLX.LT.1.0)
& WRITE(*,2000) ITER, RMSBL, RMXBL, VMXBL,IMXBL,ISMXBL,RLX
IF(RLX.EQ.1.0)
& WRITE(*,2010) ITER, RMSBL, RMXBL, VMXBL,IMXBL,ISMXBL
CDP = CD - CDF
WRITE(*,2020) ALFA/DTOR, CL, CM, CD, CDF, CDP
ENDIF

IF(RMSBL .LT. EPS1) THEN
LVCONV = .TRUE.
AVISC = ALFA
Expand All @@ -976,14 +975,20 @@ SUBROUTINE VISCAL(NITER1)
RETURN
C....................................................................
2000 FORMAT
& (/1X,I3,' rms: ',E10.4,' max: ',E10.4,3X,A1,' at ',I4,I3,
& ' RLX:',F6.3)
& (/1X,I3,' rms: ',SS,ES10.4E2,1X,SP,
& ES12.4E3,'i max: ',SS,ES11.4E2,1X,SP,ES12.4E3'i ',3X,
& A1,' at 'SS,I4,I3, ' RLX:',SS,F6.3,1X,SP,ES12.4E3)
2010 FORMAT
& (/1X,I3,' rms: ',E10.4,' max: ',E10.4,3X,A1,' at ',I4,I3)
& (/1X,I3,' rms: ',SS,ES10.4E2,1X,SP,
& ES12.4E3,'i max: ',SS,ES11.4E2,1X,SP,ES12.4E3'i ',3X,
& A1,' at 'SS,I4,I3)
2020 FORMAT
& ( 1X,3X,' a =', F7.3,' CL =',F8.4 /
& 1X,3X,' Cm =', F8.4, ' CD =',F9.5,
& ' => CDf =',F9.5,' CDp =',F9.5)
& ( 1X,3X,' a =',SS,F9.5,1X,SP,
& ES12.4E3,'i CL ='SS,F9.5,1X,SP,ES12.4E3'i ' /
& 1X,3X,' Cm =', F9.5,1X,SP,
& ES12.4E3,'i CD =',SS,F9.5,1X,SP,
& ES12.4E3,'i => CDf =',SS,F9.5,1X,SP,
& ES12.4E3,'i CDp =',SS,F9.5,1X,SP,ES12.4E3,'i')
END ! VISCAL


Expand Down
2 changes: 1 addition & 1 deletion src_cs/f2py/libcmplxfoil_cs.pyf
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ python module libcmplxfoil_cs ! in
double complex dimension(3,2,322) :: vdel
double complex dimension(3,322,322) :: vm
double complex dimension(3,2) :: vz
common /cl01/ ok,limage,sharp,lgamu,lqinu,lvisc,lalfa,lwake,lpacc,lblini,lipan,lqaij,ladij,lwdij,lcpxx,lqvdes,lqrefl,lqspec,lvconv,lcpref,lclock,lpfile,lpfilx,lppsho,lbflap,lflap,leiw,lscini,lforef,lnorm,lgsame,lplcam,lqsym,lgsym,lqgrid,lggrid,lgtick,lqslop,lgslop,lcslop,lqsppl,lgeopl,lgparm,lcpgrd,lblgrd,lblsym,lplot,lsym,liqset,lclip,lvlab,lcurs,lland,lpgrid,lpcdw,lplist,lplegn,lcminp,lhmomp,lexitflag
common /cl01/ ok,limage,sharp,lgamu,lqinu,lvisc,lalfa,lwake,lpacc,lblini,lipan,lqaij,ladij,lwdij,lcpxx,lqvdes,lqrefl,lqspec,lvconv,lcpref,lclock,lpfile,lpfilx,lppsho,lbflap,lflap,leiw,lscini,lforef,lnorm,lgsame,lplcam,lqsym,lgsym,lqgrid,lggrid,lgtick,lqslop,lgslop,lcslop,lqsppl,lgeopl,lgparm,lcpgrd,lblgrd,lblsym,lplot,lsym,liqset,lclip,lvlab,lcurs,lland,lpgrid,lpcdw,lplist,lplegn,lcminp,lhmomp,lexitflag,printconv
common /cl02/ tforce
common /cr07/ ssple,sspec,xspoc,yspoc,qgamm,qspec,qspecp,algam,clgam,cmgam,alqsp,clqsp,cmqsp,qf0,qf1,qf2,qf3,qdof0,qdof1,qdof2,qdof3,clspec,ffilt
common /cr06/ gam,gamu,gam_a,sig,nx,ny,apanel,sst,sst_go,sst_gp,gamte,gamte_a,sigte,sigte_a,dste,ante,aste
Expand Down
40 changes: 20 additions & 20 deletions tests/test_solver_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUp(self):
self.ap = AeroProblem(
name="fc", alpha=3, mach=0.2, altitude=1e3, areaRef=1.0, chordRef=1.0, evalFuncs=["cl", "cd", "cm"]
)
self.CFDSolver = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"))
self.CFDSolver = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"), options={"printRealConvergence": False})
self.alphaSequence = np.linspace(-0.5, 0.5, 11)
self.rng.shuffle(self.alphaSequence)

Expand Down Expand Up @@ -90,20 +90,21 @@ def test_function_values(self):


class TestTransition(unittest.TestCase):
def setUp(self):
self.evalFuncs = ["cl", "cd", "cm"]
self.ap = AeroProblem(
name="fc", alpha=3, mach=0.2, altitude=1e3, areaRef=1.0, chordRef=1.0, evalFuncs=self.evalFuncs
)
self.cmplxfoilOptions = {"printRealConvergence": False}
self.CFDSolver = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"), options=self.cmplxfoilOptions)

def test_trip(self):
"""
Test that setting the trip changes the result.
"""
# Set the random range to use consistent random numbers
self.rng = np.random.default_rng(7)
evalFuncs = ["cl", "cd", "cm"]
self.ap = AeroProblem(
name="fc", alpha=3, mach=0.2, altitude=1e3, areaRef=1.0, chordRef=1.0, evalFuncs=evalFuncs
)
self.CFDSolver = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"))
self.CFDSolverTripped = CMPLXFOIL(
os.path.join(baseDir, "naca0012.dat"), options={"xTrip": np.array([0.1, 0.1])}
)

self.cmplxfoilOptions.update({"xTrip": np.array([0.1, 0.1])})
self.CFDSolverTripped = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"), options=self.cmplxfoilOptions)

funcs = {}
self.CFDSolver(self.ap)
Expand All @@ -113,19 +114,16 @@ def test_trip(self):
self.CFDSolverTripped(self.ap)
self.CFDSolverTripped.evalFunctions(self.ap, funcsTripped)

for func in evalFuncs:
for func in self.evalFuncs:
self.assertNotEqual(funcs["fc_" + func], funcsTripped["fc_" + func])

def test_nCrit(self):
"""
Test that setting nCrit changes the result.
"""
evalFuncs = ["cl", "cd", "cm"]
self.ap = AeroProblem(
name="fc", alpha=3, mach=0.2, altitude=1e3, areaRef=1.0, chordRef=1.0, evalFuncs=evalFuncs
)
self.CFDSolver = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"))
self.CFDSolverNCrit = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"), options={"nCrit": 5.0})

self.cmplxfoilOptions.update({"nCrit": 5.0})
self.CFDSolverNCrit = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"), options=self.cmplxfoilOptions)

funcs = {}
self.CFDSolver(self.ap)
Expand All @@ -135,7 +133,7 @@ def test_nCrit(self):
self.CFDSolverNCrit(self.ap)
self.CFDSolverNCrit.evalFunctions(self.ap, funcsNCrit)

for func in evalFuncs:
for func in self.evalFuncs:
self.assertNotEqual(funcs["fc_" + func], funcsNCrit["fc_" + func])


Expand All @@ -152,6 +150,7 @@ def setUp(self):

# Add CMPLXFOIL solver
cmplxfoilOptions = {
"printRealConvergence": False,
"writeCoordinates": False,
"plotAirfoil": False,
"writeSolution": False,
Expand Down Expand Up @@ -288,6 +287,7 @@ def setUp(self):

# Add CMPLXFOIL solver
cmplxfoilOptions = {
"printRealConvergence": False,
"writeCoordinates": False,
"plotAirfoil": False,
"writeSolution": False,
Expand Down Expand Up @@ -439,7 +439,7 @@ def test_plotting(self):
self.ap = AeroProblem(
name="fc", alpha=3, mach=0.2, altitude=1e3, areaRef=1.0, chordRef=1.0, evalFuncs=["cl", "cd", "cm"]
)
self.CFDSolver = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"))
self.CFDSolver = CMPLXFOIL(os.path.join(baseDir, "naca0012.dat"), options={"printRealConvergence": False})

# Run an initial case and plot it
self.CFDSolver(self.ap)
Expand Down

0 comments on commit 9272199

Please sign in to comment.