Пример #1
0
class Connectable(Component):

    b_in = Bool(iotype='in')
    e_in = Enum(values=(1, 2, 3), iotype='in')
    f_in = Float(iotype='in')
    i_in = Int(iotype='in')
    s_in = Str(iotype='in')
    x_in = Float(iotype='in')
    w_in = Float(iotype='in', units='g')

    b_out = Bool(iotype='out')
    e_out = Enum(values=(1, 2, 3), iotype='out')
    f_out = Float(iotype='out')
    i_out = Int(iotype='out')
    s_out = Str(iotype='out')
    x_out = Float(iotype='out')
    w_out = Float(5.0, iotype='out', units='kg')

    def execute(self):
        self.b_out = self.b_in
        self.e_out = self.e_in
        self.f_out = self.f_in
        self.i_out = self.i_in
        self.s_out = self.s_in
        self.x_out = self.x_in
class DrivenComponent(Component):
    """ Just something to be driven and compute results. """

    x = Array([1., 1., 1., 1.], iotype='in')
    y = Array([1., 1., 1., 1.], iotype='in')
    raise_error = Bool(False, iotype='in')
    stop_exec = Bool(False, iotype='in')
    sleep = Float(0., iotype='in')

    rosen_suzuki = Float(0., iotype='out')
    sum_y = Float(0., iotype='out')
    extra = Float(1.5, iotype='out')

    def __init__(self):
        super(DrivenComponent, self).__init__()

    def execute(self):
        """ Compute results from input vector. """

        self.extra = 2.5

        if self.sleep:
            time.sleep(self.sleep)
        self.rosen_suzuki = rosen_suzuki(self.x)
        self.sum_y = sum(self.y)
        if self.raise_error:
            self.raise_exception('Forced error', RuntimeError)
        if self.stop_exec:
            self.parent.driver.stop()  # Only valid if sequential!
Пример #3
0
    def __init__(self, iotype, client, rpath):
        ProxyMixin.__init__(self, client, rpath)

        default = self._value = self._valstr == 'true'
        desc = client.get(rpath+'.description')

        Bool.__init__(self, default_value=default, iotype=iotype, desc=desc)
Пример #4
0
class GradientOptions(VariableTree):
    ''' Options for calculation of the gradient by the driver's workflow. '''

    # Finite Difference
    fd_form = Enum('forward', ['forward', 'backward', 'central', 'complex_step'],
                   desc="Finite difference mode. (forward, backward, central) "
                        "You can also set to 'complex_step' to peform the complex "
                        "step method if your components support it.",
                   framework_var=True)
    fd_step = Float(1.0e-6, desc='Default finite difference stepsize',
                    framework_var=True)
    fd_step_type = Enum('absolute',
                        ['absolute', 'relative', 'bounds_scaled'],
                        desc='Set to absolute, relative, '
                             'or scaled to the bounds (high-low) step sizes',
                        framework_var=True)

    force_fd = Bool(False, desc="Set to True to force finite difference "
                                "of this driver's entire workflow in a"
                                "single block.",
                    framework_var=True)

    directional_fd = Bool(False, desc="Set to True to do a directional "
                                      "finite difference for each GMRES "
                                      "iteration instead of pre-computing "
                                      "the full fd space.",
                          framework_var=True)

    fd_blocks = List([], desc="List of lists that contain comps which "
                              "should be finite-differenced together.",
                     framework_var=True)

    # KTM - story up for this one.
    # fd_blocks = List([], desc='User can specify nondifferentiable blocks '
    #                          'by adding sets of component names.')

    # Analytic solution with GMRES
    gmres_tolerance = Float(1.0e-9, desc='Tolerance for GMRES',
                            framework_var=True)
    gmres_maxiter = Int(100, desc='Maximum number of iterations for GMRES',
                        framework_var=True)
    derivative_direction = Enum('auto',
                                ['auto', 'forward', 'adjoint'],
                                desc="Direction for derivative calculation. "
                                     "Can be 'forward', 'adjoint', or 'auto'. "
                                     "Auto is the default setting. "
                                     "When set to auto, OpenMDAO automatically "
                                     "figures out the best direction based on the "
                                     "number of parameters and responses. "
                                     "When the number of parameters and responses "
                                     "are equal, then forward direction is used.",
                                framework_var=True)
Пример #5
0
class DrivenComponent(Component):
    """ Just something to be driven and compute results. """

    x0 = Float(1., iotype='in')
    y0 = Float(1., iotype='in')  # used just to get ParameterGroup
    x1 = Float(1., iotype='in')
    x2 = Float(1., iotype='in')
    x3 = Float(1., iotype='in')
    err_event = Event()
    stop_exec = Bool(False, iotype='in')
    rosen_suzuki = Float(0., iotype='out')

    def __init__(self):
        super(DrivenComponent, self).__init__()
        self._raise_err = False

    def _err_event_fired(self):
        self._raise_err = True

    def execute(self):
        """ Compute results from input vector. """
        self.rosen_suzuki = rosen_suzuki(self.x0, self.x1, self.x2, self.x3)
        if self._raise_err:
            self.raise_exception('Forced error', RuntimeError)
        if self.stop_exec:
            self.parent.driver.stop()  # Only valid if sequential!
Пример #6
0
class SubObj(VariableTree):
    """ Sub-object under TopObject. """

    sob = Bool(False)
    sof = Float(0.284, units='lb/inch**3')
    soi = Int(3)
    sos = Str('World')
Пример #7
0
class Insurance(Component):

    TCC = Float(iotype='in',
                units='USD/kW',
                desc='turbine capital cost per kW')
    farmSize = Float(iotype='in', units='MW', desc='wind farm size')
    foundationCost = Float(iotype='in', units='USD', desc='foundation cost')
    performanceBond = Bool(False, iotype='in', desc='performance bond')

    alpha = Float(iotype='out', desc='multiplier portion of insurance cost')
    cost = Float(iotype='out',
                 units='USD',
                 desc='constant portion of insurance cost')

    def execute(self):
        values = _landbos.insuranceMultiplierAndCost(self.TCC, self.farmSize,
                                                     self.foundationCost,
                                                     self.performanceBond)
        self.alpha = values['alpha']
        self.cost = values['cost']

    def list_deriv_vars(self):

        inputs = ('TCC', 'foundationCost')
        outputs = ('alpha', 'cost')

        return inputs, outputs

    def provideJ(self):

        dtcc, dfoundationcost = _landbos.deriv_insuranceMultiplierAndCost(
            self.farmSize, self.performanceBond)
        J = np.array([[0.0, 0.0], [dtcc, dfoundationcost]])

        return J
class VarComponent(Component):
    """Contains some vars"""

    boolvar = Bool(False, iotype='in')
    intvar = Int(333, iotype='in')
    floatvar = Float(-16.54, iotype='in')
    expvar1 = Float(1.2, iotype='in')
    expvar2 = Float(1.2, iotype='in')
    textvar = Str("This", iotype='in')
    arrayvar = Array(iotype='in')
    arrayvarsplit = Array(iotype='in')
    arrayvarsplit2 = Array(iotype='in')
    arrayvarzerod = Array(zeros(shape=(0, 0)), iotype='in')
    arrayvartwod = Array(zeros(shape=(1, 3)), iotype='in')
    arraysmall = Array(iotype='in')
    arrayshorthand = Array(iotype='in')
    single = Array(iotype='in')
    singleint = Array(iotype='in', dtype=numpy_int32)
    singlebool = Array(iotype='in', dtype=bool)
    stringarray = List([], iotype='in')
    listenumvar = List(Enum(1, (1, 2, 3)), iotype='in')
    listenumvar2 = List(Enum(1.5, (1.5, 2.4, 3.3)), iotype='in')
    listenumvar3 = List(Enum('a', ('a', 'b', 'c')), iotype='in')
    listenumvar4 = List(Enum(True, (True, False)), iotype='in')

    def __init__(self, directory=''):

        super(VarComponent, self).__init__(directory)

        # Variable Containers
        self.add('varcontainer', VarContainer())
Пример #9
0
class Erection(Component):

    rating = Float(iotype='in', units='kW', desc='machine rating')
    hubHeight = Float(iotype='in', units='m', desc='hub height')
    nTurbines = Int(iotype='in', desc='number of turbines')
    weatherDelayDays = Int(iotype='in', units='d', desc='weather delay days')
    craneBreakdowns = Int(iotype='in', desc='crane breakdowns')
    deliveryAssistRequired = Bool(iotype='in', desc='delivery assist required')

    cost = Float(iotype='out', units='USD', desc='erection cost')

    def execute(self):
        self.cost = _landbos.erectionCost(self.rating, self.hubHeight,
                                          self.nTurbines,
                                          self.weatherDelayDays,
                                          self.craneBreakdowns,
                                          self.deliveryAssistRequired)

    def list_deriv_vars(self):

        inputs = ('hubHeight', )
        outputs = ('cost', )

        return inputs, outputs

    def provideJ(self):

        dhubHt = _landbos.deriv_erectionCost(self.nTurbines)
        J = np.array([[dhubHt]])

        return J
Пример #10
0
class GradientOptions(VariableTree):
    ''' Options for calculation of the gradient by the driver's workflow. '''

    # Finite Difference
    fd_form = Enum('forward', ['forward', 'backward', 'central'],
                   desc='Finite difference mode (forward, backward, central',
                   framework_var=True)
    fd_step = Float(1.0e-6,
                    desc='Default finite difference stepsize',
                    framework_var=True)
    fd_step_type = Enum('absolute', ['absolute', 'relative', 'bounds_scaled'],
                        desc='Set to absolute, relative, '
                        'or scaled to the bounds ( high-low) step sizes',
                        framework_var=True)

    force_fd = Bool(False,
                    desc="Set to True to force finite difference " +
                    "of this driver's entire workflow in a" + "single block.",
                    framework_var=True)

    # KTM - story up for this one.
    #fd_blocks = List([], desc='User can specify nondifferentiable blocks ' + \
    #                          'by adding sets of component names.')

    # Analytic solution with GMRES
    gmres_tolerance = Float(1.0e-9,
                            desc='Tolerance for GMRES',
                            framework_var=True)
    gmres_maxiter = Int(100,
                        desc='Maximum number of iterations for GMRES',
                        framework_var=True)
Пример #11
0
    def setUp(self):
        self.startdir = os.getcwd()
        self.tempdir = tempfile.mkdtemp(prefix='test_csv-')
        os.chdir(self.tempdir)

        self.top = top = set_as_top(Assembly())
        driver = top.add('driver', SimpleCaseIterDriver())
        top.add('comp1', ExecComp(exprs=['z=x+y']))
        top.add('comp2', ExecComp(exprs=['z=x+1']))
        top.connect('comp1.z', 'comp2.x')
        top.comp1.add('a_string', Str("Hello',;','", iotype='out'))
        top.comp1.add('a_array', Array(array([1.0, 3.0, 5.5]), iotype='out'))
        top.comp1.add('x_array', Array(array([1.0, 1.0, 1.0]), iotype='in'))
        top.comp1.add('b_bool', Bool(False, iotype='in'))
        top.comp1.add('vt', VarTree(DumbVT(), iotype='out'))
        top.driver.workflow.add(['comp1', 'comp2'])

        # now create some Cases
        outputs = ['comp1.z', 'comp2.z', 'comp1.a_string', 'comp1.a_array[2]']
        cases = []
        for i in range(10):
            i = float(i)
            inputs = [('comp1.x', i + 0.1), ('comp1.y', i * 2 + .1),
                      ('comp1.x_array[1]', 99.88), ('comp1.b_bool', True)]
            cases.append(Case(inputs=inputs, outputs=outputs))

        Case.set_vartree_inputs(driver, cases)
        driver.add_responses(sorted(outputs))

        self.filename = "openmdao_test_csv_case_iterator.csv"
Пример #12
0
class ElecMaterials(Component):

    terrain = Enum('FLAT_TO_ROLLING',
                   ('FLAT_TO_ROLLING', 'RIDGE_TOP', 'MOUNTAINOUS'),
                   iotype='in',
                   desc='terrain options')
    layout = Enum('SIMPLE', ('SIMPLE', 'COMPLEX'),
                  iotype='in',
                  desc='layout options')
    farmSize = Float(iotype='in', units='MW', desc='wind farm size')
    diameter = Float(iotype='in', units='m', desc='rotor diameter')
    nTurbines = Int(iotype='in', desc='number of turbines')
    padMountTransformer = Bool(True,
                               iotype='in',
                               desc='pad mount transformer required')
    thermalBackfill = Float(0.0,
                            iotype='in',
                            units='mi',
                            desc='MV thermal backfill')

    cost = Float(iotype='out',
                 units='USD',
                 desc='MV electrical materials cost')

    def execute(self):
        self.cost = _landbos.electricalMaterialsCost(Enum2Int(self, 'terrain'),
                                                     Enum2Int(self, 'layout'),
                                                     self.farmSize,
                                                     self.diameter,
                                                     self.nTurbines,
                                                     self.padMountTransformer,
                                                     self.thermalBackfill)
Пример #13
0
class IterateUntil(Driver):
    """ A simple driver to run a workflow until some stop condition is met. """

    max_iterations = Int(10, iotype="in", desc="Maximum number of iterations.")
    iteration = Int(0, iotype="out", desc="Current iteration counter.")
    run_at_least_once = Bool(True, iotype="in", desc="If True, driver will"
                             " ignore stop conditions for the first iteration"
                             " and run at least one iteration.")

    def start_iteration(self):
        """ Code executed before the iteration. """
        self.iteration = 0

    def continue_iteration(self):
        """ Convergence check."""
        if self.iteration < 1 and self.run_at_least_once:
            self.iteration += 1
            return True

        if self.should_stop():
            return False

        if self.iteration < self.max_iterations:
            self.iteration += 1
            return True

        return False
Пример #14
0
class showBPMtext(Component):
    """
    Shows the estimated BPM in the image frame
    """
    ready = Bool(False, iotype="in")
    bpm = Float(iotype="in")
    x = Int(iotype="in")
    y = Int(iotype="in")
    fps = Float(iotype="in")
    size = Float(iotype="in")
    n = Int(iotype="in")

    def __init__(self):
        super(showBPMtext, self).__init__()
        self.add("frame_in", Array(iotype="in"))
        self.add("frame_out", Array(iotype="out"))
        self.bpms = []

    def execute(self):
        self.bpms.append([time.time(), self.bpm])
        if self.ready:
            col = (0, 255, 0)
            text = "%0.1f bpm" % self.bpm
            tsize = 2
        else:
            col = (100, 255, 100)
            gap = (self.n - self.size) / self.fps
            text = "(estimate: %0.1f bpm, wait %0.0f s)" % (self.bpm, gap)
            tsize = 1
        cv2.putText(self.frame_in, text, (self.x, self.y),
                    cv2.FONT_HERSHEY_PLAIN, tsize, col)
        self.frame_out = self.frame_in
Пример #15
0
    def __init__(self, num_elem=10):
        super(SysSpeed, self).__init__()

        # Inputs
        self.add(
            'temp',
            Array(np.zeros((num_elem + 1, )),
                  iotype='in',
                  low=0.001,
                  desc='Temperature'))
        self.add(
            'M',
            Array(np.zeros((num_elem + 1, )), iotype='in', desc='Mach Number'))
        self.add('v_spline',
                 Array(np.zeros((num_elem + 1, )), iotype='in', desc='Speed'))
        self.add(
            'v_specified',
            Bool(False,
                 iotype='in',
                 desc='Set to True to disable calculation and use v_spline '
                 'instead.'))

        # Outputs
        self.add('v',
                 Array(np.zeros((num_elem + 1, )), iotype='out', desc='Speed'))
Пример #16
0
class VarComponent(Component):
    """Contains some vars"""

    boolvar = Bool(False, iotype='in')
    intvar = Int(333, iotype='in')
    floatvar = Float(-16.54, iotype='in')
    expvar1 = Float(1.2, iotype='in')
    expvar2 = Float(1.2, iotype='in')
    textvar = Str("This", iotype='in')
    arrayvar = Array(iotype='in')
    arrayvarsplit = Array(iotype='in')
    arrayvarsplit2 = Array(iotype='in')
    arrayvarzerod = Array(zeros(shape=(0, 0)), iotype='in')
    arrayvartwod = Array(zeros(shape=(1, 3)), iotype='in')
    arraysmall = Array(iotype='in')
    arrayshorthand = Array(iotype='in')
    single = Array(iotype='in')
    singleint = Array(iotype='in', dtype=numpy_int32)
    singlebool = Array(iotype='in', dtype=bool)
    stringarray = List([], iotype='in')
    listenumvar = List(Enum(1, (1, 2, 3)), iotype='in')
    listenumvar2 = List(Enum(1.5, (1.5, 2.4, 3.3)), iotype='in')
    listenumvar3 = List(Enum('a', ('a', 'b', 'c')), iotype='in')
    listenumvar4 = List(Enum(True, (True, False)), iotype='in')

    varcontainer = VarTree(VarContainer(), iotype='in')
Пример #17
0
class RNAprops(VariableTree):
    """Basic Inertial and Geometric Properties of RNA"""
    mass = Float(units='kg', desc='RNA mass')  #RNA mass [kg]
    I = Array(np.zeros(6),
              dtype=np.float,
              units='kg*m**2',
              desc='RNA [IXX,IYY,IZZ,IXY,IXZ,IYZ] @tower top flange')
    CMoff = Array(np.zeros(3),
                  dtype=np.float,
                  units='m',
                  desc='RNA CM [x,y,z] offset from Tower Top Flange'
                  )  # RNA CMx,y,zoff [m]
    Thoff = Array(np.zeros(3),
                  dtype=np.float,
                  units='m',
                  desc='Rotor Hub Center [x,y,z] offset from Tower Top Flange'
                  )  # Thrust point of application [m]

    rna_weightM = Bool(
        True,
        units=None,
        desc='flag to consider or not the RNA weight effect on Moment')

    yawangle = Float(
        0.,
        units='deg',
        desc=
        'YAW angle CCW RH rule, to account for possible nacelle weight contribution.'
    )  # RNA Yaw angle [deg]
Пример #18
0
class VarContainer(VariableTree):
    """Contains some vars"""

    boolvar = Bool(True)
    intvar = Int(7777)
    floatvar = Float(2.14543)
    textvar = Str("Hey")
    listenumvar = List(Enum(1, (1, 2, 3)))
Пример #19
0
def configure_lcoe_with_turb_costs(assembly):
    """
    tcc_a inputs:
        advanced_blade = Bool
        offshore = Bool
        assemblyCostMultiplier = Float
        overheadCostMultiplier = Float
        profitMultiplier = Float
        transportMultiplier = Float
    """

    assembly.replace('tcc_a', Turbine_CostsSE())

    assembly.add('advanced_blade', Bool(True, iotype='in', desc='advanced (True) or traditional (False) blade design'))
    assembly.add('offshore', Bool(iotype='in', desc='flag for offshore site'))
    assembly.add('assemblyCostMultiplier',Float(0.0, iotype='in', desc='multiplier for assembly cost in manufacturing'))
    assembly.add('overheadCostMultiplier', Float(0.0, iotype='in', desc='multiplier for overhead'))
    assembly.add('profitMultiplier', Float(0.0, iotype='in', desc='multiplier for profit markup'))
    assembly.add('transportMultiplier', Float(0.0, iotype='in', desc='multiplier for transport costs'))

    # connections to turbine costs
    assembly.connect('rotor.mass_one_blade', 'tcc_a.blade_mass')
    assembly.connect('hub.hub_mass', 'tcc_a.hub_mass')
    assembly.connect('hub.pitch_system_mass', 'tcc_a.pitch_system_mass')
    assembly.connect('hub.spinner_mass', 'tcc_a.spinner_mass')
    assembly.connect('nacelle.low_speed_shaft_mass', 'tcc_a.low_speed_shaft_mass')
    assembly.connect('nacelle.main_bearing_mass', 'tcc_a.main_bearing_mass')
    assembly.connect('nacelle.second_bearing_mass', 'tcc_a.second_bearing_mass')
    assembly.connect('nacelle.gearbox_mass', 'tcc_a.gearbox_mass')
    assembly.connect('nacelle.high_speed_side_mass', 'tcc_a.high_speed_side_mass')
    assembly.connect('nacelle.generator_mass', 'tcc_a.generator_mass')
    assembly.connect('nacelle.bedplate_mass', 'tcc_a.bedplate_mass')
    assembly.connect('nacelle.yaw_system_mass', 'tcc_a.yaw_system_mass')
    assembly.connect('jacket.Twrouts.mass', 'tcc_a.tower_mass') # jacket input
    assembly.connect('rotor.control.ratedPower', 'tcc_a.machine_rating')
    assembly.connect('rotor.nBlades', 'tcc_a.blade_number')
    assembly.connect('nacelle.crane', 'tcc_a.crane')
    assembly.connect('year', 'tcc_a.year')
    assembly.connect('month', 'tcc_a.month')
    assembly.connect('nacelle.drivetrain_design', 'tcc_a.drivetrain_design')
    assembly.connect('advanced_blade','tcc_a.advanced_blade')
    assembly.connect('offshore','tcc_a.offshore')
    assembly.connect('assemblyCostMultiplier','tcc_a.assemblyCostMultiplier')
    assembly.connect('overheadCostMultiplier','tcc_a.overheadCostMultiplier')
    assembly.connect('profitMultiplier','tcc_a.profitMultiplier')
    assembly.connect('transportMultiplier','tcc_a.transportMultiplier')
Пример #20
0
def _add_bool(vartree, member, props):
    """ Helper for :meth:`_populate_from_xml`. """
    name = member.attrib['name']
    args = {}
    args['default_value'] = member.text == 'true'
    desc = props.get('description')
    if desc:
        args['desc'] = desc.decode('string_escape')
    vartree.add(name, Bool(**args))
Пример #21
0
    def __init__(self, *args, **kwargs):
        super(TopObj, self).__init__(*args, **kwargs)
        self.add('subobj', SubObj(iotype=kwargs['iotype']))
        self.add('tob', Bool(True))
        self.add('tof', Float(0.5, units='inch'))
        self.add('toi', Int(42))
        self.add('tos', Str('Hello'))
        self.add(
            'tofe',
            Enum(values=(2.781828, 3.14159),
                 aliases=('e', 'pi'),
                 desc='Float enum',
                 units='m'))
        self.add('toie', Enum(values=(9, 8, 7, 1), desc='Int enum'))
        self.add('tose', Enum(values=('cold', 'hot', 'nice'), desc='Str enum'))

        self.add(
            'tof1d',
            Array(dtype=float,
                  desc='1D float array',
                  units='cm',
                  default_value=[1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5],
                  low=0,
                  high=10))

        self.add(
            'tof2d',
            Array(dtype=float,
                  desc='2D float array',
                  units='mm',
                  default_value=[[1.5, 2.5, 3.5, 4.5], [5.5, 6.5, 7.5, 8.5]]))

        self.add(
            'tof3d',
            Array(dtype=float,
                  desc='3D float array',
                  default_value=[[[1.5, 2.5, 3.5], [4.5, 5.5, 6.5],
                                  [7.5, 8.5, 9.5]],
                                 [[10.5, 20.5, 30.5], [40.5, 50.5, 60.5],
                                  [70.5, 80.5, 90.5]]]))

        self.add(
            'toi1d',
            Array(dtype=int,
                  desc='1D int array',
                  default_value=[1, 2, 3, 4, 5, 6, 7, 8, 9]))

        self.add(
            'tos1d',
            List(Str,
                 desc='1D string array',
                 value=['Hello', 'from', 'TestComponent.tos1d']))

        self.add('toflst', List(Float, desc='Float list'))
        self.add('toilst', List(Int, desc='Int list'))
Пример #22
0
class LinProg(Component):
    """ A simple component wrapper for scipy.optimize.linprog
    """
    implements(ILinearProgram)

    # inputs
    f     = Array(iotype='in',
            desc='coefficients of the linear objective function to be maximized')

    A     = Array(iotype='in',
            desc='2-D array which, when matrix-multiplied by x, gives the values of the upper-bound inequality constraints at x')

    b     = Array(iotype='in',
            desc='1-D array of values representing the upper-bound of each inequality constraint (row) in A_ub')

    A_eq  = Array(iotype='in',
            desc='2-D array which, when matrix-multiplied by x, gives the values of the equality constraints at x')

    b_eq  = Array(iotype='in',
            desc='1-D array of values representing the RHS of each equality constraint (row) in A_eq')

    lb    = Array(iotype='in',
            desc='lower bounds for each independent variable in the solution')

    ub    = Array(iotype='in',
            desc='upper bounds for each independent variable in the solution')

    # outputs
    x     = Array(iotype='out',
            desc='independent variable vector which optimizes the linear programming problem')

    fun   = Float(iotype='out',
            desc='function value')

    success = Bool(iotype='out',
              desc='flag indicating success or failure in finding an optimal solution')

    status  = Int(iotype='out',
              desc='exit status of the optimization: 0=optimized, 1=max iterations, 2=infeasible, 3=unbounded')

    def execute(self):
        """ solve the linear program """

        results = linprog(self.f,
                          A_eq=self.A_eq,   b_eq=self.b_eq,
                          A_ub=self.A,      b_ub=self.b,
                          bounds=zip(self.lb, self.ub),
                          options={ 'maxiter': 100, 'disp': True })

        print self.get_pathname(), 'results:\n---------------\n', results, '\n---------------'
        self.x   = results.x
        self.fun = results.fun
        self.success = results.success
        self.status  = results.status
Пример #23
0
class SubGroup(Container):
    """ For checking subcontainer access. """

    b = Bool(iotype='in', default_value=True, desc='A boolean')
    f = Float(iotype='in', default_value=0.5, desc='A float')
    i = Int(iotype='in', default_value=7, desc='An int')
    s = Str(iotype='in',
            default_value='Hello World!  ( & < > )',
            desc='A string')

    fe = Enum(iotype='in',
              values=(2.781828, 3.14159),
              aliases=('e', 'pi'),
              desc='Float enum',
              units='m')
    ie = Enum(iotype='in', values=(9, 8, 7, 1), desc='Int enum')
    se = Enum(iotype='in', values=('cold', 'hot', 'nice'), desc='Str enum')

    f1d = Array(dtype=float,
                iotype='in',
                desc='1D float array',
                units='cm',
                default_value=[1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5],
                low=0,
                high=10)

    f2d = Array(dtype=float,
                iotype='in',
                desc='2D float array',
                units='mm',
                default_value=[[1.5, 2.5, 3.5, 4.5], [5.5, 6.5, 7.5, 8.5]])

    f3d = Array(dtype=float,
                iotype='in',
                desc='3D float array',
                default_value=[[[1.5, 2.5, 3.5], [4.5, 5.5, 6.5],
                                [7.5, 8.5, 9.5]],
                               [[10.5, 20.5, 30.5], [40.5, 50.5, 60.5],
                                [70.5, 80.5, 90.5]]])

    i1d = Array(dtype=int,
                iotype='in',
                desc='1D int array',
                default_value=[1, 2, 3, 4, 5, 6, 7, 8, 9])

    s1d = List(Str,
               iotype='in',
               desc='1D string array',
               value=['Hello', 'from', 'TestComponent.SubGroup'])

    flst = List(Float, iotype='in', desc='List of floats')
    ilst = List(Int, iotype='in', desc='List of ints')
Пример #24
0
class TestComponent(Component):
    """
    Component which tracks it's total executions
    and can request that the run be stopped.
    """

    dummy_input = Int(0, iotype='in')
    set_stop = Bool(False, iotype='in')
    total_executions = Int(0, iotype='out')

    def execute(self):
        self.total_executions += 1
        if self.set_stop:
            self.parent.driver.stop()
Пример #25
0
 def test_build_trait(self):
     mbc = MyBuilderContainer()
     obj_info = [
         'f_in', ('f_out', 'f_out_internal', 'out'), 'i_in', 'i_out',
         ('b_out', 'b_out_internal', 'out', Bool())
     ]
     create_io_traits(mbc, obj_info)
     create_io_traits(mbc, 'foobar')
     self.assertTrue(mbc.get_trait('b_out').is_trait_type(Bool))
     self.assertTrue(mbc.get_trait('f_out').is_trait_type(Float))
     self.assertEqual(mbc.get_trait('f_out').iotype, 'out')
     self.assertTrue(mbc.get_trait('i_in').is_trait_type(Int))
     self.assertEqual(mbc.get_trait('f_in').iotype, 'in')
     self.assertTrue(mbc.get_trait('foobar').is_trait_type(Float))
     self.assertEqual(mbc.get_trait('foobar').iotype, 'in')
Пример #26
0
class Transmission(Component):

    voltage = Float(iotype='in', units='kV', desc='interconnect voltage')
    distInter = Float(iotype='in', units='mi', desc='distance to interconnect')
    newSwitchyardRequired = Bool(True,
                                 iotype='in',
                                 desc='new switchyard required')

    cost = Float(iotype='out',
                 units='USD',
                 desc='transmission line and interconnect cost')

    def execute(self):
        self.cost = _landbos.transmissionCost(self.voltage, self.distInter,
                                              self.newSwitchyardRequired)
Пример #27
0
def configure_lcoe_with_turb_costs(assembly):
    """
    tcc_a inputs:
        advanced_blade = Bool
        offshore = Bool
        assemblyCostMultiplier = Float
        overheadCostMultiplier = Float
        profitMultiplier = Float
        transportMultiplier = Float
    """

    assembly.replace('tcc_a', nrel_csm_tcc_2015())

    # Turbine Cost and Mass Inputs
    # parameters / high level inputs
    assembly.add('machine_rating', Float(iotype='in', units='kW', desc='machine rating'))
    assembly.add('blade_number', Int(iotype='in', desc='number of rotor blades'))
    assembly.add('offshore', Bool(iotype='in', desc='flag for offshore project'))
    assembly.add('crane', Bool(iotype='in', desc='flag for presence of onboard crane'))
    assembly.add('bearing_number', Int(2, iotype='in', desc='number of main bearings []') )#number of main bearings- defaults to 2
    assembly.add('rotor_diameter', Float(units = 'm', iotype='in', desc= 'rotor diameter of the machine'))
    assembly.add('turbine_class', Enum('I', ('I', 'II/III', 'User Exponent'), iotype = 'in', desc='turbine class'))
    assembly.add('blade_has_carbon', Bool(False, iotype='in', desc= 'does the blade have carbon?')) #default to doesn't have carbon
    #assembly.add('rotor_torque', Float(iotype='in', units='N * m', desc = 'torque from rotor at rated power')) #JMF do we want this default?
    assembly.add('hub_height', Float(units = 'm', iotype='in', desc= 'hub height of wind turbine above ground / sea level'))

    assembly.connect('machine_rating','tcc_a.machine_rating')
    assembly.connect('blade_number',['tcc_a.blade_number'])
    assembly.connect('offshore',['tcc_a.offshore'])
    assembly.connect('crane',['tcc_a.crane'])
    assembly.connect('bearing_number',['tcc_a.bearing_number'])
    assembly.connect('rotor_diameter','tcc_a.rotor_diameter')
    assembly.connect('turbine_class','tcc_a.turbine_class')
    assembly.connect('blade_has_carbon','tcc_a.blade_has_carbon')
    #assembly.connect('rotor_torque','tcc_a.rotor_torque') #TODO - fix
    assembly.connect('hub_height','tcc_a.hub_height')
Пример #28
0
class Oneout(Component):
    """ A simple output component    """

    ratio1 = Float(3.54, iotype='out', desc='Float Variable')
    ratio2 = Int(9, iotype='out', desc='Integer variable')
    ratio3 = Bool(True, iotype='out', desc='Boolean Variable')
    ratio4 = Float(1.03, iotype='out', desc='Float variable ', units='cm')
    ratio5 = Str('05678', iotype='out', desc='string variable')
    ratio6 = Enum(27, (0, 3, 9, 27), iotype='out', desc='some enum')
    unit = Float(12.0, units='inch', iotype='out')
    no_unit = Float(12.0, iotype='out')

    arrout = Array(dtype=float, default_value=[1, 2, 3], iotype='out')

    def execute(self):
        """                                                                    
Пример #29
0
class Oneinp(Component):
    """ A simple input component    """

    ratio1 = Float(2., iotype='in', desc='Float   Variable')
    ratio2 = Int(2, iotype='in', desc='Int Variable')
    ratio3 = Bool(False, iotype='in', desc='Float Variable')
    ratio4 = Float(1.03, iotype='in', desc='Float variable ', units='ft')
    ratio5 = Str('01234', iotype='in', desc='string variable')
    ratio6 = Enum(0, (0, 3, 11, 27), iotype='in', desc='some enum')
    unit = Float(0.0, units='ft', iotype='in')
    no_unit = Float(0.0, iotype='in')

    arrinp = Array(dtype=float, default_value=[42, 13, 0], iotype='in')

    def execute(self):
        """                                                                    
Пример #30
0
class Erection(Component):

    rating = Float(iotype='in', units='kW', desc='machine rating')
    hubHeight = Float(iotype='in', units='m', desc='hub height')
    nTurbines = Int(iotype='in', desc='number of turbines')
    weatherDelayDays = Int(iotype='in', units='d', desc='weather delay days')
    craneBreakdowns = Int(iotype='in', desc='crane breakdowns')
    deliveryAssistRequired = Bool(iotype='in', desc='delivery assist required')

    cost = Float(iotype='out', units='USD', desc='erection cost')

    def execute(self):
        self.cost = _landbos.erectionCost(self.rating, self.hubHeight,
                                          self.nTurbines,
                                          self.weatherDelayDays,
                                          self.craneBreakdowns,
                                          self.deliveryAssistRequired)