How to use the openmdao.main.api.Assembly 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_linear_solver_KSP.py View on Github external
def test_petsc_ksp_single_comp_dict(self):

        top = set_as_top(Assembly())
        top.add('comp', Paraboloid())
        top.add('driver', SimpleDriver())
        top.driver.workflow.add(['comp'])
        top.driver.add_parameter('comp.x', low=-1000, high=1000)
        top.driver.add_parameter('comp.y', low=-1000, high=1000)
        top.driver.add_objective('comp.f_xy')

        top.driver.gradient_options.lin_solver = 'petsc_ksp'

        top.comp.x = 3
        top.comp.y = 5
        top.run()

        self.assertEqual(top.comp.f_xy, 93.)
        self.assertEqual(top._pseudo_0.out0, 93.)
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_mpi_derivatives.py View on Github external
def test_two_to_one_forward_bcast(self):

        top = set_as_top(Assembly())

        exp1 = ["y = 3.0*x"]
        exp2 = ["y = -2.0*x"]
        exp3 = ["y = 5.0*x1 + 4.0*x2"]

        deriv1 = ["dy_dx = 3.0"]
        deriv2 = ["dy_dx = -2.0"]
        deriv3 = ["dy_dx1 = 5.0", "dy_dx2 = 4.0"]

        top.add('comp1', ExecCompWithDerivatives(exp1, deriv1))
        top.add('comp2', ExecCompWithDerivatives(exp2, deriv2))
        top.add('comp3', ExecCompWithDerivatives(exp3, deriv3))
        top.add('driver', SimpleDriver())

        top.driver.workflow.add(['comp1', 'comp2', 'comp3'])
        top.connect('comp1.y', 'comp3.x1')
github WISDEM / WISDEM / src / NREL_WISDEM / LCOE / lcoe_se_bos_ecn_assembly.py View on Github external
from twister.components.varTrees import Turbine, PlantBOS, PlantOM

# Import key assemblies and components for TCC, BOS, O&M, Finance & AEP
from twister.assemblies.tcc_cst_assembly import tcc_cst_assembly
from twister.components.bos_nrel_offshore_component import bos_nrel_offshore_component
from twister.components.om_ecn_offshore_component  import om_ecn_offshore_component
from twister.components.fin_cst_component import fin_cst_component
from twister.assemblies.aep_weibull_assembly import aep_weibull_assembly

from twister.fused_cost import GenericFinancialAnalysis

# Drivetrain assembly specified at top level
from twister.models.csm.csmDriveEfficiency import DrivetrainEfficiencyModel, csmDriveEfficiency

class lcoe_cst_bos_ecn_assembly(Assembly):

    # ---- Design Variables ----------
    
    # Turbine configuration
    # drivetrain
    machine_rating = Float(5000.0, units = 'kW', iotype='in', desc= 'rated machine power in kW')
    towerTopDiameter = Float(3.87, units= 'm', iotype='in', desc= 'tower top diameter in m')
    towerBottomDiameter = Float(6.0, units= 'm', iotype='in', desc= 'tower bottom diameter in m')
    towerTopThickness = Float(0.0247, units= 'm', iotype='in', desc= 'tower top thickness in m')
    towerBottomThickness = Float(0.0351, units= 'm', iotype='in', desc= 'tower bottom diameter in m')        
    
    # Plant configuration
    # climate
    shear_exponent = Float(0.1, iotype='in', desc= 'shear exponent for wind plant') #TODO - could use wind model here
    shear_exponent = Float(8.35, units = 'm/s', iotype='in', desc='mean annual wind speed at 50 m height')
    weibull_k= Float(2.1, iotype='in', desc = 'weibull shape factor for annual wind speed distribution')
github OpenMDAO / OpenMDAO-Framework / misc / sellar-IDF.py View on Github external
"""
Individual Design Feasible (IDF) Architecture
"""

from disciplines import Discipline1, Discipline2, Coupler

# pylint: disable-msg=E0611,F0401
from openmdao.lib.api import CONMINdriver
from openmdao.main.api import Assembly, set_as_top


class SellarIDF(Assembly):
    """Solution of the sellar analytical problem using IDF."""

    def __init__(self):
        """ Creates a new Assembly with this problem
        
        Optimal Design at (1.9776, 0, 0)
        
        Optimal Objective = 3.18339"""
        
        # pylint: disable-msg=E1101
        
        super(SellarIDF, self).__init__()

        # create Optimizer instance
        self.add('driver', CONMINdriver())
github OpenMDAO / OpenMDAO-Framework / contrib / damon / doe.py View on Github external
@add_delegate(HasStopConditions)

class ConceptA(Component):
    x = Float(iotype="in",low=-3.5,high=10)
    y = Float(iotype="in",low=0.8,high=1.2)
    z = Float(iotype="in",low=0.8,high=1.2)

    f1 = Float(0.,iotype="out")
    f2 = Float(0.,iotype="out")
    
    def execute(self):
        self.f1 = self.x*self.y
        self.f2 =  (12./(self.x+4)-20.)*self.z

class Analysis(Assembly):

    def __init__(self,*args,**kwargs):
        super(Analysis,self).__init__(self,*args,**kwargs)
        
        self._tdir = mkdtemp()
        
        #Component
        self.add("A",ConceptA())

        #Driver
        self.add("DOE_A",DOEdriver())
        #self.DOE_A.sequential = True
        #self.DOE_A.DOEgenerator = FullFactorial(num_levels = 3)
        self.DOE_A.DOEgenerator = Uniform(num_levels = 3)
        self.DOE_A.add_parameter("A.x")
        self.DOE_A.add_parameter("A.y")
github OpenMDAO / OpenMDAO-Framework / contrib / enginedesign / openmdao.examples.enginedesign / openmdao / examples / enginedesign / vehicle.py View on Github external
# Assembly that contains an engine, a transmission, and a chassis
# component. Together, these output the acceleration for a set of input
# the velocity and commanded throttle/gear positions given a set of design.
# parameters.

# pylint: disable-msg=E0611,F0401

from openmdao.main.datatypes.api import Float

from openmdao.main.api import Assembly
from openmdao.examples.enginedesign.transmission import Transmission
from openmdao.examples.enginedesign.chassis import Chassis
from openmdao.examples.enginedesign.engine_wrap_c import Engine


class Vehicle(Assembly):
    """ Vehicle assembly. """

    tire_circumference = Float(75.0, iotype='in', units='inch',
                                    desc='Circumference of tire (inches)')

    velocity = Float(75.0, iotype='in', units='mi/h',
                desc='Vehicle velocity needed to determine engine RPM (mi/h)')

    def configure(self):
        """ Configures a new Vehicle Assembly object

        # Design parameters promoted from Engine
        stroke = 78.8              # Stroke (mm)
        bore = 82.0                # Bore (mm)
        conrod = 115.0             # Connecting Rod (mm)
        comp_ratio = 9.3           # Compression Ratio
github OpenMDAO / OpenMDAO-Framework / contrib / enginedesign / openmdao.examples.enginedesign / openmdao / examples / enginedesign / vehicle.py View on Github external
['chassis.velocity', 'transmission.velocity'])
        self.connect('tire_circumference',
                     ['chassis.tire_circ', 'transmission.tire_circ'])

        # Hook it all up
        self.connect('transmission.RPM', 'engine.RPM')
        self.connect('transmission.torque_ratio', 'chassis.torque_ratio')
        self.connect('engine.torque', 'chassis.engine_torque')
        self.connect('engine.engine_weight', 'chassis.mass_engine')


if __name__ == "__main__":  # pragma: no cover

    from openmdao.main.api import set_as_top

    top = set_as_top(Assembly())
    top.add('car', Vehicle())
    top.driver.workflow.add('Testing')

    top.car.current_gear = 1
    top.car.velocity = 20.0 * (26.8224 / 60.0)
    top.car.throttle = 1.0
    top.car.run()

    def prz(vehicle):
        """ Printing the results"""
        print "Accel = ", vehicle.acceleration
        print "Fuelburn = ", vehicle.fuel_burn
        print "(power, torque) ", vehicle.power, vehicle.torque
        print "RPM = ", vehicle.engine.RPM

    prz(top.car)
github OpenMDAO / OpenMDAO-Framework / examples / openmdao.examples.mdao / openmdao / examples / mdao / sellar_MDF.py View on Github external
"""
    Solution of the sellar analytical problem using MDF.
    Disciplines coupled using Fixed Point Iteration
"""
from openmdao.main.api import Assembly, Component
from openmdao.lib.drivers.api import SLSQPdriver, FixedPointIterator
from openmdao.lib.optproblems import sellar


class SellarMDF(Assembly):
    """ Optimization of the Sellar problem using MDF
    Disciplines coupled with FixedPointIterator.
    """

    def configure(self):
        """ Creates a new Assembly with this problem

        Optimal Design at (1.9776, 0, 0)

        Optimal Objective = 3.18339"""

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

        # Outer Loop - Global Optimization
        self.add('solver', FixedPointIterator())
github OpenMDAO / OpenMDAO-Framework / examples / openmdao.examples.metamodel_tutorial / openmdao / examples / metamodel_tutorial / multi_outs.py View on Github external
from openmdao.lib.casehandlers.api import DBCaseRecorder
from openmdao.lib.surrogatemodels.api import LogisticRegression, FloatKrigingSurrogate


class Trig(Component):

    x = Float(0,iotype="in",units="rad")

    f_x_sin = Float(0.0,iotype="out")
    f_x_cos = Float(0.0,iotype="out")

    def execute(self):
        self.f_x_sin = .5*sin(self.x)
        self.f_x_cos = .5*cos(self.x)

class Simulation(Assembly):

    def configure(self):

        # Our component to be meta-modeled
        self.add("trig_calc", Trig())

        # Create meta_model for two responsese
        self.add("trig_meta_model", MetaModel(params = ('x', ),
                                              responses = ('f_x_sin', 'f_x_cos')))

        # Use Kriging for the f_x output
        self.trig_meta_model.surrogates['f_x_sin'] = LogisticRegression()
        self.trig_meta_model.surrogates['f_x_cos'] = FloatKrigingSurrogate()

        # Training the MetaModel
        self.add("DOE_Trainer", DOEdriver())