How to use the openmdao.main.datatypes.api.Array 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 / analysis_server / src / analysis_server / objxml.py View on Github external
def _set_from_xml(container, root):
    """ Recursive helper for :meth:`set_from_xml`. """
    members = root.find('members')
    for member in members.findall('member'):
        name = member.attrib['name']
        obj = getattr(container, name)
        if isinstance(obj, Container):
            _set_from_xml(obj, member)
        else:
            trait = container.get_dyn_trait(name)
            ttype = trait.trait_type
            if isinstance(ttype, Array):
                _set_array(container, name, member, True)
            elif isinstance(ttype, List):
                _set_array(container, name, member, False)
            elif isinstance(ttype, Bool):
                _set_bool(container, name, member)
            elif isinstance(ttype, Enum):
                try:
                    i = trait.aliases.index(member.text)
                except (AttributeError, ValueError):
                    etyp = type(trait.values[0])
                    if etyp == float:
                        _set_float(container, name, member)
                    elif etyp == int:
                        _set_int(container, name, member)
                    else:
                        _set_str(container, name, member)
github OpenMDAO / OpenMDAO-Framework / openmdao.lib / src / openmdao / lib / components / expected_improvement_multiobj.py View on Github external
except ImportError as err:
        logging.warn("In %s: %r" % (__file__, err))
        _check.append('scipy')

from openmdao.main.datatypes.api import Slot, Enum, Float, Array, Event, Int, Instance

from openmdao.main.component import Component
from openmdao.util.decorators import stub_if_missing_deps

from openmdao.lib.casehandlers.api import CaseSet
from openmdao.main.uncertain_distributions import NormalDistribution


@stub_if_missing_deps(*_check)
class MultiObjExpectedImprovementBase(Component):
    criteria = Array(iotype="in",
                    desc="Names of responses to maximize expected improvement around. \
                    Must be NormalDistribution type.")

    predicted_values = Array([0, 0], iotype="in", dtype=NormalDistribution,
                        desc="CaseIterator which contains NormalDistributions for each \
                        response at a location where you wish to calculate EI.")

    n = Int(1000, iotype="in", desc="Number of Monte Carlo Samples with \
                        which to calculate probability of improvement.")

    calc_switch = Enum("PI", ["PI", "EI"], iotype="in", desc="Switch to use either \
                        probability (PI) or expected (EI) improvement.")

    PI = Float(0.0, iotype="out", desc="The probability of improvement of the next_case.")

    EI = Float(0.0, iotype="out", desc="The expected improvement of the next_case.")
github OpenMDAO / OpenMDAO-Framework / contrib / axod / datain.py View on Github external
icf    = Int(iotype='in',desc='Switch for flow coefficient variation, default=0')

    endplt = Float(iotype='in',desc='Switch for writing a map file in NEPP format,default=0')

    endjob = Float(iotype='in',desc='Switch for last case, default=0')

    stage  = Float(iotype='in',desc='Stage Number')

    #gamg   = Float(iotype='in',desc='Specific heat ratio')
    gamg     = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #dr     = Float(iotype='in',units='inch',desc='Hub diameter')
    dr     = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #dt     = Float(iotype='in',units='inch',desc='Tip diameter')
    dt     = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #rwg    = Float(iotype='in',desc='Ratio of Station mass-flow rate to turbine inlet mass-flow rate')
    rwg    = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #twg    = Float(iotype='in',units='degR',desc='Temperature of the Cooolant specified by rwg')
    twg    = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #pwg    = Float(iotype='in',units='psi',desc='Pressure of the Cooolant specified by pwg')
    pwg    = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #sdia   = Float(iotype='in',units='deg',desc='Stator vane inlet angle')
    sdia   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #sdea   = Float(iotype='in',units='deg',desc='Stator vane exit angle')
    sdea   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')
github OpenMDAO / OpenMDAO-Framework / examples / openmdao.examples.mdao / openmdao / examples / mdao / scalable_BLISS.py View on Github external
print "d1_local_des_vars: %s"%self.parent.d1_local_des_vars
        print "d2_local_des_vars: %s"%self.parent.d2_local_des_vars
        
        print "global_des_vars: %s"%self.parent.global_des_vars
        
        print 
        print 
        print 
        #raw_input()
        
        
        
#uses the default, 3 discipline, 3 globals, 3 locals
class Scalable(UnitScalableProblem): 
    
    global_des_vars   = Array([0.,0.,0.])
    d0_local_des_vars = Array([-.333,-.333,-.333])
    d1_local_des_vars = Array([-.333,-.333,-.333])
    d2_local_des_vars = Array([-.333,-.333,-.333])
    
    offset = Float(2,iotype="in")
    factor = Float(.95,iotype="in")
    percent = Float(1,iotype="in")
    
    def __init__(self): 
        super(Scalable,self).__init__()
        
        #three components: d0,d1,d2
        
        
        obj = "d0.z0**2+d0.z1**2+d0.z2**2+d0.y_out**2+d1.y_out**2+d2.y_out**2"
github OpenMDAO / OpenMDAO-Framework / contrib / axod / datain.py View on Github external
#sdea   = Float(iotype='in',units='deg',desc='Stator vane exit angle')
    sdea   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #spa   = Float(iotype='in',units='inch**2',desc='Stator throat area per unit height')
    spa    = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    sesth = Float(iotype='in',desc='Ratio of blade height at stator exit to blade height at stator throat')

    #rdia   = Float(iotype='in',units='deg',desc='Rotor blade inlet angle')
    rdia   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #rdea   = Float(iotype='in',units='deg',desc='Rotor blade exit angle')
    rdea   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #rpa   = Float(iotype='in',units='inch**2',desc='Rotor throat area per unit height')
    rpa    = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    rerth = Float(iotype='in',desc='Ratio of blade height at rotor exit to blade height at rotor throat')

    #srec  = Float(iotype='in',desc='Stator inlet recovery efficiency, decimal')
    srec   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #rrec  = Float(iotype='in',desc='Rotor inlet recovery efficiency, decimal')
    rrec   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #rtf   = Float(iotype='in',desc='Rotor test factor, decimal')
    rtf    = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #rvu1  = Float(iotype='in',units='inch*ft/s',desc='Design Stator-exit angular momentum')
    rvu1   = Array(_ZEROS5,dtype=float32,shape=(5,),iotype='in')

    #rvu2  = Float(iotype='in',units='inch*ft/s',desc='Design rotor-exit angular momentum')
github WISDEM / WISDEM / src / wisdem / openmdao / components.py View on Github external
class RotorAeroBase(Component):
    """base class for rotor aerodynamics"""

    # ---- in ------

    atm = VarTree(Atmosphere(), iotype='in', desc='atmospheric properties')

    B = Int(3, iotype='in', desc='number of blades')
    precone = Float(iotype='in', units='deg', desc='precone angle')
    tilt = Float(iotype='in', units='deg', desc='rotor tilt angle')
    yaw = Float(iotype='in', units='deg', desc='yaw angle')
    hubHt = Float(iotype='in', units='m', desc='hub height')

    r_structural = Array([0.0], iotype='in', units='m', desc='radial location where structural twist is defined')
    twist_structural = Array([0.0], iotype='in', units='deg', desc='structural twist (for steady aeroelastics)')


    # --- out -----
    V = Array(iotype='out', units='m/s', desc='hub height wind speeds used in power curve')
    P = Array(iotype='out', units='W', desc='corresponding power for wind speed (power curve)')
    AEP = Float(iotype='out', units='kW*h', desc='annual energy production')

    rated_conditions = VarTree(ConditionsAtRated(), iotype='out', desc='operating conditions at rated')

    loads_rated = VarTree(BladeDistributedLoads(), iotype='out', desc='aerodynamic loads at rated in airfoil-aligned c.s.')
    loads_extreme = VarTree(BladeDistributedLoads(), iotype='out', desc='aerodynamic loads at extreme condition in airfoil-aligned c.s.')
    hub_rated = VarTree(Forces(), iotype='out', desc='hub loads at rated in hub-aligned c.s.')
github WISDEM / WISDEM / src / wisdem / openmdao / rotorstruc_mdao.py View on Github external
from components import RotorStrucBase
from wisdem.rotor import RotorStruc, PreComp, Orthotropic2DMaterial, \
    CompositeSection, Profile
from wisdem.common import _akima




class RotorStrucComp(RotorStrucBase):
    """docstring for RotorStrucComp"""

    # geometry
    r = Array(iotype='in', units='m', desc='radial locations where composite sections are defined (from hub to tip)')
    chord = Array(iotype='in', units='m', desc='chord length at each section')
    theta = Array(iotype='in', units='deg', desc='twist angle at each section (positive decreases angle of attack)')
    le_location = Array(iotype='in', desc='location of pitch axis relative to leading edge in normalized chord units')
    webLoc = List(Array, iotype='in', desc='locations of shear webs')

    # composite section definition
    base_path = Str(iotype='in', desc='path to directory containing files')
    compSec = List(Str, iotype='in', desc='names of composite section layup files')
    profile = List(Str, iotype='in', desc='names of profile shape files')
    materials = Str(iotype='in', desc='name of materials file')

    # panel buckling
    panel_buckling_idx = Array(iotype='in', dtype=np.int, desc='index of sections critical for panel buckling')

    avgOmega = Float(iotype='in', units='rpm', desc='average rotation speed across wind speed distribution')


    # outputs
github WISDEM / WISDEM / src / wisdem / openmdao / rotorstruc_mdao.py View on Github external
# panel buckling
    panel_buckling_idx = Array(iotype='in', dtype=np.int, desc='index of sections critical for panel buckling')

    avgOmega = Float(iotype='in', units='rpm', desc='average rotation speed across wind speed distribution')


    # outputs

    f1 = Float(iotype='out', units='Hz', desc='first natural frequency')
    f2 = Float(iotype='out', units='Hz', desc='second natural frequency')

    tip_deflection = Float(iotype='out', units='m', desc='deflection of blade tip in azimuth-aligned x-direction')

    strain_upper = Array(iotype='out', desc='axial strain along upper surface of blade')
    strain_lower = Array(iotype='out', desc='axial strain along lower surface of blade')
    strain_buckling = Array(iotype='out', desc='maximum compressive strain along blade before panel buckling')
    r_strain = Array(iotype='out', units='m', desc='radial locations along blade where strain is evaluted')

    rootFatigue = Float(iotype='out')




    def _combineLoads(self, rotor, azimuth, pitch, r_aero, Px_aero, Py_aero, Pz_aero):

        r_w, Px_w, Py_w, Pz_w = rotor.weightLoads(self.tilt, azimuth, self.precone, pitch)

        Px = Px_w + _akima.interpolate(r_aero, Px_aero, r_w)
        Py = Py_w + _akima.interpolate(r_aero, Py_aero, r_w)
        Pz = Pz_w + _akima.interpolate(r_aero, Pz_aero, r_w)
github WISDEM / WISDEM / src / wisdem / openmdao / components.py View on Github external
Uhub = Float(iotype='in', desc='magnitude of hub height wind speed')


    # ---- out --------
    wind_wave_loads = VarTree(WindWaveDistributedLoads(), iotype='out', desc='distributed wind/wave loads along tower in yaw-aligned c.s.')



class TowerStrucBase(Component):
    """base class for tower structures"""

    # ---- in --------
    distributed_loads = VarTree(WindWaveDistributedLoads(), iotype='in', desc='applied loading on tower in yaw-aligned c.s.')
    top_forces = VarTree(Forces(), iotype='in', desc='point forces/moments at tower top in yaw-aligned c.s.')
    top_mass_properties = VarTree(MassProperties(), iotype='in', desc='RNA mass properties about tower top in yaw-aligned c.s.')
    top_cm = Array(iotype='in', units='m', desc='location of RNA center of mass relative to tower top in yaw-aligned c.s.')

    # ---- out --------
    mass = Float(iotype='out', units='kg', desc='mass of tower')




class MassTransferToTower(Component):
    """transfer rotor/nacelle mass properties to tower top"""

    # in
    rotor_mass_properties = VarTree(MassProperties(), iotype='in', desc='mass properties of rotor about its center of mass in hub-aligned c.s.')
    nacelle_mass_properties = VarTree(MassProperties(), iotype='in', desc='nacelle mass properties about its center of mass in hub-aligned c.s.')
    rotor_cm = Array(iotype='in', units='m', desc='location of rotor center of mass relative to tower top in hub-aligned c.s.')
    nacelle_cm = Array(iotype='in', units='m', desc='location of nacelle center of mass relative to tower top in hub-aligned c.s.')
    tilt = Float(iotype='in', units='deg', desc='shaft tilt angle')
github OpenMDAO / OpenMDAO-Framework / contrib / axod / axod_compn.py View on Github external
#print '  after write ...  self.nstages =', len(self._stages)
        



class AxodCompn(Component):
    """ OpenMDAO component wrapper for AXOD. """

    input_filename = Str(iotype='in')
    results = []
    hpower = Float(iotype='out')

    # 'float32' here could be just 'float', but AXOD is single-precision
    # so it just takes more space.  Not an issue with such small arrays,
    # but for larger data it may be important.
    tott  = Array(_ZEROS48, dtype=float32, shape=(48,), iotype='out')
    totp  = Array(_ZEROS48, dtype=float32, shape=(48,), iotype='out')
    mflow = Array(_ZEROS48, dtype=float32, shape=(48,), iotype='out')
    effs  = Array(_ZEROS48, dtype=float32, shape=(48,), iotype='out')
    effr  = Array(_ZEROS48, dtype=float32, shape=(48,), iotype='out')

    def __init__(self, input_filename=''):
        super(AxodCompn, self).__init__()
        self.input_filename = input_filename
        self.out_filename=self.input_filename+'O'
        self.ncases = _ncases
        self._cases = []
# This can be determined on-the-fly, but this works for now.

    def read_input(self, infilename):
        inp = open(infilename, 'r')
        status = 1