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

Adding DVGeometryMulti to MPhys #230

Merged
merged 18 commits into from
Jul 30, 2024
Merged
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
131 changes: 106 additions & 25 deletions pygeo/mphys/mphys_dvgeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openmdao.api import AnalysisError

# Local modules
from .. import DVConstraints, DVGeometry, DVGeometryESP, DVGeometryVSP
from .. import DVConstraints, DVGeometry, DVGeometryESP, DVGeometryMulti, DVGeometryVSP

Check warning on line 8 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L8

Added line #L8 was not covered by tests


# class that actually calls the DVGeometry methods
Expand Down Expand Up @@ -83,6 +83,9 @@
elif info["type"] == "esp":
self.DVGeos.update({name: DVGeometryESP(info["file"], comm=self.comm, name=DVGeoName, **options)})

elif info["type"] == "multi":
self.DVGeos.update({name: DVGeometryMulti(comm=self.comm, **options)})

Check warning on line 87 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L86-L87

Added lines #L86 - L87 were not covered by tests

# add each geometry to the constraints object
for _, DVGeo in self.DVGeos.items():
self.DVCon.setDVGeo(DVGeo, name=DVConName)
Expand Down Expand Up @@ -125,7 +128,39 @@
# next time the jacvec product routine is called
self.update_jac = True

def nom_addChild(self, ffd_file, DVGeoName=None, childName=None):
def nom_addComponent(self, comp, ffd_file, triMesh, DVGeoName=None):

Check warning on line 131 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L131

Added line #L131 was not covered by tests
hajdik marked this conversation as resolved.
Show resolved Hide resolved
hajdik marked this conversation as resolved.
Show resolved Hide resolved
"""
Add a component a DVGeometryMulti object. This is a wrapper for the DVGeoMulti.addComponent method.

Parameters
----------
comp : str
The name of the component.

ffd_file : str
Path to the FFD file for the new DVGeo object for this component.

triMesh : str, optional
Path to the triangulated mesh file for this component.

DVGeoName : str, optional
The name of the DVGeo object to add this component to.
"""

# if we have multiple DVGeos use the one specified by name
DVGeo = self.nom_getDVGeo(DVGeoName=DVGeoName)

Check warning on line 151 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L151

Added line #L151 was not covered by tests

# can only add a DVGeo to a DVGeoMulti
if not isinstance(DVGeo, DVGeometryMulti):
raise RuntimeError(

Check warning on line 155 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L154-L155

Added lines #L154 - L155 were not covered by tests
f"Only multi-based DVGeo objects can have components added to them, not type:{self.geo_type}"
)

# Add component
DVGeoComp = DVGeometry(ffd_file)
sseraj marked this conversation as resolved.
Show resolved Hide resolved
DVGeo.addComponent(comp=comp, DVGeo=DVGeoComp, triMesh=triMesh)

Check warning on line 161 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L160-L161

Added lines #L160 - L161 were not covered by tests

def nom_addChild(self, ffd_file, DVGeoName=None, childName=None, comp=None):

Check warning on line 163 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L163

Added line #L163 was not covered by tests
# if we have multiple DVGeos use the one specified by name
DVGeo = self.nom_getDVGeo(DVGeoName=DVGeoName)

Expand All @@ -137,24 +172,27 @@

# Add child FFD
child_ffd = DVGeometry(ffd_file, child=True, name=childName)
DVGeo.addChild(child_ffd)

if comp is None:
DVGeo.addChild(child_ffd)

Check warning on line 177 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L176-L177

Added lines #L176 - L177 were not covered by tests
else:
DVGeo.DVGeoDict[comp].addChild(child_ffd)

Check warning on line 179 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L179

Added line #L179 was not covered by tests

# Embed points from parent if not already done
for pointSet in DVGeo.points:
if pointSet not in child_ffd.points:
child_ffd.addPointSet(DVGeo.points[pointSet], pointSet)

def nom_add_discipline_coords(self, discipline, points=None, DVGeoName=None):
def nom_add_discipline_coords(self, discipline, points=None, DVGeoName=None, **kwargs):

Check warning on line 186 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L186

Added line #L186 was not covered by tests
# TODO remove one of these methods to keep only one method to add pointsets

if points is None:
# no pointset info is provided, just do a generic i/o. We will add these points during the first compute
self.add_input("x_%s_in" % discipline, distributed=True, shape_by_conn=True)
self.add_output("x_%s0" % discipline, distributed=True, copy_shape="x_%s_in" % discipline)

else:
# we are provided with points. we can do the full initialization now
self.nom_addPointSet(points, "x_%s0" % discipline, add_output=False, DVGeoName=DVGeoName)
self.nom_addPointSet(points, "x_%s0" % discipline, add_output=False, DVGeoName=DVGeoName, **kwargs)

Check warning on line 195 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L195

Added line #L195 was not covered by tests
self.add_input("x_%s_in" % discipline, distributed=True, val=points.flatten())
self.add_output("x_%s0" % discipline, distributed=True, val=points.flatten())

Expand Down Expand Up @@ -182,18 +220,21 @@
for k, v in point_dict.items():
self.nom_addPointSet(v, k)

def nom_getDVGeo(self, childName=None, DVGeoName=None):
def nom_getDVGeo(self, childName=None, comp=None, DVGeoName=None):

Check warning on line 223 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L223

Added line #L223 was not covered by tests
"""
Gets the DVGeometry object held in the geometry component so DVGeo methods can be called directly on it

Parameters
----------
DVGeoName : string, optional
The name of the DVGeo to return, necessary if there are multiple DVGeo objects

childName : str, optional
Name of the child FFD, if you want a child DVGeo returned

comp : str, optional
Name of the DVGeoMulti component, if this DV is for a multi component

DVGeoName : str, optional
The name of the DVGeo to return, necessary if there are multiple DVGeo objects

Returns
-------
DVGeometry object
Expand All @@ -205,14 +246,22 @@
else:
DVGeo = self.DVGeos["defaultDVGeo"]

# return the top level DVGeo
if childName is None:
return DVGeo
# return a child of a DVGeoMulti component
if childName is not None and comp is not None:
return DVGeo.DVGeoDict[comp].children[childName]

Check warning on line 251 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L250-L251

Added lines #L250 - L251 were not covered by tests

# return a child DVGeo
else:
# return a component of a DVGeoMulti
elif comp is not None:
return DVGeo.DVGeoDict[comp]

Check warning on line 255 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L254-L255

Added lines #L254 - L255 were not covered by tests

# return a child of a DVGeo
elif childName is not None:

Check warning on line 258 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L258

Added line #L258 was not covered by tests
return DVGeo.children[childName]

# return the top level DVGeo
hajdik marked this conversation as resolved.
Show resolved Hide resolved
else:
return DVGeo

Check warning on line 263 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L263

Added line #L263 was not covered by tests

def nom_getDVCon(self):
"""
Gets the DVConstraints object held in the geometry component so DVCon methods can be called directly on it
Expand All @@ -229,7 +278,16 @@
"""

def nom_addGlobalDV(
self, dvName, value, func, childName=None, isComposite=False, DVGeoName=None, prependName=False, config=None
self,
dvName,
value,
func,
childName=None,
comp=None,
isComposite=False,
DVGeoName=None,
prependName=False,
config=None,
):
"""
Add a global design variable to the DVGeo object. This is a wrapper for the DVGeo.addGlobalDV method.
Expand All @@ -248,6 +306,9 @@
childName : str, optional
Name of the child FFD, if this DV is for a child FFD.

comp : str, optional
Name of the DVGeoMulti component, if this DV is for a multi component

isComposite : bool, optional
Whether this DV is to be included in the composite DVs, by default False

Expand All @@ -261,10 +322,10 @@
"""

# if we have multiple DVGeos use the one specified by name
DVGeo = self.nom_getDVGeo(childName=childName, DVGeoName=DVGeoName)
DVGeo = self.nom_getDVGeo(childName=childName, comp=comp, DVGeoName=DVGeoName)

Check warning on line 325 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L325

Added line #L325 was not covered by tests

# global DVs are only added to FFD-based DVGeo objects
if not isinstance(DVGeo, DVGeometry):
if not isinstance(DVGeo, (DVGeometry, DVGeometryMulti)):

Check warning on line 328 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L328

Added line #L328 was not covered by tests
raise RuntimeError(f"Only FFD-based DVGeo objects can use global DVs, not type: {type(DVGeo).__name__}")

# if this DVGeo object has a name attribute, prepend it to match up with what DVGeo is expecting
Expand All @@ -287,17 +348,18 @@
axis="y",
pointSelect=None,
childName=None,
comp=None,
isComposite=False,
DVGeoName=None,
prependName=False,
volList=None,
config=None,
):
# if we have multiple DVGeos use the one specified by name
DVGeo = self.nom_getDVGeo(childName=childName, DVGeoName=DVGeoName)
DVGeo = self.nom_getDVGeo(childName=childName, comp=comp, DVGeoName=DVGeoName)

Check warning on line 359 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L359

Added line #L359 was not covered by tests

# local DVs are only added to FFD-based DVGeo objects
if not isinstance(DVGeo, DVGeometry):
if not isinstance(DVGeo, (DVGeometry, DVGeometryMulti)):

Check warning on line 362 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L362

Added line #L362 was not covered by tests
raise RuntimeError(f"Only FFD-based DVGeo objects can use local DVs, not type: {type(DVGeo).__name__}")

# if this DVGeo object has a name attribute, prepend it to match up with what DVGeo is expecting
Expand All @@ -322,6 +384,7 @@
dvName,
secIndex,
childName=None,
comp=None,
axis=1,
pointSelect=None,
volList=None,
Expand All @@ -347,6 +410,9 @@
childName : str, optional
Name of the child FFD, if this DV is for a child FFD.

comp : str, optional
Name of the DVGeoMulti component, if this DV is for a multi component

axis : int, optional
See wrapped

Expand Down Expand Up @@ -383,7 +449,7 @@
DVGeo = self.nom_getDVGeo(childName=childName, DVGeoName=DVGeoName)

# local DVs are only added to FFD-based DVGeo objects
if not isinstance(DVGeo, DVGeometry):
if not isinstance(DVGeo, (DVGeometry, DVGeometryMulti)):

Check warning on line 452 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L452

Added line #L452 was not covered by tests
raise RuntimeError(
f"Only FFD-based DVGeo objects can use local section DVs, not type: {type(DVGeo).__name__}"
)
Expand All @@ -402,7 +468,9 @@
self.add_input(dvName, distributed=False, shape=nVal)
return nVal

def nom_addShapeFunctionDV(self, dvName, shapes, childName=None, config=None, DVGeoName=None, prependName=False):
def nom_addShapeFunctionDV(

Check warning on line 471 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L471

Added line #L471 was not covered by tests
self, dvName, shapes, childName=None, comp=None, config=None, DVGeoName=None, prependName=False
):
"""
Add one or more local shape function design variables to the DVGeometry object
Wrapper for :meth:`addShapeFunctionDV <.DVGeometry.addShapeFunctionDV>`
Expand All @@ -419,6 +487,9 @@
childName : str, optional
Name of the child FFD, if this DV is for a child FFD.

comp : str, optional
Name of the DVGeoMulti component, if this DV is for a multi component

config : str or list, optional
See wrapped

Expand Down Expand Up @@ -522,6 +593,7 @@
self,
name,
childName=None,
comp=None,
DVGeoName=None,
curve=None,
xFraction=None,
Expand All @@ -542,10 +614,10 @@
# But doing this may create backward incompatibility. So we will use `volumes` for now

# if we have multiple DVGeos use the one specified by name
DVGeo = self.nom_getDVGeo(childName=childName, DVGeoName=DVGeoName)
DVGeo = self.nom_getDVGeo(childName=childName, comp=comp, DVGeoName=DVGeoName)

Check warning on line 617 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L617

Added line #L617 was not covered by tests

# references axes are only needed in FFD-based DVGeo objects
if not isinstance(DVGeo, DVGeometry):
if not isinstance(DVGeo, (DVGeometry, DVGeometryMulti)):

Check warning on line 620 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L620

Added line #L620 was not covered by tests
raise RuntimeError(f"Only FFD-based DVGeo objects can use reference axes, not type: {type(DVGeo).__name__}")

# add ref axis to this DVGeo
Expand Down Expand Up @@ -914,7 +986,16 @@
d_inputs[dvname] += jvtmp

for _, DVGeo in self.DVGeos.items():
for ptSetName in DVGeo.ptSetNames:
if isinstance(DVGeo, DVGeometryMulti):
ptSetNames = []
for comp in DVGeo.DVGeoDict.keys():
for ptSet in DVGeo.DVGeoDict[comp].ptSetNames:
if ptSet not in ptSetNames:
ptSetNames.append(ptSet)

Check warning on line 994 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L989-L994

Added lines #L989 - L994 were not covered by tests
else:
ptSetNames = DVGeo.ptSetNames

Check warning on line 996 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L996

Added line #L996 was not covered by tests

for ptSetName in ptSetNames:

Check warning on line 998 in pygeo/mphys/mphys_dvgeo.py

View check run for this annotation

Codecov / codecov/patch

pygeo/mphys/mphys_dvgeo.py#L998

Added line #L998 was not covered by tests
if ptSetName in self.omPtSetList:
dout = d_outputs[ptSetName].reshape(len(d_outputs[ptSetName]) // 3, 3)

Expand Down