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

Rename functions #91

Merged
merged 7 commits into from
Jul 14, 2021
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
2 changes: 1 addition & 1 deletion examples/deform_geometry/runScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def twist(val, geo):
geo.rot_z["wing"].coef[i] = val[i]

# Add the Twist Design Variable to DVGeo
DVGeo.addGeoDVGlobal(dvName="twist", value=[0] * nRefAxPts, func=twist, lower=-10, upper=10, scale=1.0)
DVGeo.addGlobalDV(dvName="twist", value=[0] * nRefAxPts, func=twist, lower=-10, upper=10, scale=1.0)

# Get Design Variables
dvDict = DVGeo.getValues()
Expand Down
57 changes: 37 additions & 20 deletions pygeo/DVGeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pyspline.utils import openTecplot, closeTecplot, writeTecplot1D, writeTecplot3D
from . import pyNetwork, pyBlock, geo_utils
import os
import warnings


class Error(Exception):
Expand Down Expand Up @@ -88,9 +89,9 @@ class DVGeometry(object):
>>> def twist(val, geo):
>>> geo.rot_z['wing_axis'].coef[:] = val[:]
>>> # Now add this as a global variable:
>>> DVGeo.addGeoDVGlobal('wing_twist', 0.0, twist, lower=-10, upper=10)
>>> DVGeo.addGlobalDV('wing_twist', 0.0, twist, lower=-10, upper=10)
>>> # Now add local (shape) variables
>>> DVGeo.addGeoDVLocal('shape', lower=-0.5, upper=0.5, axis='y')
>>> DVGeo.addLocalDV('shape', lower=-0.5, upper=0.5, axis='y')
>>>
"""

Expand Down Expand Up @@ -646,7 +647,7 @@ def addChild(self, childDVGeo):
# Add the child to the parent and return
self.children.append(childDVGeo)

def addGeoDVGlobal(self, dvName, value, func, lower=None, upper=None, scale=1.0, config=None):
def addGlobalDV(self, dvName, value, func, lower=None, upper=None, scale=1.0, config=None):
"""
Add a global design variable to the DVGeometry object. This
type of design variable acts on one or more reference axis.
Expand Down Expand Up @@ -696,7 +697,11 @@ def addGeoDVGlobal(self, dvName, value, func, lower=None, upper=None, scale=1.0,
config = [config]
self.DV_listGlobal[dvName] = geoDVGlobal(dvName, value, lower, upper, scale, func, config)

def addGeoDVLocal(
def addGeoDVGlobal(self, *args, **kwargs):
warnings.warn("addGeoDVGlobal will be deprecated, use addGlobalDV instead")
self.addGlobalDV(self, *args, **kwargs)

def addLocalDV(
self, dvName, lower=None, upper=None, scale=1.0, axis="y", volList=None, pointSelect=None, config=None
):
"""
Expand Down Expand Up @@ -724,7 +729,7 @@ def addGeoDVLocal(
axis : str. Default is `y`
The coordinate directions to move. Permissible values are `x`,
`y` and `z`. If more than one direction is required, use multiple
calls to addGeoDVLocal with different axis values.
calls to addLocalDV with different axis values.

volList : list
Use the control points on the volume indicies given in volList.
Expand All @@ -751,14 +756,14 @@ def addGeoDVLocal(
--------
>>> # Add all variables in FFD as local shape variables
>>> # moving in the y direction, within +/- 1.0 units
>>> DVGeo.addGeoDVLocal('shape_vars', lower=-1.0, upper= 1.0, axis='y')
>>> DVGeo.addLocalDV('shape_vars', lower=-1.0, upper= 1.0, axis='y')
>>> # As above, but moving in the x and y directions.
>>> nVar = DVGeo.addGeoDVLocal('shape_vars_x', lower=-1.0, upper= 1.0, axis='x')
>>> nVar = DVGeo.addGeoDVLocal('shape_vars_y', lower=-1.0, upper= 1.0, axis='y')
>>> nVar = DVGeo.addLocalDV('shape_vars_x', lower=-1.0, upper= 1.0, axis='x')
>>> nVar = DVGeo.addLocalDV('shape_vars_y', lower=-1.0, upper= 1.0, axis='y')
>>> # Create a point select to use: (box from (0,0,0) to (10,0,10) with
>>> # any point projecting into the point along 'y' axis will be selected.
>>> PS = geo_utils.PointSelect(type = 'y', pt1=[0,0,0], pt2=[10, 0, 10])
>>> nVar = DVGeo.addGeoDVLocal('shape_vars', lower=-1.0, upper=1.0, pointSelect=PS)
>>> nVar = DVGeo.addLocalDV('shape_vars', lower=-1.0, upper=1.0, pointSelect=PS)
"""
if self.name is not None:
dvName = self.name + "_" + dvName
Expand Down Expand Up @@ -793,7 +798,11 @@ def addGeoDVLocal(

return self.DV_listLocal[dvName].nVal

def addGeoDVSpanwiseLocal(
def addGeoDVLocal(self, *args, **kwargs):
warnings.warn("addGeoDVLocal will be deprecated, use addLocalDV instead")
self.addLocalDV(self, *args, **kwargs)

def addSpanwiseLocalDV(
self,
dvName,
spanIndex,
Expand Down Expand Up @@ -839,7 +848,7 @@ def addGeoDVSpanwiseLocal(
axis : str. Default is `y`
The coordinate directions to move. Permissible values are `x`,
`y` and `z`. If more than one direction is required, use multiple
calls to addGeoDVLocal with different axis values.
calls to addLocalDV with different axis values.

lower : float
The lower bound for the variable(s). This will be applied to
Expand Down Expand Up @@ -879,7 +888,7 @@ def addGeoDVSpanwiseLocal(
--------
>>> # Add all spanwise local variables
>>> # moving in the y direction, within +/- 0.5 units
>>> DVGeo.addGeoDVSpanwiseLocal("shape", 'k', lower=-0.5, upper=0.5, axis="z", scale=1.0)
>>> DVGeo.addSpanwiseLocalDV("shape", 'k', lower=-0.5, upper=0.5, axis="z", scale=1.0)
"""
if type(config) == str:
config = [config]
Expand Down Expand Up @@ -964,7 +973,11 @@ def addGeoDVSpanwiseLocal(

return self.DV_listSpanwiseLocal[dvName].nVal

def addGeoDVSectionLocal(
def addGeoDVSpanwiseLocal(self, *args, **kwargs):
warnings.warn("addGeoDVSpanwiseLocal will be deprecated, use addSpanwiseLocalDV instead")
self.addSpanwiseLocalDV(self, *args, **kwargs)

def addLocalSectionDV(
self,
dvName,
secIndex,
Expand Down Expand Up @@ -1028,7 +1041,7 @@ def addGeoDVSectionLocal(
2: transverse direction (out of section plane)

If more than one direction is required, use multiple calls to
`addGeoDVSectionLocal` with different axis values.
`addLocalSectionDV` with different axis values.
::

1
Expand Down Expand Up @@ -1107,7 +1120,7 @@ class in geo_utils. Using pointSelect discards everything in volList.
--------
>>> # Add all control points in FFD as local shape variables
>>> # moving in the 1 direction, within +/- 1.0 units
>>> DVGeo.addGeoDVSectionLocal('shape_vars', secIndex='k', lower=-1, upper=1, axis=1)
>>> DVGeo.addLocalSectionDV('shape_vars', secIndex='k', lower=-1, upper=1, axis=1)
"""
if self.name is not None:
dvName = self.name + "_" + dvName
Expand Down Expand Up @@ -1183,6 +1196,10 @@ class in geo_utils. Using pointSelect discards everything in volList.

return self.DV_listSectionLocal[dvName].nVal

def addGeoDVSectionLocal(self, *args, **kwargs):
warnings.warn("addGeoDVSectionLocal will be deprecated, use addLocalSectionDV instead")
self.addLocalSectionDV(self, *args, **kwargs)

def getSymmetricCoefList(self, volList=None, pointSelect=None, tol=1e-8):
"""
Determine the pairs of coefs that need to be constrained for symmetry.
Expand Down Expand Up @@ -4110,7 +4127,7 @@ def sectionFrame(self, sectionIndex, sectionTransform, sectionLink, ivol=0, orie
orient0 : None, `i`, `j`, `k`, or numpy vector. Default is None.
Although secIndex defines the '2' axis, the '0' and '1' axes are still
free to rotate within the section plane. We will choose the orientation
of the '0' axis and let '1' be orthogonal. See `addGeoDVSectionLocal`
of the '0' axis and let '1' be orthogonal. See `addLocalSectionDV`
for a more detailed description.

ivol : integer
Expand Down Expand Up @@ -4232,7 +4249,7 @@ def sectionFrame(self, sectionIndex, sectionTransform, sectionLink, ivol=0, orie
class geoDVGlobal(object):
def __init__(self, dv_name, value, lower, upper, scale, function, config):
"""Create a geometric design variable (or design variable group)
See addGeoDVGlobal in DVGeometry class for more information
See addGlobalDV in DVGeometry class for more information
"""
self.name = dv_name
self.value = np.atleast_1d(np.array(value)).astype("D")
Expand Down Expand Up @@ -4269,7 +4286,7 @@ def __init__(self, dvName, lower, upper, scale, axis, coefListIn, mask, config):
"""Create a set of geometric design variables which change the shape
of a surface surface_id. Local design variables change the surface
in all three axis.
See addGeoDVLocal for more information
See addLocalDV for more information
"""

coefList = []
Expand Down Expand Up @@ -4372,7 +4389,7 @@ def __init__(self, dvName, lower, upper, scale, axis, vol_dv_to_coefs, mask, con
"""Create a set of geometric design variables which change the shape
of a surface surface_id. Local design variables change the surface
in all three axis.
See addGeoDVLocal for more information
See addLocalDV for more information
"""

self.dv_to_coefs = []
Expand Down Expand Up @@ -4464,7 +4481,7 @@ def __init__(self, dvName, lower, upper, scale, axis, coefListIn, mask, config,
"""
Create a set of geometric design variables which change the shape
of a surface.
See `addGeoDVSectionLocal` for more information
See `addLocalSectionDV` for more information
"""

self.coefList = []
Expand Down
4 changes: 2 additions & 2 deletions pygeo/DVGeometryAxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ class DVGeometryAxi(DVGeometry):
>>> def twist(val, geo):
>>> geo.rot_z['wing_axis'].coef[:] = val[:]
>>> # Now add this as a global variable:
>>> DVGeo.addGeoDVGlobal('wing_twist', 0.0, twist, lower=-10, upper=10)
>>> DVGeo.addGlobalDV('wing_twist', 0.0, twist, lower=-10, upper=10)
>>> # Now add local (shape) variables
>>> DVGeo.addGeoDVLocal('shape', lower=-0.5, upper=0.5, axis='y')
>>> DVGeo.addLocalDV('shape', lower=-0.5, upper=0.5, axis='y')
>>>
"""

Expand Down
2 changes: 1 addition & 1 deletion pygeo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.5.0"
__version__ = "1.6.0"

from . import geo_utils
from .pyNetwork import pyNetwork
Expand Down
8 changes: 4 additions & 4 deletions tests/reg_tests/test_Blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,24 +284,24 @@ def add_vars(geo, name, translate=False, rotate=None, scale=None, local=None, sl

if translate:
dvName = "translate_{}".format(name)
geo.addGeoDVGlobal(dvName=dvName, value=[0] * 3, func=f_translate)
geo.addGlobalDV(dvName=dvName, value=[0] * 3, func=f_translate)

if rotate is not None:
rot_funcs = {"x": f_rotate_x, "y": f_rotate_y, "z": f_rotate_z, "theta": f_rotate_theta}
assert rotate in rot_funcs.keys()

dvName = "rotate_{}_{}".format(rotate, name)
dvFunc = rot_funcs[rotate]
geo.addGeoDVGlobal(dvName=dvName, value=0, func=dvFunc)
geo.addGlobalDV(dvName=dvName, value=0, func=dvFunc)

if local is not None:
assert local in ["x", "y", "z"]
dvName = "local_{}_{}".format(local, name)
geo.addGeoDVLocal(dvName, axis=local)
geo.addLocalDV(dvName, axis=local)

if slocal:
dvName = "sectionlocal_{}".format(name)
geo.addGeoDVSectionLocal(dvName, secIndex="j", axis=1, orient0="i", orient2="ffd")
geo.addLocalSectionDV(dvName, secIndex="j", axis=1, orient0="i", orient2="ffd")


def f_translate(val, geo):
Expand Down
4 changes: 2 additions & 2 deletions tests/reg_tests/test_Cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def scale_circle(val, geo):
for i in range(nAxPts):
geo.scale["thru"].coef[i] = val[0]

DVGeo.addGeoDVGlobal("scale_circle", func=scale_circle, value=[1])
DVGeo.addGlobalDV("scale_circle", func=scale_circle, value=[1])
DVCon.setDVGeo(DVGeo)

leList = [[0, 0, 0], [-radius / 2, 0, height]]
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_spanwise_dvs(self, train=False, refDeriv=False):
self.make_ffd(ffd_name, radius, height)
DVGeo = DVGeometry(ffd_name)

DVGeo.addGeoDVSpanwiseLocal("shape", "i", lower=-0.5, upper=0.5, axis="y", scale=1.0)
DVGeo.addSpanwiseLocalDV("shape", "i", lower=-0.5, upper=0.5, axis="y", scale=1.0)

size = DVGeo._getNDVSpanwiseLocal()
DVCon.setDVGeo(DVGeo)
Expand Down
30 changes: 15 additions & 15 deletions tests/reg_tests/test_DVConstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def twist(val, geo):
for i in range(1, nRefAxPts):
geo.rot_z["wing"].coef[i] = val[i - 1]

DVGeo.addGeoDVGlobal(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo.addGlobalDV(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVConstraints object for the wing
DVCon = DVConstraints()
Expand Down Expand Up @@ -119,8 +119,8 @@ def twist(val, geo):
for i in range(1, nRefAxPts):
geo.rot_z["wing"].coef[i] = val[i - 1]

DVGeo.addGeoDVGlobal(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo.addGlobalDV(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVConstraints object for the wing
DVCon = DVConstraints()
Expand Down Expand Up @@ -694,7 +694,7 @@ def test_13b(self, train=False, refDeriv=False):
handler.root_print("Test 13: PlanarityConstraint, rectangular box")
ffdfile = os.path.join(self.base_path, "../inputFiles/2x1x8_rectangle.xyz")
DVGeo = DVGeometry(ffdfile)
DVGeo.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVConstraints object with a simple plane consisting of 2 triangles
DVCon = DVConstraints()
Expand Down Expand Up @@ -810,8 +810,8 @@ def twist(val, geo):
for i in range(1, nRefAxPts):
geo.rot_z["wing"].coef[i] = val[i - 1]

DVGeo.addGeoDVGlobal(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo.addGlobalDV(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVConstraints object for the wing
DVCon = DVConstraints()
Expand Down Expand Up @@ -863,8 +863,8 @@ def twist(val, geo):
for i in range(1, nRefAxPts):
geo.rot_z["wing"].coef[i] = val[i - 1]

DVGeo.addGeoDVGlobal(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo.addGlobalDV(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVConstraints object for the wing
DVCon = DVConstraints()
Expand Down Expand Up @@ -911,16 +911,16 @@ def twist(val, geo):
for i in range(1, nRefAxPts):
geo.rot_z["wing"].coef[i] = val[i - 1]

DVGeo1.addGeoDVGlobal(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo1.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo1.addGlobalDV(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo1.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVGeo object with a few local thickness variables
DVGeo2 = DVGeometry(ffdfile, name="blobdvgeo")
DVGeo2.addGeoDVLocal("local_2", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo2.addLocalDV("local_2", lower=-0.5, upper=0.5, axis="y", scale=1)

# check that DVGeos with duplicate var names are not allowed
DVGeo3 = DVGeometry(ffdfile)
DVGeo3.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo3.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVConstraints object for the wing
DVCon = DVConstraints()
Expand Down Expand Up @@ -1018,8 +1018,8 @@ def twist(val, geo):
for i in range(1, nRefAxPts):
geo.rot_z["wing"].coef[i] = val[i - 1]

DVGeo1.addGeoDVGlobal(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo1.addGeoDVLocal("local", lower=-0.5, upper=0.5, axis="y", scale=1)
DVGeo1.addGlobalDV(dvName="twist", value=[0] * self.nTwist, func=twist, lower=-10, upper=10, scale=1)
DVGeo1.addLocalDV("local", lower=-0.5, upper=0.5, axis="y", scale=1)

# create a DVConstraints object for the wing
DVCon = DVConstraints()
Expand Down
Loading