Last active
July 27, 2020 20:11
-
-
Save bbrelje/de79ffcbb62e6f339bb5649be05a3228 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openmdao.api as om | |
import numpy as np | |
class WorkingGroup(om.Group): | |
def setup(self): | |
iv = self.add_subsystem('iv', om.IndepVarComp('x2', val=3.0*np.ones((2,)))) | |
iv.add_output('x', 2.0) | |
self.add_subsystem('ec1', om.ExecComp('y=x', x={'value':1.0})) | |
self.add_subsystem('ec2', om.ExecComp('y2=x2', y2={'value':np.ones((2,))}, x2={'value':np.ones((2,))})) | |
self.connect('iv.x2', 'ec2.x2') | |
self.connect('iv.x', 'ec1.x') | |
self.set_order(['iv','ec2','ec1']) | |
class BrokenGroup(om.Group): | |
def setup(self): | |
iv = self.add_subsystem('iv', om.IndepVarComp('x2', val=3.0*np.ones((2,)))) | |
iv.add_output('x', 2.0) | |
self.add_subsystem('ec1', om.ExecComp('y=x', x={'value':1.0})) | |
self.add_subsystem('ec2', om.ExecComp('y2=x2', y2={'value':np.ones((2,))}, x2={'value':np.ones((2,))})) | |
self.connect('iv.x2', 'ec2.x2') | |
self.connect('iv.x', 'ec1.x') | |
def configure(self): | |
self.set_order(['iv','ec2','ec1']) | |
class PotentiallyScaryGroup(om.Group): | |
def setup(self): | |
iv = self.add_subsystem('iv', om.IndepVarComp('x2', val=3.0)) | |
iv.add_output('x', 2.0) | |
self.add_subsystem('ec1', om.ExecComp('y=x', x={'value':1.0})) | |
self.add_subsystem('ec2', om.ExecComp('y2=x2', x2={'value':1.0})) | |
self.connect('iv.x2', 'ec2.x2') | |
self.connect('iv.x', 'ec1.x') | |
def configure(self): | |
self.set_order(['iv','ec2','ec1']) | |
if __name__ == "__main__": | |
print('================ Run a group that works - reorder done in setup') | |
prob = om.Problem(WorkingGroup()) | |
prob.setup() | |
prob.run_model() | |
prob.model.list_inputs(print_arrays=True) | |
print('================ Run a group that shows values go to the right place when the dimensions match - reorder done in configure') | |
prob = om.Problem(PotentiallyScaryGroup()) | |
prob.setup() | |
prob.run_model() | |
prob.model.list_inputs(print_arrays=True) | |
print('================ Run a group that fails - reorder done in configure') | |
prob = om.Problem(BrokenGroup()) | |
prob.setup() | |
prob.run_model() | |
prob.model.list_inputs(print_arrays=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment