Beispiel #1
0
 def prob(self):
     # type: () -> LEGOProblem
     """Create the problem instance of the subdriver component."""
     return LEGOProblem(cmdows_path=self.options['cmdows_path'],
                                 kb_path=self.options['kb_path'],
                                 data_folder=self.options['data_folder'],  # Output directory
                                 base_xml_file=self.options['base_xml_file'],
                                 driver_uid=self.options['driver_uid'])
Beispiel #2
0
    def setup(self):
        """Setup of the explicit component object with a nested LEGOProblem as subdriver."""

        # Set subproblem
        from openlego.core.problem import LEGOProblem
        p = self.prob = LEGOProblem(
            cmdows_path=self.options['cmdows_path'],
            kb_path=self.options['kb_path'],
            data_folder=self.options['data_folder'],  # Output directory
            base_xml_file=self.options['base_xml_file'],
            driver_uid=self.options['driver_uid'])
        #  p.driver.options['debug_print'] = ['desvars', 'nl_cons', 'ln_cons', 'objs']  # Set printing of debug info

        # Add inputs
        for input_name, shape in p.model.model_constants.items():
            self.add_input(input_name, shape=shape)

        for input_name, attrbs in p.model.model_super_inputs.items():
            self.add_input(input_name, val=attrbs['val'])

        # Add outputs
        for output_name, value in p.model.model_super_outputs.items():
            self.add_output(output_name, val=value)

        # Declare partials
        self.declare_partials('*',
                              '*',
                              method='fd',
                              step=1e-4,
                              step_calc='abs')

        # Setup
        p.setup()
        p.final_setup()

        # Store (and view?) model
        if self.options['show_model']:
            p.store_model_view(open_in_browser=self.options['show_model'])
Beispiel #3
0
def run_openlego(analyze_mdao_definitions, cmdows_dir=None, initial_file_path=None,
                 data_folder=None, run_type='test', approx_totals=False, driver_debug_print=False):
    # Check and analyze inputs
    mdao_defs_loop = get_loop_items(analyze_mdao_definitions)
    file_dir = os.path.dirname(__file__)
    if not cmdows_dir:
        cmdows_dir = os.path.join(file_dir, 'cmdows_files')
    if not initial_file_path:
        initial_file_path = os.path.join(file_dir, 'sellar-input.xml')
    if not data_folder:
        data_folder = ''

    for mdao_def in mdao_defs_loop:
        print('\n-----------------------------------------------')
        print('Running the OpenLEGO of Mdao_{}.xml...'.format(mdao_def))
        print('------------------------------------------------')
        """Solve the Sellar problem using the given CMDOWS file."""
        # 1. Create Problem
        prob = LEGOProblem(cmdows_path=os.path.join(cmdows_dir, 'Mdao_{}.xml'.format(mdao_def)),
                           kb_path=os.path.join(file_dir, 'kb'),
                           data_folder=data_folder,  # Output directory
                           base_xml_file='sellar-output.xml')  # Output file
        if driver_debug_print:
            prob.driver.options['debug_print'] = ['desvars', 'nl_cons', 'ln_cons', 'objs']
        prob.set_solver_print(0)  # Set printing of solver information

        if approx_totals:
            prob.model.approx_totals()

        # 2. Initialize the Problem and export N2 chart
        prob.store_model_view(open_in_browser=False)
        prob.initialize_from_xml(initial_file_path)

        # 3. Run the Problem
        prob.run_driver()  # Run the driver (optimization, DOE, or convergence)

        # 4. Read out the case reader
        prob.collect_results()

        if run_type == 'test':
            # 5. Collect test results for test assertions
            if '/dataSchema/variables/x0' in prob.model._outputs:
                x = [prob['/dataSchema/variables/x0']]
                y = [prob['/dataSchema/analyses/y1'], prob['/dataSchema/analyses/y2']]
                z = [prob['/dataSchema/variables/z1'], prob['/dataSchema/variables/z2']]
                f = [prob['/dataSchema/analyses/f']]
                g = [prob['/dataSchema/analyses/g1'], prob['/dataSchema/analyses/g2']]
            elif '/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/variables/x0' in prob.model._outputs:
                x = [prob['/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/variables/x0']]
                y = [prob['/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/analyses/y1'],
                     prob['/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/analyses/y2']]
                z = [prob['/dataSchema/variables/z1'], prob['/dataSchema/variables/z2']]
                f = [prob['/dataSchema/analyses/f']]
                g = [prob.model.SubOptimizer0.prob['/dataSchema/analyses/g1'],
                     prob.model.SubOptimizer1.prob['/dataSchema/analyses/g2']]

            # 6. Cleanup and invalidate the Problem afterwards
            prob.invalidate()
            return x, y, z, f, g
        elif run_type == 'validation':
            return prob
Beispiel #4
0
def run_openlego(analyze_mdao_definitions, cmdows_dir=None, initial_file_path=None,
                 data_folder=None, run_type='test', approx_totals=False, driver_debug_print=False):
    # type: (Union[int, list, str], Optional[str], Optional[str], Optional[str], Optional[str], Optional[bool], Optional[bool]) -> Union[tuple, LEGOProblem]
    """Run OpenLEGO for a list of MDAO definitions.

    Parameters
    ----------
    analyze_mdao_definitions : list
        List of MDAO definitions to be analyzed.

    cmdows_dir : str
        Path to directory with CMDOWS files

    initial_file_path : str
        Path to file containing initial values

    data_folder : str
        Path to directory where results will be stored

    run_type : str
        Option to indicate the type of run, as this changes the return statement used

    approx_totals : bool
        Setting on whether to use approx_totals on the model

    driver_debug_print : bool
        Setting on whether to print debug information in the log

    Returns
    -------
        Union[Tuple[float], LEGOProblem]
    """
    # Check and analyze inputs
    mdao_defs_loop = get_loop_items(analyze_mdao_definitions)
    file_dir = os.path.dirname(__file__)
    if not cmdows_dir:
        cmdows_dir = os.path.join(file_dir, 'cmdows_files')
    if not initial_file_path:
        initial_file_path = os.path.join(file_dir, 'SSBJ-base.xml')
    if not data_folder:
        data_folder = ''

    # Run the
    for mdao_def in mdao_defs_loop:
        print('\n-----------------------------------------------')
        print('Running the OpenLEGO of Mdao_{}.xml...'.format(mdao_def))
        print('------------------------------------------------')
        """Solve the SSBJ problem using the given CMDOWS file."""

        # 1. Create Problem
        prob = LEGOProblem(cmdows_path=os.path.join(cmdows_dir, 'Mdao_{}.xml'.format(mdao_def)),
                           kb_path=os.path.join(file_dir, 'kb'),  # Knowledge base path
                           data_folder=data_folder,  # Output directory
                           base_xml_file=os.path.join(data_folder,
                                                      'ssbj-output-{}.xml'.format(mdao_def)))
        if driver_debug_print:
            prob.driver.options['debug_print'] = ['desvars', 'nl_cons', 'ln_cons', 'objs']
        prob.set_solver_print(0)  # Set printing of solver information

        if approx_totals:
            prob.model.approx_totals()

        # 2. Initialize the Problem and export N2 chart
        prob.store_model_view()
        prob.initialize_from_xml(initial_file_path)  # Set the initial values from an XML file

        # 3. Run the Problem
        test_distributed = mdao_def in ['CO', 'BLISS-2000'] and run_type == 'test'
        if test_distributed:
            prob.run_model()
        else:
            prob.run_driver()  # Run the driver (optimization, DOE, or convergence)

        # 4. Read out the case reader
        if not test_distributed:
            prob.collect_results()

        if run_type == 'test':
            # 5. Collect test results for test assertions
            tc = prob['/dataSchema/aircraft/geometry/tc'][0]
            h = prob['/dataSchema/reference/h'][0]
            M = prob['/dataSchema/reference/M'][0]
            AR = prob['/dataSchema/aircraft/geometry/AR'][0]
            Lambda = prob['/dataSchema/aircraft/geometry/Lambda'][0]
            Sref = prob['/dataSchema/aircraft/geometry/Sref'][0]
            if mdao_def not in ['CO', 'BLISS-2000']:
                lambda_ = prob['/dataSchema/aircraft/geometry/lambda'][0]
                section = prob['/dataSchema/aircraft/geometry/section'][0]
                Cf = prob['/dataSchema/aircraft/other/Cf'][0]
                T = prob['/dataSchema/aircraft/other/T'][0]
                R = prob['/dataSchema/scaledData/R/value'][0]
                extra = prob['/dataSchema/aircraft/weight/WT'][0]
            elif mdao_def == 'CO':
                lambda_ = prob.model.SubOptimizer0.prob['/dataSchema/aircraft/geometry/lambda'][0]
                section = prob.model.SubOptimizer0.prob['/dataSchema/aircraft/geometry/section'][0]
                Cf = prob.model.SubOptimizer1.prob['/dataSchema/aircraft/other/Cf'][0]
                T = prob.model.SubOptimizer2.prob['/dataSchema/aircraft/other/T'][0]
                R = prob['/dataSchema/scaledData/R/value'][0]
                extra = (prob['/dataSchema/distributedArchitectures/group0/objective'],
                         prob['/dataSchema/distributedArchitectures/group1/objective'],
                         prob['/dataSchema/distributedArchitectures/group2/objective'])
            else:
                lambda_, section, Cf, T, R, extra = None, None, None, None, None, None

            # 6. Cleanup and invalidate the Problem afterwards
            prob.invalidate()
            return tc, h, M, AR, Lambda, Sref, lambda_, section, Cf, T, R, extra
        elif run_type == 'validation':
            return prob
        else:
            prob.invalidate()
def run_openlego(analyze_mdao_definitions):
    # Check and analyze inputs
    mdao_defs_loop = get_loop_items(analyze_mdao_definitions)

    for mdao_def in mdao_defs_loop:
        print('\n-----------------------------------------------')
        print('Running the OpenLEGO of Mdao_{}.xml...'.format(mdao_def))
        print('------------------------------------------------')
        """Solve the SSBJ problem using the given CMDOWS file."""

        # 1. Create Problem
        prob = LEGOProblem(cmdows_path=os.path.join('cmdows_files', 'Mdao_{}.xml'.format(mdao_def)),  # CMDOWS file
                           kb_path='kb',  # Knowledge base path
                           data_folder='',  # Output directory
                           base_xml_file='ssbj-output-{}.xml'.format(mdao_def))  # Output file
        # prob.driver.options['debug_print'] = ['desvars', 'nl_cons', 'ln_cons', 'objs']  # Set printing of debug info
        prob.set_solver_print(0)  # Set printing of solver information

        # 2. Initialize the Problem and export N2 chart
        prob.store_model_view()
        prob.initialize_from_xml('SSBJ-base.xml')  # Set the initial values from an XML file

        # 3. Run the Problem
        if mdao_def == 'CO':
            prob.run_model()
        else:
            prob.run_driver()  # Run the driver (optimization, DOE, or convergence)

        # 4. Read out the case reader
        if mdao_def != 'CO':
            prob.collect_results()

        # 5. Collect test results for test assertions
        tc = prob['/dataSchema/aircraft/geometry/tc']
        h = prob['/dataSchema/reference/h']
        M = prob['/dataSchema/reference/M']
        AR = prob['/dataSchema/aircraft/geometry/AR']
        Lambda = prob['/dataSchema/aircraft/geometry/Lambda']
        Sref = prob['/dataSchema/aircraft/geometry/Sref']
        if mdao_def != 'CO':
            lambda_ = prob['/dataSchema/aircraft/geometry/lambda']
            section = prob['/dataSchema/aircraft/geometry/section']
            Cf = prob['/dataSchema/aircraft/other/Cf']
            T = prob['/dataSchema/aircraft/other/T']
            R = prob['/dataSchema/scaledData/R/value']
            extra = prob['/dataSchema/aircraft/weight/WT']
        else:
            lambda_ = prob.model.SubOptimizer0.prob['/dataSchema/aircraft/geometry/lambda']
            section = prob.model.SubOptimizer0.prob['/dataSchema/aircraft/geometry/section']
            Cf = prob.model.SubOptimizer1.prob['/dataSchema/aircraft/other/Cf']
            T = prob.model.SubOptimizer2.prob['/dataSchema/aircraft/other/T']
            R = prob['/dataSchema/scaledData/R/value']
            extra = (prob['/dataSchema/distributedArchitectures/group0/objective'],
                     prob['/dataSchema/distributedArchitectures/group1/objective'],
                     prob['/dataSchema/distributedArchitectures/group2/objective'])

        # 6. Cleanup and invalidate the Problem afterwards
        prob.invalidate()

    return tc, h, M, AR, Lambda, Sref, lambda_, section, Cf, T, R, extra
def run_openlego(cmdows_file,
                 data_folder=None,
                 driver_debug_print=False,
                 discipline_resolvers=None):
    file_dir = os.path.dirname(__file__)
    initial_file_path = os.path.join(file_dir, 'input.xml')
    if not data_folder:
        data_folder = ''

    print('\n-----------------------------------------------')
    print('Running the OpenLEGO of {}...'.format(cmdows_file))
    print('------------------------------------------------')
    # 1. Create Problem
    prob = LEGOProblem(
        cmdows_path=os.path.join(file_dir, 'cmdows', cmdows_file),
        kb_path='',
        data_folder=data_folder,
        base_xml_file='sellar-output.xml',
        discipline_resolvers=discipline_resolvers,
    )
    if driver_debug_print:
        prob.driver.options['debug_print'] = [
            'desvars', 'nl_cons', 'ln_cons', 'objs'
        ]
    prob.set_solver_print(0)  # Set printing of solver information

    # 2. Initialize the Problem and export N2 chart
    prob.store_model_view(open_in_browser=False)
    prob.initialize_from_xml(initial_file_path)

    # 3. Run the Problem
    prob.run_driver()  # Run the driver (optimization, DOE, or convergence)

    # 4. Read out the case reader
    prob.collect_results()

    # 5. Collect test results for test assertions
    x = [prob['/dataSchema/variables/x1']]
    y = [prob['/dataSchema/analyses/y1'], prob['/dataSchema/analyses/y2']]
    z = [prob['/dataSchema/variables/z1'], prob['/dataSchema/variables/z2']]
    f = [prob['/dataSchema/output/f']]
    g = [prob['/dataSchema/output/g1'], prob['/dataSchema/output/g2']]

    # 6. Cleanup and invalidate the Problem afterwards
    prob.invalidate()
    return x, y, z, f, g
def run_openlego(analyze_mdao_definitions):
    # Check and analyze inputs
    mdao_defs_loop = get_loop_items(analyze_mdao_definitions)

    for mdao_def in mdao_defs_loop:
        print('\n-----------------------------------------------')
        print('Running the OpenLEGO of Mdao_{}.xml...'.format(mdao_def))
        print('------------------------------------------------')
        """Solve the Sellar problem using the given CMDOWS file."""
        # 1. Create Problem
        prob = LEGOProblem(
            cmdows_path=os.path.join(
                'cmdows_files', 'Mdao_{}.xml'.format(mdao_def)),  # CMDOWS file
            kb_path='kb',
            data_folder='',  # Output directory
            base_xml_file='sellar-output.xml')  # Output file
        # prob.driver.options['debug_print'] = ['desvars', 'nl_cons', 'ln_cons', 'objs']  # Set printing of debug info
        prob.set_solver_print(0)  # Set printing of solver information

        # 2. Initialize the Problem and export N2 chart
        prob.store_model_view(open_in_browser=False)
        prob.initialize_from_xml('sellar-input.xml')

        # 3. Run the Problem
        prob.run_driver()  # Run the driver (optimization, DOE, or convergence)

        # 4. Read out the case reader
        prob.collect_results()

        # 5. Collect test results for test assertions
        if '/dataSchema/geometry/x1' in prob.model._outputs:
            x = [prob['/dataSchema/geometry/x1']]
            y = [
                prob['/dataSchema/analyses/y1'],
                prob['/dataSchema/analyses/y2']
            ]
            z = [
                prob['/dataSchema/geometry/z1'],
                prob['/dataSchema/geometry/z2']
            ]
            f = [prob['/dataSchema/analyses/f']]
            g = [
                prob['/dataSchema/analyses/g1'],
                prob['/dataSchema/analyses/g2']
            ]
        elif '/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/geometry/x1' in prob.model._outputs:
            x = [
                prob[
                    '/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/geometry/x1']
            ]
            y = [
                prob[
                    '/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/analyses/y1'],
                prob[
                    '/dataSchema/architectureNodes/copyDesignVariables/dataSchemaCopy/analyses/y2']
            ]
            z = [
                prob['/dataSchema/geometry/z1'],
                prob['/dataSchema/geometry/z2']
            ]
            f = [prob['/dataSchema/analyses/f']]
            g = [
                prob.model.SubOptimizer0.prob['/dataSchema/analyses/g1'],
                prob.model.SubOptimizer1.prob['/dataSchema/analyses/g2']
            ]

        # 6. Cleanup and invalidate the Problem afterwards
        prob.invalidate()

    return x, y, z, f, g