Exemplo n.º 1
0
    def save_timestep(data, settings, ts, hdfile):
        if settings['save_aero']:
            h5utils.add_as_grp(data.aero.timestep_info[ts],
                               hdfile['data']['aero']['timestep_info'],
                               grpname=("%05d" % ts),
                               ClassesToSave=(sharpy.utils.datastructures.AeroTimeStepInfo,),
                               SkipAttr=settings['skip_attr'],
                               compress_float=settings['compress_float'])
        if settings['save_struct']:
            if data.structure.timestep_info[ts].in_global_AFoR:
                tstep = data.structure.timestep_info[ts]
            else:
                tstep = data.structure.timestep_info[data.ts].copy()
                tstep.whole_structure_to_global_AFoR(data.structure)

            h5utils.add_as_grp(tstep,
                               hdfile['data']['structure']['timestep_info'],
                               grpname=("%05d" % ts),
                               ClassesToSave=(sharpy.utils.datastructures.StructTimeStepInfo,),
                               SkipAttr=settings['skip_attr'],
                               compress_float=settings['compress_float'])
Exemplo n.º 2
0
    def run(self, online=False):

        # Use the following statement in case the ct types are not defined and
        # you need them on uvlm3d
        # self.data.aero.timestep_info[-1].generate_ctypes_pointers()

        if self.settings['format'] == 'h5':
            file_exists = os.path.isfile(self.filename)
            hdfile = h5py.File(self.filename, 'a')

            if (online and file_exists):
                self.save_timestep(self.data, self.settings, self.data.ts, hdfile)
            else:
                skip_attr_init = copy.deepcopy(self.settings['skip_attr'])
                skip_attr_init.append('timestep_info')

                h5utils.add_as_grp(self.data, hdfile, grpname='data',
                                   ClassesToSave=self.ClassesToSave, SkipAttr=skip_attr_init,
                                   compress_float=self.settings['compress_float'])

                if self.settings['save_struct']:
                    h5utils.add_as_grp(list(),
                               hdfile['data']['structure'],
                               grpname='timestep_info')
                if self.settings['save_aero']:
                    h5utils.add_as_grp(list(),
                               hdfile['data']['aero'],
                               grpname='timestep_info')

                for it in range(len(self.data.structure.timestep_info)):
                    tstep_p = self.data.structure.timestep_info[it]
                    if tstep_p is not None:
                        self.save_timestep(self.data, self.settings, it, hdfile)

            hdfile.close()

            if self.settings['save_linear_uvlm']:
                linhdffile = h5py.File(self.filename.replace('.data.h5', '.uvlmss.h5'), 'a')
                h5utils.add_as_grp(self.data.linear.linear_system.uvlm.ss, linhdffile, grpname='ss',
                                   ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
                                   compress_float=self.settings['compress_float'])
                h5utils.add_as_grp(self.data.linear.linear_system.linearisation_vectors, linhdffile,
                                   grpname='linearisation_vectors',
                                   ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
                                   compress_float=self.settings['compress_float'])
                linhdffile.close()

            if self.settings['save_linear']:
                with h5py.File(self.filename_linear, 'a') as linfile:
                    h5utils.add_as_grp(self.data.linear.linear_system.linearisation_vectors, linfile,
                                       grpname='linearisation_vectors',
                                       ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
                                       compress_float=self.settings['compress_float'])
                    h5utils.add_as_grp(self.data.linear.ss, linfile, grpname='ss',
                                       ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
                                       compress_float=self.settings['compress_float'])

            if self.settings['save_rom']:
                try:
                    for k, rom in self.data.linear.linear_system.uvlm.rom.items():
                        rom.save(self.filename.replace('.data.h5', '_{:s}.rom.h5'.format(k.lower())))
                except AttributeError:
                    cout.cout_wrap('Could not locate a reduced order model to save')

        elif self.settings['format'] == 'mat':
            from scipy.io import savemat
            if self.settings['save_linear']:
                # reference-forces
                linearisation_vectors = self.data.linear.linear_system.linearisation_vectors

                matfilename = self.filename.replace('.data.h5', '.linss.mat')
                A, B, C, D = self.data.linear.ss.get_mats()
                savedict = {'A': A,
                            'B': B,
                            'C': C,
                            'D': D}
                for k, v in linearisation_vectors.items():
                    savedict[k] = v
                try:
                    dt = self.data.linear.ss.dt
                    savedict['dt'] = dt
                except AttributeError:
                    pass
                savemat(matfilename, savedict)

            if self.settings['save_linear_uvlm']:
                matfilename = self.filename.replace('.data.h5', '.uvlmss.mat')
                linearisation_vectors = self.data.linear.linear_system.uvlm.linearisation_vectors
                A, B, C, D = self.data.linear.linear_system.uvlm.ss.get_mats()
                savedict = {'A': A,
                            'B': B,
                            'C': C,
                            'D': D}
                for k, v in linearisation_vectors.items():
                    savedict[k] = v
                try:
                    dt = self.data.linear.ss.dt
                    savedict['dt'] = dt
                except AttributeError:
                    pass
                savemat(matfilename, savedict)

        return self.data
Exemplo n.º 3
0
    def run(self, online=False):

        # Use the following statement in case the ct types are not defined and
        # you need them on uvlm3d
        # self.data.aero.timestep_info[-1].generate_ctypes_pointers()

        if self.settings['format'] == 'h5':
            file_exists = os.path.isfile(self.filename)
            hdfile = h5py.File(self.filename, 'a')

            if (online and file_exists):
                if self.settings['save_aero']:
                    h5utils.add_as_grp(
                        self.data.aero.timestep_info[self.data.ts],
                        hdfile['data']['aero']['timestep_info'],
                        grpname=("%05d" % self.data.ts),
                        ClassesToSave=(
                            sharpy.utils.datastructures.AeroTimeStepInfo, ),
                        SkipAttr=self.settings['skip_attr'],
                        compress_float=self.settings['compress_float'])
                if self.settings['save_struct']:
                    if self.data.structure.timestep_info[
                            self.data.ts].in_global_AFoR:
                        tstep = self.data.structure.timestep_info[self.data.ts]
                    else:
                        tstep = self.data.structure.timestep_info[
                            self.data.ts].copy()
                        tstep.whole_structure_to_global_AFoR(
                            self.data.structure)

                    h5utils.add_as_grp(
                        tstep,
                        hdfile['data']['structure']['timestep_info'],
                        grpname=("%05d" % self.data.ts),
                        ClassesToSave=(
                            sharpy.utils.datastructures.StructTimeStepInfo, ),
                        SkipAttr=self.settings['skip_attr'],
                        compress_float=self.settings['compress_float'])
            else:
                for it in range(len(self.data.structure.timestep_info)):
                    tstep_p = self.data.structure.timestep_info[it]
                    if tstep_p is not None:
                        if not tstep_p.in_global_AFoR:
                            tstep_p.whole_structure_to_global_AFoR(
                                self.data.structure)
                h5utils.add_as_grp(
                    self.data,
                    hdfile,
                    grpname='data',
                    ClassesToSave=self.ClassesToSave,
                    SkipAttr=self.settings['skip_attr'],
                    compress_float=self.settings['compress_float'])

            hdfile.close()

            if self.settings['save_linear_uvlm']:
                linhdffile = h5py.File(
                    self.filename.replace('.data.h5', '.uvlmss.h5'), 'a')
                h5utils.add_as_grp(
                    self.data.linear.linear_system.uvlm.ss,
                    linhdffile,
                    grpname='ss',
                    ClassesToSave=self.ClassesToSave,
                    SkipAttr=self.settings['skip_attr'],
                    compress_float=self.settings['compress_float'])
                h5utils.add_as_grp(
                    self.data.linear.linear_system.linearisation_vectors,
                    linhdffile,
                    grpname='linearisation_vectors',
                    ClassesToSave=self.ClassesToSave,
                    SkipAttr=self.settings['skip_attr'],
                    compress_float=self.settings['compress_float'])
                linhdffile.close()

            if self.settings['save_linear']:
                with h5py.File(self.filename_linear, 'a') as linfile:
                    h5utils.add_as_grp(
                        self.data.linear.linear_system.linearisation_vectors,
                        linfile,
                        grpname='linearisation_vectors',
                        ClassesToSave=self.ClassesToSave,
                        SkipAttr=self.settings['skip_attr'],
                        compress_float=self.settings['compress_float'])
                    h5utils.add_as_grp(
                        self.data.linear.ss,
                        linfile,
                        grpname='ss',
                        ClassesToSave=self.ClassesToSave,
                        SkipAttr=self.settings['skip_attr'],
                        compress_float=self.settings['compress_float'])

        elif self.settings['format'] == 'mat':
            from scipy.io import savemat
            if self.settings['save_linear']:
                # reference-forces
                linearisation_vectors = self.data.linear.linear_system.linearisation_vectors

                matfilename = self.filename.replace('.data.h5', '.linss.mat')
                A, B, C, D = self.data.linear.ss.get_mats()
                savedict = {'A': A, 'B': B, 'C': C, 'D': D}
                for k, v in linearisation_vectors.items():
                    savedict[k] = v
                try:
                    dt = self.data.linear.ss.dt
                    savedict['dt'] = dt
                except AttributeError:
                    pass
                savemat(matfilename, savedict)

            if self.settings['save_linear_uvlm']:
                matfilename = self.filename.replace('.data.h5', '.uvlmss.mat')
                linearisation_vectors = self.data.linear.linear_system.uvlm.linearisation_vectors
                A, B, C, D = self.data.linear.linear_system.uvlm.ss.get_mats()
                savedict = {'A': A, 'B': B, 'C': C, 'D': D}
                for k, v in linearisation_vectors.items():
                    savedict[k] = v
                try:
                    dt = self.data.linear.ss.dt
                    savedict['dt'] = dt
                except AttributeError:
                    pass
                savemat(matfilename, savedict)

        return self.data