本文整理汇总了Python中openmdao.main.api.Assembly.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Assembly.connect方法的具体用法?Python Assembly.connect怎么用?Python Assembly.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openmdao.main.api.Assembly
的用法示例。
在下文中一共展示了Assembly.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nested_2Darray_simul_element_and_full_connection
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_nested_2Darray_simul_element_and_full_connection(self):
top = Assembly()
top.add('comp', ArrayComp2D())
top.add('nest', Assembly())
top.nest.add('comp', ArrayComp2D())
top.driver.gradient_options.lin_solver = 'petsc_ksp'
top.nest.driver.gradient_options.lin_solver = 'petsc_ksp'
top.nest.driver.workflow.add(['comp'])
top.nest.create_passthrough('comp.x')
top.nest.create_passthrough('comp.y')
top.add('driver', SimpleDriver())
top.driver.workflow.add(['nest', 'comp'])
top.connect('nest.y', 'comp.x')
top.driver.add_parameter('nest.x[0][0]', low=-10, high=10)
top.driver.add_objective('comp.y[0][0]')
top.driver.add_constraint('nest.y[0][1] < 0')
top.run()
J = top.driver.calc_gradient(mode='forward')
assert_rel_error(self, J[0, 0], 24.0, .000001)
assert_rel_error(self, J[1, 0], 4.0, .000001)
J = top.driver.calc_gradient(mode='adjoint')
assert_rel_error(self, J[0, 0], 24.0, .000001)
assert_rel_error(self, J[1, 0], 4.0, .000001)
J = top.driver.calc_gradient(mode='fd')
assert_rel_error(self, J[0, 0], 24.0, .000001)
assert_rel_error(self, J[1, 0], 4.0, .000001)
示例2: test_linearGS_simul_element_and_full_connection
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_linearGS_simul_element_and_full_connection(self):
# Added because of a bug with array slices for Linear GS
top = Assembly()
top.add('comp1', ArrayComp2D())
top.add('comp2', ArrayComp2D())
top.add('driver', SimpleDriver())
top.driver.workflow.add(['comp1', 'comp2'])
top.connect('comp1.y', 'comp2.x')
top.driver.add_parameter('comp1.x[0][0]', low=-10, high=10)
top.driver.add_objective('comp1.y[0][0]')
top.driver.add_constraint('comp2.y[0][1] < 0')
top.driver.gradient_options.lin_solver = 'linear_gs'
top.driver.gradient_options.maxiter = 1
top.run()
J = top.driver.calc_gradient(mode='forward')
assert_rel_error(self, J[0, 0], 2.0, .000001)
assert_rel_error(self, J[1, 0], 39.0, .000001)
J = top.driver.calc_gradient(mode='adjoint')
assert_rel_error(self, J[0, 0], 2.0, .000001)
assert_rel_error(self, J[1, 0], 39.0, .000001)
示例3: GeomTestCase
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
class GeomTestCase(unittest.TestCase):
def setUp(self):
"""this setup function will be called before each test in this class"""
self.top = Assembly()
self.top.add('g1', GeoSource())
self.top.add('g2', GeoSink())
self.top.connect('g1.g_out', 'g2.g_inp')
self.top.driver.workflow.add(['g1', 'g2'])
def tearDown(self):
"""this teardown function will be called after each test"""
self.top = None
def testGeom(self):
self.top.run()
self.assertEqual(1, self.top.g2.g_inp.get_tessellation())
try:
self.top.g2.g_extra = "hey"
except TypeError as err:
msg = "g2 (1-2): g_extra must provide interface 'IStaticGeometry'"
self.assertEqual(str(err), msg)
else:
self.fail("exception expected")
示例4: _create_assembly
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def _create_assembly(self, dbname, drivertype):
asm = Assembly()
driver = asm.add('driver', drivertype())
asm.add('comp1', TracedExecComp(exprs=['z=x+y']))
asm.add('comp2', TracedExecComp(exprs=['z=x+y']))
asm.connect('comp1.z', 'comp2.x')
driver.workflow.add(['comp1', 'comp2'])
asm.recorders = [DBCaseRecorder(dbname, append=True)]
return asm
示例5: _create_assembly
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def _create_assembly(self, dbname, drivertype):
asm = Assembly()
driver = asm.add("driver", drivertype())
asm.add("comp1", ExecComp(exprs=["z=x+y"]))
asm.add("comp2", ExecComp(exprs=["z=x+y"]))
asm.connect("comp1.z", "comp2.x")
driver.workflow.add(["comp1", "comp2"])
driver.recorders = [DBCaseRecorder(dbname, append=True)]
return asm
示例6: _create_assembly
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def _create_assembly(self, dbname):
asm = Assembly()
driver = asm.add('driver', SimpleCaseIterDriver())
asm.add('comp1', ExecComp(exprs=['z=x+y']))
asm.add('comp2', ExecComp(exprs=['z=x+y']))
asm.connect('comp1.z', 'comp2.x')
driver.workflow.add(['comp1', 'comp2'])
driver.recorder = DBCaseRecorder(dbname, append=True)
return asm
示例7: test_multiconnect
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_multiconnect(self):
top = Assembly()
for name in ("m1", "m2", "m3"):
top.add(name, Multiplier())
top.driver.workflow.add(name)
top.connect("m1.rval_out", ("m2.mult", "m3.mult"))
top.m1.rval_in = 1.0
top.m2.rval_in = 3.0
top.m3.rval_in = 4.0
top.run()
self.assertEqual(top.m2.rval_out, 4.5)
self.assertEqual(top.m3.rval_out, 6.0)
示例8: test_multiconnect
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_multiconnect(self):
top = Assembly()
for name in ('m1', 'm2', 'm3'):
top.add(name, Multiplier())
top.driver.workflow.add(name)
top.connect('m1.rval_out', ('m2.mult', 'm3.mult'))
top.m1.rval_in = 1.
top.m2.rval_in = 3.
top.m3.rval_in = 4.
top.run()
self.assertEqual(top.m2.rval_out, 4.5)
self.assertEqual(top.m3.rval_out, 6.)
示例9: test_scid2
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_scid2(self):
logging.debug('')
logging.debug('test_simplecid')
top = Assembly()
top.add('generator', Generator())
cid = top.add('cid', SimpleCaseIterDriver())
top.add('driven', DrivenComponent())
top.add('verifier', Verifier())
top.driver.workflow.add(('generator', 'cid', 'verifier'))
cid.workflow.add('driven')
cid.add_parameter('driven.x')
cid.add_parameter('driven.y')
cid.add_response('driven.rosen_suzuki')
cid.add_response('driven.sum_y')
top.connect('generator.x', 'cid.case_inputs.driven.x')
top.connect('generator.y', 'cid.case_inputs.driven.y')
top.connect('generator.x', 'verifier.x')
top.connect('generator.y', 'verifier.y')
top.connect('cid.case_outputs.driven.rosen_suzuki', 'verifier.rosen_suzuki')
top.connect('cid.case_outputs.driven.sum_y', 'verifier.sum_y')
top.run()
示例10: test_connections
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_connections(self):
asm = Assembly()
asm.add('dummy1',Dummy())
asm.add('dummy2',Dummy())
asm.add('bcast',Broadcaster(['x']))
asm.connect('dummy1.x','bcast.x_in')
asm.connect('bcast.x','dummy2.y')
self.assertEqual(set(asm.list_connections()),set([('dummy1.x', 'bcast.x_in'), ('bcast.x', 'dummy2.y')]))
asm.bcast.names = ['z']
self.assertEqual(asm.list_connections(),[])
示例11: test_connections
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_connections(self):
logging.debug("")
logging.debug("test_connections")
top = Assembly()
top.add("generator", Generator())
top.add("cid", CaseIteratorDriver())
top.add("driven", DrivenComponent())
top.add("verifier", Verifier())
top.driver.workflow.add(("generator", "cid", "verifier"))
top.cid.workflow.add("driven")
top.cid.printvars = ["driven.extra"]
top.connect("generator.cases", "cid.iterator")
top.connect("cid.evaluated", "verifier.cases")
top.run()
示例12: test_nested
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def test_nested(self):
asm3 = Assembly()
asm3.add('comp1', ExecComp(exprs=['z=x+y']))
driver = asm3.add('driver', SLSQPdriver())
driver.workflow.add('comp1')
driver.add_parameter('comp1.y', low=-1, high=1, start=0)
driver.add_objective('comp1.z')
driver.add_constraint('comp1.z >= 0')
asm3.create_passthrough('comp1.x')
asm3.create_passthrough('comp1.z')
asm2 = Assembly()
asm2.add('comp1', ExecComp(exprs=['z=x+y']))
asm2.add('asm3', asm3)
asm2.connect('comp1.z', 'asm3.x')
driver = asm2.add('driver', SLSQPdriver())
driver.workflow.add(('comp1', 'asm3'))
driver.add_parameter('comp1.y', low=-1, high=1, start=0)
driver.add_objective('asm3.z')
driver.add_constraint('comp1.z >= 0')
asm2.create_passthrough('comp1.x')
asm2.create_passthrough('asm3.z')
asm1 = set_as_top(Assembly())
asm1.add('comp1', ExecComp(exprs=['z=x+y']))
asm1.add('asm2', asm2)
asm1.connect('comp1.z', 'asm2.x')
driver = asm1.add('driver', SLSQPdriver())
driver.workflow.add(('comp1', 'asm2'))
driver.add_parameter('comp1.y', low=-1, high=1, start=0)
driver.add_objective('asm2.z')
driver.add_constraint('comp1.z >= 0')
sout = StringIO()
asm1.recorders = [JSONCaseRecorder(sout)]
asm1.run()
if os.environ.get('REGEN_JSON_FILES'):
with open('nested.new', 'w') as out:
out.write(sout.getvalue())
verify_json(self, sout, 'nested.json')
示例13: execute
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
def execute(self):
""" Calculate the wingsurface from the spar geometry """
# Make sure that input data has the same length
self.verify_input()
for beam in self.eqbeams:
a = Assembly()
# Add a splined blade planform from the input data
a.add('pf_splines', SplinedBladePlanform(True))
a.driver.workflow.add('pf_splines')
a.pf_splines.nC = 3
a.pf_splines.pfIn = beam
a.pf_splines.configure_splines()
a.create_passthrough('pf_splines.blade_length')
a.create_passthrough('pf_splines.span_ni')
a.add('blade_surface', LoftedBladeSurface())
a.driver.workflow.add('blade_surface')
a.connect('pf_splines.pfOut', 'blade_surface.pf')
a.connect('span_ni', 'blade_surface.span_ni')
# load the planform file
a.span_ni = self.span_ni
b = a.blade_surface
# distribute 200 points evenly along the airfoil sections
b.chord_ni = 200
for f in self.airfoils:
b.base_airfoils.append(np.loadtxt(f))
b.blend_var = np.array([0.25, 0.75])
self.wingsurf.append(a)
示例14:
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
wt = top.ae.wt
wt.turbine_name = 'DTU 10MW RWT'
wt.doc = 'FUSED-Wind definition of the DTU 10MW RWT'
wt.tower_height = 115.63
wt.hub_height = 119.0
wt.towertop_height = 2.75
wt.shaft_length = 7.1
wt.tilt_angle = 5.0
wt.cone_angle = -2.5
wt.hub_radius = 2.8
wt.blade_length = 86.366
wt.rotor_diameter = 178.332
c = wt.set_machine_type('VarSpeedVarPitch')
c.vIn = 3.
c.vOut = 25.
c.minOmega = 6.
c.maxOmega = 9.6
c.minPitch = 0.
# --- 4 ---
# connect the splined planform to the blade geometry vartree
# in the aeroelastic solver
top.connect('pf_splines.pfOut', 'ae.wt.blade1.geom')
# --- 5 ---
# run it
top.run()
# --- 6 ---
示例15: ArrayTest
# 需要导入模块: from openmdao.main.api import Assembly [as 别名]
# 或者: from openmdao.main.api.Assembly import connect [as 别名]
#.........这里部分代码省略.........
def test_basic(self):
top = self.top
comp = top.comp
driver = top.driver
comp.x1d = [1, 2, 3]
comp.x2d = [[1, 2, 3], [4, 5, 6]]
top.run()
self.assertEqual(comp.fx1d, 6.)
self.assertEqual(list(comp.fx2d), [6., 15.])
code = "driver.add_parameter('comp.x1d')"
assert_raises(self, code, globals(), locals(), ValueError,
"driver: Trying to add parameter 'comp.x1d', but no"
" lower limit was found and no 'low' argument was given."
" One or the other must be specified.")
code = "driver.add_parameter('comp.x1d', low=-10)"
assert_raises(self, code, globals(), locals(), ValueError,
"driver: Trying to add parameter 'comp.x1d', but no"
" upper limit was found and no 'high' argument was given."
" One or the other must be specified.")
driver.add_parameter('comp.x1d', low=-10, high=10, start=1)
code = "driver.add_parameter('comp.x2d')"
assert_raises(self, code, globals(), locals(), ValueError,
"driver: Trying to add parameter 'comp.x2d', but no"
" lower limit was found and no 'low' argument was given."
" One or the other must be specified.")
code = "driver.add_parameter('comp.x2d', low=-10)"
assert_raises(self, code, globals(), locals(), ValueError,
"driver: Trying to add parameter 'comp.x2d', but no"
" upper limit was found and no 'high' argument was given."
" One or the other must be specified.")
driver.add_parameter('comp.x2d', low=-10, high=10, start=2)
targets = driver.list_param_targets()
self.assertEqual(targets, ['comp.x1d', 'comp.x2d'])
targets = driver.list_param_group_targets()
self.assertEqual(targets, [('comp.x1d',), ('comp.x2d',)])
self.assertEqual(list(comp.x1d), [1, 2, 3])
self.assertEqual([list(row) for row in comp.x2d[:]],
[[1, 2, 3], [4, 5, 6]])
driver.init_parameters()
self.assertEqual(list(comp.x1d), [1, 1, 1])
self.assertEqual([list(row) for row in comp.x2d[:]],
[[2, 2, 2], [2, 2, 2]])
driver.set_parameter_by_name('comp.x1d', 3)
self.assertEqual(list(comp.x1d), [3, 3, 3])
driver.set_parameter_by_name('comp.x1d', array([4, 5, 6]))
self.assertEqual(list(comp.x1d), [4, 5, 6])
driver.set_parameter_by_name('comp.x2d', 4)
self.assertEqual([list(row) for row in comp.x2d[:]],
[[4, 4, 4], [4, 4, 4]])
driver.set_parameter_by_name('comp.x2d', array([[5, 6, 7], [8, 9, 0]]))
self.assertEqual([list(row) for row in comp.x2d[:]],
[[5, 6, 7], [8, 9, 0]])
driver.set_parameters([7, 8, 9, 1, 2, 3, 4, 5, 6])
self.assertEqual(list(comp.x1d), [7, 8, 9])
self.assertEqual([list(row) for row in comp.x2d[:]],
[[1, 2, 3], [4, 5, 6]])
self.assertEqual(driver._hasparameters.get_expr_depends(),
[('driver', 'comp'), ('driver', 'comp')])
self.assertEqual(driver._hasparameters.get_referenced_compnames(),
set(['comp']))
self.assertEqual(driver._hasparameters.get_referenced_varpaths(),
set(['comp.x1d', 'comp.x2d']))
# Still have last set_parameters() values.
self.assertEqual(list(comp.x1d), [7, 8, 9])
self.assertEqual([list(row) for row in comp.x2d[:]],
[[1, 2, 3], [4, 5, 6]])
top.run()
# Now have init_parameters() values.
self.assertEqual(list(comp.x1d), [1, 1, 1])
self.assertEqual([list(row) for row in comp.x2d[:]],
[[2, 2, 2], [2, 2, 2]])
self.assertEqual(comp.fx1d, 3)
self.assertEqual(list(comp.fx2d), [6, 6])
def test_mixed_use(self):
# Connect to one element of array and use another element as parameter.
self.top.comp.x1d = [1, 2, 3]
self.top.add('exec_comp', ExecComp(exprs=['c=x+y', 'd=x-y']))
self.top.driver.workflow.add('exec_comp')
self.top.connect('exec_comp.c', 'comp.x1d[0]')
self.top.driver.add_parameter('comp.x1d[1]', low=-10, high=10, start=1)
self.top.run()