Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom pointsets for dvgeo #299

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 130 additions & 17 deletions adflow/pyADflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3253,8 +3253,6 @@
Flag to release the adjoint memory when setting a new aeroproblem, by default True
"""

ptSetName = "adflow_%s_coords" % aeroProblem.name

newAP = False
# Tell the user if we are switching aeroProblems
if self.curAP != aeroProblem:
Expand All @@ -3268,9 +3266,23 @@
aeroProblem.adflowData
except AttributeError:
aeroProblem.adflowData = adflowFlowCase()
aeroProblem.ptSetName = ptSetName
aeroProblem.surfMesh = self.getSurfaceCoordinates(self.designFamilyGroup)

# dictionary that holds the ptsetname for each family
ptSetNames = {}
if self.customPointSetFamilies is None:
# we dont have a custom child dvgeo mapping. the surface family will be only
# designFamilyGroup and we will have a single pointset
ptSetName = f"adflow_{self.designFamilyGroup}_{aeroProblem.name}_coords"
ptSetNames[self.designFamilyGroup] = ptSetName
else:
# we have a custom surface family to child dvgeo mapping.
for familyName in self.customPointSetFamilies.keys():
ptSetName = f"adflow_{familyName}_{aeroProblem.name}_coords"
ptSetNames[familyName] = ptSetName

Check warning on line 3282 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3280-L3282

Added lines #L3280 - L3282 were not covered by tests

aeroProblem.ptSetNames = ptSetNames

if self.curAP is not None:
# If we have already solved something and are now
# switching, save what we need:
Expand Down Expand Up @@ -3298,10 +3310,31 @@

# Now check if we have an DVGeo object to deal with:
if self.DVGeo is not None:
# DVGeo appeared and we have not embedded points!
if ptSetName not in self.DVGeo.points:
coords0 = self.mapVector(self.coords0, self.allFamilies, self.designFamilyGroup, includeZipper=False)
self.DVGeo.addPointSet(coords0, ptSetName, **self.pointSetKwargs)
# we have a DVGeo added. check if we have already added the points for this AP
if self.customPointSetFamilies is None:
# we have a single pointset
ptSetName = aeroProblem.ptSetNames[self.designFamilyGroup]

if ptSetName not in self.DVGeo.points:
coords0 = self.mapVector(
self.coords0, self.allFamilies, self.designFamilyGroup, includeZipper=False
)
self.DVGeo.addPointSet(coords0, ptSetName, **self.pointSetKwargs)
else:
# we have custom pointsets
for family, familyKwargs in self.customPointSetFamilies.items():
ptSetName = aeroProblem.ptSetNames[family]

Check warning on line 3326 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3325-L3326

Added lines #L3325 - L3326 were not covered by tests

if ptSetName not in self.DVGeo.points:

Check warning on line 3328 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3328

Added line #L3328 was not covered by tests
# coords0 is now the subset of this family
coords0 = self.mapVector(self.coords0, self.allFamilies, family, includeZipper=False)

Check warning on line 3330 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3330

Added line #L3330 was not covered by tests
# this pointset is added with a custom familyKwargs
self.DVGeo.addPointSet(

Check warning on line 3332 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3332

Added line #L3332 was not covered by tests
coords0,
ptSetName,
**self.pointSetKwargs,
**familyKwargs,
)

# also check if we need to embed blanking surface points
if self.getOption("oversetUpdateMode") == "full" and self.getOption("explicitSurfaceCallback") is not None:
Expand Down Expand Up @@ -3335,8 +3368,49 @@
self.DVGeo.addPointSet(procPts, surfPtSetName, **self.pointSetKwargs)

# Check if our point-set is up to date:
if not self.DVGeo.pointSetUpToDate(ptSetName) or aeroProblem.adflowData.disp is not None:
coords = self.DVGeo.update(ptSetName, config=aeroProblem.name)
updateSurface = False

# check for disp first. doing this check here is not the most efficient,
# but it results in simpler code
if aeroProblem.adflowData.disp is not None:
updateSurface = True

Check warning on line 3376 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3376

Added line #L3376 was not covered by tests

if self.customPointSetFamilies is None:
# we have a single pointset
ptSetName = aeroProblem.ptSetNames[self.designFamilyGroup]

if not self.DVGeo.pointSetUpToDate(ptSetName):
updateSurface = True

coords = self.DVGeo.update(ptSetName, config=aeroProblem.name)

else:
# we have custom pointsets
# first figure out if we want to update the pointset; check each family we are tracking
for family in self.customPointSetFamilies.keys():

Check warning on line 3390 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3390

Added line #L3390 was not covered by tests
# return immediately if we are flagged for a surfafce update
if updateSurface:
break

Check warning on line 3393 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3392-L3393

Added lines #L3392 - L3393 were not covered by tests

# check if any of the pointsets are out of date
ptSetName = aeroProblem.ptSetNames[family]
if not self.DVGeo.pointSetUpToDate(ptSetName):
updateSurface = True

Check warning on line 3398 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3396-L3398

Added lines #L3396 - L3398 were not covered by tests

# if we have the updateSurface flag True, compute the coords array
if updateSurface:

Check warning on line 3401 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3401

Added line #L3401 was not covered by tests
# get the current design surface family. we will overwrite this as we go through the families
coords = self.mapVector(self.coords0, self.allFamilies, self.designFamilyGroup, includeZipper=False)

Check warning on line 3403 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3403

Added line #L3403 was not covered by tests

for family in self.customPointSetFamilies.keys():
ptSetName = aeroProblem.ptSetNames[family]
familyCoords = self.DVGeo.update(ptSetName, config=aeroProblem.name)

Check warning on line 3407 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3405-L3407

Added lines #L3405 - L3407 were not covered by tests
# map this to the coords vector
self.mapVector(familyCoords, family, self.designFamilyGroup, vec2=coords, includeZipper=False)

Check warning on line 3409 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L3409

Added line #L3409 was not covered by tests

if updateSurface:
# the coords array is computed above. if we have the update surface flag enabled,
# run the surface update

# Potentially add a fixed set of displacements to it.
if aeroProblem.adflowData.disp is not None:
Expand Down Expand Up @@ -4672,9 +4746,22 @@
# already existing (and possibly nonzero) xsdot and xvdot
if xDvDot is not None or xSDot is not None:
if xDvDot is not None and self.DVGeo is not None:
xsdot += self.DVGeo.totalSensitivityProd(xDvDot, self.curAP.ptSetName, config=self.curAP.name).reshape(
xsdot.shape
)
if self.customPointSetFamilies is None:
# no custom pointset families, just process the entire dvdot and add to xsdot
xsdot += self.DVGeo.totalSensitivityProd(
xDvDot, self.curAP.ptSetNames[self.designFamilyGroup], config=self.curAP.name
).reshape(xsdot.shape)
else:
# custom pointsets. accumulate local xsdots in the complete vector
for family in self.customPointSetFamilies.keys():

Check warning on line 4756 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L4756

Added line #L4756 was not covered by tests
# process this family's xsdot
ptSetName = self.curAP.ptSetNames[family]
xsdot_family = self.DVGeo.totalSensitivityProd(

Check warning on line 4759 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L4758-L4759

Added lines #L4758 - L4759 were not covered by tests
xDvDot, ptSetName, self.comm, config=self.curAP.name
)
# map it to an empty surface vector and accumulate
xsdot += self.mapVector(xsdot_family, family, self.designFamilyGroup)

Check warning on line 4763 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L4763

Added line #L4763 was not covered by tests

if self.mesh is not None:
xsdot = self.mapVector(xsdot, self.meshFamilyGroup, self.designFamilyGroup, includeZipper=False)
xvdot += self.mesh.warpDerivFwd(xsdot)
Expand Down Expand Up @@ -4990,12 +5077,38 @@
if xDvDeriv:
xdvbar = {}
if self.mesh is not None: # Include geometric
# derivatives if mesh is
# present
# derivatives if mesh is present
if self.DVGeo is not None and self.DVGeo.getNDV() > 0:
xdvbar.update(
self.DVGeo.totalSensitivity(xsbar, self.curAP.ptSetName, self.comm, config=self.curAP.name)
)
# we have a DVGeo added. check if we have already added the points for this AP
if self.customPointSetFamilies is None:
# we have a single pointset
ptSetName = self.curAP.ptSetNames[self.designFamilyGroup]

xdvbar.update(
self.DVGeo.totalSensitivity(xsbar, ptSetName, self.comm, config=self.curAP.name)
)

else:
# we have custom pointsets
# start with an empty dict, we set the entries in the first pass,
# and add in the following passes
for family in self.customPointSetFamilies.keys():
ptSetName = self.curAP.ptSetNames[family]

Check warning on line 5096 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L5095-L5096

Added lines #L5095 - L5096 were not covered by tests

# get the mapped xsbar
xsbarFamily = self.mapVector(xsbar, self.designFamilyGroup, family, includeZipper=False)

Check warning on line 5099 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L5099

Added line #L5099 was not covered by tests

familySens = self.DVGeo.totalSensitivity(

Check warning on line 5101 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L5101

Added line #L5101 was not covered by tests
xsbarFamily, ptSetName, self.comm, config=self.curAP.name
)

for key, val in familySens.items():

Check warning on line 5105 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L5105

Added line #L5105 was not covered by tests
# not the best way to do this but should work...
if key in xdvbar:
xdvbar[key] += val

Check warning on line 5108 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L5107-L5108

Added lines #L5107 - L5108 were not covered by tests
else:
xdvbar[key] = val

Check warning on line 5110 in adflow/pyADflow.py

View check run for this annotation

Codecov / codecov/patch

adflow/pyADflow.py#L5110

Added line #L5110 was not covered by tests

else:
if self.comm.rank == 0:
ADFLOWWarning(
Expand Down