OpenMDAO单数输入

时间:2018-04-11 13:49:07

标签: openmdao

我试图理解OpenMDAO错误消息

RuntimeError: Singular entry found in '' for column associated with state/residual 'x'.

RuntimeError: Singular entry found in '' for row associated with state/residual 'y'.

有人能解释一下吗?例如。运行代码时

from openmdao.api import Problem, Group, IndepVarComp, ImplicitComponent, ScipyOptimizeDriver, NewtonSolver, DirectSolver, view_model, view_connections


class Test1Comp(ImplicitComponent):

    def setup(self):
        self.add_input('x', 0.5)
        self.add_input('design_x', 1.0)
        self.add_output('z', val=0.0)
        self.add_output('obj')

        self.declare_partials(of='*', wrt='*', method='fd', form='central', step=1.0e-4)

    def apply_nonlinear(self, inputs, outputs, resids):
        x = inputs['x']
        design_x = inputs['design_x']
        z = outputs['z']

        resids['z'] = x*z + z - 4
        resids['obj'] = (z/5.833333 - design_x)**2


if __name__ == "__main__":

    prob = Problem()
    model = prob.model = Group()

    model.add_subsystem('p1', IndepVarComp('x', 0.5))
    model.add_subsystem('d1', IndepVarComp('design_x', 1.0))
    model.add_subsystem('comp', Test1Comp())

    model.connect('p1.x', 'comp.x')
    model.connect('d1.design_x', 'comp.design_x')

    prob.driver = ScipyOptimizeDriver()
    prob.driver.options["optimizer"] = 'SLSQP'
    model.add_design_var("d1.design_x", lower=0.5, upper=1.5)
    model.add_objective('comp.obj')

    model.nonlinear_solver = NewtonSolver()
    model.nonlinear_solver.options['iprint'] = 2
    model.nonlinear_solver.options['maxiter'] = 20
    model.linear_solver = DirectSolver()

    prob.setup()
    prob.run_model()
    print(prob['comp.z'])

我收到错误消息:

  File "C:\Scripts/mockup_component3.py", line 46, in <module>
    prob.run_model()
  File "C:\Python_32\lib\site-packages\openmdao\core\problem.py", line 315, in run_model
    return self.model.run_solve_nonlinear()
  File "C:\Python_32\lib\site-packages\openmdao\core\system.py", line 2960, in run_solve_nonlinear
    result = self._solve_nonlinear()
  File "C:\Python_32\lib\site-packages\openmdao\core\group.py", line 1420, in _solve_nonlinear
    result = self._nonlinear_solver.solve()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\solver.py", line 602, in solve
    fail, abs_err, rel_err = self._run_iterator()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\solver.py", line 349, in _run_iterator
    self._iter_execute()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\nonlinear\newton.py", line 234, in _iter_execute
    system._linearize()
  File "C:\Python_32\lib\site-packages\openmdao\core\group.py", line 1562, in _linearize
    self._linear_solver._linearize()
  File "C:\Python_32\lib\site-packages\openmdao\solvers\linear\direct.py", line 199, in _linearize
    raise RuntimeError(format_singluar_error(err, system, mtx))
RuntimeError: Singular entry found in '' for column associated with state/residual 'comp.obj'.

我可以通过在- outputs['obj']的等式中添加resids['obj']来解决此错误。但我仍然不清楚这两个错误消息的含义。什么矩阵是单数?

是什么意思

1)列的单数条目?

2)一行的单数条目?

1 个答案:

答案 0 :(得分:1)

我意识到单数的原因是我没有为组件定义偏导数。我通过将命令declare_partials添加到顶级系统来解决此问题。追溯给了我线索,表明矩阵与线性化有关。

单数的情况似乎与apply_nonlinear中有两个方程有关,但只有一个未知(z)。