From 3e6680cf6b80ea99e26ac43573fba488f2c87856 Mon Sep 17 00:00:00 2001 From: arshsaja Date: Wed, 18 Jan 2023 11:03:17 -0500 Subject: [PATCH] minor changes --- pygeo/mphys/mphys_dvgeo.py | 39 +++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/pygeo/mphys/mphys_dvgeo.py b/pygeo/mphys/mphys_dvgeo.py index 7cf4c542..9abdaeca 100644 --- a/pygeo/mphys/mphys_dvgeo.py +++ b/pygeo/mphys/mphys_dvgeo.py @@ -1,5 +1,6 @@ import openmdao.api as om from .. import DVGeometry, DVConstraints +from ..constraints.baseConstraint import LinearConstraint try: from .. import DVGeometryVSP @@ -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 @@ -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}") @@ -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 @@ -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}") @@ -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}") @@ -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