Ejemplo n.º 1
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"
Ejemplo n.º 2
0
    def __init__(self, num_elem=10):
        super(SysAeroSurrogate, self).__init__()

        # Inputs
        self.add(
            'alpha',
            Array(np.zeros((num_elem + 1, )),
                  iotype='in',
                  desc='Angle of attack'))
        self.add(
            'eta',
            Array(np.zeros((num_elem + 1, )),
                  iotype='in',
                  desc='Tail rotation angle'))
        self.add('AR', Float(0.0, iotype='in', desc='Aspect Ratio'))
        self.add('oswald', Float(0.0, iotype='in', desc="Oswald's efficiency"))

        # Outputs
        self.add(
            'CL',
            Array(np.zeros((num_elem + 1, )),
                  iotype='out',
                  desc='Lift Coefficient'))
        self.add(
            'CD',
            Array(np.zeros((num_elem + 1, )),
                  iotype='out',
                  desc='Drag Coefficient'))
Ejemplo n.º 3
0
class MyComp_Full_Array(ImplicitComponent):
    ''' Single implicit component with 3 states and residuals, all as arrays.

    For c=2.0, (x,y,z) = (1.0, -2.333333, -2.1666667)
    '''

    # External inputs
    c = Float(
        2.0,
        iotype="in",
        fd_step=.00001,
        desc=
        "arbitrary constant that is not iterated on but does affect the results"
    )

    # States
    xx = Array(np.zeros((3)), iotype="state")

    # Residuals
    res = Array(np.zeros((3)), iotype="residual")

    # Outputs
    y_out = Float(iotype='out')

    def evaluate(self):
        """run a single step to calculate the residual
        values for the given state var values"""

        c, x, y, z = self.c, self.xx[0], self.xx[1], self.xx[2]

        self.res[0] = self.c * (3 * x + 2 * y - z) - 1
        self.res[1] = 2 * x - 2 * y + 4 * z + 2
        self.res[2] = -x + y / 2. - z

        self.y_out = c + x + y + z
Ejemplo n.º 4
0
        class TestAssembly(Assembly):

            V = Array(iotype='in')
            P = Array(iotype='in')
            Prated = Float(iotype='in')
            Vin = Float(iotype='in')
            Vout = Float(iotype='in')
            invalid_bracket_return = Float(iotype='in')

            Vrated = Float(iotype='out')


            def configure(self):

                self.add('comp', TestComponent())
                self.add('brent', Brent())

                self.brent.workflow.add(['comp'])
                self.driver.workflow.add(['brent'])

                # connections to comp
                self.connect('V', 'comp.V')
                self.connect('P', 'comp.P')
                self.connect('Prated', 'comp.Prated')

                # setup Brent
                self.connect('Vin', 'brent.lower_bound')
                self.connect('Vout', 'brent.upper_bound')
                self.brent.add_parameter('comp.Vrated')
                self.brent.add_constraint('comp.residual = 0')
                self.connect('invalid_bracket_return', 'brent.invalid_bracket_return')

                # connect outputs
                self.connect('comp.Vrated', 'Vrated')
Ejemplo n.º 5
0
    def __init__(self, n=10):
        super(BEMPerf, self).__init__()

        #array size based on number of elements
        self.add(
            'delta_Ct',
            Array(iotype='in',
                  desc='thrusts from %d different blade elements' % n,
                  default_value=np.ones((n, )),
                  shape=(n, ),
                  dtype=Float,
                  units="N"))
        self.add(
            'delta_Cp',
            Array(iotype='in',
                  desc='Cp integrant points from %d different blade elements' %
                  n,
                  default_value=np.ones((n, )),
                  shape=(n, ),
                  dtype=Float))
        self.add(
            'lambda_r',
            Array(iotype='in',
                  desc='lambda_r from %d different blade elements' % n,
                  default_value=np.ones((n, )),
                  shape=(n, ),
                  dtype=Float))
Ejemplo n.º 6
0
class JacketUtilOutputs(VariableTree):
    """Jacket Utilization Basic Outputs"""

    t_util   = Array(np.array([-9999.]),dtype=np.float, desc='Member Utilization (tensile strength)')
    cb_util  = Array(np.array([-9999.]),dtype=np.float, desc='Member Utilization (compression-bending buckling)')
    XjntUtil = Array(np.array([-9999.]),dtype=np.float, desc='X-Joint Utilization')
    KjntUtil = Array(np.array([-9999.]),dtype=np.float, desc='K-Joint Utilization')
Ejemplo n.º 7
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]
Ejemplo n.º 8
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'))
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())
Ejemplo n.º 10
0
        class Dummy(Component):

            x = Array([[-1, 1], [-2, 2]], iotype="in", shape=(2, 2))
            y = Array([[-1, 1], [-2, 2]], iotype="out", shape=(2, 2))

            def execute(self):
                self.y = self.x
Ejemplo n.º 11
0
 def __init__(self, func, *args, **kwargs):
     super(CVwrapped, self).__init__()
     self.add("frame_in", Array(iotype="in"))
     self.add("frame_out", Array(iotype="out"))
     self._func = func
     self._args = args
     self._kwargs = kwargs
Ejemplo n.º 12
0
    def __init__(self):
        super(RGBmuxer, self).__init__()
        self.add("R", Array(iotype="in"))
        self.add("G", Array(iotype="in"))
        self.add("B", Array(iotype="in"))

        self.add("frame_out", Array(iotype="out"))
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!
Ejemplo n.º 14
0
class HubBase(Assembly):

    # variables
    blade_mass = Float(iotype='in', units='kg', desc='mass of one blade')
    rotor_bending_moment = Float(iotype='in',
                                 units='N*m',
                                 desc='flapwise bending moment at blade root')
    rotor_diameter = Float(iotype='in', units='m', desc='rotor diameter')
    blade_root_diameter = Float(iotype='in',
                                units='m',
                                desc='blade root diameter')

    # parameters
    blade_number = Int(3, iotype='in', desc='number of turbine blades')

    # outputs
    hub_system_mass = Float(0.0,
                            iotype='out',
                            units='kg',
                            desc='overall component mass')
    hub_system_cm = Array(
        iotype='out',
        desc=
        'center of mass of the hub relative to tower to in yaw-aligned c.s.')
    hub_system_I = Array(
        iotype='out',
        desc=
        'mass moments of Inertia of hub [Ixx, Iyy, Izz, Ixy, Ixz, Iyz] around its center of mass in yaw-aligned c.s.'
    )

    hub_mass = Float(0.0, iotype='out', units='kg')
    pitch_system_mass = Float(0.0, iotype='out', units='kg')
    spinner_mass = Float(0.0, iotype='out', units='kg')
Ejemplo n.º 15
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')
Ejemplo n.º 16
0
    def __init__(self, num_elem=10):
        super(SysTemp, self).__init__()

        # Inputs
        self.add(
            'h', Array(np.zeros((num_elem + 1, )),
                       iotype='in',
                       desc='Altitude'))

        # Outputs
        self.add(
            'temp',
            Array(np.zeros((num_elem + 1, )),
                  iotype='out',
                  low=0.001,
                  desc='Temperature'))

        self.epsilon = 500
        h_lower = 11000 - self.epsilon
        h_upper = 11000 + self.epsilon

        matrix = np.array([[h_lower**3, h_lower**2, h_lower, 1],
                           [h_upper**3, h_upper**2, h_upper, 1],
                           [3 * h_lower**2, 2 * h_lower, 1, 0],
                           [3 * h_upper**2, 2 * h_upper, 1, 0]])
        rhs = np.array([288.16 - (6.5e-3) * h_lower, 216.65, -6.5e-3, 0])
        self.coefs = np.linalg.solve(matrix, rhs)
Ejemplo n.º 17
0
class SetupRunVarSpeed(Component):
    """determines approriate conditions to run AeroBase code across the power curve"""

    control = VarTree(VarSpeedMachine(), iotype='in', desc='control parameters')
    R = Float(iotype='in', units='m', desc='rotor radius')
    npts = Int(20, iotype='in', desc='number of points to evalute aero code to generate power curve')

    # outputs
    Uhub = Array(iotype='out', units='m/s', desc='freestream velocities to run')
    Omega = Array(iotype='out', units='rpm', desc='rotation speeds to run')
    pitch = Array(iotype='out', units='deg', desc='pitch angles to run')

    missing_deriv_policy = 'assume_zero'

    def execute(self):

        ctrl = self.control
        n = self.npts
        R = self.R

        # # attempt to distribute points mostly before rated
        # cpguess = 0.5
        # Vr0 = (ctrl.ratedPower/(cpguess*0.5*rho*pi*R**2))**(1.0/3)
        # Vr0 *= 1.20

        # V1 = np.linspace(Vin, Vr0, 15)
        # V2 = np.linspace(Vr0, Vout, 6)
        # V = np.concatenate([V1, V2[1:]])

        # velocity sweep
        V = np.linspace(ctrl.Vin, ctrl.Vout, n)

        # corresponding rotation speed
        Omega_d = ctrl.tsr*V/R*RS2RPM
        Omega, dOmega_dOmegad, dOmega_dmaxOmega = smooth_min(Omega_d, ctrl.maxOmega, pct_offset=0.01)

        # store values
        self.Uhub = V
        self.Omega = Omega
        self.pitch = ctrl.pitch*np.ones_like(V)

        # gradients
        dV = np.zeros((n, 3))
        dOmega_dtsr = dOmega_dOmegad * V/R*RS2RPM
        dOmega_dR = dOmega_dOmegad * -ctrl.tsr*V/R**2*RS2RPM
        dOmega = hstack([dOmega_dtsr, dOmega_dR, dOmega_dmaxOmega])
        dpitch = np.zeros((n, 3))
        self.J = vstack([dV, dOmega, dpitch])


    def list_deriv_vars(self):

        inputs = ('control.tsr', 'R', 'control.maxOmega')
        outputs = ('Uhub', 'Omega', 'pitch')

        return inputs, outputs

    def provideJ(self):

        return self.J
Ejemplo n.º 18
0
        class MyComp(Component):

            x = Array([0, 0], iotype="in", dtype=float)
            y = Array([0, 0], iotype="out", dtype=float)

            def execute(self):
                self.y = self.x**2
Ejemplo n.º 19
0
def common_io(assembly, varspeed, varpitch):

    regulated = varspeed or varpitch

    # add inputs
    assembly.add('npts_coarse_power_curve', Int(20, iotype='in', desc='number of points to evaluate aero analysis at'))
    assembly.add('npts_spline_power_curve', Int(200, iotype='in', desc='number of points to use in fitting spline to power curve'))
    assembly.add('AEP_loss_factor', Float(1.0, iotype='in', desc='availability and other losses (soiling, array, etc.)'))
    if varspeed:
        assembly.add('control', VarTree(VarSpeedMachine(), iotype='in', desc='control parameters'))
    else:
        assembly.add('control', VarTree(FixedSpeedMachine(), iotype='in', desc='control parameters'))


    # add slots (must replace)
    assembly.add('geom', Slot(GeomtrySetupBase))
    assembly.add('analysis', Slot(AeroBase))
    assembly.add('dt', Slot(DrivetrainLossesBase))
    assembly.add('cdf', Slot(CDFBase))


    # add outputs
    assembly.add('AEP', Float(iotype='out', units='kW*h', desc='annual energy production'))
    assembly.add('V', Array(iotype='out', units='m/s', desc='wind speeds (power curve)'))
    assembly.add('P', Array(iotype='out', units='W', desc='power (power curve)'))
    assembly.add('diameter', Float(iotype='out', units='m', desc='rotor diameter'))
    if regulated:
        assembly.add('ratedConditions', VarTree(RatedConditions(), iotype='out'))
class Oneout(Component):
    """ A simple output component    """

    # pressure units
    ratio1 = Float(1.00, iotype='out',
                   desc='Float Variable',units='Pa')         #   pressure units
    ratio2 = Float(1, iotype='out',
                   desc='Float variable', units= 'mi')       #   Mile
    ratio3 = Float(1, iotype='out',
                   desc='Float variable', units= 'degF')     #   temperature in F
    ratio4 = Float(8.314472, iotype='out',
                   desc='Float variable ',units='J/(mol*degK)') # R, gas const
    ratio5 = Float(1, iotype='out',
                   desc='Float variable', units= 'degC')      #   temperature in C
    ratio6 = Float(1, iotype='out',
                   desc='Float variable', units= 'N')         #   force in N
    ratio7 = Float(1, iotype='out',
                   desc='Float variable', units= 'lbf')       #   force in lbf
    ratio8 = Float(1, iotype='out',
                   desc='Float variable', units= 'kg')        #   mass  in kg 
    ratio9 = Float(1, iotype='out',
                   desc='Float variable')                     #   no units defined 
    ratio10 = Float(1, iotype='out',
                   desc='Float variable', units= 'rad')       #   angle in rad 
    arr_in = Array([1.,2.,3.], units='ft', iotype='in')
    arr_out = Array([4.,5.,6.], units='kg', iotype='out')

    def __init__(self):

        super(Oneout, self).__init__()

    def execute(self):
        """                                                                    
Ejemplo n.º 21
0
class PreProc(Component):
    """ Dummy pre-processor. """
    x_in = Array([1., 1., 1., 1.], iotype='in', low=-10, high=99)
    x_out = Array(iotype='out')

    def execute(self):
        self.x_out = self.x_in
Ejemplo n.º 22
0
    def __init__(self, num_elem=10):
        super(SysRho, self).__init__()

        # Inputs
        self.add('temp', Array(np.zeros((num_elem+1, )), iotype='in',
                            desc = 'Temperature'))
        self.add('h', Array(np.zeros((num_elem+1, )), iotype='in',
                            desc = 'Altitude'))

        # Outputs
        self.add('rho', Array(np.zeros((num_elem+1, )), iotype='out', low=0.001,
                            desc = 'Density'))

        self.epsilon = 500
        h_lower = 11000 - self.epsilon
        h_upper = 11000 + self.epsilon
        matrix = np.array([[h_lower**3, h_lower**2, h_lower, 1],
                           [h_upper**3, h_upper**2, h_upper, 1],
                           [3*h_lower**2, 2*h_lower, 1, 0],
                           [3*h_upper**2, 2*h_upper, 1, 0]])
        rhs = np.array([101325*(1-0.0065*h_lower/288.16)**5.2561,
                        22632*np.exp(-9.81*self.epsilon/(288*216.65)),
                        (-101325*5.2561*(0.0065/288.16)*
                         (1-0.0065*h_lower/288.15)**4.2561),
                        (22632*(-9.81/(288*216.65))*
                         np.exp(-9.81*self.epsilon/(288*216.65)))])
        self.coefs = np.linalg.solve(matrix, rhs)
        class AComp(Component):

            x = Array([[1.0, 3.0], [-2.0, 4.0]], iotype='in')
            y = Array(np.zeros((2, 2)), iotype='out')

            def __init__(self):
                super(AComp, self).__init__()
                self.J = np.array([[3.5, -2.5, 1.5, 4.0],
                                   [4.0, 2.0, -1.1, 3.4], [7.7, 6.6, 4.4, 1.1],
                                   [0.1, 3.3, 6.8, -5.5]])

            def execute(self):
                """ Run arraycomp"""
                y = self.J.dot(self.x.flatten())
                self.y = y.reshape((2, 2))

            def list_deriv_vars(self):
                """ x and y """
                input_keys = ('x', )
                output_keys = ('y', )
                return input_keys, output_keys

            def provideJ(self):
                """Analytical first derivatives"""
                return self.J
Ejemplo n.º 24
0
 def configure(self):
     self.add("X", Array(np.zeros(self.m), iotype="in"))
     self.add("roots", Array(np.zeros(self.m), iotype="in"))
     if not len(self.idx):
         num_vars = np.random.randint(2, self.m)
         self.idx = np.random.choice(range(self.m), num_vars,
                                     replace=False),
Ejemplo n.º 25
0
    def test_array_1D(self):
        self.model.c1.add('y_a', Array(iotype='out'))
        self.model.c1.y_a = array([1.0, 2.0])

        self.model.c2.add('x_a', Array(iotype='in'))
        self.model.c2.x_a = array([3.0, 6.0])

        self.model.connect('c1.y_a', 'c2.x_a')
        self.model.connect('c2.y', 'c1.x')

        self.model.driver.workflow.initialize_residual()
        self.model.run()

        indep = self.model.driver.workflow.get_independents()
        self.assertEqual(indep[0], 1.0)
        self.assertEqual(indep[1], 2.0)
        dep = self.model.driver.workflow.get_dependents()
        self.assertEqual(dep[0], 0.0)
        self.assertEqual(dep[1], 0.0)

        dv = array([3.0, 5.0])
        self.model.driver.workflow.set_independents(dv)
        indep = self.model.driver.workflow.get_independents()
        self.assertEqual(indep[0], 3.0)
        self.assertEqual(indep[1], 5.0)
Ejemplo n.º 26
0
class MIMOEquation(Component):
    """Equation with 2 inputs and 2 outputs"""

    # pylint: disable-msg=E1101
    x = Array([1., 1., 1., 1., 1.],
              iotype='in',
              desc='Global Design Variables')

    f1 = Float(iotype='out', desc='Output of this Discipline')
    f2 = Float(iotype='out', desc='Output of this Discipline')
    f3 = Float(iotype='out', desc='Output of this Discipline')
    f4 = Float(iotype='out', desc='Output of this Discipline')
    f5 = Float(iotype='out', desc='Output of this Discipline')

    ff = Array([0., 0., 0., 0., 0.], iotype='out')

    def execute(self):
        """Should converge to x=[0,0,0,0,0]"""

        d = numpy.array([3, 2, 1.5, 1, 0.5])
        c = 0.01

        self.ff = -d * self.x - c * self.x**3

        self.f1 = self.ff[0]
        self.f2 = self.ff[1]
        self.f3 = self.ff[2]
        self.f4 = self.ff[3]
        self.f5 = self.ff[4]
Ejemplo n.º 27
0
    def test_full_matrix(self):
        self.model.c1.add('y_a', Array(iotype='out'))
        self.model.c1.y_a = array([[1.0, 2.0], [3.0, 4.0]])

        self.model.c2.add('x_a', Array(iotype='in'))
        self.model.c2.x_a = array([[2.0, 5.0], [11.0, 17.0]])

        self.model.connect('c1.y_a', 'c2.x_a')
        self.model.connect('c2.y', 'c1.x')

        self.model.driver.workflow.initialize_residual()
        self.model.run()

        dv = array([3.0, 5.0, -8.0, -13.0])
        self.model.driver.workflow.set_independents(dv)
        indep = self.model.driver.workflow.get_independents()
        self.assertEqual(indep[0], 3.0)
        self.assertEqual(indep[1], 5.0)
        self.assertEqual(indep[2], -8.0)
        self.assertEqual(indep[3], -13.0)

        dep = self.model.driver.workflow.get_dependents()
        self.assertEqual(dep[0], -2.0)
        self.assertEqual(dep[1], -3.0)
        self.assertEqual(dep[2], 11.0)
        self.assertEqual(dep[3], 17.0)
Ejemplo n.º 28
0
    def __init__(self, n_x=None):
        """Initialize pyopt
        n_x: number of design variables"""

        super(pyOptSparseDriver, self).__init__()

        #create lb and ub inputs so external components can set the bounds
        self.n_x = None
        if n_x is not None:
            shape = (n_x, )
            self.n_x = n_x
            self.add(
                'lb',
                Array(
                    np.zeros(shape),
                    iotype="in",
                    desc=
                    "lower bounds for the design variables, which will override values given in the add_parameter",
                    shape=shape))
            self.add(
                'ub',
                Array(
                    np.zeros(shape),
                    iotype="in",
                    desc=
                    "upper bounds for the design variables, which will override values given in the add_parameter",
                    shape=shape))

        self.pyOpt_solution = None
        self.param_type = {}
        self.nparam = None

        self.objs = None
        self.nlcons = None
        self.lin_jacs = {}
Ejemplo n.º 29
0
        class Dummy(Component):

            x = Array([[-1., 1.],[-2., 2.]],iotype="in",shape=(2,2), dtype='f')
            y = Array([[-1., 1.],[-2., 2.]],iotype="out",shape=(2,2), dtype='f')

            def execute(self):
                self.y = self.x
Ejemplo n.º 30
0
class InducedVelocity(Component):
    vc = Float(iotype="in")
    rho = Float(iotype="in")
    b = Float(iotype="in")
    R = Float(iotype="in")
    h = Float(iotype="in")

    Ns = Int(iotype="in")

    dT = Array(iotype="in")
    r = Array(iotype="in")
    dr = Array(iotype="in")

    vi = Array(iotype="out")

    def execute(self):
        self.vi = np.zeros(self.Ns)
        sqrt = np.zeros(self.Ns)

        sqrt = 0.25 * self.b * self.dT / (np.pi * self.rho * self.r * self.dr)
        sqrt += 0.25 * self.vc**2
        sqrt = np.sqrt(sqrt)

        self.vi += -0.5 * self.vc
        self.vi += sqrt

        self.vi /= (1. + (self.R / self.h / 4.)**2)
Ejemplo n.º 31
0
    def __init__(self, iotype, client, rpath, typ):
        ProxyMixin.__init__(self, client, rpath)
        self._type = typ

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

        if typ == float:
            as_units = client.get(rpath+'.units')
            if as_units:
                om_units = get_translation(as_units)
            else:
                om_units = None

        if typ != str:
            if client.get(rpath+'.hasUpperBound') == 'true':
                high = typ(client.get(rpath+'.upperBound'))
            else:
                high = None
            if client.get(rpath+'.hasLowerBound') == 'true':
                low = typ(client.get(rpath+'.lowerBound'))
            else:
                low = None

        if typ == float:
            Array.__init__(self, dtype=typ, iotype=iotype, desc=desc,
                           default_value=default, low=low, high=high,
                           units=om_units)
        elif typ == int:
            Array.__init__(self, dtype=typ, iotype=iotype, desc=desc,
                           default_value=default, low=low, high=high)
        else:
# FIXME: This will pickle, but not unpickle.
#        Probabably don't want fixed max-length string storage anyway.
            Array.__init__(self, dtype=typ, iotype=iotype, desc=desc,
                           default_value=default)