CMPLXFOIL API

CMPLXFOIL

class cmplxfoil.CMPLXFOIL(*args, **kwargs)[source]

CMPLXFOIL Class Initialization

Parameters:
fileNamestr

Filename of DAT file to read in

optionsdict of option-value pairs, optional

Options for the solver. Available options can be found in the Options section of the documentation or the options.yaml file in the docs directory.

debugbool, optional

Set this flag to true when debugging with a symbolic debugger. The MExt module deletes the copied .so file when not required which causes issues debugging, by default False

checkAdjointFailure(aeroProblem, funcsSens)[source]

Pass through to checkSolutionFailure to maintain the same interface as ADflow.

This checks if the primal solve fails and can be called when the sensitivity is being evaluated (either through FD or CS).

Parameters:
aeroProblempyAero_problem class

The aerodynamic problem to to get the solution for

funcsSensdict

Dictionary into which the functions are saved.

checkSolutionFailure(aeroProblem, funcs)[source]

Take in a an aeroProblem and check for failure.

Then append the fail flag in funcs. Information regarding whether or not the last analysis with the aeroProblem was sucessful is included. This information is included as “funcs[‘fail’]”. If the ‘fail’ entry already exits in the dictionary the following operation is performed:

funcs[‘fail’] = funcs[‘fail’] or <did this problem fail>

In other words, if any one problem fails, the funcs[‘fail’] entry will be True. This information can then be used directly in multiPointSparse. For direct interface with pyOptSparse the fail flag needs to be returned separately from the funcs.

Parameters:
aeroProblempyAero_problem class

The aerodynamic problem to get the solution for

funcsdict

Dictionary into which the functions are saved.

computeJacobianVectorProductFwd(xDvDot=None, xSDot=None, mode='CS', h=None)[source]

This the main Python gateway for producing forward mode jacobian vector products. They are computed using either the complex step or finite difference method. This function is not generally called by the user but rather internally or from another solver. A DVGeo object must be set for this routine.

Parameters:
xDvDotdict

Perturbation on the design variables

xSDotnumpy array

Perturbation on the surface

modestr [“FD” or “CS”]

Specifies how the jacobian vector products will be computed

hfloat

Step sized used when the mode is “FD” or “CS” (must be complex if mode = “CS”), by default 1e-6 for FD and 1e-200j for CS

Returns:
dict

Jacobian vector product of evalFuncs given perturbation

evalFunctions(aeroProblem, funcs, evalFuncs=None, ignoreMissing=False)[source]

This is the main routine for returning useful information from CMPLXFOIL. The functions corresponding to the strings in evalFuncs are evaluated and updated into the provided dictionary.

Parameters:
aeroProblemAeroProblem instance

Aero problem from which to pull evalFuncs and flight conditions.

funcsdict

Dictionary into which the functions are saved.

evalFuncsiterable object containing strings

If not none, use these functions to evaluate.

ignoreMissingbool

Flag to supress checking for a valid function. Please use this option with caution.

evalFunctionsSens(aeroProblem, funcsSens, evalFuncs=None, mode='CS', h=None)[source]

Evaluate the sensitivity of the desired functions given in iterable object, ‘evalFuncs’ and add them to the dictionary ‘funcSens’. The keys in the ‘funcsSens’ dictionary will be have an <ap.name>_ prepended to them.

Parameters:
funcsSensdict

Dictionary into which the function derivatives are saved

evalFuncsiterable object containing strings

The additional functions the user wants returned that are not already defined in the aeroProblem

modestr [“FD” or “CS”]

Specifies how the jacobian vector products will be computed

hfloat

Step sized used when the mode is “FD” or “CS” (must be complex if mode = “CS”)

getCoordinates()[source]

Return the current airfoil coordinates

Returns:
coordsndarray

Airfoil coordinates with each column being (x, y, z) where z is a dummy value.

getTriangulatedMeshSurface(offsetDist=1.0)[source]

This function returns a pyGeo surface. The intent is to use this for DVConstraints.

Note

This method requires the pyGeo library

Parameters:
offsetDistfloat

Distance to extrude airfoil (same units as airfoil coordinates)

Returns:
pyGeo surface

Extruded airfoil surface

plotAirfoil(fileName=None, showPlot=True)[source]

Plots the current airfoil and returns the figure.

Parameters:
fileNamestr, optional

FileName to save to, if none specified it will show the plot with plt.show()

showPlotbool, optional

Pop open the plot, by default True

Returns:
matplotlib figure

Figure with airfoil plotted to it

list of matplotlib axes

List of matplotlib axes for CP and airfoil plots (in that order)

setAeroProblem(aeroProblem)[source]

Sets the aeroProblem to by used by CMPLXFOIL.

Parameters:
aeroProblemAeroProblem instance

Aero problem to set (gives flight conditions)

setCoordinates(coords)[source]

Update the airfoil coordinates and associated point sets.

Parameters:
coordsndarray

New airfoil coordinates (either 2 or 3 columns)

setCoordinatesComplex(coords)[source]

Update the complex airfoil coordinates and associated point sets.

Parameters:
coordsndarray

New airfoil coordinates (either 2 or 3 columns)

setDVGeo(DVGeo, pointSetKwargs=None)[source]

Set the DVGeometry object that will manipulate ‘geometry’ in this object. Note that CMPLXFOIL does not strictly need a DVGeometry object, but if optimization with geometric changes is desired, then it is required.

Parameters:
DVGeoA DVGeometry object.

Object responsible for manipulating the constraints that this object is responsible for.

pointSetKwargsdict

Keyword arguments to be passed to the DVGeo addPointSet call. Useful for DVGeometryMulti, specifying FFD projection tolerances, etc

solveCL(aeroProblem, CLStar, alpha0=None, alphaBound=None, delta=0.5, tol=0.001, CLalphaGuess=None, maxIter=20, useNewton=False)[source]

Find the angle of attack that gives a target lift coefficient.

Parameters:
aeroProblempyAero_problem class

The aerodynamic problem to solve

CLStarfloat

The desired CL

alpha0float, optional

Initial guess for secant search (deg). If None, use the value in the aeroProblem, by default None

alphaBoundfloat, tuple, list, optional

Bounds for angle of attack, if scalar then value is treated as a +- bound, by default None, in which case limit is +/-15 deg

deltafloat, optional

Initial step direction for secant search, by default 0.5

tolfloat, optional

Desired tolerance for CL, by default 1e-3

CLalphaGuessfloat, optional

The user can provide an estimate for the lift curve slope in order to accelerate convergence. If the user supplies a value to this option, it will not use the delta value anymore to select the angle of attack of the second run. The value should be in 1/deg., by default None

maxIterint, optional

Maximum number of iterations, by default 20

useNewtonbool, optional

If True, Newton’s method will be used where the dCL/dAlpha is computed using complex-step, otherwise the secant method is used, by default False

Returns:
None, but the correct alpha is stored in the aeroProblem
writeCoordinates(fileName)[source]

Write dat file with the current coordinates.

Parameters:
fileNamestr

File name for saved dat file (“.dat” will be automatically appended).

writeSlice(fileName)[source]

Write pickle file containing the sliceData dictionary. The data can be accessed using the AeroProblem name as the key. Within that is a dictionary containing

  • Pressure coefficient data on the upper surface

    • "cp_visc_upper": viscous CP on the airfoil’s upper surface

    • "cp_invisc_upper": inviscid CP on the airfoil’s upper surface

    • "x_upper": x coordinates of the upper surface CP data

    • "y_upper": y coordinates of the upper surface CP data

  • Pressure coefficient data on the lower surface

    • "cp_visc_lower": viscous CP on the airfoil’s lower surface

    • "cp_invisc_lower": inviscid CP on the airfoil’s lower surface

    • "x_lower": x coordinates of the lower surface CP data

    • "y_lower": y coordinates of the lower surface CP data

  • Skin friction coefficient data on the upper surface

    • "cf_upper": skin friction coefficient on the upper surface

    • "x_cf_upper": x coordinates of upper surface skin friction coefficient

    • "y_cf_upper": y coordinates of upper surface skin friction coefficient

  • Skin friction coefficient data on the lower surface

    • "cf_lower": skin friction coefficient on the lower surface

    • "x_cf_lower": x coordinates of lower surface skin friction coefficient

    • "y_cf_lower": y coordinates of lower surface skin friction coefficient

Parameters:
fileNamestr

File name for saved pkl file (“.pkl” will be automatically appended).

writeSolution(outputDir=None, baseName=None, number=None)[source]

This is a generic shell function that potentially writes the various output files. The intent is that the user or calling program can call this file and CMPLXFOIL write all the files that the user has defined. It is recommended that this function is used along with the associated logical flags in the options to determine the desired writing procedure.

Parameters:
outputDirstr

Use the supplied output directory

baseNamestr

Use this supplied string for the base filename. Typically only used from an external solver.

numberint

Use the user supplied number to index solution. Again, only typically used from an external solver.

AnimateAirfoilOpt

class cmplxfoil.AnimateAirfoilOpt(dirName, APName)[source]

Class for generating animations of airfoil optimization

Initialize the object with the directory and AeroProblem name. This object assumes that the files are accessible under the name <dirName>/<APName>_<iteration number>.<dat or pkl> and that BOTH dat (airfoil shape) and pkl (chordwise data) files are available.

Parameters:
dirNamestr

Name of directory that contains the airfoil optimization data files

APNamestr

Name of the AeroProblem to be animated.

animate(outputFileName='airfoil_opt', ext='mp4', **animKwargs)[source]

Generate an animation of an optimization.

Parameters:
outputFileNamestr, optional

Movie filename to save to with no extension (default “airfoil_opt”)

extstr, optional

Extension for animation (“mp4” and “gif” are useful ones)

animKwargsoptional

Additional keyword arguments to be passed to matplotlib’s FuncAnimation save method