Skip to content

Commit

Permalink
Merge pull request #32 from mdolab/main
Browse files Browse the repository at this point in the history
pull main
  • Loading branch information
DavidAnderegg committed Mar 6, 2024
2 parents a784190 + de01140 commit 156b582
Show file tree
Hide file tree
Showing 46 changed files with 5,119 additions and 3,104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ doc/tmp*.rst
*.bak
src/build/adflow_project.dep
src/build/libadflow-f2pywrappers2.f90
src/build/libadflow-f2pywrappers.f
src/build/libadflowmodule.c
src/build/importTest.py

Expand Down
188 changes: 162 additions & 26 deletions adflow/mphys/mphys_adflow.py

Large diffs are not rendered by default.

54 changes: 38 additions & 16 deletions adflow/pyADflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def setDisplacements(self, aeroProblem, dispFile):
Parameters
----------
aeroProblem : aeroProblem class
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The AP object that the displacements should be applied to.
dispFile : str
The file contaning the displacements. This file should have
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def __call__(self, aeroProblem, **kwargs):
Parameters
----------
aeroProblem : pyAero_problem class
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The complete description of the problem to solve
mdCallBack : python function
Call back for doing unsteady aeroelastic. Currently
Expand Down Expand Up @@ -1352,7 +1352,8 @@ def __call__(self, aeroProblem, **kwargs):
)

if self.adflow.killsignals.fatalfail:
fileName = f"failed_mesh_{self.curAP.name}_{self.curAP.adflowData.callCounter:03}.cgns"
numDigits = self.getOption("writeSolutionDigits")
fileName = f"failed_mesh_{self.curAP.name}_{self.curAP.adflowData.callCounter:0{numDigits}}.cgns"
self.pp(f"Fatal failure during mesh warp! Bad mesh is written in output directory as {fileName}")
self.writeMeshFile(os.path.join(self.getOption("outputDirectory"), fileName))
self.curAP.fatalFail = True
Expand Down Expand Up @@ -1636,7 +1637,7 @@ def evalFunctions(self, aeroProblem, funcs, evalFuncs=None, ignoreMissing=False)
Parameters
----------
aeroProblem : pyAero_problem class
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aerodynamic problem to to get the solution for
funcs : dict
Expand Down Expand Up @@ -1879,7 +1880,7 @@ def propagateUncertainty(self, aeroProblem, evalFuncs=None, UQDict=None):
Parameters
----------
aeroProblem : pyAero_problem class
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aerodynamic problem to solve
evalFuncs : iterable object containing strings
Expand Down Expand Up @@ -1961,7 +1962,7 @@ def solveCL(
Parameters
----------
aeroProblem : pyAero_problem class
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aerodynamic problem to solve
CLStar : float
The desired target CL
Expand Down Expand Up @@ -2464,7 +2465,7 @@ def solveTargetFuncs(self, aeroProblem, funcDict, tol=1e-4, nIter=10, Jac0=None)
Parameters
----------
AeroProblem : AeroProblem instance
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aerodynamic problem to be solved
funcDict : dict
Dictionary of function DV pairs to solve:
Expand Down Expand Up @@ -2615,7 +2616,7 @@ def solveSep(
Parameters
----------
aeroProblem : pyAero_problem class
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aerodynamic problem to solve
sepStar : float
The desired target separation sensor value
Expand Down Expand Up @@ -2785,14 +2786,15 @@ def writeSolution(self, outputDir=None, baseName=None, number=None, writeSlices=

# If we are numbering solution, it saving the sequence of
# calls, add the call number
numDigits = self.getOption("writeSolutionDigits")
if number is not None:
# We need number based on the provided number:
baseName = baseName + "_%3.3d" % number
baseName = baseName + f"_%.{numDigits}d" % number
else:
# if number is none, i.e. standalone, but we need to
# number solutions, use internal counter
if self.getOption("numberSolutions"):
baseName = baseName + "_%3.3d" % self.curAP.adflowData.callCounter
baseName = baseName + f"_%.{numDigits}d" % self.curAP.adflowData.callCounter

# Join to get the actual filename root
base = os.path.join(outputDir, baseName)
Expand Down Expand Up @@ -3170,7 +3172,7 @@ def resetFlow(self, aeroProblem, releaseAdjointMemory=True):
Parameters
----------
aeroProblem : pyAero_problem object
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aeroproblem with the flow information we would like
to reset the flow to.
"""
Expand Down Expand Up @@ -3213,7 +3215,7 @@ def resetANKCFL(self, aeroProblem):
Parameters
----------
aeroProblem : pyAero_problem object
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aeroproblem whose ANK CFL will be reset.
"""
aeroProblem.adflowData.ank_cfl = self.getOption("ANKCFL0")
Expand Down Expand Up @@ -3332,7 +3334,15 @@ def setSurfaceCoordinates(self, coordinates, groupName=None):
self.mesh.setSurfaceCoordinates(meshSurfCoords)

def setAeroProblem(self, aeroProblem, releaseAdjointMemory=True):
"""Set the supplied aeroProblem to be used in ADflow"""
"""Set the supplied aeroProblem to be used in ADflow.
Parameters
----------
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The supplied aeroproblem to be set.
releaseAdjointMemory : bool, optional
Flag to release the adjoint memory when setting a new aeroproblem, by default True
"""

ptSetName = "adflow_%s_coords" % aeroProblem.name

Expand Down Expand Up @@ -3460,9 +3470,16 @@ def setAeroProblem(self, aeroProblem, releaseAdjointMemory=True):
self.adflow.anksolver.ank_cfl = aeroProblem.adflowData.ank_cfl

def _setAeroProblemData(self, aeroProblem, firstCall=False):
"""After an aeroProblem has been associated with self.curAP, set
all the updated information in ADflow.
Parameters
----------
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The current aeroProblem object.
firstCall : bool, optional
Flag that signifies this is being called for the first time, by default False
"""
After an aeroProblem has been associated with self.curAP, set
all the updated information in ADflow."""

# Set any additional adflow options that may be defined in the
# aeroproblem. While we do it we save the options that we've
Expand Down Expand Up @@ -5277,7 +5294,7 @@ def solveErrorEstimate(self, aeroProblem, funcError, evalFuncs=None):
Parameters
----------
aeroProblem : pyAero_problem class
aeroProblem : :class:`~baseclasses:baseclasses.problems.pyAero_problem.AeroProblem`
The aerodynamic problem to get the error for
funcError : dict
Expand Down Expand Up @@ -5746,6 +5763,7 @@ def _getDefaultOptions():
"partitionLikeNProc": [int, -1],
# Misc Parameters
"numberSolutions": [bool, True],
"writeSolutionDigits": [int, 3],
"printIterations": [bool, True],
"printTiming": [bool, True],
"printIntro": [bool, True],
Expand Down Expand Up @@ -6240,6 +6258,7 @@ def _getSpecialOptionLists(self):

pythonOptions = {
"numbersolutions",
"writesolutiondigits",
"writetecplotsurfacesolution",
"coupledsolution",
"partitiononly",
Expand Down Expand Up @@ -6407,6 +6426,9 @@ def _getObjectivesAndDVs(self):
"cofzx": self.adflow.constants.costfunccoforcezx,
"cofzy": self.adflow.constants.costfunccoforcezy,
"cofzz": self.adflow.constants.costfunccoforcezz,
"colx": self.adflow.constants.costfunccofliftx,
"coly": self.adflow.constants.costfunccoflifty,
"colz": self.adflow.constants.costfunccofliftz,
}

return iDV, BCDV, adflowCostFunctions
Expand Down
15 changes: 15 additions & 0 deletions doc/costFunctions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ cofzz:
See ``cofxx`` description for more details.
Units: ``Meter``
colx:
desc: >
Center of lift force, ``x`` coordinate.
Units: ``Meter``
coly:
desc: >
Center of lift force, ``y`` coordinate.
Units: ``Meter``
colz:
desc: >
Center of lift force, ``z`` coordinate.
Units: ``Meter``
fx:
desc: >
Force from surface stresses (this includes shear/viscous, normal/pressure, and momentum/unsteady stresses) integrated in the global :math:`x` direction.
Expand Down
5 changes: 5 additions & 0 deletions doc/options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,11 @@ numberSolutions:
desc: >
Flag to set whether to attach the numbering of the AeroProblem to the grid solution file.
writeSolutionDigits:
desc: >
Number of digits in the solution output filenames.
A value of 4 will give, for example, 0023, while a value of 3 will give 023.
printIterations:
desc: >
Flag to set whether to print out the monitoring values at each iteration.
Expand Down
8 changes: 6 additions & 2 deletions src/adjoint/Makefile_tapenade
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ALL_RES_FILES = $(SRC)/adjoint/adjointExtra.F90\
$(SRC)/solver/surfaceIntegrations.F90\
$(SRC)/solver/zipperIntegrations.F90\
$(SRC)/solver/ALEUtils.F90\
$(SRC)/solver/actuatorRegion.F90\
$(SRC)/initFlow/initializeFlow.F90\
$(SRC)/turbulence/turbUtils.F90\
$(SRC)/turbulence/turbBCRoutines.F90\
Expand Down Expand Up @@ -103,6 +104,9 @@ bcData%BCDataSubsonicOutflow(bcVarArray, Pref) > \
bcData%BCDataSupersonicInflow(bcVarArray, muRef, rhoRef, Pref, uRef, wInf, pInfCorr) > \
(bcData%rho, bcData%velx, bcData%vely, bcData%velz, bcData%ps, bcData%turbInlet, muRef, rhoRef, Pref, uRef, wInf, pInfCorr) \
\
actuatorRegion%computeActuatorRegionVolume(vol, actuatorRegions%volLocal) > \
(vol, actuatorRegions%volLocal)\
\
adjointExtra%xhalo_block(x) > \
(x) \
\
Expand Down Expand Up @@ -179,8 +183,8 @@ sa%saViscous(w, vol, si, sj, sk, rlv, scratch) > \
sa%saResScale(scratch, dw) > \
(dw) \
\
residuals%sourceTerms_block(w, pref, uref, plocal, dw, actuatorRegions%force, actuatorRegions%heat) > \
(w, pref, uref, plocal, dw, actuatorRegions%force, actuatorRegions%heat) \
residuals%sourceTerms_block(w, pref, uref, plocal, dw, vol, actuatorRegions%force, actuatorRegions%heat, actuatorRegions%volume) > \
(w, pref, uref, plocal, dw, vol, actuatorRegions%force, actuatorRegions%heat, actuatorRegions%volume) \
\
residuals%initres_block(dw, fw, flowDoms%w, flowDoms%vol, dscalar, dvector) > \
(dw, fw, flowDoms%w, flowDoms%vol, dscalar, dvector) \
Expand Down
1 change: 1 addition & 0 deletions src/adjoint/adjointUtils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ subroutine zeroADSeeds(nn, level, sps)
actuatorRegionsd(i)%force = zero
actuatorRegionsd(i)%torque = zero
actuatorRegionsd(i)%heat = zero
actuatorRegionsd(i)%volume = zero
end do

end subroutine zeroADSeeds
Expand Down
3 changes: 2 additions & 1 deletion src/adjoint/autoEdit/autoEditReverseFast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

# Import modules
import os
import sys
import re
import sys

# Specify file extension
EXT = "_fast_b.f90"
Expand Down Expand Up @@ -58,6 +58,7 @@
"BCData_fast_b.f90",
"oversetUtilities_fast_b.f90",
"zipperIntegrations_fast_b.f90",
"actuatorRegion_fast_b.f90",
]

for f in os.listdir(DIR_ORI):
Expand Down
Loading

0 comments on commit 156b582

Please sign in to comment.