How to use the openmdao.main.api.set_as_top function in openmdao

To help you get started, we’ve selected a few openmdao examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_mpicidriver.py View on Github external
def model_par3_setup(num_inputs, mpi=True):
    vsize = 5   # array var size

    # a comp feeds 3 parallel comps which feed
    # another comp
    top = set_as_top(Assembly())
    if mpi:
        drv = MPICaseDriver()
    else:
        drv = SimpleCaseIterDriver()
    driver = top.add("driver", drv)
    top.add("C1", ABCDArrayComp(vsize))
    top.add("C2", ABCDArrayComp(vsize))
    top.add("C3", ABCDArrayComp(vsize))
    top.add("C4", ABCDArrayComp(vsize))
    top.add("C5", ABCDArrayComp(vsize))
    top.driver.workflow.add(['C1', 'C2', 'C3', 'C4', 'C5'])
    top.connect('C1.c', 'C2.a')
    top.connect('C1.out_string', 'C2.in_string')
    top.connect('C1.out_list', 'C4.in_list')

    top.connect('C1.d', 'C3.b')
github OpenMDAO / OpenMDAO-Framework / openmdao.lib / src / openmdao / lib / architectures / mdao_test_suite.py View on Github external
The architectures to test.
        
    optproblems: list of OptProblems 
        The OptProblems to use for testing the Architectures. 
    """
    
    compat_data = {}
    
    for p in optproblems: 
        arch_data = {}
        prob_name = p.__class__.__name__

        converge_file = open('%s_convergence_data.py'%prob_name,'w')
        
        for a in arch:
            prob = set_as_top(p.__class__())
            arch_name = a.__class__.__name__
            
            prob.architecture = a.__class__()
            recorders = [DBCaseRecorder()]
            prob.architecture.data_recorders = recorders
            
            
            print "Testing %s on %s"%(arch_name,prob_name), "...", 
            try:
                prob.check_config()
                arch_data[p] = True
                
            except RuntimeError: 
                arch_data[p] = False #not compatible, so just move on
                print "Incompatible"
                #raise err
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_mpi.py View on Github external
def test_simple_opaque(self):
        size = 5

        # 2 parallel comps feeding another comp
        top = set_as_top(Assembly())
        top.add('driver', SimpleDriver())
        top.add("C1", ABCDArrayComp(size))
        top.add("C2", ABCDArrayComp(size))
        top.driver.workflow.add(['C1', 'C2'])
        top.connect('C1.c', 'C2.a')

        top.C1.a = np.ones(size, float) * 3.0
        top.C1.b = np.ones(size, float) * 7.0
        top.C2.b = np.ones(size, float) * 5.0

        top.run()

        if self.comm.rank == 0:
            self.assertTrue(all(top.C2.a==np.ones(size, float)*10.))
            self.assertTrue(all(top.C2.b==np.ones(size, float)*5.))
            self.assertTrue(all(top.C2.c==np.ones(size, float)*15.))
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_mpi_hdf5case.py View on Github external
def create_serial_file():
    '''Create the HDF5 case record files for the serial case. Only run as needed'''

    top = set_as_top(SellarMDF())

    top.connect('C1.y1','C2.y1')

    top.driver.add_parameter('C1.y2', low=-1.e99, high=1.e99)
    top.driver.add_constraint('C1.y2 = C2.y2')

    hdf5_filename = 'test_sellar_params1_serial.hdf5'
    top.recorders = [HDF5CaseRecorder(hdf5_filename)]

    top.run()
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_mpi_opt.py View on Github external
def test_COBYLA(self):

        top = set_as_top(Assembly())
        top.add('parab1', Parab1())
        top.add('parab2', Parab2())

        top.add('driver', COBYLAdriver())
        top.driver.workflow.add(['parab1', 'parab2'])
        top.driver.add_parameter(['parab1.x', 'parab2.x'], low=-100, high=100)
        top.driver.add_parameter(['parab1.y', 'parab2.y'], low=-100, high=100)
        top.driver.add_objective('parab1.f_xy + parab2.f_xy')
        top.driver.add_constraint('parab1.x-parab1.y >= 15.0')

        top.run()

        assert_rel_error(self, top.parab1.x, 7.166, 0.001)
        assert_rel_error(self, top.parab1.y, -7.833, 0.001)
        assert_rel_error(self, top._pseudo_0.out0, -27.083, 0.001)
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_mpi_derivatives.py View on Github external
def test_three_comp_diamond_forward(self):

        self.top = set_as_top(Assembly())

        exp1 = ['y1 = 50.0*x1',
                'y2 = 1.0*x1']
        deriv1 = ['dy1_dx1 = 50.0',
                  'dy2_dx1 = 1.0']

        exp2 = ['y1 = 1.2*x1']
        deriv2 = ['dy1_dx1 = 1.2']

        exp3 = ['y1 = 100.0*x1*x2 + 30*x1 + 0.3*x2']
        deriv3 = ['dy1_dx1 = 100.0*x2 + 30',
                  'dy1_dx2 = 100.0*x1 + 0.3']

        self.top.add('comp1', ExecCompWithDerivatives(exp1, deriv1))
        self.top.add('comp2', ExecCompWithDerivatives(exp2, deriv2))
        self.top.add('comp3', ExecCompWithDerivatives(exp3, deriv3))
github JustinSGray / Hyperloop / src / hyperloop / cycle / compression_system.py View on Github external
#driver setup
        design = self.driver
        comp_list = ['tube','inlet','comp1',
            'duct1', 'split', 'nozzle', 'comp2', 'duct2', 'perf']

        design.workflow.add(comp_list)
        for comp_name in comp_list: #need to put everything in design mode
            design.add_event('%s.design'%comp_name)


if __name__ == "__main__": 
    from math import pi
    from openmdao.main.api import set_as_top

    hlc = set_as_top(CompressionSystem())
    hlc.Mach_pod_max = 1
    hlc.run()

    print "pwr: ", hlc.comp1.pwr+hlc.comp2.pwr,hlc.comp1.pwr,hlc.comp2.pwr 
    print "tube area:", hlc.tube.Fl_O.area 
    print "tube Ps", hlc.tube.Fl_O.Ps, hlc.tube.Fl_O.Pt
    print "tube Rhos", hlc.tube.Fl_O.rhos
    print "tube W", hlc.tube.W
    print "inlet W", hlc.inlet.Fl_I.W
    print "tube rad: ", (hlc.tube.Fl_O.area/pi)**.5
    print "tube V: ", hlc.tube.Fl_O.Vflow, hlc.tube.Fl_O.Mach

    fs = hlc.tube.Fl_O
github OpenMDAO / OpenMDAO-Framework / contrib / damon / doe.py View on Github external
#Iteration Hierarchy
        self.driver.workflow.add(['DOE_A'])
        self.DOE_A.workflow.add('A')

    def cleanup(self):
        shutil.rmtree(self._tdir, ignore_errors=True)

if __name__ == "__main__": #pragma: no cover
    import sys
    from openmdao.main.api import set_as_top
    from openmdao.lib.casehandlers.db import case_db_to_dict

    analysis = Analysis()
    
    set_as_top(analysis)

    analysis.run()
    
    DOE1 = case_db_to_dict(os.path.join(analysis._tdir,'A.db'),['A.x','A.y','A.z','A.f1','A.f2'])
    DOE2 = case_db_to_dict(os.path.join(analysis._tdir,'A.db'),['A.x','A.y','A.f1','A.f2'])
    
    print DOE1
    print DOE2
    
    analysis.cleanup()
github WISDEM / WISDEM / src / wisdem / lcoe / lcoe_se_seam_assembly.py View on Github external
def create_example_se_assembly(wind_class='I',sea_depth=0.0,with_new_nacelle=False,with_landbos=False,flexible_blade=False,with_3pt_drive=False, with_ecn_opex=False, ecn_file=None,with_openwind=False,ow_file=None,ow_wkbook=None):
    """
    Inputs:
        wind_class : str ('I', 'III', 'Offshore' - selected wind class for project)
        sea_depth : float (sea depth if an offshore wind plant)
    """

    # === Create LCOE SE assembly ========
    from openmdao.main.api import set_as_top
    lcoe_se = set_as_top(lcoe_se_seam_assembly(with_new_nacelle,with_landbos,flexible_blade,with_3pt_drive,with_ecn_opex,ecn_file))

    # === Set assembly variables and objects ===
    lcoe_se.sea_depth = sea_depth # 0.0 for land-based turbine
    lcoe_se.turbine_number = 100
    lcoe_se.year = 2009
    lcoe_se.month = 12

    # bos_a = lcoe_se.bos_a
    # opex_a = lcoe_se.opex_a
    aep_a = lcoe_se.aep_a
    fin_a = lcoe_se.fin_a

    # Turbine ===========
    #=========== SEAM inputs

    # DTU 10 MW Turbine
github JustinSGray / Hyperloop / src / hyperloop / tube_limit_flow.py View on Github external
p.plot(MN,W_kant, label="Kantrowitz Limit",   lw=5)
    p.legend(loc="best")
    p.xlabel('Pod Mach Number')
    p.ylabel('Mass Flow Rate (kg/sec)')
    p.title('Kantrowitz Limit Flow')
    #p.show()

    print np.array(W_tube)- np.array(W_kant)

        


if __name__ == "__main__": 

    from openmdao.main.api import set_as_top
    comp = set_as_top(TubeLimitFlow())
    comp.radius_tube = 2000
    comp.run()
    #print comp.Mach_pod, comp.W_tube, comp.W_kant, comp.W_excess
    #print comp.MN[-1]
    #print comp.W_tube[-1]
    #print comp.W_kant[-1]
    plot_data(comp)