Public Member Functions | |
def | __init__ (self) |
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... | |
objFunc | |
Information on objective function. More... | |
designVar | |
Design variable information. More... | |
designSurfaces | |
List of patch names for the design surface. More... | |
couplingInfo | |
MDO coupling information for aerostructural, aerothermal, or aeroacoustic optimization. More... | |
aeroPropulsive | |
Aero-propulsive options. More... | |
primalOnly | |
An option to run the primal only; no adjoint or optimization will be run. 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... | |
primalVarBounds | |
The variable upper and lower bounds for primal solution. More... | |
discipline | |
The discipline name. More... | |
multiPoint | |
Whether to perform multipoint optimization. More... | |
nMultiPoints | |
If multiPoint = True, how many primal configurations for the multipoint optimization. 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... | |
objFuncAvgStart | |
At which iteration should we start the averaging of objective functions. 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... | |
rigidBodyMotion | |
Rigid body motion for dynamic mesh This option will be used in DAPimpleDyMFoam to simulate dynamicMesh motion. More... | |
runStatus | |
The run status which can be solvePrimal, solveAdjoint, or calcTotalDeriv. More... | |
printPYDAFOAMOptions | |
Whether to print all options defined in pyDAFoam to screen before optimization. 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... | |
meshSurfaceFamily | |
Default name for the mesh surface family. 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. 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... | |
runLowOrderPrimal4PC | |
whether to run the primal using the first order div scheme. More... | |
wingProp | |
Parameters for wing-propeller coupling optimizations. More... | |
primalMinIters | |
number of minimal primal iterations. More... | |
tensorflow | |
tensorflow related functions More... | |
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.
def __init__ | ( | self | ) |
Definition at line 54 of file pyDAFoam.py.
solverName |
The name of the DASolver to use for primal and adjoint computation.
See dafoam/src/adjoint/DASolver for more details Currently support:
Definition at line 71 of file pyDAFoam.py.
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 |
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 |
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.
objFunc |
Information on objective function.
Each objective function requires a different input forma But for all objectives, we need to give a name to the objective function, e.g., CD or any other preferred name, and the information for each part of the objective function. Most of the time, the objective has only one part (in this case part1), but one can also combine two parts of objectives, e.g., we can define a new objective that is the sum of force and moment. For each part, we need to define the type of objective (e.g., force, moment; we need to use the reserved type names), how to select the discrete mesh faces to compute the objective (e.g., we select them from the name of a patch patchToFace), the name of the patch (wing) for patchToFace, the scaling factor "scale", and whether to compute adjoint for this objective "addToAdjoint". For force objectives, 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 attack design variable to determine the flow direction. Here alpha will be defined in runScript.py: DVGeo.addGeoDVGlobal("alpha", [alpha0], alpha, lower=-10.0, upper=10.0, scale=1.0). NOTE: if no alpha is added in DVGeo.addGeoDVGlobal, we can NOT use parallelToFlow. For this case, we have to use "directionMode": "fixedDirection". Example "objFunc": { "CD": { "part1": { "type": "force", "source": "patchToFace", "patches": ["wing"], "directionMode": "parallelToFlow", "alphaName": "alpha", "scale": 1.0 / (0.5 * UmagIn * UmagIn * ARef), "addToAdjoint": True, } }, "CL": { "part1": { "type": "force", "source": "patchToFace", "patches": ["wing"], "directionMode": "normalToFlow", "alphaName": "alpha", "scale": 1.0 / (0.5 * UmagIn * UmagIn * ARef), "addToAdjoint": True, } }, "CMZ": { "part1": { "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), "addToAdjoint": True, } }, "TPR": { "part1": { "type": "totalPressureRatio", "source": "patchToFace", "patches": ["inlet", "outlet"], "inletPatches": ["inlet"], "outletPatches": ["outlet"], "scale": 1.0, "addToAdjoint": True, } }, "TTR": { "part1": { "type": "totalTemperatureRatio", "source": "patchToFace", "patches": ["inlet", "outlet"], "inletPatches": ["inlet"], "outletPatches": ["outlet"], "scale": 1.0, "addToAdjoint": False, } }, "MFR": { "part1": { "type": "massFlowRate", "source": "patchToFace", "patches": ["inlet"], "scale": -1.0, "addToAdjoint": True, } }, "PL": { "part1": { "type": "totalPressure", "source": "patchToFace", "patches": ["inlet"], "scale": 1.0 / (0.5 * U0 * U0), "addToAdjoint": True, }, "part2": { "type": "totalPressure", "source": "patchToFace", "patches": ["outlet"], "scale": -1.0 / (0.5 * U0 * U0), "addToAdjoint": True, } }, "NU": { "part1": { "type": "wallHeatFlux", "source": "patchToFace", "patches": ["ubend"], "scale": 1.0, "addToAdjoint": True, } }, "VMS": { "part1": { "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, "addToAdjoint": True, } }, "M": { "part1": { "type": "mass", "source": "boxToCell", "min": [-10.0, -10.0, -10.0], "max": [10.0, 10.0, 10.0], "scale": 1.0, "addToAdjoint": True, } }, "THRUST": { "part1": { "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, "addToAdjoint": True, }, }, "FI": { "part1": { "type": "stateErrorNorm", "source": "boxToCell", "min": [-100.0, -100.0, -100.0], "max": [100.0, 100.0, 100.0], "stateName": "U", "stateRefName": "UTrue", "stateType": "vector", "scale": 1.0, "addToAdjoint": True, }, "part2": { "type": "stateErrorNorm", "source": "boxToCell", "min": [-100.0, -100.0, -100.0], "max": [100.0, 100.0, 100.0], "stateName": "betaSA", "stateRefName": "betaSATrue", "stateType": "scalar", "scale": 0.01, "addToAdjoint": True, }, }, "COP": { "part1": { "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 278 of file pyDAFoam.py.
designVar |
Design variable information.
Different type of design variables require different keys For alpha, we need to prescribe 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 designVar = { "shapey" : {"designVarType": "FFD"}, "twist": {"designVarType": "FFD"}, "alpha" = { "designVarType": "AOA", "patches": ["farField"], "flowAxis": "x", "normalAxis": "y" }, "ux0" = { "designVarType": "BC", "patches": ["inlet"], "variable": "U", "comp": 0 }, }
Definition at line 301 of file pyDAFoam.py.
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 305 of file pyDAFoam.py.
couplingInfo |
MDO coupling information for aerostructural, aerothermal, or aeroacoustic optimization.
We can have ONLY one coupling scenario active, e.g., aerostructural and aerothermal can't be both active. We can have more than one couplingSurfaceGroups, e.g., wingGroup and tailGroup or blade1Group, blade2Group, and blade3Group. Each group subdict can have multiple patches. These patches should be consistent with the patch names defined in constant/polyMesh/boundary
Definition at line 312 of file pyDAFoam.py.
aeroPropulsive |
Aero-propulsive options.
Definition at line 338 of file pyDAFoam.py.
primalOnly |
An option to run the primal only; no adjoint or optimization will be run.
Definition at line 341 of file pyDAFoam.py.
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 392 of file pyDAFoam.py.
adjEqnSolMethod |
The adjoint equation solution method.
Options are: Krylov or fixedPoint
Definition at line 395 of file pyDAFoam.py.
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 402 of file pyDAFoam.py.
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 435 of file pyDAFoam.py.
multiPoint |
Whether to perform multipoint optimization.
Definition at line 438 of file pyDAFoam.py.
nMultiPoints |
If multiPoint = True, how many primal configurations for the multipoint optimization.
Definition at line 441 of file pyDAFoam.py.
adjPartDerivFDStep |
The step size for finite-difference computation of partial derivatives.
The default values will work for most of the case.
Definition at line 445 of file pyDAFoam.py.
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 457 of file pyDAFoam.py.
unsteadyAdjoint |
Options for unsteady adjoint.
mode can be hybridAdjoint or timeAccurateAdjoint Here nTimeInstances is the number of time instances and periodicity is the periodicity of flow oscillation (hybrid adjoint only)
Definition at line 462 of file pyDAFoam.py.
objFuncAvgStart |
At which iteration should we start the averaging of objective functions.
This is only used for unsteady solvers
Definition at line 466 of file pyDAFoam.py.
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 474 of file pyDAFoam.py.
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 483 of file pyDAFoam.py.
rigidBodyMotion |
Rigid body motion for dynamic mesh This option will be used in DAPimpleDyMFoam to simulate dynamicMesh motion.
Definition at line 487 of file pyDAFoam.py.
runStatus |
The run status which can be solvePrimal, solveAdjoint, or calcTotalDeriv.
This parameter is used internally, so users should never change this option in the Python layer.
Definition at line 495 of file pyDAFoam.py.
printPYDAFOAMOptions |
Whether to print all options defined in pyDAFoam to screen before optimization.
Definition at line 498 of file pyDAFoam.py.
printDAOptions |
Whether to print all DAOption defined in the C++ layer to screen before optimization.
Definition at line 501 of file pyDAFoam.py.
debug |
Whether running the optimization in the debug mode, which prints extra information.
Definition at line 504 of file pyDAFoam.py.
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 510 of file pyDAFoam.py.
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 514 of file pyDAFoam.py.
printIntervalUnsteady |
The print interval of unsteady primal solvers, e.g., for DAPisoFoam.
Definition at line 517 of file pyDAFoam.py.
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 521 of file pyDAFoam.py.
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 525 of file pyDAFoam.py.
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 530 of file pyDAFoam.py.
normalizeResiduals |
Normalization for residuals.
We should normalize all residuals!
Definition at line 552 of file pyDAFoam.py.
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 568 of file pyDAFoam.py.
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 583 of file pyDAFoam.py.
maxTractionBCIters |
The maximal iterations of tractionDisplacement boundary conditions.
Definition at line 589 of file pyDAFoam.py.
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 594 of file pyDAFoam.py.
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 603 of file pyDAFoam.py.
meshSurfaceFamily |
Default name for the mesh surface family.
Users typically don't need to change
Definition at line 606 of file pyDAFoam.py.
checkMeshThreshold |
The threshold for check mesh call.
Definition at line 609 of file pyDAFoam.py.
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 The surface sensitivity map is separated from the primal solution because they only have surface mesh. They will be saved to folders such as 1e-11, 2e-11, 3e-11, etc, When loading in paraview, you need to uncheck the "internalMesh", and check "allWalls" on the left panel If your design variable is of field type, the sensitivity map will be saved along with the primal solution because they share the same mesh. The sensitivity files read sens_objFuncName_designVarName NOTE: this function only supports useAD->mode:reverse Example: "writeSensMap" : ["shapex", "shapey"]
Definition at line 626 of file pyDAFoam.py.
writeDeformedFFDs |
Whether to write deformed FFDs to the disk during optimization.
Definition at line 629 of file pyDAFoam.py.
Referenced by PYDAFOAM.solvePrimal().
maxCorrectBCCalls |
The max number of correctBoundaryConditions calls in the updateOFField function.
Definition at line 632 of file pyDAFoam.py.
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 639 of file pyDAFoam.py.
runLowOrderPrimal4PC |
whether to run the primal using the first order div scheme.
This can be used to generate smoother flow field for computing the preconditioner matrix to avoid singularity. It can help the adjoint convergence for y+ = 1 meshes. If True, we will run the primal using low order scheme when computing or updating the PC mat. To enable this option, set "active" to True.
Definition at line 645 of file pyDAFoam.py.
wingProp |
Parameters for wing-propeller coupling optimizations.
We can add multiple propellers
Definition at line 648 of file pyDAFoam.py.
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 a negative value (always satisfied).
Definition at line 661 of file pyDAFoam.py.
tensorflow |
tensorflow related functions
Definition at line 664 of file pyDAFoam.py.