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

ESP Version Update #132

Merged
merged 9 commits into from
Apr 7, 2022
2 changes: 1 addition & 1 deletion .github/test_real.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e
./input_files/get-input-files.sh

# all tests should pass on private
if [[ $IMAGE == "private" ]] && [[ $OS == "ubuntu" ]]; then
if [[ $OS == "ubuntu" ]]; then
EXTRA_FLAGS='--disallow_skipped'
fi

Expand Down
2 changes: 1 addition & 1 deletion pygeo/constraints/areaConstraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def evalFunctionsSens(self, funcsSens, config):
# for j in range(3):
# areas(i) = areas(i) + crosses(i, j)**2
# areas[i] = np.sum(crosses[i, :]**2)
areas = np.sum(crosses ** 2, axis=1)
areas = np.sum(crosses**2, axis=1)
for i in range(self.n): # DO i=1,n
if areas[i] == 0.0:
areasb[i] = 0.0
Expand Down
20 changes: 10 additions & 10 deletions pygeo/constraints/radiusConstraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,24 @@ def computeCircle(self, coords):
# Compute the radius of curvature
A = xi1 * (eta2 - eta3) - eta1 * (xi2 - xi3) + xi2 * eta3 - xi3 * eta2
B = (
(xi1 ** 2 + eta1 ** 2) * (eta3 - eta2)
+ (xi2 ** 2 + eta2 ** 2) * (eta1 - eta3)
+ (xi3 ** 2 + eta3 ** 2) * (eta2 - eta1)
(xi1**2 + eta1**2) * (eta3 - eta2)
+ (xi2**2 + eta2**2) * (eta1 - eta3)
+ (xi3**2 + eta3**2) * (eta2 - eta1)
)
C = (
(xi1 ** 2 + eta1 ** 2) * (xi2 - xi3)
+ (xi2 ** 2 + eta2 ** 2) * (xi3 - xi1)
+ (xi3 ** 2 + eta3 ** 2) * (xi1 - xi2)
(xi1**2 + eta1**2) * (xi2 - xi3)
+ (xi2**2 + eta2**2) * (xi3 - xi1)
+ (xi3**2 + eta3**2) * (xi1 - xi2)
)
D = (
(xi1 ** 2 + eta1 ** 2) * (xi3 * eta2 - xi2 * eta3)
+ (xi2 ** 2 + eta2 ** 2) * (xi1 * eta3 - xi3 * eta1)
+ (xi3 ** 2 + eta3 ** 2) * (xi2 * eta1 - xi1 * eta2)
(xi1**2 + eta1**2) * (xi3 * eta2 - xi2 * eta3)
+ (xi2**2 + eta2**2) * (xi1 * eta3 - xi3 * eta1)
+ (xi3**2 + eta3**2) * (xi2 * eta1 - xi1 * eta2)
)

xiC = -B / 2 / A
etaC = -C / 2 / A
r = np.sqrt((B ** 2 + C ** 2 - 4 * A * D) / 4 / A ** 2)
r = np.sqrt((B**2 + C**2 - 4 * A * D) / 4 / A**2)

# Convert center coordinates back
center = origin + nxi * xiC[:, None] + neta * etaC[:, None]
Expand Down
4 changes: 2 additions & 2 deletions pygeo/constraints/thicknessConstraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ def evalFunctionsSens(self, funcsSens, config):

dToCdPt[i, 4 * i, :] = p1b / c / self.ToC0[i]
dToCdPt[i, 4 * i + 1, :] = p2b / c / self.ToC0[i]
dToCdPt[i, 4 * i + 2, :] = (-p3b * t / c ** 2) / self.ToC0[i]
dToCdPt[i, 4 * i + 3, :] = (-p4b * t / c ** 2) / self.ToC0[i]
dToCdPt[i, 4 * i + 2, :] = (-p3b * t / c**2) / self.ToC0[i]
dToCdPt[i, 4 * i + 3, :] = (-p4b * t / c**2) / self.ToC0[i]

funcsSens[self.name] = self.DVGeo.totalSensitivity(dToCdPt, self.name, config=config)

Expand Down
6 changes: 3 additions & 3 deletions pygeo/geo_utils/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ def rotVbyW(V, W, theta):

R = np.zeros((3, 3), dtype)

R[0, 0] = ux ** 2 + (1 - ux ** 2) * c
R[0, 0] = ux**2 + (1 - ux**2) * c
R[0, 1] = ux * uy * (1 - c) - uz * s
R[0, 2] = ux * uz * (1 - c) + uy * s

R[1, 0] = ux * uy * (1 - c) + uz * s
R[1, 1] = uy ** 2 + (1 - uy ** 2) * c
R[1, 1] = uy**2 + (1 - uy**2) * c
R[1, 2] = uy * uz * (1 - c) - ux * s

R[2, 0] = ux * uz * (1 - c) - uy * s
R[2, 1] = uy * uz * (1 - c) + ux * s
R[2, 2] = uz ** 2 + (1 - uz ** 2) * c
R[2, 2] = uz**2 + (1 - uz**2) * c

return np.dot(R, V)

Expand Down
2 changes: 1 addition & 1 deletion pygeo/parameterization/DVGeoAxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, pts, center, collapse_into, isComplex=False, **kwargs):
beta = pts[:, self.beta_idx] - center[self.beta_idx]
gamma = pts[:, self.gamma_idx] - center[self.gamma_idx]

self.radii = np.sqrt(beta ** 2 + gamma ** 2)
self.radii = np.sqrt(beta**2 + gamma**2)
# need to get the real part because arctan2 is not complex save
# but its ok, becuase these are constants
self.thetas = np.arctan2(gamma.real, beta.real)
Expand Down
49 changes: 26 additions & 23 deletions pygeo/parameterization/DVGeoESP.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from collections import OrderedDict
from mpi4py import MPI
from pyOCSM import pyOCSM
from pyOCSM import ocsm
from contextlib import contextmanager
from baseclasses.utils import Error

Expand Down Expand Up @@ -147,13 +147,15 @@ def __init__(

t1 = time.time()
# read the model
self.espModel = pyOCSM.Ocsm(self.espFile)
pyOCSM.SetOutLevel(0)
self.espModel = ocsm.Ocsm(self.espFile)
ocsm.SetOutLevel(0)

# build the baseline model
if self.comm.rank == 0:
pyOCSM.SetOutLevel(0)
ocsm.SetOutLevel(0)
else:
pyOCSM.SetOutLevel(0)
ocsm.SetOutLevel(0)

self.num_branches_baseline, _, allBodyIndices = self.espModel.Build(
0, 200
) # pick 200 as arbitrary large number of bodies to allocate
Expand Down Expand Up @@ -201,24 +203,27 @@ def __init__(
pmtrIndex += 1
pmtrType, numRow, numCol, pmtrName = self.espModel.GetPmtr(pmtrIndex)
baseValue = np.zeros(numRow * numCol)

for rowIdx in range(numRow):
for colIdx in range(numCol):
try:
baseValue[colIdx + numCol * rowIdx] = self.espModel.GetValu(
pmtrIndex, rowIdx + 1, colIdx + 1
)[0]
except pyOCSM.OcsmError as e:
except ocsm.OcsmError as e:
if e.value == "ILLEGAL_PTMR_INDEX":
# I don't think we should ever make it here if the GetPmtr check is correct
raise Error("Column or row index out of range in design parameter " + pmtrName)

if pmtrType == ocsmExternal:
self.csmDesPmtrs[pmtrName] = ESPParameter(pmtrName, pmtrIndex, numRow, numCol, baseValue)
except pyOCSM.OcsmError as e:

except ocsm.OcsmError as e:
if e.value == "ILLEGAL_PMTR_INDEX":
pmtrsleft = False
else:
raise e

if pmtrIndex == 1:
if comm.rank == 0:
print("DVGeometryESP Warning: no design parameters defined in the CSM file")
Expand All @@ -240,7 +245,7 @@ def addPointSet(self, points, ptName, distributed=True, cache_projections=False,
project into the interior of the FFD volume.
ptName : str
A user supplied name to associate with the set of
coordinates. Thisname will need to be provided when
coordinates. This name will need to be provided when
updating the coordinates or when getting the derivatives
of the coordinates.
distributed : bool
Expand All @@ -259,8 +264,7 @@ def addPointSet(self, points, ptName, distributed=True, cache_projections=False,
"""

# save this name so that we can zero out the jacobians properly
self.points[ptName] = True # ADFlow checks self.points to see
# if something is added or not.
self.points[ptName] = True # ADFlow checks self.points to see if something is added or not
points = np.array(points).real.astype("d")

# check that duplicated pointsets are actually the same length
Expand Down Expand Up @@ -471,12 +475,12 @@ def addPointSet(self, points, ptName, distributed=True, cache_projections=False,
# try to match point on edges first
with stdout_redirected(self.suppress_stdout):
# get the parametric coordinate along the edge
ttemp = self.espModel.GetUV(bodyIndex, pyOCSM.EDGE, edgeIndex, 1, truexyz.tolist())
ttemp = self.espModel.GetUV(bodyIndex, ocsm.EDGE, edgeIndex, 1, truexyz.tolist())
# get the xyz location of the newly projected point
xyztemp = np.array(self.espModel.GetXYZ(bodyIndex, pyOCSM.EDGE, edgeIndex, 1, ttemp))
xyztemp = np.array(self.espModel.GetXYZ(bodyIndex, ocsm.EDGE, edgeIndex, 1, ttemp))
dist_temp = np.sum((truexyz - xyztemp) ** 2)
ttemp = ttemp[0]
tlimits = self._getUVLimits(bodyIndex, pyOCSM.EDGE, edgeIndex)
tlimits = self._getUVLimits(bodyIndex, ocsm.EDGE, edgeIndex)
if not (ttemp < tlimits[0] - rejectuvtol or ttemp > tlimits[1] + rejectuvtol):
if dist_temp < dist_best:
tlimits_best = tlimits
Expand All @@ -489,14 +493,14 @@ def addPointSet(self, points, ptName, distributed=True, cache_projections=False,
for faceIndex in range(1, nFaces + 1):
with stdout_redirected(self.suppress_stdout):
# get the projected points on the ESP surface in UV coordinates
uvtemp = self.espModel.GetUV(bodyIndex, pyOCSM.FACE, faceIndex, 1, truexyz.tolist())
uvtemp = self.espModel.GetUV(bodyIndex, ocsm.FACE, faceIndex, 1, truexyz.tolist())
# get the XYZ location of the newly projected points
xyztemp = np.array(self.espModel.GetXYZ(bodyIndex, pyOCSM.FACE, faceIndex, 1, uvtemp))
xyztemp = np.array(self.espModel.GetXYZ(bodyIndex, ocsm.FACE, faceIndex, 1, uvtemp))
dist_temp = np.sum((truexyz - xyztemp) ** 2)
# validate u and v
utemp = uvtemp[0]
vtemp = uvtemp[1]
uvlimits = self._getUVLimits(bodyIndex, pyOCSM.FACE, faceIndex)
uvlimits = self._getUVLimits(bodyIndex, ocsm.FACE, faceIndex)
if not (
utemp < uvlimits[0] - rejectuvtol
or utemp > uvlimits[1] + rejectuvtol
Expand Down Expand Up @@ -596,8 +600,7 @@ def addPointSet(self, points, ptName, distributed=True, cache_projections=False,

def setDesignVars(self, dvDict, updateJacobian=True):
"""
Standard routine for setting design variables from a design
variable dictionary.
Standard routine for setting design variables from a design variable dictionary.

Parameters
----------
Expand Down Expand Up @@ -1035,7 +1038,7 @@ def _getUVLimits(self, ibody, seltype, iselect):
ibody : int
Body index
seltype : int
pyOCSM.EDGE or pyOCSM.FACE
ocsm.EDGE or ocsm.FACE
iselect : int
Index of edge or face

Expand Down Expand Up @@ -1164,26 +1167,26 @@ def _evaluatePoints(self, u, v, t, uvlimits0, tlimits0, bodyID, faceID, edgeID,
# get the point from an edge
# get upper and lower parametric limits of updated model
tlim0 = tlimits0[ptidx]
tlim = self._getUVLimits(bid, pyOCSM.EDGE, eid)
tlim = self._getUVLimits(bid, ocsm.EDGE, eid)
trange0 = tlim0[1] - tlim0[0]
trange = tlim[1] - tlim[0]
tnew = (t[ptidx] - tlim0[0]) * trange / trange0 + tlim[0]
points[ptidx, :] = self.espModel.GetXYZ(bid, pyOCSM.EDGE, eid, 1, [tnew])
points[ptidx, :] = self.espModel.GetXYZ(bid, ocsm.EDGE, eid, 1, [tnew])
else:
# point from a face
if fid == -1:
raise ValueError("both edge ID and face ID are unset")
# get the upper and lower uv limits of the updated model
uvlim0 = uvlimits0[ptidx]
uvlim = self._getUVLimits(bid, pyOCSM.FACE, fid)
uvlim = self._getUVLimits(bid, ocsm.FACE, fid)
urange0 = uvlim0[1] - uvlim0[0]
vrange0 = uvlim0[3] - uvlim0[2]
urange = uvlim[1] - uvlim[0]
vrange = uvlim[3] - uvlim[2]
# scale the input uv points according to the original uv limits
unew = (u[ptidx] - uvlim0[0]) * urange / urange0 + uvlim[0]
vnew = (v[ptidx] - uvlim0[2]) * vrange / vrange0 + uvlim[2]
points[ptidx, :] = self.espModel.GetXYZ(bid, pyOCSM.FACE, fid, 1, [unew, vnew])
points[ptidx, :] = self.espModel.GetXYZ(bid, ocsm.FACE, fid, 1, [unew, vnew])
points = points * self.espScale
return points

Expand Down
6 changes: 3 additions & 3 deletions pygeo/parameterization/DVGeoMulti.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ def update_d(self, ptSetName, dPt, dSeam):
# Do it vectorized
rr = pts[j] - self.seam0
LdefoDist = 1.0 / np.sqrt(rr[:, 0] ** 2 + rr[:, 1] ** 2 + rr[:, 2] ** 2 + 1e-16)
LdefoDist3 = LdefoDist ** 3
LdefoDist3 = LdefoDist**3
Wi = LdefoDist3
den = np.sum(Wi)
interp_d = np.zeros(3)
Expand Down Expand Up @@ -2152,7 +2152,7 @@ def _warpSurfPts(self, pts0, ptsNew, indices, curvePtCoords, delta):
# Vectorized point-based warping
rr = ptCoords - curvePtCoords
LdefoDist = 1.0 / np.sqrt(rr[:, 0] ** 2 + rr[:, 1] ** 2 + rr[:, 2] ** 2 + 1e-16)
LdefoDist3 = LdefoDist ** 3
LdefoDist3 = LdefoDist**3
Wi = LdefoDist3
den = np.sum(Wi)
interp = np.zeros(3)
Expand Down Expand Up @@ -2185,7 +2185,7 @@ def _warpSurfPts_b(self, dIdPt, pts0, indices, curvePtCoords):
# Vectorized point-based warping
rr = ptCoords - curvePtCoords
LdefoDist = 1.0 / np.sqrt(rr[:, 0] ** 2 + rr[:, 1] ** 2 + rr[:, 2] ** 2 + 1e-16)
LdefoDist3 = LdefoDist ** 3
LdefoDist3 = LdefoDist**3
Wi = LdefoDist3
den = np.sum(Wi)

Expand Down
2 changes: 1 addition & 1 deletion pygeo/pyBlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def projectPoints(self, x0, checkErrors, embTol, eps, nIter):
if nrm > DMax:
DMax = nrm

DRms += nrm ** 2
DRms += nrm**2
if nrm > embTol:
counter += 1
badPts.append([x0[i], D[i]])
Expand Down