Esempio n. 1
0
    def check_length(self):
        # Load the current sqlitedict
        cr = self.case_reader = SqliteCaseReader(self.db_name)

        # Get the number of current iterations
        # Minus one because OpenMDAO uses 1-indexing
        self.num_iters = int(cr.driver_cases.list_cases()[-1].split('|')[-1])
Esempio n. 2
0
    def check_length(self):
        # Load the current sqlitedict
        cr = self.case_reader = SqliteCaseReader(self.db_name)

        # Get the number of current iterations
        # Minus one because OpenMDAO uses 1-indexing
        self.num_iters = len(cr.get_cases('driver'))
Esempio n. 3
0
def CaseReader(filename):
    """ A factory function that returns a CaseReader for the given file.

    Parameters
    ----------
    filename : str
        A path to the recorded file.  The file should have been recorded using
        either the SqliteRecorder or the HDF5Recorder.

    Returns
    -------
    An instance of SqliteCaseReader or HDF5CaseReader, depending on the
    contents of the given file.
    """

    try:
        reader = SqliteCaseReader(filename)
        return reader
    except IOError:
        # filename not a valid Sqlite database file
        pass

    try:
        reader = HDF5CaseReader(filename)
        return reader
    except IOError:
        raise IOError('Unable to load cases from file {0}'.format(filename))
Esempio n. 4
0
def CaseReader(filename):
    """
    Return a CaseReader for the given file.

    Parameters
    ----------
    filename : str
        A path to the recorded file.  The file should have been recorded using
        either the SqliteRecorder or the HDF5Recorder.

    Returns
    -------
    reader : BaseCaseReader
        An instance of a SqliteCaseReader that is reading filename.
    """
    reader = SqliteCaseReader(filename)
    return reader
Esempio n. 5
0
def upload(sqlite_file, token, name=None, case_id=None, suppress_output=False):
    """
    Upload sqlite recording to the web server.

    Parameters
    ----------
    sqlite_file : str
        The location of the sqlite file.
    token : str
        The web recorder token.
    name : str
        The name of the recording (defaults to None).
    case_id : str
        The case_id if this upload is intended to update a recording.
    suppress_output : bool
        Indicates whether or not the upload status should be printed.
    """
    reader = SqliteCaseReader(sqlite_file)
    if case_id is None:
        recorder = WebRecorder(token, name)
    else:
        recorder = WebRecorder(token, name, case_id=case_id)

    if not suppress_output:
        print('Data Uploader: Recording metadata')
    _upload_metadata(reader._abs2prom, reader._prom2abs, recorder)

    if not suppress_output:
        print('Data Uploader: Recording driver iteration data')
    _upload_driver_iterations(reader.driver_cases, recorder)

    if not suppress_output:
        print('Data Uploader: Recording system iteration data')
    _upload_system_iterations(reader.system_cases, recorder)

    if not suppress_output:
        print('Data Uploader: Recording solver iteration data')
    _upload_solver_iterations(reader.solver_cases, recorder)

    recorder._record_driver_metadata('Driver', json.dumps(reader.driver_metadata))
    for item in reader.solver_metadata:
        recorder._record_solver_metadata(reader.solver_metadata[item]['solver_options'],
                                         reader.solver_metadata[item]['solver_class'], '')

    if not suppress_output:
        print('Finished uploading')
Esempio n. 6
0
def CaseReader(filename, pre_load=True):
    """
    Return a CaseReader for the given file.

    Parameters
    ----------
    filename : str
        A path to the recorded file.
        Currently only sqlite database files recorded via SqliteRecorder are supported.
    pre_load : bool
        If True, load all the data into memory during initialization.

    Returns
    -------
    reader : BaseCaseReader
        An instance of a CaseReader.
    """
    return SqliteCaseReader(filename, pre_load)
Esempio n. 7
0
def CaseReader(filename):
    """
    Return a CaseReader for the given file.

    Parameters
    ----------
    filename : str
        A path to the recorded file.  The file should have been recorded using
        either the SqliteRecorder or the HDF5Recorder.

    Returns
    -------
    An instance of SqliteCaseReader.
    """
    try:
        reader = SqliteCaseReader(filename)
        return reader
    except IOError:
        # filename not a valid Sqlite database file
        raise IOError('Unable to load cases from file {0}'.format(filename))
Esempio n. 8
0
def CaseReader(filename, pre_load=True, metadata_filename=None):
    """
    Return a CaseReader for the given file.

    Parameters
    ----------
    filename : str
        A path to the recorded file.
        Currently only sqlite database files recorded via SqliteRecorder are supported.
    pre_load : bool
        If True, load all the data into memory during initialization.
    metadata_filename : str
        For separate metadata from parallel runs, the metadata database filename.

    Returns
    -------
    BaseCaseReader
        An instance of a CaseReader.
    """
    return SqliteCaseReader(filename, pre_load, metadata_filename)
Esempio n. 9
0
    def load_db(self):
        cr = self.case_reader = SqliteCaseReader(self.db_name, pre_load=True)
        last_case = next(reversed(cr.get_cases('driver')))

        names = []

        # Aero or aerostructural
        for key in cr.system_metadata.keys():
            try:
                surfaces = cr.system_metadata[key]['component_options'][
                    'surfaces']
                for surface in surfaces:
                    names.append(surface['name'])
                break
            except:
                pass

        # Structural-only
        if not names:
            for key in cr.system_metadata.keys():
                try:
                    surface = cr.system_metadata[key]['component_options'][
                        'surface']
                    names = [surface['name']]
                except:
                    pass

        # figure out if this is an optimization and what the objective is
        obj_keys = last_case.get_objectives()
        if obj_keys.keys():  # if its not an empty list
            self.opt = True
            self.obj_key = list(obj_keys.keys())[0]
        else:
            self.opt = False

        self.twist = []
        self.mesh = []
        self.def_mesh = []
        self.radius = []
        self.thickness = []
        sec_forces = []
        normals = []
        widths = []
        self.lift = []
        self.lift_ell = []
        self.vonmises = []
        alpha = []
        rho = []
        v = []
        self.CL = []
        self.AR = []
        self.S_ref = []
        self.obj = []
        self.cg = []
        self.point_mass_locations = []

        pt_names = []
        for key in last_case.outputs:
            if 'coupled' in key:
                self.aerostruct = True

        for key in last_case.outputs:
            if 'CL' in key:
                pt_names.append(key.split('.')[0])
                break

        if pt_names:
            self.pt_names = pt_names = list(set(pt_names))
            pt_name = pt_names[0]
        else:
            pt_names = ['']
        self.names = names
        n_names = len(names)

        # loop to pull data out of case reader and organize it into arrays
        for i, case in enumerate(cr.get_cases()):

            if self.opt:
                self.obj.append(case.outputs[self.obj_key])

            # Loop through each of the surfaces
            for name in names:

                # Check if this is an aerostructual case; treat differently
                # due to the way the problem is organized
                if not self.aerostruct:

                    # A mesh exists for all types of cases
                    self.mesh.append(case.outputs[name + '.mesh'])

                    try:
                        self.radius.append(
                            np.squeeze(case.outputs[name + '.radius']))
                        self.thickness.append(case.outputs[name +
                                                           '.thickness'])
                        self.vonmises.append(
                            np.max(case.outputs[name + '.vonmises'], axis=1))
                        self.show_tube = True
                    except:
                        self.show_tube = False
Esempio n. 10
0
    def load_db(self):
        cr = self.case_reader = SqliteCaseReader(self.db_name, pre_load=True)
        last_case = next(reversed(cr.get_cases('driver')))

        names = []
        for key in cr.system_metadata.keys():
            try:
                surfaces = cr.system_metadata[key]['component_options'][
                    'surfaces']
                for surface in surfaces:
                    names.append(surface['name'])
                break
            except:
                pass

        # figure out if this is an optimization and what the objective is
        obj_keys = last_case.get_objectives()
        if obj_keys.keys():  # if its not an empty list
            self.opt = True
            self.obj_key = list(obj_keys.keys())[0]
        else:
            self.opt = False

        self.twist = []
        self.mesh = []
        self.def_mesh = []
        self.def_mesh_maneuver = []
        self.radius = []
        self.spar_thickness = []
        self.skin_thickness = []
        self.t_over_c = []
        sec_forces = []
        sec_forces_maneuver = []
        normals = []
        normals_maneuver = []
        widths = []
        widths_maneuver = []
        self.lift = []
        self.lift_ell = []
        self.lift_maneuver = []
        self.lift_ell_maneuver = []
        self.vonmises = []
        alpha = []
        alpha_maneuver = []
        rho = []
        rho_maneuver = []
        v = []
        self.CL = []
        self.AR = []
        self.S_ref = []
        self.obj = []
        self.struct_masses = []
        self.cg = []
        self.point_mass_locations = []

        # find the names of all surfaces
        pt_names = []
        for key in last_case.outputs:

            # Aerostructural
            if 'coupled' in key:
                self.aerostruct = True

            if 'loads' in key:
                pt_names.append(key.split('.')[0])

        # This logic isn't guaranteed to always be in the same order.
        # Hardcoding for now because this script is already non-general.
        # if pt_names:
        #     self.pt_names = pt_names = list(set(pt_names))
        #     pt_name = pt_names[0]

        self.pt_names = pt_names = ['AS_point_0', 'AS_point_1']
        pt_name = self.pt_names[0]

        self.names = names
        n_names = len(names)

        # loop to pull data out of case reader and organize it into arrays
        for i, case in enumerate(cr.get_cases()):

            if self.opt:
                self.obj.append(case.outputs[self.obj_key])

            # Loop through each of the surfaces
            for name in names:

                # Check if this is an aerostructual case; treat differently
                # due to the way the problem is organized
                if not self.aerostruct:

                    # A mesh exists for all types of cases
                    self.mesh.append(case.outputs[name + '.mesh'])

                    try:
                        self.radius.append(
                            np.squeeze(case.outputs[name + '.radius']))
                        self.thickness.append(case.outputs[name +
                                                           '.thickness'])
                        self.vonmises.append(
                            np.max(case.outputs[name + '.vonmises'], axis=1))
                        self.show_tube = True
                    except:
                        self.show_tube = False
Esempio n. 11
0
    def load_db(self):
        cr = self.case_reader = SqliteCaseReader(self.db_name)
        cr.load_cases()
        last_case = cr.driver_cases.get_case(-1)

        # figure out if this is an optimization and what the objective is
        obj_keys = last_case.get_objectives()
        try: # if its not an empty list
            self.obj_key = obj_keys.keys[0]
            self.opt = True
        except IndexError:
            self.opt = False

        self.twist = []
        self.mesh = []
        self.def_mesh = []
        self.radius = []
        self.thickness = []
        sec_forces = []
        normals = []
        widths = []
        self.lift = []
        self.lift_ell = []
        self.vonmises = []
        alpha = []
        rho = []
        v = []
        self.CL = []
        self.AR = []
        self.S_ref = []
        self.obj = []
        self.cg = []

        # find the names of all surfaces
        names = []
        pt_names = []
        for key in last_case.outputs:
            # Aerostructural
            if 'coupled' in key and 'loads' in key:
                self.aerostruct = True
                # convoluted way to get the surface name from `<point_name>.coupled.<surf_name>_loads`
                surf_name = (key.split('.')[2]).split("_")[0]
                names.append(surf_name)

            # Aero only
            elif 'sec_forces' in key and 'coupled' not in key:
                surf_name = (key.split('.')[2]).split("_")[0]
                names.append(surf_name)

            # Structural only
            elif 'disp_aug' in key and 'coupled' not in key:
                surf_name = key.split('.')[0]
                names.append(surf_name)

            if 'CL' in key:
                pt_names.append(key.split('.')[0])

        if pt_names:
            self.pt_names = pt_names = list(set(pt_names))
            pt_name = pt_names[0]
        self.names = names
        n_names = len(names)

        # loop to pull data out of case reader and organize it into arrays
        for i, case in enumerate(cr.get_cases()):

            if self.opt:
                self.obj.append(case.outputs[self.obj_key])

            # Loop through each of the surfaces
            for name in names:

                # Check if this is an aerostructual case; treat differently
                # due to the way the problem is organized
                if not self.aerostruct:

                    # A mesh exists for all types of cases
                    self.mesh.append(case.outputs[name+'.mesh'])

                    try:
                        self.radius.append(case.outputs[name+'.radius'])
                        self.thickness.append(case.outputs[name+'.thickness'])
                        self.vonmises.append(
                            np.max(case.outputs[name+'.vonmises'], axis=1))
                        self.show_tube = True
                    except:
                        self.show_tube = False
Esempio n. 12
0
def read_db(db_name):
    output_dict = {}

    cr = SqliteCaseReader(db_name, pre_load=True)
    last_case = next(reversed(cr.get_cases('driver')))

    names = []
    for key in cr.system_metadata.keys():
        try:
            surfaces = cr.system_metadata[key]['component_options']['surfaces']
            for surface in surfaces:
                names.append(surface['name'])
            break
        except:
            pass

    obj_keys = last_case.get_objectives()
    output_dict['opt'] = True
    obj_key = list(obj_keys.keys())[0]

    output_dict['twist'] = []
    output_dict['mesh'] = []
    output_dict['def_mesh'] = []
    output_dict['def_mesh_maneuver'] = []
    output_dict['spar_thickness'] = []
    output_dict['skin_thickness'] = []
    output_dict['t_over_c'] = []
    sec_forces = []
    sec_forces_maneuver = []
    normals = []
    normals_maneuver = []
    widths = []
    widths_maneuver = []
    output_dict['lift'] = []
    output_dict['lift_ell'] = []
    output_dict['lift_maneuver'] = []
    output_dict['lift_ell_maneuver'] = []
    output_dict['lift_ell_span'] = []
    output_dict['vonmises'] = []
    alpha_maneuver = []
    rho = []
    rho_maneuver = []
    output_dict['alpha'] = []
    output_dict['v'] = []
    output_dict['CL'] = []
    output_dict['CD'] = []
    output_dict['AR'] = []
    output_dict['S_ref'] = []
    output_dict['obj'] = []
    output_dict['struct_masses'] = []
    output_dict['cg'] = []
    output_dict['point_mass_locations'] = []
    output_dict['total_weight'] = []

    pt_names = ['AS_point_0', 'AS_point_1']
    pt_name = pt_names[0]

    n_names = len(names)

    # loop to pull data out of case reader and organize it into arrays
    for i, case in enumerate(cr.get_cases()):

        output_dict['obj'].append(case.outputs[obj_key])

        # Loop through each of the surfaces
        for name in names:

            output_dict['mesh'].append(case.outputs[name + '.mesh'])
            output_dict['skin_thickness'].append(
                case.outputs[name + '.skin_thickness'])
            output_dict['spar_thickness'].append(
                case.outputs[name + '.spar_thickness'])
            output_dict['t_over_c'].append(case.outputs[name + '.t_over_c'])
            output_dict['struct_masses'].append(
                case.outputs[name + '.structural_mass'])

            vm_var_name = '{pt_name}.{surf_name}_perf.vonmises'.format(
                pt_name=pt_names[1], surf_name=name)
            output_dict['vonmises'].append(
                np.max(case.outputs[vm_var_name], axis=1))

            def_mesh_var_name = '{pt_name}.coupled.{surf_name}.def_mesh'.format(
                pt_name=pt_name, surf_name=name)
            output_dict['def_mesh'].append(case.outputs[def_mesh_var_name])

            def_mesh_var_name = '{pt_name}.coupled.{surf_name}.def_mesh'.format(
                pt_name=pt_names[1], surf_name=name)
            output_dict['def_mesh_maneuver'].append(
                case.outputs[def_mesh_var_name])

            normals_var_name = '{pt_name}.coupled.{surf_name}.normals'.format(
                pt_name=pt_name, surf_name=name)
            normals.append(case.outputs[normals_var_name])

            normals_var_name = '{pt_name}.coupled.{surf_name}.normals'.format(
                pt_name=pt_names[1], surf_name=name)
            normals_maneuver.append(case.outputs[normals_var_name])

            widths_var_name = '{pt_name}.coupled.{surf_name}.widths'.format(
                pt_name=pt_name, surf_name=name)
            widths.append(case.outputs[widths_var_name])

            widths_var_name = '{pt_name}.coupled.{surf_name}.widths'.format(
                pt_name=pt_names[1], surf_name=name)
            widths_maneuver.append(case.outputs[widths_var_name])

            sec_forces.append(case.outputs[pt_name + '.coupled.aero_states.' +
                                           name + '_sec_forces'])
            sec_forces_maneuver.append(
                case.outputs[pt_names[1] + '.coupled.aero_states.' + name +
                             '_sec_forces'])

            cl_var_name = '{pt_name}.{surf_name}_perf.CL1'.format(
                pt_name=pt_name, surf_name=name)
            output_dict['CL'].append(case.outputs[cl_var_name])

            cd_var_name = '{pt_name}.CD'.format(pt_name=pt_name)
            output_dict['CD'].append(case.outputs[cd_var_name])

            S_ref_var_name = '{pt_name}.coupled.{surf_name}.aero_geom.S_ref'.format(
                pt_name=pt_name, surf_name=name)
            output_dict['S_ref'].append(case.outputs[S_ref_var_name])

            output_dict['twist'].append(case.outputs[name + '.geometry.twist'])