当前位置: 首页>>代码示例>>Python>>正文


Python Assembly.connect方法代码示例

本文整理汇总了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)
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:34,代码来源:test_linear_solver_KSP.py

示例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)
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:27,代码来源:test_linear_solvers.py

示例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")
开发者ID:hitej,项目名称:meta-core,代码行数:29,代码来源:test_geom.py

示例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
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:11,代码来源:test_dbcaserecorder.py

示例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
开发者ID:naylor-b,项目名称:OpenMDAO-Framework,代码行数:11,代码来源:test_dbcaserecorder.py

示例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
开发者ID:drousis,项目名称:OpenMDAO-Framework,代码行数:11,代码来源:test_dbcaserecorder.py

示例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)
开发者ID:relf,项目名称:OpenMDAO-Framework,代码行数:14,代码来源:test_assembly.py

示例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.)
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:14,代码来源:test_assembly.py

示例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()
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:28,代码来源:test_simplecid.py

示例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(),[])    
开发者ID:Kenneth-T-Moore,项目名称:OpenMDAO-Framework,代码行数:16,代码来源:test_broadcaster.py

示例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()
开发者ID:Kenneth-T-Moore,项目名称:OpenMDAO-Framework,代码行数:20,代码来源:test_caseiterdriver.py

示例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')
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:43,代码来源:test_jsonrecorder.py

示例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)
开发者ID:sebasanper,项目名称:BISDEM,代码行数:39,代码来源:wingsurface.py

示例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 ---
开发者ID:FUSED-Wind,项目名称:fusedwind,代码行数:33,代码来源:aeroelastic_turbine.py

示例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()
开发者ID:FashtimeDotCom,项目名称:OpenMDAO-Framework,代码行数:104,代码来源:test_hasparameters.py


注:本文中的openmdao.main.api.Assembly.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。