2017-03-20 1 views

Antwort

1

Sie benötigen, wie etwas zu tun:

assembly2.create_passthrough ('component5.input')

und dann können Sie

verbinden ('component1.output', 'assembly2.i nput ')

+0

Wie fügen Sie eine Baugruppe in einer anderen Baugruppe hinzu? –

+0

Beachten Sie, dass OpenMDAO v0.13 nicht mehr unterstützt wird und nicht aktiv entwickelt wird. Sie sollten Ihre Modellierung auf 1.7.x umstellen. –

+0

Eine Baugruppe verhält sich genau wie eine Komponente (sie ist tatsächlich eine Komponente, nur eine kompliziertere) und wird auf die gleiche Weise hinzugefügt wie jede andere Komponente. auch, sollten Sie eine neuere, unterstützte Version von OpenMDAO per Justin Kommentar. – swryan

0

Für diejenigen, die darauf stoßen, konnten wir die in der Abbildung gezeigten Verbindungen implementieren. Wir mussten create_passthrough nicht verwenden.

from openmdao.main.api import Component, Assembly 
from openmdao.main.datatypes.api import Float, Bool, Int, Str, Array, Enum 

from openmdao.main.api import Assembly 
from openmdao.examples.simple.paraboloid import Paraboloid 

class New1(Assembly): 

    x=Float(iotype='in') 
    f_xy=Float(iotype='out') 

    out=Float(iotype='out') 
    def configure(self): 
     self.add('C5',Paraboloid()) 
     self.add('C6',Paraboloid()) 
     self.connect('x','C5.x') 
     self.driver.workflow.add(['C5','C6']) 
     self.connect("C5.f_xy","C6.x") 
     self.connect('C6.f_xy', 'f_xy') 



class New(Assembly): 

    def configure(self): 
     self.add('C1',Paraboloid()) 
     self.add('C2',Paraboloid()) 
     self.add('C4',Paraboloid()) 
     self.add('A2',New1()) 
     self.connect("C1.f_xy","A2.x") 
     self.connect("A2.f_xy", "C4.x") 
     self.driver.workflow.add(['C1','C2','C4','A2']) 

     self.connect("C1.f_xy","C2.x") 
     self.connect("C2.f_xy","C4.y") 

if __name__ == "__main__": 
    a = New() 

    a.C1.x = 2.3 
    a.C1.y = 7.2 
    a.C2.y = 9.8 
    a.C4.x = 1.5 

    a.run() 

    print "C1 has output of %0.2f and C5 has input of %0.2f" % (a.C1.f_xy,a.A2.C5.x) 
    print "C4 has input of %0.2f and C6 has output of %0.2f" % (a.C4.x,a.A2.C6.f_xy) 

Ausgang:

C1 has output of 139.49 and C5 has input of 139.49 
C4 has input of 347431722.56 and C6 has output of 347431722.56 

bearbeiten

Hier ist die gleiche Anordnung mit einer äußeren Optimierung

from openmdao.main.api import Component, Assembly 
from openmdao.main.datatypes.api import Float, Bool, Int, Str, Array, Enum 
from openmdao.lib.drivers.api import SLSQPdriver 
from openmdao.main.api import Assembly 
from openmdao.examples.simple.paraboloid import Paraboloid 

class New1(Assembly): 

    x=Float(iotype='in') 
    f_xy=Float(iotype='out') 
    def configure(self): 
     self.add('C5',Paraboloid()) 
     self.add('C6',Paraboloid()) 
     self.connect('x','C5.x') 
     self.driver.workflow.add(['C5','C6']) 
     self.connect("C5.f_xy","C6.x") 
     self.connect('C6.f_xy', 'f_xy') 



class New(Assembly): 
    x=Float(3., iotype='in') 
    f_xy=Float(iotype='out') 
    def configure(self): 
     self.add('C1',Paraboloid()) 
     self.add('C2',Paraboloid()) 
     self.add('C4',Paraboloid()) 
     self.add('A2',New1()) 
     self.connect("A2.f_xy", "C4.x") 
     self.driver.workflow.add(['C1','C2','C4','A2']) 
     self.connect('x', 'A2.x') 
     self.connect('A2.f_xy', 'f_xy') 
     self.connect("C1.f_xy","C2.x") 
     self.connect("C2.f_xy","C4.y") 

if __name__ == "__main__": 
    class optim(Assembly): 
     def configure(self): 
      self.add('driver', SLSQPdriver()) 
      self.add('modl', New()) 
      self.driver.workflow.add('modl') 
      self.driver.add_parameter('modl.x', low=-2., high=2.) 
      self.driver.add_objective('modl.f_xy') 
    a = optim() 
    print "C1 has output of %0.2f and C5 has input of %0.2f" % (a.modl.C1.f_xy,a.modl.A2.C5.x) 
    print "C4 has input of %0.2f and C6 has output of %0.2f" % (a.modl.C4.x,a.modl.A2.C6.f_xy) 
    print 'initial objective: ', a.modl.f_xy 
    a.run() 
    print 'optimized objective: ', a.modl.f_xy 
    print "New has output of ", a.modl.f_xy 

Ausgabe:

C1 has output of 0.00 and C5 has input of 0.00 
C4 has input of 0.00 and C6 has output of 0.00 
initial objective: 0.0 
optimized objective: 113.0 
New has output of 113.0 
Verwandte Themen