Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/add_mphys' into add_mphys
Browse files Browse the repository at this point in the history
  • Loading branch information
anilyil committed Mar 21, 2022
2 parents 84de2ac + ca40c00 commit e5f1a47
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/azure-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
trigger:
- master
- main

pr:
- master
- main

resources:
repositories:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pyGeo
[![Build Status](https://dev.azure.com/mdolab/Public/_apis/build/status/mdolab.pygeo?branchName=master)](https://dev.azure.com/mdolab/Public/_build/latest?definitionId=17&branchName=master)
[![Build Status](https://dev.azure.com/mdolab/Public/_apis/build/status/mdolab.pygeo?branchName=main)](https://dev.azure.com/mdolab/Public/_build/latest?definitionId=17&branchName=main)
[![Documentation Status](https://readthedocs.com/projects/mdolab-pygeo/badge/?version=latest)](https://mdolab-pygeo.readthedocs-hosted.com/en/latest/?badge=latest)
[![codecov](https://codecov.io/gh/mdolab/pygeo/branch/master/graph/badge.svg?token=N2L58WGCDI)](https://codecov.io/gh/mdolab/pygeo)
[![codecov](https://codecov.io/gh/mdolab/pygeo/branch/main/graph/badge.svg?token=N2L58WGCDI)](https://codecov.io/gh/mdolab/pygeo)

pyGeo is an object oriented geometry manipulation framework for multidisciplinary design optimization.
It provides a free form deformation (FFD) based geometry manipulation object, an interface to NASA's Vehicle Sketch Pad geometry engine, a simple geometric constraint formulation object, and some utility functions for geometry manipulation.
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.9.0"
__version__ = "1.10.0"

from .pyNetwork import pyNetwork
from .pyGeo import pyGeo
Expand Down
6 changes: 3 additions & 3 deletions pygeo/constraints/areaConstraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def getVarNames(self):
variables, but some constraints may extend this to include other variables.
"""
if self.DVGeo1 is not None:
varnamelist = self.DVGeo1.getVarNames()
varnamelist = self.DVGeo1.getVarNames(pyOptSparse=True)
if self.DVGeo2 is not None:
varnamelist.extend(self.DVGeo2.getVarNames())
varnamelist.extend(self.DVGeo2.getVarNames(pyOptSparse=True))
else:
varnamelist = self.DVGeo2.getVarNames()
varnamelist = self.DVGeo2.getVarNames(pyOptSparse=True)

return varnamelist

Expand Down
29 changes: 28 additions & 1 deletion pygeo/constraints/baseConstraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Imports
# ======================================================================
from abc import ABC, abstractmethod
from collections import OrderedDict
import numpy as np
from baseclasses.utils import Error

Expand Down Expand Up @@ -56,7 +57,7 @@ def getVarNames(self):
return the var names relevant to this constraint. By default, this is the DVGeo
variables, but some constraints may extend this to include other variables.
"""
return self.DVGeo.getVarNames()
return self.DVGeo.getVarNames(pyOptSparse=True)

def addConstraintsPyOpt(self, optProb, exclude_wrt=None):
"""
Expand Down Expand Up @@ -256,6 +257,32 @@ def _finalize(self):
# with-respect-to are just the keys of the jacobian
self.wrt = list(self.jac.keys())

# now map the jac to composite domain:
# we assume jac is always only wrt "local" DVs
if self.DVGeo.useComposite:
nDV = self.DVGeo.getNDV()
# for the jac, we need to "pad" the rest of the matrix with zero, then perform mat-mat product
newJac = np.zeros((self.ncon, nDV))
for i in range(self.ncon):
temp_dict = {}
# all_DVs just contains all the DVs so we can loop over them easily
all_DVs = OrderedDict({})
all_DVs.update(self.DVGeo.DV_listGlobal)
all_DVs.update(self.DVGeo.DV_listLocal)
all_DVs.update(self.DVGeo.DV_listSectionLocal)
all_DVs.update(self.DVGeo.DV_listSpanwiseLocal)

for dv in all_DVs.keys():
if dv in self.wrt:
temp_dict[dv] = self.jac[dv][i, :].flatten()
else:
temp_dict[dv] = np.zeros(all_DVs[dv].nVal)
newJac[i, :] = self.DVGeo.convertDictToSensitivity(temp_dict)
# now multiply by the mapping
newJac = newJac @ self.DVGeo.DVComposite.u
self.jac = {self.DVGeo.DVComposite.name: newJac}
self.wrt = [self.DVGeo.DVComposite.name]

def writeTecplot(self, handle):
"""
Write the visualization of this set of lete constraints
Expand Down
4 changes: 2 additions & 2 deletions pygeo/constraints/thicknessConstraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, name, coords, lower, upper, scaled, scale, DVGeo, addToPyOpt,
# Now get the reference lengths
self.D0 = np.zeros(self.nCon)
for i in range(self.nCon):
self.D0[i] = np.linalg.norm(self.coords[2 * i] - self.coords[2 * i + 1])
self.D0[i] = geo_utils.norm.euclideanNorm(self.coords[2 * i] - self.coords[2 * i + 1])

def evalFunctions(self, funcs, config):
"""
Expand All @@ -42,7 +42,7 @@ def evalFunctions(self, funcs, config):
self.coords = self.DVGeo.update(self.name, config=config)
D = np.zeros(self.nCon)
for i in range(self.nCon):
D[i] = np.linalg.norm(self.coords[2 * i] - self.coords[2 * i + 1])
D[i] = geo_utils.norm.euclideanNorm(self.coords[2 * i] - self.coords[2 * i + 1])
if self.scaled:
D[i] /= self.D0[i]
funcs[self.name] = D
Expand Down
4 changes: 3 additions & 1 deletion pygeo/geo_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def convertTo1D(value, dim1):
if temp.shape[0] == dim1:
return value
else:
raise ValueError("The size of the 1D array was the incorrect shape")
raise ValueError(
"The size of the 1D array was the incorrect shape! " + f"Expected {dim1} but got {temp.size}"
)


def convertTo2D(value, dim1, dim2):
Expand Down
6 changes: 1 addition & 5 deletions pygeo/geo_utils/norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ def euclideanNorm(inVec):
CS derivatives.
"""
inVec = np.array(inVec)
temp = 0.0
for i in range(inVec.shape[0]):
temp += inVec[i] ** 2

return np.sqrt(temp)
return np.sqrt(inVec.dot(inVec))


def cross_b(a, b, crossb):
Expand Down
Loading

0 comments on commit e5f1a47

Please sign in to comment.