Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArshSaja committed Jan 18, 2023
1 parent 081bdac commit 3e6680c
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions pygeo/mphys/mphys_dvgeo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import openmdao.api as om
from .. import DVGeometry, DVConstraints
from ..constraints.baseConstraint import LinearConstraint

try:
from .. import DVGeometryVSP
Expand Down Expand Up @@ -141,14 +142,15 @@ def nom_add_point_dict(self, point_dict):
for k, v in point_dict.items():
self.nom_addPointSet(v, k)

def nom_addGlobalDV(self, dvName, value, func, childIdx=None, add_input=True):
def nom_addGlobalDV(self, dvName, value, func, childIdx=None, isComposite=False):
# global DVs are only added to FFD-based DVGeo objects
if self.geo_type != "ffd":
raise RuntimeError(f"Only FFD-based DVGeo objects can use global DVs, not type:{self.geo_type}")

# define the input
# When composite DVs are used, input is not required for the default DVs
if add_input:
# When composite DVs are used, input is not required for the default DVs. Now the composite DVs are
# the actual DVs. So OpenMDAO don't need the default DVs as inputs.
if not isComposite:
self.add_input(dvName, distributed=False, shape=len(value))

# call the dvgeo object and add this dv
Expand All @@ -157,7 +159,7 @@ def nom_addGlobalDV(self, dvName, value, func, childIdx=None, add_input=True):
else:
self.DVGeo.children[childIdx].addGlobalDV(dvName, value, func)

def nom_addLocalDV(self, dvName, axis="y", pointSelect=None, childIdx=None, add_input=True):
def nom_addLocalDV(self, dvName, axis="y", pointSelect=None, childIdx=None, isComposite=False):
# local DVs are only added to FFD-based DVGeo objects
if self.geo_type != "ffd":
raise RuntimeError(f"Only FFD-based DVGeo objects can use local DVs, not type:{self.geo_type}")
Expand All @@ -167,8 +169,10 @@ def nom_addLocalDV(self, dvName, axis="y", pointSelect=None, childIdx=None, add_
else:
nVal = self.DVGeo.children[childIdx].addLocalDV(dvName, axis=axis, pointSelect=pointSelect)

# When composite DVs are used, input is not required for the default DVs
if add_input:
# define the input
# When composite DVs are used, input is not required for the default DVs. Now the composite DVs are
# the actual DVs. So OpenMDAO don't need the default DVs as inputs.
if not isComposite:
self.add_input(dvName, distributed=False, shape=nVal)
return nVal

Expand All @@ -180,7 +184,7 @@ def nom_addGeoCompositeDV(self, dvName, ptSetName=None, u=None, scale=None, **kw
# define the input
self.add_input(dvName, distributed=False, shape=self.DVGeo.getNDV(), val=val[dvName][0])

def nom_addVSPVariable(self, component, group, parm, add_input=True, **kwargs):
def nom_addVSPVariable(self, component, group, parm, isComposite=False, **kwargs):
# VSP DVs are only added to VSP-based DVGeo objects
if self.geo_type != "vsp":
raise RuntimeError(f"Only VSP-based DVGeo objects can use VSP DVs, not type:{self.geo_type}")
Expand All @@ -194,10 +198,13 @@ def nom_addVSPVariable(self, component, group, parm, add_input=True, **kwargs):
# get the value
val = self.DVGeo.DVs[dvName].value.copy()

if add_input:
# define the input
# When composite DVs are used, input is not required for the default DVs. Now the composite DVs are
# the actual DVs. So OpenMDAO don't need the default DVs as inputs.
if not isComposite:
self.add_input(dvName, distributed=False, shape=1, val=val)

def nom_addESPVariable(self, desmptr_name, add_input=True, **kwargs):
def nom_addESPVariable(self, desmptr_name, isComposite=False, **kwargs):
# ESP DVs are only added to VSP-based DVGeo objects
if self.geo_type != "esp":
raise RuntimeError(f"Only ESP-based DVGeo objects can use ESP DVs, not type:{self.geo_type}")
Expand All @@ -209,10 +216,20 @@ def nom_addESPVariable(self, desmptr_name, add_input=True, **kwargs):
val = self.DVGeo.DVs[desmptr_name].value.copy()

# add the input with the correct value, VSP DVs always have a size of 1
# When composite DVs are used, input is not required for the default DVs
if add_input:
# When composite DVs are used, input is not required for the default DVs. Now the composite DVs are
# the actual DVs. So OpenMDAO don't need the default DVs as inputs.
if not isComposite:
self.add_input(desmptr_name, distributed=False, shape=val.shape, val=val)

def nom_addLinearConstraintForComposite(self, name):
self.DVCon.addLinearCompositeConstraint(name)
nval = self.DVGeo.getNDV()
comm = self.comm
if comm.rank == 0:
self.add_output(name, distributed=True, val=np.ones((nval,)), shape=nval)
else:
self.add_output(name, distributed=True, shape=(0,))

def nom_addThicknessConstraints2D(self, name, leList, teList, nSpan=10, nChord=10):
self.DVCon.addThicknessConstraints2D(leList, teList, nSpan, nChord, lower=1.0, name=name)
comm = self.comm
Expand Down

0 comments on commit 3e6680c

Please sign in to comment.