Skip to content

Commit

Permalink
added child warning example (#55)
Browse files Browse the repository at this point in the history
* added child warning example

* formatting changes

* added unittest.main

* tweaked unittest.main

* tweaked unittest.main again

* add issue ref in code
  • Loading branch information
Josh Anibal authored Jan 23, 2021
1 parent f8176b0 commit 45c4c2e
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 168 deletions.
166 changes: 0 additions & 166 deletions examples/childffd_warning/warning_childFFD.py

This file was deleted.

5 changes: 4 additions & 1 deletion pygeo/DVGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,10 @@ def addChild(self, childDVGeo):
children. The parent object will take care of that in a call
to addPointSet().
See https://github.com/mdolab/pygeo/issues/7 for a description of an
issue with Child FFDs that you should be aware of if you are combining
shape changes of a parent FFD with rotation or shape changes of a child FFD.
Parameters
----------
childDVGeo : instance of DVGeometry
Expand Down Expand Up @@ -1536,7 +1540,6 @@ def getVarNames(self):

return names


def totalSensitivity(self, dIdpt, ptSetName, comm=None, config=None):
"""
This function computes sensitivty information.
Expand Down
2 changes: 1 addition & 1 deletion tests/reg_tests/test_Blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def f_rotate_z(val, geo):

def f_rotate_theta(val, geo):
geo.rot_theta['ref'].coef[:] = val[0]


if __name__ == '__main__':
unittest.main()
110 changes: 110 additions & 0 deletions tests/reg_tests/warning_childFFD.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from __future__ import print_function
import os
import unittest
import numpy
import copy
from baseclasses import BaseRegTest
from pygeo import DVGeometry, geo_utils

from test_Blocks import add_vars, f_translate, f_rotate_x, f_rotate_y, f_rotate_z, f_rotate_theta


class RegTestPyGeo(unittest.TestCase):

N_PROCS = 1

def make_cube_ffd(self, file_name, x0, y0, z0, dx, dy, dz):
# Write cube ffd with i along x-axis, j along y-axis, and k along z-axis
axes = ["k", "j", "i"]
slices = numpy.array(
# Slice 1
[
[[[x0, y0, z0], [x0 + dx, y0, z0]], [[x0, y0 + dy, z0], [x0 + dx, y0 + dy, z0]]],
# Slice 2
[[[x0, y0, z0 + dz], [x0 + dx, y0, z0 + dz]], [[x0, y0 + dy, z0 + dz], [x0 + dx, y0 + dy, z0 + dz]]],
],
dtype="d",
)

N0 = [2]
N1 = [2]
N2 = [2]

geo_utils.write_wing_FFD_file(file_name, slices, N0, N1, N2, axes=axes)

def test_parent_shape_child_rot(self, train=False, refDeriv=False):
ffd_name = "../../tests/inputFiles/small_cube.xyz"
self.make_cube_ffd(ffd_name, 0.1, 0.1, 0.1, 0.8, 0.8, 0.8)
small = DVGeometry(ffd_name, child=True)
small.addRefAxis("ref", xFraction=0.5, alignIndex="j")

x0 = 0.0
y0 = 0.0
z0 = 0.0
dx = 1.0
dy = 1.0
dz = 1.0

axes = ["k", "j", "i"]
slices = numpy.array(
# Slice 1
[
[
[[x0, y0, z0], [x0 + dx, y0, z0], [x0 + 2 * dx, y0, z0]],
[[x0, y0 + dy, z0], [x0 + dx, y0 + dy, z0], [x0 + 2 * dx, y0 + dy, z0]],
],
# Slice 2
[
[[x0, y0, z0 + dz], [x0 + dx, y0, z0 + dz], [x0 + 2 * dx, y0, z0 + dz]],
[[x0, y0 + dy, z0 + dz], [x0 + dx, y0 + dy, z0 + dz], [x0 + 2 * dx, y0 + dy, z0 + dz]],
],
],
dtype="d",
)

N0 = [2]
N1 = [2]
N2 = [3]
ffd_name = "../../tests/inputFiles/big_cube.xyz"

geo_utils.write_wing_FFD_file(ffd_name, slices, N0, N1, N2, axes=axes)
big = DVGeometry(ffd_name)
big.addRefAxis("ref", xFraction=0.5, alignIndex="j")
big.addChild(small)

# Add point set
points = numpy.array([[0.5, 0.5, 0.5]])
big.addPointSet(points, "X")

# Add only translation variables
add_vars(big, "big", local="z", rotate="y")
add_vars(small, "small", rotate="y")

ang = 45
ang_r = numpy.deg2rad(ang)

# Modify design variables
x = big.getValues()

# add a local shape change
x["local_z_big"] = numpy.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 0.5])
big.setDesignVars(x)
Xs = big.update("X")

# add a rotation of the child FFD
x["rotate_y_small"] = ang
big.setDesignVars(x)
Xrot_ffd = big.update("X")

# the modification caused by the child FFD should be the same as rotating the deformed point of the parent
# (you would think)
rot_mat = numpy.array(
[[numpy.cos(ang_r), 0, numpy.sin(ang_r)], [0, 1, 0], [-numpy.sin(ang_r), 0, numpy.cos(ang_r)]]
)
Xrot = numpy.dot(rot_mat, (Xs - points).T) + points.T

numpy.testing.assert_array_almost_equal(Xrot_ffd.T, Xrot)


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

0 comments on commit 45c4c2e

Please sign in to comment.