Beispiel #1
0
    def _fill_abaqus_case(
            self, cases, ID: int, node_ids, nodes, nelements: int,
            unused_model: Abaqus
    ) -> Tuple[Any, Any, int, np.ndarray, np.ndarray]:
        """creates the result objects for abaqus"""
        #return [], {}, 0
        #nelements = elements.shape[0]
        nnodes = nodes.shape[0]

        element_ids = np.arange(1, nelements + 1)
        #print(nodes)
        #node_ids = np.arange(1, nnodes + 1)
        #cnormals = model.get_normals(shift_nodes=False)
        #cnnodes = cnormals.shape[0]
        #assert cnnodes == nelements, len(cnnodes)

        #print('nnodes =', nnodes)
        #print('nelements =', nelements)
        #print('regions.shape =', regions.shape)
        #subcase_id = 0
        #labels = ['NodeID', 'ElementID']
        #cart3d_geo = Cart3dGeometry(subcase_id, labels,
        #nids, eids, regions, cnormals,
        #uname='Cart3dGeometry')
        colormap = 'jet'
        nid_res = GuiResult(ID,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=node_ids)
        eid_res = GuiResult(ID,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=element_ids)
        nxyz_res = NormalResult(0,
                                'Normals',
                                'Normals',
                                nlabels=2,
                                labelsize=5,
                                ncolors=2,
                                colormap=colormap,
                                data_format='%.1f',
                                uname='NormalResult')

        cases[0] = (nid_res, (0, 'NodeID'))
        cases[1] = (eid_res, (0, 'ElementID'))
        cases[2] = (nxyz_res, (0, 'Normal'))

        geometry_form = [
            ('NodeID', 0, []),
            ('ElementID', 1, []),
            ('Normal', 2, []),
        ]
        form = [
            ('Geometry', None, geometry_form),
        ]
        icase = 2
        return form, cases, icase, node_ids, element_ids
Beispiel #2
0
    def _fill_stl_case(self, cases, ID, elements, nodes, normals, areas):
        """adds the sidebar results"""
        self.gui.isubcase_name_map[ID] = ('STL', '')
        colormap = 'jet'
        nelements = elements.shape[0]
        nnodes = nodes.shape[0]
        icase = 0
        itime = 0
        eids = arange(1, nelements + 1, dtype='int32')
        nids = arange(1, nnodes + 1, dtype='int32')
        eid_res = GuiResult(ID, header='ElementID', title='ElementID',
                            location='centroid', scalar=eids)
        nid_res = GuiResult(ID, header='NodeID', title='NodeID',
                            location='node', scalar=nids)
        area_res = GuiResult(ID, header='Area', title='Area',
                             location='centroid', scalar=areas)
        nx_res = GuiResult(ID, header='NormalX', title='NormalX',
                           location='centroid', scalar=normals[:, 0])
        ny_res = GuiResult(ID, header='NormalY', title='NormalY',
                           location='centroid', scalar=normals[:, 1])
        nz_res = GuiResult(ID, header='NormalZ', title='NormalZ',
                           location='centroid', scalar=normals[:, 2])
        nxyz_res = NormalResult(0, 'Normals', 'Normals',
                                nlabels=2, labelsize=5, ncolors=2,
                                colormap=colormap, data_format='%.1f',
                                uname='NormalResult')
        cases[icase] = (eid_res, (itime, 'ElementID'))
        cases[icase + 1] = (nid_res, (itime, 'NodeID'))
        cases[icase + 2] = (area_res, (itime, 'Area'))
        cases[icase + 3] = (nx_res, (itime, 'NormalX'))
        cases[icase + 4] = (ny_res, (itime, 'NormalY'))
        cases[icase + 5] = (nz_res, (itime, 'NormalZ'))
        cases[icase + 6] = (nxyz_res, (itime, 'Normal'))

        form = [
            ('ElementID', icase, []),
            ('NodeID', icase + 1, []),
            ('Area', icase + 2, []),
            ('NormalX', icase + 3, []),
            ('NormalY', icase + 4, []),
            ('NormalZ', icase + 5, []),
            ('Normal', icase + 6, []),
        ]
        return form, cases, nids, eids
Beispiel #3
0
    def load_vrml_geometry(self, vrml_filename, name='main', plot=True):
        """loads a VRML file into the GUI"""
        model_name = name
        #key = self.case_keys[self.icase]
        #case = self.result_cases[key]
        self.gui.eid_maps[name] = {}
        self.gui.nid_maps[name] = {}

        skip_reading = self.gui._remove_old_geometry(vrml_filename)
        if skip_reading:
            return

        nodes, quads, tris = read_vrml(vrml_filename)
        points = numpy_to_vtk_points(nodes)

        nnodes = nodes.shape[0]
        assert nnodes > 0
        ntris = len(tris)
        nquads = len(quads)
        nelements = ntris + nquads

        self.gui.nelements = nelements
        self.gui.nnodes = nnodes

        self.gui.log.info(
            f"nnodes={nnodes} nelements={nelements} (nquads={nquads} ntris={ntris})"
        )
        assert nelements > 0, nelements

        grid = self.gui.grid
        grid.Allocate(self.gui.nelements, 1000)

        #self.gui.nid_map = {}

        etypes = []
        elements = []
        if ntris:
            elements.append(tris)
            etypes.append(5)  # vtkTriangle().GetCellType()
        if nquads:
            elements.append(quads)
            etypes.append(9)  # vtkQuad().GetCellType()

        assert len(etypes) > 0, etypes
        #self.gui.model.elements = elements
        #self.gui.model.etypes = etypes
        create_vtk_cells_of_constant_element_types(grid, elements, etypes)

        self.gui.nelements = nelements
        grid.SetPoints(points)
        grid.Modified()
        #------------------------------------------------
        self.gui.scalar_bar_actor.VisibilityOn()
        self.gui.scalar_bar_actor.Modified()

        self.gui.isubcase_name_map = {1: ['AFLR UGRID Surface', '']}
        cases = OrderedDict()
        ID = 1

        node_ids = np.arange(1, nnodes + 1, dtype='int32')
        element_ids = np.arange(1, nelements + 1, dtype='int32')
        self.gui.node_ids = node_ids
        self.gui.element_ids = element_ids

        #eids = arange(1, len(elements) + 1, dtype='int32')
        #nids = arange(1, len(nodes) + 1, dtype='int32')
        #regions = np.array(regions, dtype='int32')

        icase = 0
        colormap = self.gui.settings.colormap
        eid_res = GuiResult(ID,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=element_ids)
        nid_res = GuiResult(ID,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=node_ids)
        nxyz_res = NormalResult(0,
                                'Normals',
                                'Normals',
                                nlabels=2,
                                labelsize=5,
                                ncolors=2,
                                colormap=colormap,
                                data_format='%.1f',
                                uname='NormalResult')

        geometry_form = [
            ('ElementID', icase, []),
            ('NodeID', icase + 1, []),
            ('Normals', icase + 2, []),
        ]
        cases[icase] = (eid_res, (ID, 'ElementID'))
        cases[icase + 1] = (nid_res, (ID, 'NodeID'))
        cases[icase + 2] = (nxyz_res, (0, 'Normals'))

        form = geometry_form
        if plot:
            self.gui._finish_results_io2(model_name, form, cases)
Beispiel #4
0
    def _fill_ugrid3d_case(self, base, cases, ID, nnodes, nelements, model,
                           read_solids):
        if os.path.exists(base):
            # base = 'C:/data/'
            # tag_filename = 'C:/data/.tags'
            self.gui.log.info('mapbc_filename does not exist')
            self.gui.log.info('tag_filename does not exist')
            tag_filename = None
            mapbc_filename = None
        else:
            tag_filename = base + '.tags'
            mapbc_filename = base.split('.')[0] + '.mapbc'
            self.gui.log.info('mapbc_filename = %r' % mapbc_filename)

        colormap = self.gui.settings.colormap

        #cases_new = []
        has_tag_data = False
        has_mapbc_data = False
        results_form = []
        mapbc_form = []

        geometry_form = [
            #('Region', 0, []),
            ('ElementID', 0, []),
            ('NodeID', 1, []),
            ('Normals', 2, []),
            #('normSpacing', 3, []),
            #('BL_thick', 4, []),
            #('ReconFlag', 5, []),
            #('GridBC', 6, []),
        ]
        if not read_solids:
            geometry_form.append(('SurfaceID', 3, []))

        #ntris = model.tris.shape[0]
        #nquads = model.quads.shape[0]
        #nelements = ntris + nquads
        eids = arange(1, nelements + 1)
        nids = arange(1, nnodes + 1)

        #grid_bcs = element_props[:, 2]

        #npids = len(model.pids)
        pids = model.pids
        eid_res = GuiResult(0,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=eids,
                            colormap=colormap)
        nid_res = GuiResult(0,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids,
                            colormap=colormap)
        nxyz_res = NormalResult(0,
                                'Normals',
                                'Normals',
                                nlabels=2,
                                labelsize=5,
                                ncolors=2,
                                colormap=colormap,
                                data_format='%.1f',
                                uname='NormalResult')

        icase = 0
        cases[icase] = (eid_res, (0, 'ElementID'))
        cases[icase + 1] = (nid_res, (0, 'NodeID'))
        cases[icase + 2] = (nxyz_res, (0, 'Normals'))
        icase += 3
        if not read_solids:
            surface_res = GuiResult(0,
                                    header='SurfaceID',
                                    title='SurfaceID',
                                    location='centroid',
                                    scalar=pids,
                                    colormap=colormap)
            cases[icase] = (surface_res, (0, 'SurfaceID'))
            icase += 1

        if tag_filename is not None and os.path.exists(
                tag_filename) and not read_solids:
            #surf_ids = element_props[:, 0]
            #recon_flags = element_props[:, 1]
            #cases[(ID, 2, 'ReconFlag', 1, 'centroid', '%i')] = recon_flags
            #cases[(ID, 3, 'GridBC',    1, 'centroid', '%i')] = grid_bcs

            tagger = TagReader()
            data = tagger.read_tag_filename(tag_filename)

            int_data = ones((nelements, 8), dtype='int32') * -10.
            float_data = zeros((nelements, 2), dtype='float64')
            for key, datai in sorted(data.items()):
                #self.gui.log.info(datai)
                [
                    name, is_visc, is_recon, is_rebuild, is_fixed, is_source,
                    is_trans, is_delete, bl_spacing, bl_thickness, nlayers
                ] = datai
                i = where(pids == key)[0]
                int_data[i, :] = [
                    is_visc, is_recon, is_rebuild, is_fixed, is_source,
                    is_trans, is_delete, nlayers
                ]
                float_data[i, :] = [bl_spacing, bl_thickness]
                self.gui.log.info('data[%i] = %s' % (key, name))

            has_tag_data = True
            tag_form = []
            tag_form.append(('is_visc', icase, []))
            tag_form.append(('is_recon', icase + 1, []))
            tag_form.append(('is_rebuild', icase + 2, []))
            tag_form.append(('is_fixed', icase + 3, []))
            tag_form.append(('is_source', icase + 4, []))
            tag_form.append(('is_trans', icase + 5, []))
            tag_form.append(('is_delete', icase + 6, []))
            tag_form.append(('nlayers', icase + 7, []))
            tag_form.append(('bl_spacing', icase + 8, []))
            tag_form.append(('bl_thickness', icase + 9, []))

            visc_res = GuiResult(0,
                                 header='is_visc',
                                 title='is_visc',
                                 location='node',
                                 scalar=int_data[:, 0],
                                 colormap=colormap)
            recon_res = GuiResult(0,
                                  header='is_recon',
                                  title='is_recon',
                                  location='node',
                                  scalar=int_data[:, 1],
                                  colormap=colormap)
            rebuild_res = GuiResult(0,
                                    header='is_rebuild',
                                    title='is_rebuild',
                                    location='node',
                                    scalar=int_data[:, 2],
                                    colormap=colormap)
            fixed_res = GuiResult(0,
                                  header='is_fixed',
                                  title='is_fixed',
                                  location='node',
                                  scalar=int_data[:, 3],
                                  colormap=colormap)
            source_res = GuiResult(0,
                                   header='is_source',
                                   title='is_source',
                                   location='node',
                                   scalar=int_data[:, 4],
                                   colormap=colormap)
            trans_res = GuiResult(0,
                                  header='is_trans',
                                  title='is_trans',
                                  location='node',
                                  scalar=int_data[:, 5],
                                  colormap=colormap)
            delete_res = GuiResult(0,
                                   header='is_delete',
                                   title='is_delete',
                                   location='node',
                                   scalar=int_data[:, 6],
                                   colormap=colormap)
            nlayers_res = GuiResult(0,
                                    header='nlayers',
                                    title='nlayers',
                                    location='node',
                                    scalar=int_data[:, 7],
                                    colormap=colormap)

            spacing_res = GuiResult(0,
                                    header='bl_spacing',
                                    title='bl_spacing',
                                    location='centroid',
                                    scalar=float_data[:, 0],
                                    colormap=colormap)
            blthickness_res = GuiResult(0,
                                        header='bl_thickness',
                                        title='bl_thickness',
                                        location='centroid',
                                        scalar=float_data[:, 1],
                                        colormap=colormap)

            cases[icase] = (visc_res, (0, 'is_visc'))
            cases[icase + 1] = (recon_res, (0, 'is_recon'))
            cases[icase + 2] = (rebuild_res, (0, 'is_rebuild'))
            cases[icase + 3] = (fixed_res, (0, 'is_fixed'))
            cases[icase + 4] = (source_res, (0, 'is_source'))
            cases[icase + 5] = (trans_res, (0, 'is_trans'))
            cases[icase + 6] = (delete_res, (0, 'is_delete'))
            cases[icase + 7] = (nlayers_res, (0, 'nlayers'))

            cases[icase + 8] = (spacing_res, (0, 'bl_spacing'))
            cases[icase + 9] = (blthickness_res, (0, 'bl_thickness'))

            icase += 10
        elif tag_filename is not None:
            self.gui.log.warning('tag_filename=%r could not be found' %
                                 tag_filename)

        if mapbc_filename is not None and os.path.exists(
                mapbc_filename) and not read_solids:
            has_mapbc_data = True
            with open(mapbc_filename, 'r') as mapbc:
                lines = mapbc.readlines()
            lines = [
                line.strip() for line in lines
                if not line.strip().startswith('#') and line.strip()
            ]
            npatches = int(lines[0])
            mapbcs = zeros(pids.shape, dtype='int32')
            for ipatch in range(npatches):
                line = lines[ipatch + 1]
                iline, bc_num, name = line.split()
                iline = int(iline)
                bc_num = int(bc_num)
                assert ipatch + 1 == iline, 'line=%r; ipatch=%s iline=%s' % (
                    line, ipatch + 1, iline)
                islot = where(pids == ipatch + 1)[0]
                if len(islot) == 0:
                    upids = unique(pids)
                    msg = 'ipatch=%s not found in pids=%s' % (ipatch + 1,
                                                              upids)
                    raise RuntimeError(msg)
                mapbcs[islot] = bc_num
                self.gui.log.info(line)
            mapbc_form.append(('Map BC', icase, []))

            mapbc_res = GuiResult(0,
                                  header='Map BC',
                                  title='Map BC',
                                  location='centroid',
                                  scalar=mapbcs,
                                  colormap=colormap)
            cases[icase + 9] = (mapbc_res, (0, 'Map BC'))
        elif mapbc_filename is not None:
            self.gui.log.warning('mapbc_filename=%r could not be found' %
                                 mapbc_filename)

        #norm_spacing = model.node_props[:, 0]
        #bl_thickness = model.node_props[:, 1]
        #cases[(ID, 1, 'normSpacing', 1, 'node', '%.3e', '')] = norm_spacing
        #cases[(ID, 2, 'BL_thick',    1, 'node', '%.3e', '')] = bl_thickness

        form = [
            ('Geometry', None, geometry_form),
        ]
        if has_tag_data:
            form.append(('Tag Data', None, tag_form), )
        if has_mapbc_data:
            form.append(('Map BC Data', None, mapbc_form), )

        results_form = []
        if len(results_form):
            form.append(('Results', None, results_form))
        self.gui.log.info(form)
        return form, cases, nids, eids
Beispiel #5
0
    def _fill_panair_geometry_case(self, cases, ID, nodes, elements, regions,
                                   kt, cp_norm, unused_loads):
        self.elements = elements
        colormap = 'jet' # self.colormap
        nnids = nodes.shape[0]
        neids = elements.shape[0]
        nids = arange(0., nnids, dtype='int32') + 1
        eids = arange(0., neids, dtype='int32') + 1

        # centroidal
        #nelements = len(elements)
        #print('nelements = ', nelements)
        #print('nnodes = ', nodes.shape)

        p1 = nodes[elements[:, 0]]
        p2 = nodes[elements[:, 1]]
        p3 = nodes[elements[:, 2]]
        p4 = nodes[elements[:, 3]]
        xyz_centroid = (p1 + p2 + p3 + p4) / 4.

        n = np.cross(p3 - p1, p4 - p2)
        n_norm = np.linalg.norm(n, axis=1)
        area = n_norm / 2.
        normal = n / n_norm[:, np.newaxis]

        itime = 0
        # ID, header, title, location, values, format, uname
        region_res = GuiResult(ID, 'Network', 'Network', 'centroid', regions,
                               data_format=None, colormap=colormap, uname='Network')
        eid_res = GuiResult(ID, 'ElementID', 'ElementID', 'centroid', eids,
                            data_format=None, colormap=colormap, uname='ElementID')
        nid_res = GuiResult(ID, 'NodeID', 'NodeID', 'node', nids,
                            data_format=None, colormap=colormap, uname='NodeID')
        area_res = GuiResult(ID, 'Area', 'Area', 'centroid', area,
                             data_format=None, colormap=colormap, uname='Area')

        nxyz_res = NormalResult(0, 'Normals', 'Normals',
                                nlabels=2, labelsize=5, ncolors=2,
                                #colormap=colormap,
                                data_format='%.1f',
                                uname='NormalResult')
        nx_res = GuiResult(ID, 'normal_x', 'NormalX', 'centroid', normal[:, 0],
                           data_format='%.3f', colormap=colormap, uname='NormalX')
        ny_res = GuiResult(ID, 'normal_y', 'NormalY', 'centroid', normal[:, 1],
                           data_format='%.3f', colormap=colormap, uname='NormalY')
        nz_res = GuiResult(ID, 'normal_z', 'NormalZ', 'centroid', normal[:, 2],
                           data_format='%.3f', colormap=colormap, uname='NormalZ')
        cenx_res = GuiResult(ID, 'centroid_x', 'CentroidX', 'centroid', xyz_centroid[:, 0],
                             data_format=None, colormap=colormap, uname='CentroidX')
        ceny_res = GuiResult(ID, 'centroid_y', 'CentroidY', 'centroid', xyz_centroid[:, 1],
                             data_format=None, colormap=colormap, uname='CentroidY')
        cenz_res = GuiResult(ID, 'centroid_z', 'CentroidZ', 'centroid', xyz_centroid[:, 2],
                             data_format=None, colormap=colormap, uname='CentroidZ')

        kt_res = GuiResult(ID, 'Kt', 'Kt', 'centroid', kt,
                           data_format=None, colormap=colormap, uname='Kt')
        cp_res = GuiResult(ID, 'CpNorm', 'CpNorm', 'centroid', cp_norm,
                           data_format=None, colormap=colormap, uname='CpNorm')

        # nodal
        cenx_res = GuiResult(ID, 'node_x', 'NodeX', 'node', nodes[:, 0],
                             data_format='%.2f', colormap=colormap, uname='node_x')
        ceny_res = GuiResult(ID, 'node_y', 'NodeY', 'node', nodes[:, 1],
                             data_format='%.2f', colormap=colormap, uname='node_y')
        cenz_res = GuiResult(ID, 'node_z', 'NodeZ', 'node', nodes[:, 2],
                             data_format='%.2f', colormap=colormap, uname='node_z')

        icase = 0
        location_form = [
            ('Normal', icase + 4, []),
            ('normal_x', icase + 5, []),
            ('normal_y', icase + 6, []),
            ('normal_z', icase + 7, []),

            ('centroid_x', icase + 8, []),
            ('centroid_y', icase + 9, []),
            ('centroid_z', icase + 10, []),

            ('node_x', icase + 11, []),
            ('node_y', icase + 12, []),
            ('node_z', icase + 13, []),
        ]

        geometry_form = [
            ('Patch', icase, []),
            ('ElementID', icase + 1, []),
            ('NodeID', icase + 2, []),
            ('Area', icase + 3, []),
            ('Location', None, location_form),
            ('Kt', icase + 14, []),
            ('CpNorm', icase + 15, []),
        ]
        form = [
            ('Geometry', None, geometry_form),
        ]

        cases[icase] = (region_res, (itime, 'Patch'))
        cases[icase + 1] = (eid_res, (itime, 'ElementID'))
        cases[icase + 2] = (nid_res, (itime, 'NodeID'))
        cases[icase + 3] = (area_res, (itime, 'Area'))

        # location_form
        cases[icase + 4] = (nxyz_res, (itime, 'Normal'))
        cases[icase + 5] = (nx_res, (itime, 'NormalX'))
        cases[icase + 6] = (ny_res, (itime, 'NormalY'))
        cases[icase + 7] = (nz_res, (itime, 'NormalZ'))
        #---
        cases[icase + 8] = (cenx_res, (itime, 'CentroidX'))
        cases[icase + 9] = (ceny_res, (itime, 'CentroidY'))
        cases[icase + 10] = (cenz_res, (itime, 'CentroidZ'))
        #---
        cases[icase + 11] = (cenx_res, (itime, 'node_x'))
        cases[icase + 12] = (ceny_res, (itime, 'node_y'))
        cases[icase + 13] = (cenz_res, (itime, 'node_z'))

        cases[icase + 14] = (kt_res, (itime, 'Kt'))
        cases[icase + 15] = (cp_res, (itime, 'CpNorm'))

        return form, cases, nids, eids