Пример #1
0
    def _create_groups_by_name(self, name, prefix, nlimit=500):
        """
        Helper method for `create_groups_by_visible_result` and `create_groups_by_property_id`
        """
        #eids = self.find_result_by_name('ElementID')
        #elements_pound = eids.max()
        try:
            eids = self.gui.groups['main'].element_ids
            elements_pound = self.gui.groups['main'].elements_pound
        except Exception as error:
            self.gui.log.error('Cannot create groups as there are no elements in the model')
            self.gui.log.error(str(error))
            if self.gui.IS_GUI_TESTING:
                raise
            return 0

        result = self.gui.find_result_by_name(name)
        ures = np.unique(result)
        ngroups = len(ures)
        if ngroups > nlimit:
            self.gui.log.error('not creating result; %i new groups would be created; '
                               'increase nlimit=%i if you really want to' % (ngroups, nlimit))
            return 0

        for uresi in ures:
            ids = np.where(uresi == result)[0]

            name = '%s %s' % (prefix, uresi)
            element_str = ''
            group = Group(
                name, element_str, elements_pound,
                editable=True)
            group.element_ids = eids[ids]
            self.gui.log_info('creating group=%r' % name)
            self.gui.groups[name] = group
        return ngroups
Пример #2
0
    def _finish_results_io2(self, model_name, form, cases, reset_labels=True):
        """
        This is not quite the same as the main one.
        It's more or less just _set_results
        """
        if self.node_ids is None:  # pragma: no cover
            raise RuntimeError('implement self.node_ids for this format')
        if self.element_ids is None:  # pragma: no cover
            raise RuntimeError('implement self.element_ids for this format')

        #assert hasattr(self, 'gui'), 'gui does not exist for this format'
        assert hasattr(self, 'isubcase_name_map'
                       ), 'isubcase_name_map does not exist for this format'
        assert isinstance(self.nnodes,
                          int), 'nnodes=%r must be an integer' % self.nnodes
        assert isinstance(
            self.nelements,
            int), 'nelements=%r must be an integer' % self.nelements

        assert len(cases) > 0, cases
        if isinstance(cases, OrderedDict):
            self.case_keys = list(cases.keys())
        else:
            self.case_keys = sorted(cases.keys())
            assert isinstance(cases, dict), type(cases)

        #print('self.case_keys = ', self.case_keys)
        for key in self.case_keys:
            assert isinstance(key, int), key
            obj, (i, name) = cases[key]
            value = cases[key]
            if isinstance(value[0], int):
                raise RuntimeError(
                    'old style key is being used.\n key=%s\n type=%s value=%s'
                    % (key, type(value[0]), value))
            #assert len(value) == 2, 'value=%s; len=%s' % (str(value), len(value))

            unused_subcase_id = obj.subcase_id
            unused_case = obj.get_result(i, name)
            unused_result_type = obj.get_title(i, name)
            vector_size = obj.get_vector_size(i, name)
            #location = obj.get_location(i, name)
            unused_methods = obj.get_methods(i)
            unused_data_format = obj.get_data_format(i, name)
            scale = obj.get_scale(i, name)
            phase = obj.get_phase(i, name)
            unused_label2 = obj.get_header(i, name)
            unused_flag = obj.is_normal_result(i, name)
            #scalar_result = obj.get_scalar(i, name)
            nlabels, labelsize, ncolors, colormap = obj.get_nlabels_labelsize_ncolors_colormap(
                i, name)
            if vector_size == 3:
                unused_plot_value = obj.get_plot_value(i, name)  # vector
                scale = 1.0
                phase = 2.0
                obj.set_scale(i, name, scale)
                obj.set_phase(i, name, phase)
                assert obj.deflects(i, name) in [True,
                                                 False], obj.deflects(i, name)
                unused_xyz, unused_deflected_xyz = obj.get_vector_result(
                    i, name)
            else:
                unused_scalar_result = obj.get_scalar(i, name)

            unused_default_data_format = obj.get_default_data_format(i, name)
            default_min, unused_default_max = obj.get_default_min_max(i, name)
            unused_default_scale = obj.get_default_scale(i, name)
            unused_default_title = obj.get_default_title(i, name)
            unused_default_phase = obj.get_default_phase(i, name)
            out_labels = obj.get_default_nlabels_labelsize_ncolors_colormap(
                i, name)
            nlabels = 4
            labelsize = 10
            ncolors = 20
            colormap = 'jet'
            obj.set_nlabels_labelsize_ncolors_colormap(i, name, nlabels,
                                                       labelsize, ncolors,
                                                       colormap)
            (unused_default_nlabels, unused_default_labelsize,
             unused_default_ncolors, unused_default_colormap) = out_labels

            #default_max, default_min = obj.get_default_min_max(i, name)
            unused_min_value, unused_max_value = obj.get_min_max(i, name)

        self.result_cases = cases

        if len(self.case_keys) > 1:
            self.icase = -1
            self.ncases = len(
                self.result_cases)  # number of keys in dictionary
        elif len(self.case_keys) == 1:
            self.icase = -1
            self.ncases = 1
        else:
            self.icase = -1
            self.ncases = 0

        if self.is_groups:
            #eids = np.arange(172)
            #eids = []
            #self.hide_elements_mask(eids)
            elements_pound = self.element_ids[-1]
            main_group = Group('main', '', elements_pound, editable=False)
            main_group.element_ids = self.element_ids
            self.groups['main'] = main_group
            self.post_group(main_group)
            #self.show_elements_mask(np.arange(self.nelements))

        for unused_module_name, module in self.modules.items():
            module.post_load_geometry()