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

fixed span derivative issues #143

Merged
merged 7 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions pygeo/parameterization/DVGeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3721,8 +3721,12 @@ def _attachedPtJacobian(self, config):

# We need to save the reference state so that we can always start
# from the same place when calling _update_deriv
refFFDCoef = copy.copy(self.FFD.coef)
refCoef = copy.copy(self.coef)
if not self.isChild:
refFFDCoef = copy.copy(self.origFFDCoef.astype("D"))
refCoef = copy.copy(self.coef0.astype("D"))
else:
refFFDCoef = copy.copy(self.FFD.coef)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the reset happen only if the FFD is not a child?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the FFD is child then it's nodes will be moved by the parent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this the test_block test were failing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does that work even if I define the span variable directly on the child?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure.
Probably not

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a test using a span variable on a child FFD.
It looks like it worked

refCoef = copy.copy(self.coef)

iDV = self.nDVG_count
for key in self.DV_listGlobal:
Expand Down
21 changes: 18 additions & 3 deletions tests/reg_tests/commonUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,8 @@ def totalSensitivityFD(DVGeo, nPt, ptName, step=1e-1):
nDV = len(baseVar)
dIdxFD[key] = np.zeros([nPt, nDV])
for i in range(nDV):
# print('perturbing',key)
xDV[key][i] = baseVar[i] + step
# print('setting design vars')
DVGeo.setDesignVars(xDV)
# print('calling top level update')
newPoints = DVGeo.update(ptName)

deriv = (newPoints - refPoints) / step
Expand Down Expand Up @@ -264,3 +261,21 @@ def chord(val, geo):

for i in range(1, nRefAxPts):
geo.scale_x[axis_key].coef[i] = val[i - fix_root_sect]


def span(val, geo):
axis_key = list(geo.axis.keys())[0]
C = geo.extractCoef(axis_key)
for i in range(1, C.shape[0]):
C[i, 2] *= val

geo.restoreCoef(C, axis_key)


def spanX(val, geo):
axis_key = list(geo.axis.keys())[0]
C = geo.extractCoef(axis_key)
for i in range(1, C.shape[0]):
C[i, 0] *= val

geo.restoreCoef(C, axis_key)
60 changes: 60 additions & 0 deletions tests/reg_tests/test_DVGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,66 @@ def test_ffdSplineOrder(self, train=False, refDeriv=False):

commonUtils.testSensitivities(DVGeo, refDeriv, handler, pointset=3)

def test_spanDV(self, train=False):
"""
Test span DV
If the design FFD coef are not reset between updating the points and the derivative routines this will fail.
"""
DVGeo = DVGeometry(os.path.join(self.base_path, "../../input_files/2x1x8_rectangle.xyz"))

DVGeo.addRefAxis("RefAx", xFraction=0.5, alignIndex="k", rotType=0, rot0ang=-90)
DVGeo.addGlobalDV(dvName="span", value=0.5, func=commonUtils.span, lower=0.1, upper=10, scale=1)

points = np.zeros([2, 3])
points[0, :] = [0.25, 0.4, 4]
points[1, :] = [-0.8, 0.2, 7]
ptName = "testPoints"
DVGeo.addPointSet(points, ptName)

nPt = points.size
dIdx_FD = commonUtils.totalSensitivityFD(DVGeo, nPt, ptName)

dIdPt = np.zeros([nPt, 2, 3])
dIdPt[0, 0, 0] = 1.0
dIdPt[1, 0, 1] = 1.0
dIdPt[2, 0, 2] = 1.0
dIdPt[3, 1, 0] = 1.0
dIdPt[4, 1, 1] = 1.0
dIdPt[5, 1, 2] = 1.0
dIdx = DVGeo.totalSensitivity(dIdPt, ptName)

np.testing.assert_allclose(dIdx["span"], dIdx_FD["span"], atol=1e-15)

def test_spanDV_child(self, train=False):
"""
Test span DV with child
"""
DVGeo, DVGeoChild = commonUtils.setupDVGeo(self.base_path)

# add design variables
DVGeoChild.addGlobalDV(dvName="span", value=0.5, func=commonUtils.spanX, lower=0.1, upper=10, scale=1)
DVGeo.addChild(DVGeoChild)

points = np.zeros([2, 3])
points[0, :] = [0.25, 0, 0]
points[1, :] = [-0.25, 0, 0]
ptName = "testPoints"
DVGeo.addPointSet(points, ptName)

nPt = points.size
dIdx_FD = commonUtils.totalSensitivityFD(DVGeo, nPt, ptName)

dIdPt = np.zeros([nPt, 2, 3])
dIdPt[0, 0, 0] = 1.0
dIdPt[1, 0, 1] = 1.0
dIdPt[2, 0, 2] = 1.0
dIdPt[3, 1, 0] = 1.0
dIdPt[4, 1, 1] = 1.0
dIdPt[5, 1, 2] = 1.0
dIdx = DVGeo.totalSensitivity(dIdPt, ptName)

np.testing.assert_allclose(dIdx["span"], dIdx_FD["span"], atol=1e-15)


if __name__ == "__main__":
unittest.main()
Expand Down