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

Fix shape handling in nom_addGlobalDV #194

Merged
merged 11 commits into from
Apr 21, 2023
Merged
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
1 change: 1 addition & 0 deletions doc/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This package consists of the following modules:
:maxdepth: 1

DVConstraints
mphys_dvgeo
DVGeometry
DVGeometryMulti
DVGeometryESP
Expand Down
13 changes: 12 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@
)

# mock import for autodoc
autodoc_mock_imports = ["numpy", "mpi4py", "scipy", "pyspline", "baseclasses", "pysurf", "prefoil", "pyOCSM", "openvsp"]
autodoc_mock_imports = [
"numpy",
"mpi4py",
"scipy",
"pyspline",
"baseclasses",
"pysurf",
"prefoil",
"pyOCSM",
"openvsp",
"openmdao",
]

# This sets the bibtex bibliography file(s) to reference in the documentation
bibtex_bibfiles = ["ref.bib"]
6 changes: 6 additions & 0 deletions doc/mphys_dvgeo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _OM_DVGEOCOMP:

MPhys DVGeo Component
---------------------
.. autoclass:: pygeo.mphys.mphys_dvgeo.OM_DVGEOCOMP
:members:
40 changes: 34 additions & 6 deletions pygeo/mphys/mphys_dvgeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,49 @@ def nom_add_point_dict(self, point_dict):
self.nom_addPointSet(v, k)

def nom_addGlobalDV(self, dvName, value, func, childIdx=None, isComposite=False):
"""Add a global design variable to the DVGeo object. This is a wrapper for the DVGeo.addGlobalDV method.

Parameters
----------
dvName : str
See :meth:`addGlobalDV <.DVGeometry.addGlobalDV>`

value : float, or iterable list of floats
See :meth:`addGlobalDV <.DVGeometry.addGlobalDV>`

func : python function
See :meth:`addGlobalDV <.DVGeometry.addGlobalDV>`

childIdx : int, optional
The zero-based index of the child FFD, if this DV is for a child FFD.
The index is defined by the order in which you add the child FFD to the parent.
For example, the first child FFD has an index of 0, the second an index of 1, and so on.

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

Raises
------
RuntimeError
Raised if the underlying DVGeo object is not an FFD
"""
# 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. 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
if childIdx is None:
self.DVGeo.addGlobalDV(dvName, value, func)
shape = self.DVGeo.DV_listGlobal[dvName].nVal
else:
self.DVGeo.children[childIdx].addGlobalDV(dvName, value, func)
shape = self.DVGeo.children[childIdx].DV_listGlobal[dvName].nVal

# 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, val=value, distributed=False, shape=shape)

def nom_addLocalDV(self, dvName, axis="y", pointSelect=None, childIdx=None, isComposite=False):
# local DVs are only added to FFD-based DVGeo objects
Expand Down