How to use the openmdao.api.Group 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 WISDEM / WISDEM / test / rotorse / test_rotor_aeropower_gradients.py View on Github external
data['rated_Omega_in'] = 12.
    data['rated_pitch_in'] = 0.0
    data['rated_T_in'] = 714206.5321080858
    data['rated_Q_in'] = 3978873.5772973835
    data['hub_diameter_in'] = 3.075
    data['diameter_in'] = 125.95500453593273
    data['max_chord_in'] = 3.0459289459935825
    data['V_extreme_in'] = 70.0
    data['T_extreme_in'] = 0.0
    data['Q_extreme_in'] = 0.0
    data['Rtip_in'] = 63.0375
    data['precurveTip_in'] = 0.0
    data['precsweepTip_in'] = 0.0

    prob = Problem()
    prob.root = Group()
    prob.root.add('comp', OutputsAero(len(data['P_in'])), promotes=['*'])
    prob = init_IndepVar_add(prob, data)
    prob.root.comp.deriv_options['check_step_calc'] = 'relative' 
    prob.setup(check=False)
    prob = init_IndepVar_set(prob, data)

    check_gradient_unit_test(prob)
github OpenMDAO / OpenMDAO / openmdao / test_suite / components / sellar_feature.py View on Github external
def setup(self):
        indeps = self.add_subsystem('indeps', IndepVarComp(), promotes=['*'])
        indeps.add_output('x', 1.0)
        indeps.add_output('z', np.array([5.0, 2.0]))

        cycle = self.add_subsystem('cycle', Group(), promotes=['*'])
        cycle.add_subsystem('d1', SellarDis1(), promotes_inputs=['x', 'z', 'y2'], promotes_outputs=['y1'])
        cycle.add_subsystem('d2', SellarDis2(), promotes_inputs=['z', 'y1'], promotes_outputs=['y2'])

        # Nonlinear Block Gauss Seidel is a gradient free solver
        cycle.nonlinear_solver = NonlinearBlockGS()

        self.add_subsystem('obj_cmp', ExecComp('obj = x**2 + z[1] + y1 + exp(-y2)',
                           z=np.array([0.0, 0.0]), x=0.0),
                           promotes=['x', 'z', 'y1', 'y2', 'obj'])

        self.add_subsystem('con_cmp1', ExecComp('con1 = 3.16 - y1'), promotes=['con1', 'y1'])
        self.add_subsystem('con_cmp2', ExecComp('con2 = y2 - 24.0'), promotes=['con2', 'y2'])
github OpenMDAO / dymos / dymos / phases / simulation / simulation_phase.py View on Github external
def _setup_segments(self):
        gd = self.options['grid_data']
        num_seg = gd.num_segments

        segments_group = self.add_subsystem(name='segments', subsys=Group(),
                                            promotes_outputs=['*'], promotes_inputs=['*'])

        for i in range(num_seg):
            seg_i_comp = SegmentSimulationComp(index=i,
                                               grid_data=self.options['grid_data'],
                                               ode_class=self.options['ode_class'],
                                               ode_init_kwargs=self.options['ode_init_kwargs'],
                                               t_eval=self.t_eval_per_seg[i])

            seg_i_comp.time_options.update(self.time_options)
            seg_i_comp.state_options.update(self.state_options)
            seg_i_comp.control_options.update(self.control_options)
            seg_i_comp.design_parameter_options.update(self.design_parameter_options)
            seg_i_comp.input_parameter_options.update(self.input_parameter_options)
            seg_i_comp.traj_parameter_options.update(self.traj_parameter_options)
github daniel-de-vries / OpenLEGO / openlego / core / model.py View on Github external
def _configure_coupled_groups(self, hierarchy, root=True):
        # type: (List) -> Optional[Group]
        """:obj:`Group`, optional: Group wrapping the coupled blocks with a converger specified in the CMDOWS file.

        This method enables the iterative configuration of groups of distributed convergers based on the convergence
        hierarchy.
        """
        if not root:
            coupled_group = Group()
        # TODO: adjust hierarchy to take partitions into account...
        for entry in hierarchy:
            if isinstance(entry, dict):  # if entry specifies a coupled group
                uid = entry.keys()[0]
                if root:
                    subsys = self.add_subsystem(str_to_valid_sys_name(uid),
                                                self._configure_coupled_groups(entry[uid], False), ['*'])
                else:
                    subsys = coupled_group.add_subsystem(str_to_valid_sys_name(uid),
                                                         self._configure_coupled_groups(entry[uid], False), ['*'])
                conv_elem = get_element_by_uid(self.elem_arch_elems, uid)
                # Define linear solver
                linsol_elem = conv_elem.find('settings/linearSolver')
                if isinstance(linsol_elem, _Element):
                    if linsol_elem.find('method').text == 'Gauss-Seidel':
                        linsol = subsys.linear_solver = LinearBlockGS()
github WISDEM / WISDEM / wisdem / turbine_costsse / nrel_csm_tcc_2015.py View on Github external
self.add_subsystem('lss',LowSpeedShaftMass(), promotes=['*'])
        self.add_subsystem('bearing',BearingMass(), promotes=['*'])
        self.add_subsystem('gearbox',GearboxMass(), promotes=['*'])
        self.add_subsystem('hss',HighSpeedSideMass(), promotes=['*'])
        self.add_subsystem('generator',GeneratorMass(), promotes=['*'])
        self.add_subsystem('bedplate',BedplateMass(), promotes=['*'])
        self.add_subsystem('yaw',YawSystemMass(), promotes=['*'])
        self.add_subsystem('hvac',HydraulicCoolingMass(), promotes=['*'])
        self.add_subsystem('cover',NacelleCoverMass(), promotes=['*'])
        self.add_subsystem('other',OtherMainframeMass(), promotes=['*'])
        self.add_subsystem('transformer',TransformerMass(), promotes=['*'])
        self.add_subsystem('tower',TowerMass(), promotes=['*'])
        self.add_subsystem('turbine',turbine_mass_adder(), promotes=['*'])
       

class nrel_csm_2015(Group):
    
    def setup(self):
        self.add_subsystem('nrel_csm_mass', nrel_csm_mass_2015(), promotes=['*'])
        self.add_subsystem('turbine_costs', Turbine_CostsSE_2015(verbosity=False, topLevelFlag=False), promotes=['*'])

#-----------------------------------------------------------------

def mass_example():

    # simple test of module
    trb = nrel_csm_mass_2015()
    prob = Problem(trb)
    prob.setup()
    
    prob['rotor_diameter'] = 126.0
    prob['turbine_class'] = 1
github OpenMDAO / dymos / dymos / examples / aircraft_steady_flight / ex_aircraft_steady_flight.py View on Github external
def ex_aircraft_steady_flight(optimizer='SLSQP',
                              solve_segments=False, show_plots=True,
                              use_boundary_constraints=False, compressed=False):
    p = Problem(model=Group())
    p.driver = pyOptSparseDriver()
    _, optimizer = set_pyoptsparse_opt(optimizer, fallback=False)
    p.driver.options['optimizer'] = optimizer
    p.driver.options['dynamic_simul_derivs'] = True
    if optimizer == 'SNOPT':
        p.driver.opt_settings['Major iterations limit'] = 20
        p.driver.opt_settings['Major feasibility tolerance'] = 1.0E-6
        p.driver.opt_settings['Major optimality tolerance'] = 1.0E-6
        p.driver.opt_settings["Linesearch tolerance"] = 0.10
        p.driver.opt_settings['iSumm'] = 6
    if optimizer == 'SLSQP':
        p.driver.opt_settings['MAXIT'] = 50

    num_seg = 15
    seg_ends, _ = lgl(num_seg + 1)
github mdolab / OpenAeroStruct / assignment / prob2b.py View on Github external
prob_dict = OAS_prob.prob_dict
num_y = surface['num_y']
r = radii(surface['mesh'])
thickness = r / 10
thickness[:] = numpy.max((thickness))
num_twist = num_thickness = num_y

span = surface['span']
v = prob_dict['v']
alpha = prob_dict['alpha']
rho = prob_dict['rho']
M = prob_dict['M']
Re = prob_dict['Re']

# Create the top-level system
root = Group()

# Define the independent variables
indep_vars = [
    ('span', span),
    ('twist', numpy.zeros(num_twist)),
    ('thickness', thickness),
    ('v', v),
    ('alpha', alpha),
    ('rho', rho),
    ('r', r),
    ('M', M),
    ('Re', Re),
]

############################################################
# These are your components, put them in the correct groups.
github mdolab / OpenAeroStruct / prob3a.py View on Github external
('twist', numpy.zeros(num_y)),
    ('v', v),
    ('alpha', alpha),
    ('rho', rho),
    ('r', r),
    ('t', t),
]

root.add('des_vars',
         IndepVarComp(des_vars),
         promotes=['*'])
root.add('tube',
         MaterialsTube(num_y),
         promotes=['*'])

coupled = Group() # add components for MDA to this group
coupled.add('mesh',
            GeometryMesh(mesh),
            promotes=['*'])
coupled.add('def_mesh',
            TransferDisplacements(num_y),
            promotes=['*'])
coupled.add('weissingerstates',
            WeissingerStates(num_y),
            promotes=['*'])
coupled.add('loads',
            TransferLoads(num_y),
            promotes=['*'])
coupled.add('spatialbeamstates',
            SpatialBeamStates(num_y, cons, E, G),
            promotes=['*'])
github daniel-de-vries / OpenLEGO / openlego / core / model.py View on Github external
def mathematical_functions_groups(self):
        # type: () -> Dict[str, Group]
        """:obj:`dict`: Dictionary of execute components by their mathematical function ``uID`` from CMDOWS.
        """
        _mathematical_functions = dict()
        for mathematical_function in self.elem_cmdows.iter('mathematicalFunction'):
            uid = mathematical_function.attrib['uID']
            group = Group()

            eq_mapping = dict()
            for output in mathematical_function.iter('output'):
                if output.find('equations') is not None:
                    for equation in output.iter('equation'):
                        if equation.attrib['language'] == 'Python':
                            eq_uid = equation.getparent().attrib['uID']
                            eq_expr = equation.text
                            eq_output = xpath_to_param(output.find('parameterUID').text)

                            promotes = list()
                            for eq_label, input_name in self.mathematical_functions_inputs[uid]:
                                # TODO: This mapping of the input name should get a more sophisticated logic
                                if input_name in self.mapped_parameters and input_name not in self.design_vars:
                                    input_name = self.mapped_parameters[input_name]
github OpenMDAO / dymos / dymos / examples / vanderpol / vanderpol_dymos.py View on Github external
def vanderpol(transcription='gauss-lobatto', num_segments=8, transcription_order=3,
              compressed=True, optimizer='SLSQP', use_pyoptsparse=False, delay=None):
    """Dymos problem definition for optimal control of a Van der Pol oscillator"""

    # define the OpenMDAO problem
    p = om.Problem(model=om.Group())

    if not use_pyoptsparse:
        p.driver = om.ScipyOptimizeDriver()
    else:
        p.driver = om.pyOptSparseDriver()
    p.driver.options['optimizer'] = optimizer
    if use_pyoptsparse and optimizer == 'SNOPT':
        p.driver.opt_settings['iSumm'] = 6  # show detailed SNOPT output
    p.driver.declare_coloring()

    # define a Trajectory object and add to model
    traj = dm.Trajectory()
    p.model.add_subsystem('traj', subsys=traj)

    # define a Transcription
    if transcription == 'gauss-lobatto':