Пример #1
0
    def _view_metamodel(prob):
        if bokeh is None:
            print("bokeh must be installed to view a MetaModel.  Use the command:\n",
                  "    pip install bokeh")
            exit()

        hooks._unregister_hook('final_setup', 'Problem')

        mm_types = (MetaModelStructuredComp, MetaModelUnStructuredComp,
                    MetaModelSemiStructuredComp)

        pathname = options.pathname
        port_number = options.port_number
        resolution = options.resolution
        browser = options.browser

        if pathname:
            comp = prob.model._get_subsystem(pathname)
            if comp and isinstance(comp, mm_types):
                view_metamodel(comp, resolution, port_number, browser)
                exit()
        else:
            comp = None

        metamodels = {mm.pathname: mm for
                      mm in prob.model.system_iter(include_self=True, typ=mm_types)}

        mm_names = list(metamodels.keys())
        mm_count = len(mm_names)

        def _mm_list(mm_names, options):
            for mm in mm_names:
                print("openmdao view_mm -m {} {}".format(mm, options.file[0]))

        if mm_count == 0:
            print("No Metamodel components found in model.")

        elif mm_count == 1 and not pathname:
            comp = metamodels[mm_names[0]]
            view_metamodel(comp, resolution, port_number, browser)

        else:
            if not pathname:
                print("\nMetamodel not specified. Try one of the following:\n")
                _mm_list(mm_names, options)
            elif not comp:
                if len(mm_names) > 1:
                    print("\nMetamodel '{}' not found. Try one of the "
                          "following:\n".format(pathname))
                else:
                    print("\nMetamodel '{}' not found. Try the "
                          "following:\n".format(pathname))
                _mm_list(mm_names, options)
            else:
                if len(mm_names) > 1:
                    print("\n'{}' is not a Metamodel. Try one of the "
                          "following:\n".format(pathname))
                else:
                    print("\n'{}' is not a Metamodel. Try the following:\n".format(pathname))
                _mm_list(mm_names, options)
Пример #2
0
    def _view_metamodel(prob):
        if bokeh is None:
            print(
                "bokeh must be installed to view a MetaModel.  Use the command:\n",
                "    pip install bokeh")
            exit()

        Problem._post_setup_func = None

        mm_types = (MetaModelStructuredComp, MetaModelUnStructuredComp)

        pathname = options.pathname
        port_number = options.port_number

        if pathname:
            comp = prob.model._get_subsystem(pathname)
            if comp and isinstance(comp, mm_types):
                view_metamodel(comp, port_number)
                exit()
        else:
            comp = None

        metamodels = {
            mm.pathname: mm
            for mm in prob.model.system_iter(include_self=True, typ=mm_types)
        }

        mm_names = list(metamodels.keys())
        mm_count = len(mm_names)

        if mm_count == 0:
            print("No Metamodel components found in model.")

        elif mm_count == 1 and not pathname:
            comp = metamodels[mm_names[0]]
            view_metamodel(comp, port_number)
            exit()

        else:
            try_str = "Try one of the following: {}.".format(mm_names)

            if not pathname:
                print("\nMetamodel not specified. {}".format(try_str))
            elif not comp:
                print("\nMetamodel '{}' not found.\n {}".format(
                    pathname, try_str))
            else:
                print("\n'{}' is not a Metamodel.\n {}".format(
                    pathname, try_str))
        exit()