This little notebook compares viiflow and XFOIL runtimes for different panel densities of the S805 airfoil. It is not 100% fair, because

  • XFOIL does plot some things in the background and because XFOIL has to write some things into a text file. But that cost should stay quite the same with increasing panel densities and therefore seems negligible.
  • viiflow uses numpys solve call for the coupling Newton step which might use processor features unused in XFOIL (i.e. SIMD instructions).
  • the airfoil tested, the Selig S805, is the one I use during debugging, which may suggest that for different airfoils, the convergence rate of viiflow may be lower and the runtime higher. Failing an angle of attack means iterating the maximum number of iterations for both methods.

Note: These results were generated with a PC with a AMD Ryzen 3700 processor on a windows 10 64bit OS with numpy built with Intel MKL and the xfoil 6.99 binary version.

In [1]:
import os # For calling xfoil

'''
Numpy (with MKL in this case) might want to use multiple threads to do linalg.solve. 
Solving 150x150->500x500 matrices with multiple cores it not super efficient,  
especially if your processor uses a higher clock if only one core is used.
And even if it would be faster with multiple cores, it would not be fair to compare
these results with single-core using XFOIL.
'''
#os.environ["OMP_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"
# viiflow imports
import viiflow as vf
import viiflowtools.vf_tools as vft
import numpy as np

import time # For timing

# For plotting at the end
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
import matplotlib
In [2]:
NVEC = np.arange(100,500,10) # Panel densities to compare

# AOA Sweep
AOA0 = -5
AOAE = 16
DAOA = .5

RE = 1e6 # Reynolds Number
maxiter = 50 # maximum iterations for both methods
FOIL = "S805b.dat"

# Container for results
elapsedXF=[]
elapsedVF=[]

for N in NVEC:
    
    ## Build correct file with N panels by XFOIL, compare both solvers with this file
    # Make XFOIL command
    com = "load %s\nPPAR\nN %u\n\n\nsave tmpfoil.dat\ny\n"%(FOIL,N)
    # Save Xfoil Command
    with open('xfcom.inp', 'w') as f:
        print(com,file=f)
        f.close()
    # Run XFOIL
    os.system("xfoil < xfcom.inp > xf.out")
    
    
    ## XFOIL
    # Make XFOIL command
    com = "load %s\nOPER\nv %u\nITER %u\nASEQ %f %f %f\n\nquit\n"%('tmpfoil.dat',RE,maxiter,AOA0,AOAE,DAOA)
    #com = "load %s\nOPER\nv %u\nITER %u\nASEQ %f %f %f\n\nquit\n"%('tmpfoil.dat',RE,maxiter,AOA0,AOA0,DAOA)
    # Save Xfoil Command
    with open('xfcom.inp', 'w') as f:
        print(com,file=f)
        f.close()
    # Run XFOIL
    t = time.time()
    os.system("xfoil < xfcom.inp > xf.out")
    elapsedXF.append(time.time() - t)
    
    # Check for convergence
    f = open("xf.out", "r")
    lines = f.readlines()
    f.close()
    xf_unconverged=0
    for line in lines:
        if line.startswith(" VISCAL:  Convergence failed"):
            xf_unconverged+=1
    
    
    ## viiflow
    s = vf.setup(Re=RE,Ma=0.0,Ncrit=9.0,Alpha=AOA0)
    s.Silent = True # Do not output residual/iterations internally
    s.Itermax = maxiter

    t = time.time()
    # Set-up and initialize based on inviscid panel solution
    # This calculates panel operator
    [p,bl,x] = vf.init(vft.read_selig('tmpfoil.dat'),s)
    #vf.set_forced_transition(bl,p,[0.5],[0.5])
    
    vf_unconverged = 0
    for alpha in np.arange(AOA0,AOAE+DAOA,DAOA):
    
        # Set current alpha and set res/grad to None to tell viiflow that they are not valid
        s.Alpha = alpha
        res = None
        grad = None

        # Run viiflow
        [x,flag,res,_,_] = vf.iter(x,bl,p,s,res,grad)

        # Print if not converged
        if flag<=0:
            #print('Not converged at AL: %f' % alpha)
            vf_unconverged+=1

    elapsedVF.append(time.time() - t)
    time.sleep(.1) 
    
    # Print comparison
    print("N: %u XF: %5.5ss (%u failed) VF:%5.5ss (%u failed)"%(N,elapsedXF[-1],xf_unconverged,elapsedVF[-1],vf_unconverged))
    
    
N: 100 XF: 0.656s (1 failed) VF:0.678s (0 failed)
WARNING:ibl.ibl_classes:solve_delta: laminar bl solve failed (Iterations exceeded) at iter=249
 xi=0.106134,delta=0.000350,theta=0.000158,ue=1.803983,n/ct=8.465907
N: 110 XF: 0.779s (1 failed) VF:0.775s (0 failed)
N: 120 XF: 0.962s (2 failed) VF:0.809s (0 failed)
N: 130 XF: 1.297s (3 failed) VF:0.880s (0 failed)
N: 140 XF: 1.054s (0 failed) VF:0.934s (0 failed)
N: 150 XF: 1.463s (2 failed) VF:1.074s (0 failed)
N: 160 XF: 1.413s (0 failed) VF:1.178s (0 failed)
N: 170 XF: 1.847s (1 failed) VF:1.263s (0 failed)
N: 180 XF: 1.852s (0 failed) VF:1.319s (0 failed)
N: 190 XF: 2.317s (1 failed) VF:1.434s (0 failed)
N: 200 XF: 3.179s (2 failed) VF:1.562s (0 failed)
N: 210 XF: 3.110s (1 failed) VF:1.638s (0 failed)
N: 220 XF: 3.443s (1 failed) VF:1.801s (0 failed)
N: 230 XF: 4.613s (2 failed) VF:1.956s (0 failed)
N: 240 XF: 3.801s (0 failed) VF:2.009s (0 failed)
N: 250 XF: 4.740s (1 failed) VF:2.208s (0 failed)
N: 260 XF: 6.079s (2 failed) VF:2.375s (0 failed)
N: 270 XF: 5.016s (0 failed) VF:2.593s (0 failed)
N: 280 XF: 5.844s (0 failed) VF:2.673s (0 failed)
N: 290 XF: 7.922s (2 failed) VF:2.842s (0 failed)
N: 300 XF: 8.807s (2 failed) VF:3.009s (0 failed)
N: 310 XF: 7.811s (0 failed) VF:3.409s (0 failed)
N: 320 XF: 8.236s (0 failed) VF:3.575s (0 failed)
N: 330 XF: 10.08s (1 failed) VF:4.161s (0 failed)
N: 340 XF: 10.89s (1 failed) VF:4.463s (0 failed)
N: 350 XF: 12.99s (2 failed) VF:4.506s (0 failed)
N: 360 XF: 12.82s (1 failed) VF:4.620s (0 failed)
N: 370 XF: 15.36s (2 failed) VF:4.710s (0 failed)
N: 380 XF: 15.44s (1 failed) VF:5.055s (0 failed)
N: 390 XF: 13.28s (0 failed) VF:5.504s (0 failed)
N: 400 XF: 18.72s (1 failed) VF:5.739s (0 failed)
N: 410 XF: 18.83s (1 failed) VF:6.048s (0 failed)
N: 420 XF: 17.82s (0 failed) VF:6.278s (0 failed)
N: 430 XF: 17.14s (0 failed) VF:6.573s (0 failed)
N: 440 XF: 19.29s (0 failed) VF:7.026s (0 failed)
N: 450 XF: 21.69s (1 failed) VF:7.396s (0 failed)
N: 460 XF: 20.77s (0 failed) VF:7.598s (0 failed)
N: 470 XF: 21.68s (0 failed) VF:8.065s (0 failed)
N: 480 XF: 42.65s (5 failed) VF:8.103s (0 failed)
N: 490 XF: 37.24s (3 failed) VF:8.489s (0 failed)
In [3]:
matplotlib.rcParams['figure.figsize'] = [11, 6] # Make plots bigger than default
n = len(elapsedVF)
plt.plot(NVEC[0:n],elapsedVF,'-o')
plt.plot(NVEC[0:n],elapsedXF,'-o')
plt.legend(["viiflow","xfoil"])
plt.xlabel("Panels")
plt.ylabel("Runtime [s]")
plt.grid(1)
plt.ylim([0,30])
plt.xlim([90,500]);
2022-06-26T20:18:48.789436 image/svg+xml Matplotlib v3.3.3, https://matplotlib.org/

The runtime difference increases with increasing panel density. This is to be expected. XFOIL needs to solve a system of 3xNP linear equations at every Newton step, while viiflow only needs to solve a 1xNP system.