Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ doc/_build
input_files
.isort.cfg
*.vscode
tests/reg_tests/reports/
tests/reg_tests/test_MPhysGeo*_out
40 changes: 32 additions & 8 deletions pygeo/mphys/mphys_dvgeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def initialize(self):
# since `nom_add_discipline_coords` can be called before `setup`
self.omPtInOutDict = {}

self.update_jac = True

def setup(self):
# create a constraints object to go with this DVGeo(s)
self.DVCon = DVConstraints()
Expand Down Expand Up @@ -225,22 +227,38 @@ def nom_add_discipline_coords(self, discipline, points=None, DVGeoName=None, **k
self.add_input(inputName, distributed=True, val=points.flatten())
self.add_output(outputName, distributed=True, val=points.flatten())

def nom_addPointSet(self, points, ptName, add_output=True, DVGeoName=None, **kwargs):
def nom_addPointSet(self, points, ptName, add_output=True, DVGeoName=None, distributed=True, **kwargs):
"""Add a pointset to the DVGeo object and create an output for it in the OpenMDAO component.

Parameters
----------
points : numpy array
3D points to add to the DVGeo object, shape (N,3) or (3N,)
ptName : str
Name for the pointset
add_output : bool, optional
Whether to add the deformed points as an output of the component, by default True
DVGeoName : str, optional
The name of the DVGeo to add the points to, necessary if there are multiple DVGeo objects. By default `None`.
distributed : bool, optional
Whether the output of the component should be a distributed variable, by default True

Returns
-------
None or float
If using DVGeometryESP or DVGeometryVSP, returns the maximum distance between pointset and the CAD model
"""
# if we have multiple DVGeos use the one specified by name
DVGeo = self.nom_getDVGeo(DVGeoName=DVGeoName)

# add the points to the dvgeo object
dMaxGlobal = None
if isinstance(DVGeo, DVGeometryESP):
# DVGeoESP can return a value to check the pointset distribution
dMaxGlobal = DVGeo.addPointSet(points.reshape(len(points) // 3, 3), ptName, **kwargs)
else:
DVGeo.addPointSet(points.reshape(len(points) // 3, 3), ptName, **kwargs)
# DVGeoESP and DVGeoVSP can return a value to check the pointset distribution
dMaxGlobal = DVGeo.addPointSet(points.reshape(-1, 3), ptName, **kwargs)
self.omPtSetList.append(ptName)

if add_output:
# add an output to the om component
self.add_output(ptName, distributed=True, val=points.flatten())
self.add_output(ptName, distributed=distributed, val=points.flatten())

return dMaxGlobal

Expand Down Expand Up @@ -269,6 +287,12 @@ def nom_getDVGeo(self, childName=None, comp=None, DVGeoName=None):
DVGeometry object
DVGeometry object held by this geometry component
"""
# Calling this function before setup is not allowed because the DVGeo object(s) do not exist yet
if not hasattr(self, "DVGeos"):
raise RuntimeError(
"Cannot call `nom_getDVGeo` before OM_DVGEOCOMP's `setup` method has been called. If you are calling this function in the `setup` method of a group containing an OM_DVGEOCOMP, move the call to `configure` instead."
) from None

# if we have multiple DVGeos use the one specified by name
if self.multDVGeo:
DVGeo = self.DVGeos[DVGeoName]
Expand Down
21 changes: 18 additions & 3 deletions tests/reg_tests/test_MPhysGeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def configure(self):

self.add_constraint(f"geometry.{ptName}")

self.prob = Problem(model=FFDGroup())
self.prob = Problem(model=FFDGroup(), reports=False)

def test_run_model(self):
self.prob.setup()
Expand Down Expand Up @@ -404,7 +404,7 @@ def twist(val, geo):
self.add_design_var("local")
self.add_objective(paramKwargs["name"])

p = Problem(model=BoxGeo())
p = Problem(model=BoxGeo(), reports=False)
return p

def test_undeformed_vals(self):
Expand Down Expand Up @@ -529,7 +529,7 @@ def configure(self):

self.add_constraint(f"geometry.{ptName}")

self.prob = Problem(model=ESPGroup())
self.prob = Problem(model=ESPGroup(), reports=False)

def test_run_model(self):
self.prob.setup()
Expand Down Expand Up @@ -562,5 +562,20 @@ def test_deriv_rev(self):
commonUtils.assert_check_totals(totals, atol=1e-5, rtol=1e-5)


@unittest.skipUnless(omInstalled, "OpenMDAO is required to test the pyGeo MPhys wrapper")
class TestGetDVGeoError(unittest.TestCase):
# Make sure we get an error if we try to call nom_getDVGeo before setup
def test_getDVGeo_error(self):
class BadGroup(Group):
def setup(self):
geometryComp = OM_DVGEOCOMP(file=outerFFD, type="ffd")
self.add_subsystem("geometry", geometryComp, promotes=["*"])
geometryComp.nom_getDVGeo()

prob = Problem(model=BadGroup(), reports=False)
with self.assertRaises(RuntimeError):
prob.setup()


if __name__ == "__main__":
unittest.main()