MDO测试套件丙烷燃烧

时间:2017-01-17 07:37:34

标签: python openmdao

我收到一些我无法解决的错误。有人可以帮我弄这个吗? 这是我的代码。

提前致谢

from openmdao.main.api import Assembly, set_as_top
from openmdao.lib.drivers.api import SLSQPdriver
from openmdao.lib.optproblems import PropaneDisciplines

class PropIDF(Assembly):

    def configure(self):

        # create Optimizer instance
        self.add('driver', SLSQPdriver())

        # Disciplines
        self.add('dis1', PropaneDisciplines.PropDiscipline1())
        self.add('dis2', PropaneDisciplines.PropDiscipline2())
        self.add('dis3', PropaneDisciplines.PropDiscipline3())

        # Driver process definition
        self.driver.workflow.add(['dis1', 'dis2', 'dis3'])


        # Optimization parameters
        self.driver.add_objective('(dis1.z1)*2+ dis1.y13+ dis1.y123+ dis1.z4+ dis2.y2+ dis3.y3+ (dis2.y23)*2- 10 +\
                              (abs(dis1.y13 * dis1.y123)**0.5) - (abs((40 * dis1.z1/ dis3.y32)**0.5))*dis1.z3 +\
                              (abs(dis1.y13 * dis1.z1)**0.5) - (abs((40 * dis1.y123/ dis3.y32)**0.5))*dis1.z4 +\
                              (dis1.z1 * (abs(dis1.z3)**0.5)) - (dis1.y123 * dis2.y2 * (abs(40 / dis3.y32)**0.5))')


        #Global Design Variables
        self.driver.add_parameter(('dis1.z1','dis2.z1', 'dis3.z1'), low =-1e99, high=1e99)
        self.driver.add_parameter(('dis1.z2', 'dis2.z2', 'dis3.z2'), low=-1e99, high=1e99)
        self.driver.add_parameter(('dis1.z3', 'dis2.z3', 'dis3.z3'), low=-1e99, high=1e99)
        self.driver.add_parameter(('dis1.z4', 'dis2.z4', 'dis3.z4'), low=-1e99, high=1e99)

        self.driver.add_constraint('(dis1.z1)*2+ dis1.y13+ dis1.y123+ dis1.z4+ dis2.y2+ dis3.y3+ (dis2.y23)*2- 10 < 0')
        self.driver.add_constraint('(abs(dis1.y13*dis1.y123)**0.5) -(abs((40 * dis1.z1/ dis3.y32)**0.5))*dis1.z3 <= 0')
        self.driver.add_constraint('(abs(dis1.y13*dis1.z1)**0.5) -(abs((40 * dis1.y123/ dis3.y32)**0.5))*dis1.z4 <=0')
        self.driver.add_constraint('(dis1.z1*(abs(dis1.z3)**0.5))-(dis1.y123*dis2.y2*(abs(40 / dis3.y32)**0.5))>= 0')

        self.driver.iprint = 0


if __name__ == "__main__":

    import time

    prob = PropIDF()

    prob.dis1.z1 = prob.dis2.z1 = prob.dis3.z1 = 2.0
    prob.dis1.z2 = prob.dis2.z2 = prob.dis3.z2 = 2.0
    prob.dis1.z3 = prob.dis2.z3 = prob.dis3.z3 = 2.0
    prob.dis1.z4 = prob.dis2.z4 = prob.dis3.z4 = 2.0
    prob.dis1.y13 = 1.0
    prob.dis1.y123 = 1.0
    prob.dis3.y31 = 1.0
    prob.dis2.y2 = 1.0
    prob.dis3.y3 = 1.0
    prob.dis2.y23 = 1.0
    prob.dis3.y32 = 1.0


    tt = time.time()
    prob.run()

    print "\n"
    print "Minimum found at (%f, %f, %f, %f)" % (prob.dis1.z1, \
                                         prob.dis1.z2, \
                                         prob.dis1.z3, \
                                         prob.dis1.z4)
    print "Couping vars from discipline 1: %f, %f" % (prob.dis1.y13, prob.dis1.y123)
    print "Coupling vars from discipline 2: %f, %f" % (prob.dis2.y2, prob.dis2.y23)
    print "Coupling vars from discipline 2: %f, %f, %f" %(prob.dis3.y31, prob.dis3.y3, prob.dis3.y32)
    print "Minimum objective: ", prob.driver.eval_objective()
    print "Elapsed time: ", time.time()-tt, "seconds"

输出: D:\ Anaconda2 \ Scripts \ python.exe D:/OpenMDAO/Mitul/Problems/Propane_Combustion/IDF.py

追踪(最近一次呼叫最后一次):

  File "D:/OpenMDAO/Mitul/Problems/Propane_Combustion/IDF.py", line 55, in <module>

    prob = PropIDF()

  File "d:\anaconda2\lib\site-packages\openmdao\main\assembly.py", line 182, in __init__

    set_as_top(self, first_only=True)

  File "d:\anaconda2\lib\site-packages\openmdao\main\assembly.py", line 78, in set_as_top

    cont.cpath_updated()

  File "d:\anaconda2\lib\site-packages\openmdao\main\component.py", line 420, in cpath_updated

    self.configure()

  File "D:/OpenMDAO/Mitul/Problems/Propane_Combustion/IDF.py", line 20, in configure

    self.add('f2', (dis1.z1)*2+ dis1.y13+ dis1.y123+ dis1.z4+ dis2.y2+ dis3.y3+ (dis2.y23)*2- 10)

NameError:全局名称&#39; dis1&#39;未定义

3 个答案:

答案 0 :(得分:0)

因为您是从openmdao.main.api导入的,所以您似乎正在尝试使用非常旧版本的openMDAO(&lt; 0.13.X)。

您需要将代码更新为OpenMDAO 1.x,因为不再支持旧版本。

答案 1 :(得分:0)

我尝试安装openmdao-0.13.0,但无法解析https:\ conda.binstar.org。

当我尝试安装较低版本时,它很容易安装。对更高版本有什么具体要求吗?

答案 2 :(得分:0)

我也遇到了Anaconda的问题。我在Fedora 25盒子上运行。相反,我必须首先手动安装每个依赖项,然后是openmdao。现在一切都很完美,但这是一件苦差事。