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


Python Problem.driver方法代码示例

本文整理汇总了Python中openmdao.core.Problem.driver方法的典型用法代码示例。如果您正苦于以下问题:Python Problem.driver方法的具体用法?Python Problem.driver怎么用?Python Problem.driver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openmdao.core.Problem的用法示例。


在下文中一共展示了Problem.driver方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from openmdao.core import Problem [as 别名]
# 或者: from openmdao.core.Problem import driver [as 别名]
    def setUp(self):
        if SKIP:
            raise unittest.SkipTest('Could not import pyOptSparseDriver. Is pyoptsparse installed?')

        prob = Problem(impl=impl)
        root = prob.root = Group()
        #root.ln_solver = lin_solver()
        root.ln_solver = LinearGaussSeidel()
        par = root.add('par', ParallelGroup())
        par.ln_solver = LinearGaussSeidel()

        ser1 = par.add('ser1', Group())
        ser1.ln_solver = LinearGaussSeidel()

        ser1.add('p1', IndepVarComp('x', np.zeros([2])))
        ser1.add('comp', SimpleArrayComp())
        ser1.add('con', ExecComp('c = y - 20.0', c=np.array([0.0, 0.0]),
                                  y=np.array([0.0, 0.0])))
        ser1.add('obj', ExecComp('o = y[0]', y=np.array([0.0, 0.0])))

        ser2 = par.add('ser2', Group())
        ser2.ln_solver = LinearGaussSeidel()

        ser2.add('p1', IndepVarComp('x', np.zeros([2])))
        ser2.add('comp', SimpleArrayComp())
        ser2.add('con', ExecComp('c = y - 30.0', c=np.array([0.0, 0.0]),
                                 y=np.array([0.0, 0.0])))
        ser2.add('obj', ExecComp('o = y[0]', y=np.array([0.0, 0.0])))

        root.add('total', ExecComp('obj = x1 + x2'))

        ser1.connect('p1.x', 'comp.x')
        ser1.connect('comp.y', 'con.y')
        ser1.connect('comp.y', 'obj.y')
        root.connect('par.ser1.obj.o', 'total.x1')

        ser2.connect('p1.x', 'comp.x')
        ser2.connect('comp.y', 'con.y')
        ser2.connect('comp.y', 'obj.y')
        root.connect('par.ser2.obj.o', 'total.x2')

        prob.driver = pyOptSparseDriver()
        prob.driver.add_desvar('par.ser1.p1.x', low=-50.0, high=50.0)
        prob.driver.add_desvar('par.ser2.p1.x', low=-50.0, high=50.0)

        prob.driver.add_objective('total.obj')
        prob.driver.add_constraint('par.ser1.con.c', equals=0.0)
        prob.driver.add_constraint('par.ser2.con.c', equals=0.0)

        self.prob = prob
开发者ID:briantomko,项目名称:OpenMDAO,代码行数:52,代码来源:test_mpi_opt.py

示例2: openmdao_sellar_converged

# 需要导入模块: from openmdao.core import Problem [as 别名]
# 或者: from openmdao.core.Problem import driver [as 别名]
def openmdao_sellar_converged():
    from openmdao.core import Problem
    from openmdao.drivers import ScipyOptimizer

    top = Problem()
    top.root = SellarDerivatives()

    top.driver = ScipyOptimizer()
    top.driver.options['optimizer'] = 'SLSQP'
    top.driver.options['tol'] = 1.0e-8
    top.driver.options['disp'] = False

    top.driver.add_desvar('z', low=np.array([-10.0, 0.0]),
                         high=np.array([10.0, 10.0]))
    top.driver.add_desvar('x', low=0.0, high=10.0)

    top.driver.add_objective('obj')
    top.driver.add_constraint('con1', upper=0.0)
    top.driver.add_constraint('con2', upper=0.0)

    top.setup(check=False)
    top.run()
    return top    
开发者ID:thearn,项目名称:adjoint_writeup,代码行数:25,代码来源:openmdao_sellar.py


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