Public Member Functions | Public Attributes | List of all members
DAOPTION Class Reference
Inheritance diagram for DAOPTION:
Inheritance graph
[legend]
Collaboration diagram for DAOPTION:
Collaboration graph
[legend]

Public Member Functions

def __init__ (self)
 Example "unsteadyCompOutput": {"output1": ["function1", "function2"], "output2": ["function3"]}. More...
 

Public Attributes

 solverName
 The name of the DASolver to use for primal and adjoint computation. More...
 
 primalMinResTol
 The convergence tolerance for the primal solver. More...
 
 primalBC
 The boundary condition for primal solution. More...
 
 normalizeStates
 State normalization for dRdWT computation. More...
 
 function
 Information on objective and constraint functions. More...
 
 inputInfo
 General input information. More...
 
 outputInfo
 General input information. More...
 
 designSurfaces
 List of patch names for the design surface. More...
 
 fvSource
 Information for the finite volume source term, which will be added in the momentum equation We support multiple source terms Example "fvSource": { "disk1": { "type": "actuatorDisk", # Actuator disk source. More...
 
 adjEqnSolMethod
 The adjoint equation solution method. More...
 
 dynamicMesh
 whether the dynamic mesh is activated. More...
 
 primalVarBounds
 The variable upper and lower bounds for primal solution. More...
 
 discipline
 The discipline name. More...
 
 adjPartDerivFDStep
 The step size for finite-difference computation of partial derivatives. More...
 
 transonicPCOption
 Which options to use to improve the adjoint equation convergence of transonic conditions This is used only for transonic solvers such as DARhoSimpleCFoam. More...
 
 unsteadyAdjoint
 Options for unsteady adjoint. More...
 
 adjPCLag
 The interval of recomputing the pre-conditioner matrix dRdWTPC for solveAdjoint By default, dRdWTPC will be re-computed each time the solveAdjoint function is called However, one can increase the lag to skip it and reuse the dRdWTPC computed previously. More...
 
 useAD
 Whether to use AD: Mode options: forward, reverse, or fd. More...
 
 useConstrainHbyA
 whether to use the constrainHbyA in the pEqn. More...
 
 regressionModel
 parameters for regression models we support defining multiple regression models. More...
 
 useMeanStates
 whether to use step-averaged state variables. More...
 
 solveLinearFunctionName
 The current objective function name. More...
 
 printDAOptions
 Whether to print all DAOption defined in the C++ layer to screen before optimization. More...
 
 debug
 Whether running the optimization in the debug mode, which prints extra information. More...
 
 writeJacobians
 Whether to write Jacobian matrices to file for debugging Example: writeJacobians = ["dRdWT", "dFdW"] This will write the dRdWT and dFdW matrices to the disk. More...
 
 printInterval
 The print interval of primal and adjoint solution, e.g., how frequent to print the primal solution steps, how frequent to print the dRdWT partial derivative computation. More...
 
 printIntervalUnsteady
 The print interval of unsteady primal solvers, e.g., for DAPisoFoam. More...
 
 primalMinResTolDiff
 Users can adjust primalMinResTolDiff to tweak how much difference between primalMinResTol and the actual primal convergence is consider to be fail=True for the primal solution. More...
 
 adjUseColoring
 Whether to use graph coloring to accelerate partial derivative computation. More...
 
 adjEqnOption
 The Petsc options for solving the adjoint linear equation. More...
 
 normalizeResiduals
 Normalization for residuals. More...
 
 maxResConLv4JacPCMat
 The maximal connectivity level for the dRdWTPC matrix. More...
 
 jacLowerBounds
 The min bound for Jacobians, any value that is smaller than the bound will be set to 0 Setting a large lower bound for preconditioner (PC) can help to reduce memory. More...
 
 maxTractionBCIters
 The maximal iterations of tractionDisplacement boundary conditions. More...
 
 decomposeParDict
 decomposeParDict option. More...
 
 adjStateOrdering
 The ordering of state variable. More...
 
 checkMeshThreshold
 The threshold for check mesh call. More...
 
 writeSensMap
 The sensitivity map will be saved to disk during optimization for the given design variable names in the list. More...
 
 writeDeformedFFDs
 Whether to write deformed FFDs to the disk during optimization, i.e., DVGeo.writeTecplot. More...
 
 writeDeformedConstraints
 Whether to write deformed constraints to disk during optimization, i.e., DVCon.writeTecplot. More...
 
 writeAdjointFields
 Whether to write adjoint variables in OpenFOAM field format for post-processing. More...
 
 maxCorrectBCCalls
 The max number of correctBoundaryConditions calls in the updateOFField function. More...
 
 writeMinorIterations
 Whether to write the primal solutions for minor iterations (i.e., line search). More...
 
 primalMinIters
 number of minimal primal iterations. More...
 
 tensorflow
 tensorflow related functions More...
 
 wallDistanceMethod
 Whether to use OpenFOAMs snGrad() function or to manually compute distance for wall interfaces. More...
 
 unsteadyCompOutput
 the component output for the unsteady solvers. More...
 

Detailed Description

Define a set of options to use in PYDAFOAM and set their initial values.
This class will be used by PYDAFOAM._getDefOptions()

NOTE: Give an initial value for a new option, this help PYDAFOAM determine the type of this
option. If it is a list, give at least one default value. If it is a dict, you can leave it
blank, e.g., {}. Also, use ## to add comments before the new option such that these comments
will be  picked up by Doxygen. If possible, give examples.

NOTE: We group these options into three categories.
- The basic options are those options that will be used for EVERY solvers and EVERY cases.
- The intermediate options are options that will be used in some of solvers for special
  situation (e.g., primalVarBounds to prevent solution from divergence).
- The advanced options will be used in special situation to improve performance, e.g.,
  maxResConLv4JacPCMat to reduce memory of preconditioner. Its usage is highly case dependent.
  It may also include options that have a default value that is rarely changed, except for
  very special situation.

Definition at line 34 of file pyDAFoam.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)

Example "unsteadyCompOutput": {"output1": ["function1", "function2"], "output2": ["function3"]}.

here we have two outputs and they can be used as objective or constraints. the first output is the summation of function1 and function2, here function1 and function2 should be the function name defined in the function dict in DAOption

Definition at line 54 of file pyDAFoam.py.

Member Data Documentation

◆ solverName

solverName

The name of the DASolver to use for primal and adjoint computation.

See dafoam/src/adjoint/DASolver for more details Currently support:

  • DASimpleFoam: Incompressible steady-state flow solver for Navier-Stokes equations
  • DASimpleTFoam: Incompressible steady-state flow solver for Navier-Stokes equations with temperature
  • DAPisoFoam: Incompressible transient flow solver for Navier-Stokes equations
  • DAPimpleFoam: Incompressible transient flow solver for Navier-Stokes equations
  • DARhoSimpleFoam: Compressible steady-state flow solver for Navier-Stokes equations (subsonic)
  • DARhoSimpleCFoam: Compressible steady-state flow solver for Navier-Stokes equations (transonic)
  • DATurboFoam: Compressible steady-state flow solver for Navier-Stokes equations (turbomachinery)
  • DASolidDisplacementFoam: Steady-state structural solver for linear elastic equations

Definition at line 71 of file pyDAFoam.py.

◆ primalMinResTol

primalMinResTol

The convergence tolerance for the primal solver.

If the primal can not converge to 2 orders of magnitude (default) higher than this tolerance, the primal solution will return fail=True

Definition at line 75 of file pyDAFoam.py.

◆ primalBC

primalBC

The boundary condition for primal solution.

The keys should include "variable", "patch", and "value". For turbulence variable, one can also set "useWallFunction" [bool]. Note that setting "primalBC" will overwrite any values defined in the "0" folder. The primalBC setting will be printed to screen for each primal solution during the optimization Example "primalBC": { "U0": {"variable": "U", "patches": ["inlet"], "value": [10.0, 0.0, 0.0]}, "p0": {"variable": "p", "patches": ["outlet"], "value": [101325.0]}, "nuTilda0": {"variable": "nuTilda", "patches": ["inlet"], "value": [1.5e-4]}, "useWallFunction": True, },

Definition at line 88 of file pyDAFoam.py.

◆ normalizeStates

normalizeStates

State normalization for dRdWT computation.

Typically, we set far field value for each state variable. NOTE: If you forget to set normalization value for a state variable, the adjoint may not converge or it may be inaccurate! For "phi", use 1.0 to normalization Example normalizeStates = {"U": 10.0, "p": 101325.0, "phi": 1.0, "nuTilda": 1.e-4}

Definition at line 95 of file pyDAFoam.py.

◆ function

function

Information on objective and constraint functions.

Each function requires a different input form But for all functions, we need to give a name to the function, e.g., CD or any other preferred name. Then, define the type of function (e.g., force, moment; we need to use the reserved type names), how to select the discrete mesh faces to compute the function (e.g., we select them from the name of a patch patchToFace), the name of the patch (wing) for patchToFace, the scaling factor "scale". For forces, we need to project the force vector to a specific direction. The following example defines that CD is the force that is parallel to flow (parallelToFlow). Alternative, we can also use fixedDirection and provide a direction key for force, i.e., "directionMode": "fixedDirection", "direction": [1.0, 0.0, 0.0]. Since we select parallelToFlow, we need to prescribe the name of angle of patchVelocityInputName to determine the flow direction. NOTE: if patchVelocity not added in inputInfo, we can NOT use parallelToFlow. For this case, we have to use "directionMode": "fixedDirection". Example "function": { "CD": { "type": "force", "source": "patchToFace", "patches": ["wing"], "directionMode": "parallelToFlow", "patchVelocityInputName": "patchV", "scale": 1.0 / (0.5 * UmagIn * UmagIn * ARef), }, "CL": { "type": "force", "source": "patchToFace", "patches": ["wing"], "directionMode": "normalToFlow", "patchVelocityInputName": "patchV", "scale": 1.0 / (0.5 * UmagIn * UmagIn * ARef), }, "CMZ": { "type": "moment", "source": "patchToFace", "patches": ["wing"], "axis": [0.0, 0.0, 1.0], "center": [0.25, 0.0, 0.05], "scale": 1.0 / (0.5 * UmagIn * UmagIn * ARef * LRef), }, "TPR": { "type": "totalPressureRatio", "source": "patchToFace", "patches": ["inlet", "outlet"], "inletPatches": ["inlet"], "outletPatches": ["outlet"], "scale": 1.0, }, "TTR": { "type": "totalTemperatureRatio", "source": "patchToFace", "patches": ["inlet", "outlet"], "inletPatches": ["inlet"], "outletPatches": ["outlet"], "scale": 1.0, }, "MFR": { "part1": { "type": "massFlowRate", "source": "patchToFace", "patches": ["inlet"], "scale": -1.0, "addToAdjoint": True, } }, "TP": { "type": "totalPressure", "source": "patchToFace", "patches": ["inlet"], "scale": 1.0 / (0.5 * U0 * U0), }, "NU": { "type": "wallHeatFlux", "source": "patchToFace", "patches": ["ubend"], "scale": 1.0, }, "VMS": { "type": "vonMisesStressKS", "source": "boxToCell", "min": [-10.0, -10.0, -10.0], "max": [10.0, 10.0, 10.0], "scale": 1.0, "coeffKS": 2.0e-3, }, "M": { "type": "mass", "source": "boxToCell", "min": [-10.0, -10.0, -10.0], "max": [10.0, 10.0, 10.0], "scale": 1.0, }, "THRUST": { "type": "variableVolSum", "source": "boxToCell", "min": [-50.0, -50.0, -50.0], "max": [50.0, 50.0, 50.0], "varName": "fvSource", "varType": "vector", "component": 0, "isSquare": 0, "scale": 1.0, }, "COP": { "type": "centerOfPressure", "source": "patchToFace", "patches": ["wing"], "axis": [1.0, 0.0, 0.0], "forceAxis": [0.0, 1.0, 0.0], "center": [0, 0, 0], "scale": 1.0, "addToAdjoint": True, }, },

Definition at line 210 of file pyDAFoam.py.

◆ inputInfo

inputInfo

General input information.

Different type of inputs require different keys For patchVelocity, we need to set a list of far field patch names from which the angle of attack is computed, this is usually a far field patch. Also, we need to prescribe flow and normal axies, and alpha = atan( U_normal / U_flow ) at patches Example inputInfo = { "aero_vol_coords" : {"type": "volCoord", "addToSolver": True}, "patchV" = { "type": "patchVelocity", "patches": ["farField"], "flowAxis": "x", "normalAxis": "y", "addToSolver": True, }, "ux0" = { "type": "patchVariable", "patches": ["inlet"], "variable": "U", "comp": 0, "addToSolver": True, }, }

Definition at line 234 of file pyDAFoam.py.

◆ outputInfo

outputInfo

General input information.

Different type of outputs require different keys Example outputInfo = { "T_conduct" : {"type": "thermalVar", "patches": ["wing"]}, "f_aero": {"type": "surfForce", "patches": ["wing"]} }

Definition at line 242 of file pyDAFoam.py.

◆ designSurfaces

designSurfaces

List of patch names for the design surface.

These patch names need to be of wall type and shows up in the constant/polyMesh/boundary file

Definition at line 246 of file pyDAFoam.py.

◆ fvSource

fvSource

Information for the finite volume source term, which will be added in the momentum equation We support multiple source terms Example "fvSource": { "disk1": { "type": "actuatorDisk", # Actuator disk source.

This is a child class in DAFvSource "source": "cylinderAnnulusToCell", # Define a volume to add the fvSource term "p1": [-0.4, -0.1, 0.05], # p1 and p2 define the axis and width "p2": [-0.1, -0.1, 0.05], # p2-p1 should be streamwise "innerRadius": 0.01, "outerRadius": 0.5, "rotDir": "left", "scale": 50.0, "POD": 0.7, # pitch/diameter }, "disk2": { "type": "actuatorDisk", "source": "cylinderAnnulusToCell", "p1": [-0.4, 0.1, 0.05], "p2": [-0.1, 0.1, 0.05], "innerRadius": 0.01, "outerRadius": 0.5, "rotDir": "right", "scale": 25.0, # scale the source such the integral equals desired thrust "POD": 1.0, }, "line1": { "type": "actuatorPoint", "smoothFunction": "hyperbolic", # or gaussian "center": [-0.55, 0.0, 0.05], # center and size define a rectangular "size": [0.2, 0.2, 0.1], "amplitude": [0.0, 0.2, 0.0], "thrustDirIdx": 0, "periodicity": 0.1, "eps": 10.0, "scale": 10.0 # scale the source such the integral equals desired thrust }, "gradP" { "type": "uniformPressureGradient", "value": 1e-3, "direction": [1.0, 0.0, 0.0], }, },

Definition at line 297 of file pyDAFoam.py.

◆ adjEqnSolMethod

adjEqnSolMethod

The adjoint equation solution method.

Options are: Krylov or fixedPoint

Definition at line 300 of file pyDAFoam.py.

◆ dynamicMesh

dynamicMesh

whether the dynamic mesh is activated.

The default is False, but if we need to use DAPimpleDyMFoam, we need to set this flaf to True

Definition at line 304 of file pyDAFoam.py.

◆ primalVarBounds

primalVarBounds

The variable upper and lower bounds for primal solution.

The key is variable+"Max/Min". Setting the bounds increases the robustness of primal solution for compressible solvers. Also, we set lower bounds for turbulence variables to ensure they are physical Example primalValBounds = {"UMax": 1000, "UMin": -1000, "pMax": 1000000}

Definition at line 317 of file pyDAFoam.py.

◆ discipline

discipline

The discipline name.

The default is "aero". If we need to couple two solvers using DAFoam, e.g., aero+thermal, we need to set it to something like "thermal"

Definition at line 350 of file pyDAFoam.py.

◆ adjPartDerivFDStep

adjPartDerivFDStep

The step size for finite-difference computation of partial derivatives.

The default values will work for most of the case.

Definition at line 354 of file pyDAFoam.py.

◆ transonicPCOption

transonicPCOption

Which options to use to improve the adjoint equation convergence of transonic conditions This is used only for transonic solvers such as DARhoSimpleCFoam.

Definition at line 360 of file pyDAFoam.py.

◆ unsteadyAdjoint

unsteadyAdjoint

Options for unsteady adjoint.

mode can be hybrid or timeAccurate Here nTimeInstances is the number of time instances and periodicity is the periodicity of flow oscillation (hybrid adjoint only)

Definition at line 365 of file pyDAFoam.py.

◆ adjPCLag

adjPCLag

The interval of recomputing the pre-conditioner matrix dRdWTPC for solveAdjoint By default, dRdWTPC will be re-computed each time the solveAdjoint function is called However, one can increase the lag to skip it and reuse the dRdWTPC computed previously.

This obviously increses the speed because the dRdWTPC computation takes about 30% of the adjoint total runtime. However, setting a too large lag value will decreases the speed of solving the adjoint equations. One needs to balance these factors

Definition at line 380 of file pyDAFoam.py.

◆ useAD

useAD

Whether to use AD: Mode options: forward, reverse, or fd.

If forward mode AD is used the seedIndex will be set to compute derivative by running the whole primal solver. dvName is the name of design variable to set the seed for the forward AD setting seedIndex to -1 for dFdField will assign seeds for all design variables. If reverse mode is used, the adjoint will be computed by a Jacobian free approach refer to: Kenway et al. Effective adjoint approach for computational fluid dynamics, Progress in Aerospace Science, 2019.

Definition at line 389 of file pyDAFoam.py.

◆ useConstrainHbyA

useConstrainHbyA

whether to use the constrainHbyA in the pEqn.

The DASolvers are similar to OpenFOAM's native solvers except that we directly compute the HbyA term without any constraints. In other words, we comment out the constrainHbyA line in the pEqn. However, some cases may diverge without the constrainHbyA, e.g., the MRF cases with the SST model. Here we have an option to add the constrainHbyA back to the primal and adjoint solvers.

Definition at line 396 of file pyDAFoam.py.

◆ regressionModel

regressionModel

parameters for regression models we support defining multiple regression models.

Each regression model can have only one output but it can have multiple input features. Refer to src/adjoint/DARegression/DARegression.C for a full list of supported input features. There are two supported regression model types: neural network and radial basis function. We can shift and scale the inputs and outputs we can also prescribe a default output value. The default output will be used in resetting when they are nan, inf, or out of the prescribe upper and lower bounds

Definition at line 405 of file pyDAFoam.py.

◆ useMeanStates

useMeanStates

whether to use step-averaged state variables.

This can be useful when the primal solution exhibits LCO. To make this work, users need to setup function-fieldAverage in system/controlDict for all state variables

Definition at line 441 of file pyDAFoam.py.

◆ solveLinearFunctionName

solveLinearFunctionName

The current objective function name.

This variable will be reset in DAFoamFunctions Then, we know which objective function is used in solve_linear in DAFoamSolver

Definition at line 449 of file pyDAFoam.py.

◆ printDAOptions

printDAOptions

Whether to print all DAOption defined in the C++ layer to screen before optimization.

Definition at line 452 of file pyDAFoam.py.

◆ debug

debug

Whether running the optimization in the debug mode, which prints extra information.

Definition at line 455 of file pyDAFoam.py.

◆ writeJacobians

writeJacobians

Whether to write Jacobian matrices to file for debugging Example: writeJacobians = ["dRdWT", "dFdW"] This will write the dRdWT and dFdW matrices to the disk.

Definition at line 461 of file pyDAFoam.py.

◆ printInterval

printInterval

The print interval of primal and adjoint solution, e.g., how frequent to print the primal solution steps, how frequent to print the dRdWT partial derivative computation.

Definition at line 465 of file pyDAFoam.py.

◆ printIntervalUnsteady

printIntervalUnsteady

The print interval of unsteady primal solvers, e.g., for DAPisoFoam.

Definition at line 468 of file pyDAFoam.py.

◆ primalMinResTolDiff

primalMinResTolDiff

Users can adjust primalMinResTolDiff to tweak how much difference between primalMinResTol and the actual primal convergence is consider to be fail=True for the primal solution.

Definition at line 472 of file pyDAFoam.py.

◆ adjUseColoring

adjUseColoring

Whether to use graph coloring to accelerate partial derivative computation.

Unless you are debugging the accuracy of partial computation, always set it to True

Definition at line 476 of file pyDAFoam.py.

◆ adjEqnOption

adjEqnOption

The Petsc options for solving the adjoint linear equation.

These options should work for most of the case. If the adjoint does not converge, try to increase pcFillLevel to 2, or try "jacMatReOrdering": "nd"

Definition at line 481 of file pyDAFoam.py.

◆ normalizeResiduals

normalizeResiduals

Normalization for residuals.

We should normalize all residuals!

Definition at line 503 of file pyDAFoam.py.

◆ maxResConLv4JacPCMat

maxResConLv4JacPCMat

The maximal connectivity level for the dRdWTPC matrix.

Reducing the connectivity level reduce the memory usage, however, it may slow down the adjoint equation convergence. The default value should have the best convergence speed but not optimal memory usage.

Definition at line 519 of file pyDAFoam.py.

◆ jacLowerBounds

jacLowerBounds

The min bound for Jacobians, any value that is smaller than the bound will be set to 0 Setting a large lower bound for preconditioner (PC) can help to reduce memory.

Definition at line 536 of file pyDAFoam.py.

◆ maxTractionBCIters

maxTractionBCIters

The maximal iterations of tractionDisplacement boundary conditions.

Definition at line 542 of file pyDAFoam.py.

◆ decomposeParDict

decomposeParDict

decomposeParDict option.

This file will be automatically written such that users can run optimization with any number of CPU cores without the need to manually change decomposeParDict

Definition at line 547 of file pyDAFoam.py.

◆ adjStateOrdering

adjStateOrdering

The ordering of state variable.

Options are: state or cell. Most of the case, the state odering is the best choice.

Definition at line 557 of file pyDAFoam.py.

◆ checkMeshThreshold

checkMeshThreshold

The threshold for check mesh call.

Definition at line 560 of file pyDAFoam.py.

◆ writeSensMap

writeSensMap

The sensitivity map will be saved to disk during optimization for the given design variable names in the list.

Currently only support design variable type FFD and Field NOTE: this function only supports useAD->mode:reverse Example: "writeSensMap" : ["shapex", "shapey"]

Definition at line 572 of file pyDAFoam.py.

◆ writeDeformedFFDs

writeDeformedFFDs

Whether to write deformed FFDs to the disk during optimization, i.e., DVGeo.writeTecplot.

Definition at line 575 of file pyDAFoam.py.

◆ writeDeformedConstraints

writeDeformedConstraints

Whether to write deformed constraints to disk during optimization, i.e., DVCon.writeTecplot.

Definition at line 578 of file pyDAFoam.py.

◆ writeAdjointFields

writeAdjointFields

Whether to write adjoint variables in OpenFOAM field format for post-processing.

Definition at line 581 of file pyDAFoam.py.

◆ maxCorrectBCCalls

maxCorrectBCCalls

The max number of correctBoundaryConditions calls in the updateOFField function.

Definition at line 584 of file pyDAFoam.py.

◆ writeMinorIterations

writeMinorIterations

Whether to write the primal solutions for minor iterations (i.e., line search).

The default is False. If set it to True, it will write flow fields (and the deformed geometry) for each primal solution. This will significantly increases the IO runtime, so it should never be True for production runs. However, it is useful for debugging purpose (e.g., to find out the poor quality mesh during line search)

Definition at line 591 of file pyDAFoam.py.

◆ primalMinIters

primalMinIters

number of minimal primal iterations.

The primal has to run this many iterations, even the primal residual has reduced below the tolerance. The default is 1: the primal has to run for at least one iteration

Definition at line 595 of file pyDAFoam.py.

◆ tensorflow

tensorflow

tensorflow related functions

Definition at line 598 of file pyDAFoam.py.

◆ wallDistanceMethod

wallDistanceMethod

Whether to use OpenFOAMs snGrad() function or to manually compute distance for wall interfaces.

Definition at line 606 of file pyDAFoam.py.

◆ unsteadyCompOutput

unsteadyCompOutput

the component output for the unsteady solvers.

This will be used in mphys_dafoam's DAFoamBuilderUnsteady to determine the component's output

Definition at line 610 of file pyDAFoam.py.


The documentation for this class was generated from the following file: