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

fix camelcase to be consistent with adflow #169

Merged
merged 3 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
42 changes: 21 additions & 21 deletions pygeo/parameterization/DVGeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __init__(self, fileName, *args, isComplex=False, child=False, faceFreeze=Non
self.nPts = {}

# dictionary to save any coordinate transformations we are given
self.coord_xfer = {}
self.coordXfer = {}

# Derivatives of Xref and Coef provided by the parent to the
# children
Expand Down Expand Up @@ -655,7 +655,7 @@ def addRefAxis(

return nAxis

def addPointSet(self, points, ptName, origConfig=True, coord_xfer=None, **kwargs):
def addPointSet(self, points, ptName, origConfig=True, coordXfer=None, **kwargs):
"""
Add a set of coordinates to DVGeometry

Expand All @@ -677,7 +677,7 @@ def addPointSet(self, points, ptName, origConfig=True, coord_xfer=None, **kwargs
undeformed or deformed configuration. This should almost
always be True except in circumstances when the user knows
exactly what they are doing.
coord_xfer : function
coordXfer : function
A callback function that performs a coordinate transformation
between the DVGeo reference frame and any other reference
frame. The DVGeo object uses this routine to apply the coordinate
Expand All @@ -688,26 +688,26 @@ def addPointSet(self, points, ptName, origConfig=True, coord_xfer=None, **kwargs
the user to do whatever they want with the coordinate transformation.
The function must have the first positional argument as the array that is
(npt, 3) and the two keyword arguments that must be available are "mode"
("fwd" or "bwd") and "apply_displacement" (True or False). This function
("fwd" or "bwd") and "applyDisplacement" (True or False). This function
can then be passed to DVGeo through something like ADflow, where the
set DVGeo call can be modified as:
CFDSolver.setDVGeo(DVGeo, pointSetKwargs={"coord_xfer": coord_xfer})
CFDSolver.setDVGeo(DVGeo, pointSetKwargs={"coordXfer": coordXfer})

An example function is as follows:

.. code-block:: python

def coord_xfer(coords, mode="fwd", apply_displacement=True, **kwargs):
def coordXfer(coords, mode="fwd", applyDisplacement=True, **kwargs):
# given the (npt by 3) array "coords" apply the coordinate transformation.
# The "fwd" mode implies we go from DVGeo reference frame to the
# application, e.g. CFD, the "bwd" mode is the opposite;
# goes from the CFD reference frame back to the DVGeo reference frame.
# the apply_displacement flag needs to be correctly implemented
# the applyDisplacement flag needs to be correctly implemented
# by the user; the derivatives are also passed through this routine
# and they only need to be rotated when going between reference frames,
# and they should NOT be displaced.

# In summary, all the displacements MUST be within the if apply_displacement == True
# In summary, all the displacements MUST be within the if applyDisplacement == True
# checks, otherwise the derivatives will be wrong.

# Example transfer: The CFD mesh
Expand All @@ -730,12 +730,12 @@ def coord_xfer(coords, mode="fwd", apply_displacement=True, **kwargs):
coords_new = np.dot(coords, rot_mat)

# then the translation
if apply_displacement:
if applyDisplacement:
coords_new[:, 2] -= 5
elif mode == "bwd":
# apply the operations in reverse
coords_new = coords.copy()
if apply_displacement:
if applyDisplacement:
coords_new[:, 2] += 5

# and the rotation. note the rotation matrix is transposed
Expand All @@ -757,14 +757,14 @@ def coord_xfer(coords, mode="fwd", apply_displacement=True, **kwargs):
points = np.array(points).real.astype("d")

# save the coordinate transformation info
if coord_xfer is not None:
self.coord_xfer[ptName] = coord_xfer
if coordXfer is not None:
self.coordXfer[ptName] = coordXfer

# Also apply the first coordinate transformation while adding this ptset.
# The child FFDs only interact with their parent FFD, and therefore,
# do not need to access the coordinate transformation routine; i.e.
# all transformations are applied once during the highest level DVGeo object.
points = self.coord_xfer[ptName](points, mode="bwd", apply_displacement=True)
points = self.coordXfer[ptName](points, mode="bwd", applyDisplacement=True)

self.points[ptName] = points

Expand Down Expand Up @@ -1979,8 +1979,8 @@ def update(self, ptSetName, childDelta=True, config=None):
# we only check if we need to apply the coordinate transformation
# and move the pointset to the reference frame of the application,
# if this is the last pygeo in the chain
if ptSetName in self.coord_xfer:
Xfinal = self.coord_xfer[ptSetName](Xfinal, mode="fwd", apply_displacement=True)
if ptSetName in self.coordXfer:
Xfinal = self.coordXfer[ptSetName](Xfinal, mode="fwd", applyDisplacement=True)
return Xfinal

def applyToChild(self, iChild):
Expand Down Expand Up @@ -2217,12 +2217,12 @@ def totalSensitivity(self, dIdpt, ptSetName, comm=None, config=None):
N = dIdpt.shape[0]

# apply the coordinate transformation on dIdpt if this pointset has it.
if ptSetName in self.coord_xfer:
if ptSetName in self.coordXfer:
# loop over functions
for ifunc in range(N):
# its important to remember that dIdpt are vector-like values,
# so we don't apply the transformations and only the rotations!
dIdpt[ifunc] = self.coord_xfer[ptSetName](dIdpt[ifunc], mode="bwd", apply_displacement=False)
dIdpt[ifunc] = self.coordXfer[ptSetName](dIdpt[ifunc], mode="bwd", applyDisplacement=False)

# generate the total Jacobian self.JT
self.computeTotalJacobian(ptSetName, config=config)
Expand Down Expand Up @@ -2326,10 +2326,10 @@ def totalSensitivityProd(self, vec, ptSetName, config=None):
xsdot.reshape(len(xsdot) // 3, 3)

# check if we have a coordinate transformation on this ptset
if ptSetName in self.coord_xfer:
if ptSetName in self.coordXfer:
# its important to remember that dIdpt are vector-like values,
# so we don't apply the transformations and only the rotations!
xsdot = self.coord_xfer[ptSetName](xsdot, mode="fwd", apply_displacement=False)
xsdot = self.coordXfer[ptSetName](xsdot, mode="fwd", applyDisplacement=False)

# Maybe this should be:
# xsdot = xsdot.reshape(len(xsdot)//3, 3)
Expand Down Expand Up @@ -2388,10 +2388,10 @@ def totalSensitivityTransProd(self, vec, ptSetName, config=None):
else:

# check if we have a coordinate transformation on this ptset
if ptSetName in self.coord_xfer:
if ptSetName in self.coordXfer:
# its important to remember that dIdpt are vector-like values,
# so we don't apply the transformations and only the rotations!
vec = self.coord_xfer[ptSetName](vec, mode="bwd", apply_displacement=False)
vec = self.coordXfer[ptSetName](vec, mode="bwd", applyDisplacement=False)

xsdot = self.JT[ptSetName].dot(np.ravel(vec))

Expand Down
4 changes: 2 additions & 2 deletions tests/reg_tests/test_DVGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def test_coord_xfer(self):
DVGeo.addLocalDV("ydir", lower=-1.0, upper=1.0, axis="y", scale=1.0)
DVGeo.addLocalDV("zdir", lower=-1.0, upper=1.0, axis="z", scale=1.0)

def coord_xfer(coords, mode="fwd", apply_displacement=True):
def coordXfer(coords, mode="fwd", apply_displacement=True):
rot_mat = np.array(
[
[1, 0, 0],
Expand Down Expand Up @@ -1129,7 +1129,7 @@ def coord_xfer(coords, mode="fwd", apply_displacement=True):
]
)

DVGeo.addPointSet(test_points, "test", coord_xfer=coord_xfer)
DVGeo.addPointSet(test_points, "test", coordXfer=coordXfer)

# check if we can query the same point back
pts_new = DVGeo.update("test")
Expand Down