How to use the openmdao.main.api.Component 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_distribcomp.py View on Github external
start, end, sizes, offsets = evenly_distrib_idxs(comm, self.arr_size)

        self.invec = np.ones(sizes[rank], dtype=float)
        self.outvec = np.ones(sizes[rank], dtype=float)

        print self.name,".outvec",self.outvec

        return {
            'invec': make_idx_array(start, end),
            'outvec': make_idx_array(start, end)
        }

    def get_req_cpus(self):
        return 2

class DistribNoncontiguousComp(Component):
    """Uses 2 procs and takes non-contiguous input var slices and has output
    var slices as well
    """
    def __init__(self, arr_size=11):
        super(DistribNoncontiguousComp, self).__init__()
        self.arr_size = arr_size
        self.add_trait('invec', Array(np.ones(arr_size, float), iotype='in'))
        self.add_trait('outvec', Array(np.ones(arr_size, float), iotype='out'))

    def execute(self):
        if self.mpi.comm == MPI.COMM_NULL:
            return

        for i,val in enumerate(self.invec):
            self.outvec[i] = 2*val
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_distribcomp.py View on Github external
class InOutArrayComp(Component):
    delay = Float(0.01, iotype='in')

    def __init__(self, arr_size=10):
        super(InOutArrayComp, self).__init__()
        self.mpi.requested_cpus = 2

        self.add_trait('invec', Array(np.ones(arr_size, float), iotype='in'))
        self.add_trait('outvec', Array(np.ones(arr_size, float), iotype='out'))

    def execute(self):
        time.sleep(self.delay)
        self.outvec = self.invec * 2.

class DistribCompSimple(Component):
    """Uses 2 procs but takes full input vars"""
    def __init__(self, arr_size=10):
        super(DistribCompSimple, self).__init__()
        self.mpi.requested_cpus = 2

        self.add_trait('invec', Array(np.ones(arr_size, float), iotype='in'))
        self.add_trait('outvec', Array(np.ones(arr_size, float), iotype='out'))

    def execute(self):
        if self.mpi.comm == MPI.COMM_NULL:
            return
        if self.mpi.comm != MPI.COMM_NULL:
            if self.mpi.comm.rank == 0:
                self.outvec = self.invec * 0.25
            elif self.mpi.comm.rank == 1:
                self.outvec = self.invec * 0.5
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_assembly.py View on Github external
def test_remove(self):
        top = Assembly()
        top._setup()
        g = top._depgraph.component_graph()
        comps = [name for name in g]
        self.assertEqual(comps, ['driver'])

        top.add('comp', Component())
        top._setup()

        g = top._depgraph.component_graph()
        comps = [name for name in g]
        self.assertEqual(set(comps), set(['driver', 'comp']))

        top.remove('comp')
        top._setup()

        g = top._depgraph.component_graph()
        comps = [name for name in g]
        self.assertEqual(comps, ['driver'])
github OpenMDAO / OpenMDAO-Framework / contrib / testmpi / test_assembly.py View on Github external
self.assertEqual(top.get('z'), 42.)
        self.assertEqual(top.get('comp.z'), 42.)

        top.set('x', 7)
        top.set('y', 8)
        top.run()
        self.assertEqual(top.get('x'), 7.)
        self.assertEqual(top.get('comp.x'), 7.)
        self.assertEqual(top.get('y'), 8.)
        self.assertEqual(top.get('comp.y'), 8.)
        self.assertEqual(top.get('z'), 56.)
        self.assertEqual(top.get('comp.z'), 56.)

        egg_info = top.save_to_egg('Top', 'v1')
        try:
            egg = Component.load_from_eggfile(egg_info[0])
            self.assertEqual(egg.get('x'), 7.)
            self.assertEqual(egg.get('comp.x'), 7.)
            self.assertEqual(egg.get('y'), 8.)
            self.assertEqual(egg.get('comp.y'), 8.)
            self.assertEqual(egg.get('z'), 56.)
            self.assertEqual(egg.get('comp.z'), 56.)

            egg.set('x', 11)
            egg.set('y', 3)
            egg.run()
            self.assertEqual(egg.get('x'), 11.)
            self.assertEqual(egg.get('comp.x'), 11.)
            self.assertEqual(egg.get('y'), 3)
            self.assertEqual(egg.get('comp.y'), 3.)
            self.assertEqual(egg.get('z'), 33.)
            self.assertEqual(egg.get('comp.z'), 33.)
github OpenMDAO / OpenMDAO-Framework / examples / openmdao.examples.singleEI / openmdao / examples / singleEI / sin_component.py View on Github external
import math

from openmdao.main.api import Component
from openmdao.lib.api import Float

class SinComponent(Component): 
    x = Float(0,iotype="in")
    
    f_x = Float(0,iotype="out")
    
    def execute(self):
        self.f_x = math.sin(self.x)
github thearn / webcam-pulse-detector / lib / signalProcess.py View on Github external
def execute(self):
        self.samples.append(self.data_in)
        self.times.append(time.time())
        self.size = len(self.samples)
        if self.size > self.n:
            self.ready = True
            self.samples = self.samples[-self.n:]
            self.times = self.times[-self.n:]
        if self.size>4:
            self.fft = self.get_fft()
            if self.spike_limit:
                if max(self.samples)-min(self.samples) > self.spike_limit:
                    self.reset()

class bandProcess(Component):
    """
    Component to isolate specific frequency bands
    """
    hz = Float(iotype="out")
    peak_hz = Float(iotype="out")
    phase = Float(iotype="out")
    def __init__(self, limits = [0.,3.], make_filtered = True, 
                 operation = "pass"):
        super(bandProcess,self).__init__()
        self.add("freqs_in",Array(iotype="in"))
        self.add("fft_in", Array(iotype="in"))
        
        self.add("freqs", Array(iotype="out"))
        self.make_filtered = make_filtered
        if make_filtered:
            self.add("filtered", Array(iotype="out"))
github OpenMDAO / OpenMDAO-Framework / contrib / enginedesign / openmdao.examples.enginedesign / openmdao / examples / enginedesign / chassis.py View on Github external
"""
    chassis.py - Chassis component for the vehicle example problem.
"""

# This openMDAO component determines the vehicle acceleration based on the
# power output of the engine, modified by the transmission torque ratio.

from math import pi

# pylint: disable-msg=E0611,F0401
from openmdao.main.api import Component
from openmdao.main.datatypes.api import Float



class Chassis(Component):
    """ A vehicle dynamics component - calculates acceleration.

    Design parameters:
    mass_vehicle        # Vehicle Mass (kg)
    Cf                  # Friction coef (multiplies W)
    Cd                  # Drag coef (multiplies V**2)
    area                # Frontal area (for drag calc) (sq m)
    
    Simulation inputs:
    mass_engine         # Engine Mass (kg)
    velocity            # Vehicle velocity (m/s)
    engine_torque       # Engine Torque (Nm)
    torque_ratio        # Torque ratio due to Transmission
    tire_circ           # Circumference of tire (m)
    
    Outputs:
github OpenMDAO / OpenMDAO-Framework / examples / openmdao.examples.expected_improvement / openmdao / examples / expected_improvement / branin_component.py View on Github external
from math import cos, pi

from openmdao.main.api import Component
from openmdao.lib.datatypes.api import Float


class BraninComponent(Component): 
    x = Float(0.,iotype="in",low=-5.,high=10.)
    y = Float(0.,iotype="in",low=0.,high=15.)
    
    f_xy = Float(0.,iotype="out")
    
    def execute(self):
        print "HERE"
        self.f_xy = (self.y-(5.1/(4.*pi**2.))*self.x**2.+5.*self.x/pi-6.)**2.+10.*(1.-1./(8.*pi))*cos(self.x)+10.
github OpenMDAO / OpenMDAO-Framework / contrib / example_plugins / mycomp / src / mycomp / mycomp.py View on Github external
from openmdao.main.api import Component
from openmdao.main.datatypes.api import Float


# Make sure that your class has some kind of docstring. Otherwise
# the descriptions for your variables won't show up in the
# source documentation.
class MyComponent(Component):
    """An example Component plugin class. """
    
    x = Float(0.0, iotype='in', desc='some input')
    y = Float(0.0, iotype='out', desc='x + 1')

    def execute(self):
        """y = x + 1"""
        self.y = self.x + 1.0
github WISDEM / WISDEM / src / wisdem / turbinese / turbine_jacket.py View on Github external
#from towerse.tower import TowerSE
from commonse.rna import RNAMass, RotorLoads
from jacketse.jacket import JacketSE
from jacketse.jacket import JcktGeoInputs,SoilGeoInputs,WaterInputs,WindInputs,RNAprops,TPlumpMass,Frame3DDaux,\
                    MatInputs,LegGeoInputs,XBrcGeoInputs,MudBrcGeoInputs,HBrcGeoInputs,TPGeoInputs,PileGeoInputs,\
                    TwrGeoInputs, LegGeoOutputs, TwrGeoOutputs
from commonse.Tube import Tube
from drivewpact.drive import DriveWPACT
from drivewpact.hub import HubWPACT
from commonse.csystem import DirectionVector
from commonse.utilities import interp_with_deriv, hstack, vstack
from drivese.drive import Drive4pt, Drive3pt
from drivese.hub import HubSE


class MaxTipDeflection(Component):

    Rtip = Float(iotype='in', units='m')
    precurveTip = Float(iotype='in', units='m')  # TODO: add gradients for precurveTip and presweepTip
    presweepTip = Float(iotype='in', units='m')
    precone = Float(iotype='in', units='deg')
    tilt = Float(iotype='in', units='deg')
    hub_tt = Array(iotype='in', units='m', desc='location of hub relative to tower-top in yaw-aligned c.s.')
    tower_z = Array(iotype='in', units='m')
    #tower_d = Array(np.array([3.87, 3.87]),iotype='in', units='m') #TODO remove default
    towerHt = Float(iotype='in', units='m')

    max_tip_deflection = Float(iotype='out', units='m', desc='clearance between undeflected blade and tower')
    ground_clearance = Float(iotype='out', units='m', desc='distance between blade tip and ground')
    Twrouts  = VarTree(TwrGeoOutputs(), iotype='in', desc='Basic Output data for Tower')

    def execute(self):