예제 #1
0
    def _fill_degen_geom_case(self, cases, ID, model, nnodes,
                              nelements):  # pragma: no cover
        icase = 0
        itime = 0
        form = [
            ('ElementID', icase, []),
            ('NodeID', icase + 1, []),
        ]

        #form = ['Geometry', None, []]
        #form0 = form[2]
        formi = []
        form0 = form

        nodes = np.arange(nnodes, dtype='int32')
        elements = np.arange(nelements, dtype='int32')

        eid_res = GuiResult(0,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=elements)
        nid_res = GuiResult(0,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nodes)
        cases[icase] = (eid_res, (itime, 'ElementID'))
        cases[icase + 1] = (nid_res, (itime, 'NodeID'))
        return form, cases
예제 #2
0
    def _fill_obj_geometry_objects(self, cases, ID, nodes, nelements, model):
        nnodes = nodes.shape[0]

        eids = arange(1, nelements + 1)
        nids = arange(1, nnodes + 1)

        subcase_id = 0
        nid_res = GuiResult(subcase_id, 'NodeID', 'NodeID', 'node', nids)
        eid_res = GuiResult(subcase_id, 'ElementID', 'ElementID', 'centroid',
                            eids)

        cases[0] = (nid_res, (0, 'NodeID'))
        cases[1] = (eid_res, (0, 'ElementID'))
        #2 : (area_res, (0, 'Area')),
        #4 : (cart3d_geo, (0, 'NormalX')),
        #5 : (cart3d_geo, (0, 'NormalY')),
        #6 : (cart3d_geo, (0, 'NormalZ')),

        geometry_form = [
            ('NodeID', 0, []),
            ('ElementID', 1, []),
            #('Area', 2, []),
            #('Normal X', 4, []),
            #('Normal Y', 5, []),
            #('Normal Z', 6, []),
        ]

        form = [
            ('Geometry', None, geometry_form),
        ]
        icase = 2
        return form, cases, icase, nids, eids
예제 #3
0
    def _fill_avl_case(self, cases, ID, nnodes, nelements, surfaces):
        #results_form = []
        geometry_form = [
            ('NodeID', 0, []),
            ('ElementID', 1, []),
            ('SurfaceID', 2, []),
        ]

        nids = arange(1, nnodes + 1)
        eids = arange(1, nelements + 1)

        assert len(eids) == nelements, len(eids)

        nid_res = GuiResult(ID, 'NodeID', 'NodeID', 'node', nids)
        eid_res = GuiResult(ID, 'ElementID', 'ElementID', 'centroid', eids)
        surface_res = GuiResult(ID, 'SurfaceID', 'SurfaceID', 'centroid',
                                surfaces)

        i = 0
        cases[i] = (nid_res, (0, 'NodeID'))
        cases[i + 1] = (eid_res, (0, 'ElementID'))
        cases[i + 2] = (surface_res, (0, 'SurfaceID'))

        form = [
            ('Geometry', None, geometry_form),
        ]
        return form, cases, nids, eids
예제 #4
0
    def _fill_ugrid2d_case(self, cases, unused_id, nnodes, nelements):
        #cases_new = []
        #results_form = []
        colormap = self.gui.settings.colormap
        geometry_form = [
            ('ElementID', 0, []),
            ('NodeID', 1, []),
        ]

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

        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)

        icase = 0
        cases[icase] = (eid_res, (0, 'ElementID'))
        cases[icase + 1] = (nid_res, (0, 'NodeID'))

        form = [
            ('Geometry', None, geometry_form),
        ]
        #if has_tag_data:
            #form.append(('Tag Data', None, tag_form),)

        #results_form = []
        #if len(results_form):
            #form.append(('Results', None, results_form))
        return form, cases, nids, eids
예제 #5
0
파일: su2_io.py 프로젝트: ratalex/pyNastran
    def _fill_su2_case(self, cases, ID, nelements, nnodes):
        """adds the sidebar results"""
        self.gui.isubcase_name_map = {
            ID: ('SU2', ''),
        }

        #nelements = elements.shape[0]
        #nnodes = nodes.shape[0]
        icase = 0
        itime = 0
        eids = np.arange(1, nelements + 1, dtype='int32')
        nids = np.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)

        icase = 0
        itime = 0
        cases[icase] = (eid_res, (itime, 'ElementID'))
        cases[icase + 1] = (nid_res, (itime, 'NodeID'))
        form = [
            ('ElementID', icase, []),
            ('NodeID', icase + 1, []),
        ]
        return form, cases, nids, eids
예제 #6
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
예제 #7
0
    def load_panair_results(self, panair_filename, dirname):
        cases = self.result_cases
        if os.path.basename(panair_filename) == 'agps':
            model = AGPS(log=self.log, debug=self.debug)
            model.read_agps(panair_filename)
        else:
            raise RuntimeError('only files named "agps" files are supported')

        # get the Cp on the nodes
        Cp_array = zeros(self.nNodes, dtype='float32')
        imin = 0
        for ipatch, Cp in sorted(iteritems(model.pressures)):
            Cpv = ravel(Cp)
            nCp = len(Cpv)
            try:
                Cp_array[imin:imin + nCp] = Cpv
            except ValueError:
                # agps stores implicit and explicit wakes
                # we're skipping all wakes
                pass
            imin += nCp

        Cp_array2 = (
            Cp_array[self.elements[:, 0]] + Cp_array[self.elements[:, 1]] +
            Cp_array[self.elements[:, 2]] + Cp_array[self.elements[:, 3]]) / 4.

        icase = len(self.result_cases)

        form = self.get_form()
        results_form = [
            ('Cp Nodal', icase, []),
            (
                'Cp Centroidal',
                icase + 1,
                [],
            ),
        ]
        form.append(('Results', None, results_form))

        ID = 1
        Cpn_res = GuiResult(ID,
                            'Cp Nodal',
                            'Cp',
                            'node',
                            Cp_array,
                            data_format='%.3f',
                            uname='Cp_nodal')
        Cpc_res = GuiResult(ID,
                            'Cp Centroidal',
                            'Cp',
                            'centroid',
                            Cp_array2,
                            data_format='%.3f',
                            uname='Cp_centroidal')
        cases[icase] = (Cpn_res, (0, 'Cp_nodal'))
        cases[icase + 1] = (Cpc_res, (0, 'Cp_centroidal'))

        self._finish_results_io2(form, cases)
예제 #8
0
    def load_shabp_results(self, shabp_filename):
        #print(dir(self))
        #print(dir(self.gui))
        model_name = 'main'
        #print(self.model)
        model = self.gui.bkp
        out_model = ShabpOut(model, log=self.gui.log, debug=self.gui.debug)
        Cpd, deltad = out_model.read_shabp_out(shabp_filename)

        cases = self.gui.result_cases
        icase = len(cases)
        mach_results = []

        form = self.gui.get_form()
        form.append(('Results', None, mach_results))
        mach_forms = defaultdict(list)
        for case_id, Cp in sorted(Cpd.items()):
            Cp = Cpd[case_id]
            delta = deltad[case_id]

            try:
                mach, alpha, unused_beta = model.shabp_cases[case_id]
                name = 'Mach=%g Alpha=%g' % (mach, alpha)
            except KeyError:
                name = 'Mach=? Alpha=? (Case %i)' % case_id
            #name = 'Mach=%g Alpha=%g' % (mach, alpha)
            #(name, icase, 'Cp', 1, 'centroid', '%.3f', '')
            cases[icase] = Cp
            #cp_form = [
            #('Cp', icase, [])
            #]

            ID = 1
            cp_res = GuiResult(ID,
                               header='Cp',
                               title='Cp',
                               location='centroid',
                               scalar=Cp)  # data_format='%.2f
            delta_res = GuiResult(ID,
                                  header='delta',
                                  title='delta',
                                  location='centroid',
                                  scalar=delta)  # data_format='%.2f
            itime = 0
            cases[icase] = (cp_res, (itime, name))
            cases[icase + 1] = (delta_res, (itime, name))
            mach_forms[mach].append(('Cp', icase, []))
            mach_forms[mach].append(('delta', icase + 1, []))
            icase += 2
            #self.result_cases[(name, 'delta', 1, 'centroid', '%.3f')] = delta

        for mach, mach_form in sorted(mach_forms.items()):
            mach_formi = ('Mach=%s' % mach, None, mach_form)
            mach_results.append(mach_formi)
        self.gui._finish_results_io2(model_name, form, cases)
예제 #9
0
    def _fill_lawgs_case(self, cases, ID, nodes, elements, regions):
        eids = arange(1, len(elements) + 1, dtype='int32')
        nids = arange(1, len(nodes) + 1, dtype='int32')
        regions = array(regions, dtype='int32')

        icase = 0
        geometry_form = [
            ('Region', icase, []),
            ('ElementID', icase + 1, []),
            ('NodeID', icase + 2, []),
            ('X', icase + 3, []),
            ('Y', icase + 4, []),
            ('Z', icase + 5, []),
            ('NormalX', icase + 6, []),
            ('NormalY', icase + 7, []),
            ('NormalZ', icase + 8, []),
        ]
        region_res = GuiResult(ID, header='Region', title='Region',
                               location='centroid', scalar=regions)
        eid_res = GuiResult(ID, header='ElementID', title='ElementID',
                            location='centroid', scalar=eids)
        nid_res = GuiResult(ID, header='NodeID', title='NodeID',
                            location='node', scalar=nids)
        cases[icase] = (region_res, (ID, 'Region'))
        cases[icase + 1] = (eid_res, (ID, 'ElementID'))
        cases[icase + 2] = (nid_res, (ID, 'NodeID'))

        #nnids = len(nids)
        neids = len(elements)

        a = nodes[elements[:, 2], :] - nodes[elements[:, 0], :]
        b = nodes[elements[:, 3], :] - nodes[elements[:, 1], :]
        normals = cross(a, b, axis=1)

        assert normals.shape[0] == neids, normals.shape
        assert normals.shape[1] == 3, normals.shape

        x_res = GuiResult(ID, header='X', title='X',
                          location='node', scalar=nodes[:, 0])
        y_res = GuiResult(ID, header='X', title='X',
                          location='node', scalar=nodes[:, 1])
        z_res = GuiResult(ID, header='X', title='X',
                          location='node', scalar=nodes[:, 2])

        nx_res = GuiResult(ID, header='NormalX', title='NormalX',
                           location='node', scalar=normals[:, 0])
        ny_res = GuiResult(ID, header='NormalY', title='NormalY',
                           location='node', scalar=normals[:, 1])
        nz_res = GuiResult(ID, header='NormalZ', title='NormalZ',
                           location='node', scalar=normals[:, 2])

        cases[icase + 3] = (x_res, (ID, 'X'))
        cases[icase + 4] = (y_res, (ID, 'Y'))
        cases[icase + 5] = (z_res, (ID, 'Z'))

        cases[icase + 6] = (nx_res, (ID, 'NormalX'))
        cases[icase + 7] = (ny_res, (ID, 'NormalY'))
        cases[icase + 8] = (nz_res, (ID, 'NormalZ'))
        return geometry_form, cases
예제 #10
0
    def _fill_avus_case(self, cases, ID, model, is_surface):
        #'x', 'y', 'z',
        #result_names = ['rho', 'U', 'V', 'W', 'p']
        #result_names = []
        # result_names = model.variables[3:]
        #nelements = elements.shape[0]
        nelements = model.nelements
        nnodes = model.nnodes
        #nnodes = nodes.shape[0]

        #cases_new = []
        #new = False

        #is_results = False
        #is_results = True
        #results_form = []

        if is_surface:
            element_id = 'FaceID'
        else:
            element_id = 'ElementID'

        geometry_form = [
            ('NodeID', 0, []),
            (element_id, 1, []),
            #('Region', 2, []),
        ]

        eids = arange(1, nelements + 1)
        nids = arange(1, nnodes + 1)

        eid_res = GuiResult(ID,
                            header=element_id,
                            title=element_id,
                            location='centroid',
                            scalar=eids)
        nid_res = GuiResult(ID,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids)
        icase = 0
        itime = 0
        cases[icase] = (eid_res, (itime, element_id))
        cases[icase + 1] = (nid_res, (itime, 'NodeID'))

        #cases[(ID, 2, 'Region', 1, 'centroid', '%i')] = regions

        return geometry_form, cases, nids, eids
예제 #11
0
    def _fill_cart3d_results(self, cases, form, icase, ID, loads, model, mach):
        results_form = []
        cases_new = []
        result_names = [
            'Cp', 'Mach', 'U', 'V', 'W', 'E', 'rho', 'rhoU', 'rhoV', 'rhoW',
            'rhoE', 'a', 'T', 'q', 'Pressure'
        ]

        inan = None
        if 'rho' in loads:
            rho = loads['rho']
            inan = np.where(rho == 0.)
        for result_name in result_names:
            #print('result_name = %r' % result_name)
            if result_name in loads:
                nodal_data = loads[result_name]
                if inan is not None:
                    nodal_data[inan] = np.nan
                rho_res = GuiResult(ID,
                                    header=result_name,
                                    title=result_name,
                                    location='node',
                                    scalar=nodal_data)
                cases[icase] = (rho_res, (0, result_name))
                results_form.append((result_name, icase, []))
                icase += 1

        if len(results_form):
            form.append(('Results', None, results_form))
        return form, cases, icase
예제 #12
0
    def test_gui_result(self):
        """tests GuiResult"""
        subcase_id = 1
        header = 'cat'
        title = 'dog'
        location = 'node'
        scalar = np.ones(10)
        x = GuiResult(subcase_id, header, title, location, scalar,
                      mask_value=None, nlabels=None, labelsize=None, ncolors=None,
                      colormap='jet', data_map=None, data_format=None, uname='GuiResult')
        y = x + x
        #print(y.scalar)

        y = x + 3
        #print(y.scalar)

        y = x - 3
        #print(y.scalar)

        y = x * 3
        y = x / 3

        y = 2 * x
        y = 2 - x
        y = 2 + x
        #print(y.scalar)

        y = (-x - 1) ** 3
        #print(y.scalar)

        y = (+x + 1) ** 3
        #print(y.scalar)

        scalar = np.ones(8) * 2.
        x2 = GuiResult(subcase_id, header, title, location, scalar,
                      mask_value=None, nlabels=None, labelsize=None, ncolors=None,
                      colormap='jet', data_map=None, data_format=None, uname='GuiResult')
        y2 = 3. / x2
        #print(x2.scalar)
        #print(y2.scalar)

        x2 + y2
        x2 / y2
        x2 * y2
        x2 ** y2
        x2 % 3
        x2 % y2
예제 #13
0
    def _fill_abaqus_case(self, cases, ID, nodes, nelements, model):
        """creates the result objects for abaqus"""
        #return [], {}, 0
        #nelements = elements.shape[0]
        nnodes = nodes.shape[0]

        element_ids = np.arange(1, nelements + 1)
        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')

        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)

        cases = {
            0: (nid_res, (0, 'NodeID')),
            1: (eid_res, (0, 'ElementID')),
        }
        geometry_form = [
            ('NodeID', 0, []),
            ('ElementID', 1, []),
        ]
        form = [
            ('Geometry', None, geometry_form),
        ]
        icase = 2
        return form, cases, icase
예제 #14
0
    def _fill_ugrid2d_case(self, base, cases, ID, nnodes, nelements, model):
        cases_new = []
        results_form = []

        geometry_form = [
            ('ElementID', 0, []),
            ('NodeID', 1, []),
        ]

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

        #cases[(ID, 0, 'ElementID', 1, 'centroid', '%i', '')] = eids
        #cases[(ID, 1, 'NodeID', 1, 'node', '%i', '')] = nids

        eid_res = GuiResult(0,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=eids)
        nid_res = GuiResult(0,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids)

        icase = 0
        cases[icase] = (eid_res, (0, 'ElementID'))
        cases[icase + 1] = (nid_res, (0, 'NodeID'))

        form = [
            ('Geometry', None, geometry_form),
        ]
        #if has_tag_data:
        #form.append(('Tag Data', None, tag_form),)

        #results_form = []
        #if len(results_form):
        #form.append(('Results', None, results_form))
        return form, cases
예제 #15
0
    def _fill_tetgen_case(self, nnodes, nelements):
        subcase_id = 0
        self.gui.isubcase_name_map = {subcase_id: ('Tetgen', '')}

        icase = 0
        form = [
            ('NodeID', 0, []),
            ('ElementID', 1, []),
        ]
        nids = np.arange(1, nnodes + 1)
        nid_res = GuiResult(subcase_id,
                            'NodeID',
                            'NodeID',
                            'node',
                            nids,
                            mask_value=None,
                            nlabels=None,
                            labelsize=None,
                            ncolors=None,
                            colormap='jet',
                            data_format=None,
                            uname='GuiResult')

        eids = np.arange(1, nelements + 1)
        eid_res = GuiResult(subcase_id,
                            'ElementID',
                            'ElementID',
                            'centroid',
                            eids,
                            mask_value=None,
                            nlabels=None,
                            labelsize=None,
                            ncolors=None,
                            colormap='jet',
                            data_format=None,
                            uname='GuiResult')

        cases = OrderedDict()
        cases[icase] = (nid_res, (0, 'NodeID'))
        cases[icase + 1] = (eid_res, (0, 'ElementID'))
        return form, cases, nids, eids
예제 #16
0
파일: stl_io.py 프로젝트: ratalex/pyNastran
    def _fill_stl_case(self, cases, ID, elements, nodes, normals, areas):
        """adds the sidebar results"""
        self.gui.isubcase_name_map[ID] = ('STL', '')

        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])
        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'))

        form = [
            ('ElementID', icase, []),
            ('NodeID', icase + 1, []),
            ('Area', icase + 2, []),
            ('NormalX', icase + 3, []),
            ('NormalY', icase + 4, []),
            ('NormalZ', icase + 5, []),
        ]
        return form, cases, nids, eids
예제 #17
0
    def _fill_nastran_temperatures(self, cases, model, key, icase,
                                   form_dict, header_dict, keys_map):
        """loads the nodal temperatures"""
        nnodes = self.nnodes
        #nids = self.node_ids
        temperature_like = [
            (model.temperatures, 'Temperature'),
        ]
        for (result, name) in temperature_like:
            if key not in result:
                continue
            case = result[key]
            subcase_idi = case.isubcase
            if not hasattr(case, 'data'):
                continue

            if not case.is_sort1:
                self.log.warning('Skipping because SORT2\n' + str(case))
                continue
            assert case.is_sort1, case.is_sort1

            ntimes = case.ntimes
            for itime in range(ntimes):
                dt = case._times[itime]
                header = _get_nastran_header(case, dt, itime)
                header_dict[(key, itime)] = header
                keys_map[key] = (case.subtitle, case.label,
                                 case.superelement_adaptivity_index, case.pval_step)

                loads = case.data[itime, :, :]
                nxyz = norm(loads[:, :3], axis=1)
                assert len(nxyz) == nnodes, 'len(nxyz)=%s nnodes=%s' % (
                    len(nxyz), nnodes)

                temp_res = GuiResult(subcase_idi, header=name, title=name,
                                     location='node', scalar=loads[:, 0])
                cases[icase] = (temp_res, (0, name))
                form_dict[(key, itime)].append((name, icase, []))
                icase += 1
예제 #18
0
    def _create_box(self, cart3d_filename, ID, form, cases, icase, regions):
        stack = True
        dirname = os.path.dirname(os.path.abspath(cart3d_filename))
        input_c3d_filename = os.path.join(dirname, 'input.c3d')
        input_cntl_filename = os.path.join(dirname, 'input.cntl')
        mach = None
        alpha = None
        beta = None
        if os.path.exists(input_cntl_filename):
            cntl = read_input_cntl(input_cntl_filename, log=self.log, debug=self.debug)
            mach, alpha, beta = cntl.get_flow_conditions()
            bcs = cntl.get_boundary_conditions()
            bc_xmin, bc_xmax, bc_ymin, bc_ymax, bc_xmin, bc_xmax, surfbcs = bcs
            #stack = False

            if surfbcs:
                bc_form = [
                    ('Rho', icase, []),
                    ('xVelocity', icase + 1, []),
                    ('yVelocity', icase + 2, []),
                    ('zVelocity', icase + 3, []),
                    ('Mach', icase + 4, []),
                    ('Pressure', icase + 5, []),
                ]
                icase += 5
                nelements = self.nElements
                rho = zeros(nelements, dtype='float32')
                xvel = zeros(nelements, dtype='float32')
                yvel = zeros(nelements, dtype='float32')
                zvel = zeros(nelements, dtype='float32')
                #vel = zeros(nelements, dtype='float32')
                pressure = zeros(nelements, dtype='float32')

                uregions = set(unique(regions))
                surf_bc_regions = set(surfbcs.keys())
                invalid_regions = surf_bc_regions - uregions
                if len(invalid_regions) != 0:
                    assert len(invalid_regions) == 0, invalid_regions

                for bc_id, bc_values in sorted(iteritems(surfbcs)):
                    rhoi, xveli, yveli, zveli, pressi = bc_values
                    i = where(regions == bc_id)[0]
                    rho[i] = rhoi
                    xvel[i] = xveli
                    yvel[i] = yveli
                    zvel[i] = zveli
                    pressure[i] = pressi

                mach = sqrt(xvel ** 2 + yvel ** 2 + zvel ** 2)

                rho_res = GuiResult(ID, header='Rho', title='Rho',
                                    location='centroid', scalar=rho)
                xvel_res = GuiResult(ID, header='xVelocity', title='xVelocity',
                                     location='centroid', scalar=xvel)
                yvel_res = GuiResult(ID, header='yVelocity', title='yVelocity',
                                     location='centroid', scalar=yvel)
                zvel_res = GuiResult(ID, header='zVelocity', title='zVelocity',
                                     location='centroid', scalar=zvel)
                mach_res = GuiResult(ID, header='Mach', title='Mach',
                                     location='centroid', scalar=mach)
                pressure_res = GuiResult(ID, header='Pressure', title='Pressure',
                                         location='centroid', scalar=pressure)

                cases[icase] = (rho_res, (ID, 'Rho'))
                cases[icase + 1] = (xvel_res, (ID, 'xVelocity'))
                cases[icase + 2] = (yvel_res, (ID, 'yVelocity'))
                cases[icase + 3] = (zvel_res, (ID, 'zVelocity'))
                cases[icase + 4] = (mach_res, (ID, 'Mach'))
                cases[icase + 5] = (pressure_res, (ID, 'Pressure'))
                form.append(('Boundary Conditions', None, bc_form))
        else:
            self.log.warning('input_cntl_filename doesnt exist = %s' % input_cntl_filename)


        if os.path.exists(input_c3d_filename):
            nodes, elements = read_input_c3d(input_c3d_filename, stack=stack,
                                             log=self.log, debug=self.debug)

            # Planes
            # ----------
            # xmin, xmax
            # ymin, ymax
            # zmin, zmax

            if stack:
                red = (1., 0., 0.)
                color = red
                self.set_quad_grid('box', nodes, elements, color, line_width=1, opacity=1.)
            else:
                red = (1., 0., 0.)
                inflow_nodes = []
                inflow_elements = []

                green = (0., 1., 0.)
                symmetry_nodes = []
                symmetry_elements = []

                colori = (1., 1., 0.)
                outflow_nodes = []
                outflow_elements = []

                blue = (0., 0., 1.)
                farfield_nodes = []
                farfield_elements = []

                ifarfield = 0
                isymmetry = 0
                iinflow = 0
                ioutflow = 0

                nfarfield_nodes = 0
                nsymmetry_nodes = 0
                ninflow_nodes = 0
                noutflow_nodes = 0
                for bcsi, nodesi, elementsi in zip(bcs, nodes, elements):
                    # 0 = FAR FIELD
                    # 1 = SYMMETRY
                    # 2 = INFLOW  (specify all)
                    # 3 = OUTFLOW (simple extrap)
                    self.log.info('bcsi = %s' % bcsi)
                    nnodes = nodesi.shape[0]
                    bc = bcsi
                    if isinstance(bc, int):
                        if bc == 0:
                            farfield_nodes.append(nodesi)
                            farfield_elements.append(elementsi + nfarfield_nodes)
                            nfarfield_nodes += nnodes
                            ifarfield += 1
                        elif bc == 1:
                            symmetry_nodes.append(nodesi)
                            symmetry_elements.append(elementsi + nsymmetry_nodes)
                            nsymmetry_nodes += nnodes
                            isymmetry += 1
                        elif bc == 2:
                            inflow_nodes.append(nodesi)
                            inflow_elements.append(elementsi + ninflow_nodes)
                            ninflow_nodes += nnodes
                            iinflow += 1
                        elif bc == 3:
                            outflow_nodes.append(nodesi)
                            outflow_elements.append(elementsi + noutflow_nodes)
                            noutflow_nodes += nnodes
                            ioutflow += 1
                        else:
                            msg = 'bc=%s' % str(bc)
                            raise NotImplementedError(msg)
                    elif isinstance(bc, dict):
                        continue
                    else:
                        msg = 'bc=%s' % str(bc)
                        raise NotImplementedError(msg)

                if ifarfield:
                    color = blue
                    nodes = vstack(farfield_nodes)
                    elements = vstack(farfield_elements)
                    self.set_quad_grid('farfield', nodes, elements, color, line_width=1, opacity=1.)

                if isymmetry:
                    color = green
                    nodes = vstack(symmetry_nodes)
                    elements = vstack(symmetry_elements)
                    self.set_quad_grid('symmetry', nodes, elements, color, line_width=1, opacity=1.)

                if iinflow:
                    color = red
                    nodes = vstack(inflow_nodes)
                    elements = vstack(inflow_elements)
                    self.set_quad_grid('inflow', nodes, elements, color, line_width=1, opacity=1.)

                if ioutflow:
                    color = colori
                    nodes = vstack(outflow_nodes)
                    elements = vstack(outflow_elements)
                    self.set_quad_grid('outflow', nodes, elements, color, line_width=1, opacity=1.)

                #i = 0
                #for nodesi, elementsi in zip(nodes, elements):
                    #self.set_quad_grid('box_%i' % i, nodesi, elementsi, color,
                                       #line_width=1, opacity=1.)
                    #i += 1
        else:
            self.log.warning('input_c3d_filename doesnt exist = %s' % input_c3d_filename)
        return mach, alpha, beta
예제 #19
0
    def _fill_bedge_case(self, bedge_filename, cases, unused_ID, nnodes,
                         nelements, model):
        """
        creates the data for the sidebar 'form' and the result 'cases'
        """
        base, ext = os.path.splitext(bedge_filename)
        assert ext == '.bedge', bedge_filename

        unused_tag_filename = base + '.tags'

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

        geometry_form = [
            ('ElementID', 0, []),
            ('NodeID', 1, []),
            #('Region', 1, []),
            ('CurveID', 2, []),
            ('SubcurveID', 3, []),
            ('GridBC', 4, []),

            #('TurnAngle', 5, [])
            #('normSpacing', 6, []),
            #('BL_thick', 7, []),
        ]

        form = [
            ('Geometry', None, geometry_form),
        ]

        eids = np.arange(1, nelements + 1)
        nids = np.arange(1, nnodes + 1)

        eid_res = GuiResult(0,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=eids)
        nid_res = GuiResult(0,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids)
        curve_res = GuiResult(0,
                              header='CurveID',
                              title='CurveID',
                              location='centroid',
                              scalar=model.curves)
        subcurve_res = GuiResult(0,
                                 header='SubcurveID',
                                 title='SubcurveID',
                                 location='centroid',
                                 scalar=model.subcurves)
        gridbc_res = GuiResult(0,
                               header='GridBC',
                               title='GridBC',
                               location='centroid',
                               scalar=model.grid_bcs)

        icase = 0
        cases[icase] = (eid_res, (0, 'ElementID'))
        cases[icase + 1] = (nid_res, (0, 'NodeID'))
        cases[icase + 2] = (curve_res, (0, 'CurveID'))
        cases[icase + 3] = (subcurve_res, (0, 'SubcurveID'))
        cases[icase + 4] = (gridbc_res, (0, 'GridBC'))
        icase += 5

        #if 0:
        #surf_ids = element_props[:, 0]
        #recon_flags = element_props[:, 1]
        #grid_bcs = element_props[:, 2]

        if hasattr(model, 'turn_angle'):
            gf = ('TurnAngle', 5, [])
            geometry_form.append(gf)
            turnangle_res = GuiResult(0,
                                      header='TurnAngle',
                                      title='TurnAngle',
                                      location='centroid',
                                      scalar=np.degrees(
                                          np.abs(model.turn_angle)))
            cases[icase] = (turnangle_res, (0, 'TurnAngle'))
            icase += 1

        #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:
            tag_form = []
            form.append(('Tag Data', None, tag_form), )

        results_form = []
        if len(results_form):
            form.append(('Results', None, results_form))
        return form, cases
예제 #20
0
def create_res_obj(islot,
                   headers,
                   header,
                   A,
                   fmt_dict,
                   result_type,
                   dim_max=None,
                   xyz_cid0=None,
                   colormap='jet'):
    """
    Parameters
    ----------
    islot : int
        ???
    A : dict[key] = (n, m) array
        the numpy arrays
        key : str
            the name
        n : int
            number of nodes/elements
        m : int
            secondary dimension
            N/A : 1D array
            3 : deflection
    headers : List[str]???
        the titles???
    fmt_dict : dict[header] = fmt
        the format of the arrays
        header : str
            the name
        fmt : str
            '%i', '%f'
    result_type : str
        'node', 'centroid'
    dim_max : float
        required for forces/displacements
    xyz_cid0 : (nnodes, 3)
        the points
    """
    #print('create_res_object, header=%r' % header)
    datai = A[header]
    fmti = fmt_dict[header]
    title = header
    location = result_type

    dimension = len(datai.shape)
    if dimension == 1:
        vector_size = 1
    elif dimension == 2:
        vector_size = datai.shape[1]
    else:
        raise RuntimeError('dimension=%s' % (dimension))

    if vector_size == 1:
        res_obj = GuiResult(
            islot,
            header,
            title,
            location,
            datai,
            nlabels=None,
            labelsize=None,
            ncolors=None,
            colormap=colormap,
            data_format=fmti,
        )
    elif vector_size == 3:
        # title is 3 values
        # header is 3 values
        # scale is 3 values
        titles = [header]
        headers = header

        norm_max = np.linalg.norm(datai, axis=1).max()
        scales = [dim_max / norm_max * 0.25]
        data_formats = [fmti] * 3
        scalar = None
        dxyz = datai
        xyz = xyz_cid0
        res_obj = DisplacementResults(islot,
                                      titles,
                                      headers,
                                      xyz,
                                      dxyz,
                                      scalar,
                                      scales,
                                      data_formats=data_formats,
                                      nlabels=None,
                                      labelsize=None,
                                      ncolors=None,
                                      colormap=colormap,
                                      set_max_min=True)
    else:
        raise RuntimeError('vector_size=%s' % (vector_size))
    return res_obj, title
예제 #21
0
    def _fill_shabp_geometry_case(self, cases, ID, nodes, elements, patches,
                                  components, impact, shadow):

        icase = 0
        location_form = [
            ('CentroidX', icase + 5, []),
            ('CentroidY', icase + 6, []),
            ('CentroidZ', icase + 7, []),
            ('NodeX', icase + 8, []),
            ('NodeY', icase + 9, []),
            ('NodeZ', icase + 10, []),
        ]
        normal_form = [
            ('NormalX', icase + 11, []),
            ('NormalY', icase + 12, []),
            ('NormalZ', icase + 13, []),
        ]

        geometry_form = [
            ('Component', icase, []),
            ('PatchID', icase + 1, []),
            ('Impact', icase + 2, []),
            ('Shadow', icase + 3, []),
            ('Area', icase + 4, []),
            ('Location', None, location_form),
            ('Normal', None, normal_form),
        ]
        form = [
            ('Geometry', None, geometry_form),
        ]
        itime = 0
        ID = 0
        components_res = GuiResult(ID,
                                   header='Component',
                                   title='Component',
                                   location='centroid',
                                   scalar=components)
        patch_res = GuiResult(ID,
                              header='PatchID',
                              title='PatchID',
                              location='centroid',
                              scalar=patches)
        impact_res = GuiResult(ID,
                               header='Impact',
                               title='Impact',
                               location='centroid',
                               scalar=impact)
        shadow_res = GuiResult(ID,
                               header='Shadow',
                               title='Shadow',
                               location='centroid',
                               scalar=shadow)

        cases[icase] = (components_res, (itime, 'Component'))
        cases[icase + 1] = (patch_res, (itime, 'PatchID'))
        cases[icase + 2] = (impact_res, (itime, 'Impact'))
        cases[icase + 3] = (shadow_res, (itime, 'Shadow'))

        XYZc = zeros((len(elements), 3), dtype='float32')
        Normal = zeros((len(elements), 3), dtype='float32')
        area = zeros(len(elements), dtype='float32')

        if 0:
            elements = np.array(elements, dtype='int32')
            p1 = nodes[elements[:, 0]]
            p2 = nodes[elements[:, 1]]
            p3 = nodes[elements[:, 2]]
            p4 = nodes[elements[:, 3]]
            a = p3 - p1
            b = p4 - p2
            n = np.cross(a, b)
            ni = np.linalg.norm(n, axis=1)
            assert len(ni) == n.shape[0]
            i = np.where(ni != 0.0)[0]
            #n[i] /= ni[:, i]
            area[i] = 0.5 * ni[i]
            assert p1.shape == n.shape, n.shape

        for i, element in enumerate(elements):
            n1, n2, n3, n4 = element
            p1 = nodes[n1, :]
            p2 = nodes[n2, :]
            p3 = nodes[n3, :]
            p4 = nodes[n4, :]
            a = p3 - p1
            b = p4 - p2
            n = cross(a, b)
            nnorm = norm(n)

            XYZc[i, :] = (p1 + p2 + p3 + p4) / 4.0
            if nnorm == 0.:
                print('p1=%s p2=%s p3=%s p4=%s; area=0' % (p1, p2, p3, p4))
                continue
            normal = n / nnorm
            A = 0.5 * nnorm

            Normal[i, :] = normal
            area[i] = A

        area_res = GuiResult(ID,
                             header='Area',
                             title='Area',
                             location='centroid',
                             scalar=area)  # data_format='%.2f

        cenx_res = GuiResult(ID,
                             header='CentroidX',
                             title='CentroidX',
                             location='centroid',
                             scalar=XYZc[:, 0])  # data_format='%.2f
        ceny_res = GuiResult(ID,
                             header='CentroidY',
                             title='CentroidY',
                             location='centroid',
                             scalar=XYZc[:, 1])  # data_format='%.2f
        cenz_res = GuiResult(ID,
                             header='CentroidZ',
                             title='CentroidZ',
                             location='centroid',
                             scalar=XYZc[:, 2])  # data_format='%.2f

        nodex_res = GuiResult(ID,
                              header='NodeX',
                              title='NodeX',
                              location='node',
                              scalar=nodes[:, 0])  # data_format='%.2f
        nodey_res = GuiResult(ID,
                              header='NodeY',
                              title='NodeY',
                              location='node',
                              scalar=nodes[:, 1])  # data_format='%.2f
        nodez_res = GuiResult(ID,
                              header='NodeZ',
                              title='NodeZ',
                              location='node',
                              scalar=nodes[:, 2])  # data_format='%.2f

        nx_res = GuiResult(ID,
                           header='NormalX',
                           title='NormalX',
                           location='centroid',
                           scalar=Normal[:, 0])  # data_format='%.2f
        ny_res = GuiResult(ID,
                           header='NormalY',
                           title='NormalY',
                           location='centroid',
                           scalar=Normal[:, 1])  # data_format='%.2f
        nz_res = GuiResult(ID,
                           header='NormalZ',
                           title='NormalZ',
                           location='centroid',
                           scalar=Normal[:, 2])  # data_format='%.2f

        cases[icase + 4] = (area_res, (itime, 'Area'))
        cases[icase + 5] = (cenx_res, (itime, 'CentroidX'))
        cases[icase + 6] = (ceny_res, (itime, 'CentroidY'))
        cases[icase + 7] = (cenz_res, (itime, 'CentroidZ'))
        cases[icase + 8] = (nodex_res, (itime, 'NodeX'))
        cases[icase + 9] = (nodey_res, (itime, 'NodeY'))
        cases[icase + 10] = (nodez_res, (itime, 'NodeZ'))

        cases[icase + 11] = (nx_res, (itime, 'NormalX'))
        cases[icase + 12] = (ny_res, (itime, 'NormalY'))
        cases[icase + 13] = (nz_res, (itime, 'NormalZ'))
        return form, cases
예제 #22
0
    def _fill_tecplot_case(self, cases, ID, model, is_surface):
        #'x', 'y', 'z',
        #result_names = ['rho', 'U', 'V', 'W', 'p']
        zone = model.zones[0]
        result_names = zone.variables[3:]
        #nelements = elements.shape[0]
        nelements = self.gui.nelements
        nnodes = self.gui.nnodes
        #nnodes = zone.nnodes
        #nnodes = nodes.shape[0]

        #is_results = False
        is_results = True
        results_form = []

        if is_surface:
            element_id = 'FaceID'
        else:
            element_id = 'ElementID'

        geometry_form = [
            ('NodeID', 0, []),
            (element_id, 1, []),
        ]
        assert isinstance(nnodes,
                          int), 'nnodes=%s type=%s' % (nnodes, type(nnodes))
        assert isinstance(
            nelements,
            int), 'nelements=%s type=%s' % (nelements, type(nelements))
        assert nnodes > 0, nnodes
        assert nelements > 0, nelements

        nids = np.arange(1, nnodes + 1, dtype='int32')
        eids = np.arange(1, nelements + 1, dtype='int32')

        nid_res = GuiResult(ID,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids)
        eid_res = GuiResult(ID,
                            header=element_id,
                            title=element_id,
                            location='centroid',
                            scalar=eids)

        icase = 0
        cases[icase] = (nid_res, (0, 'NodeID'))
        cases[icase + 1] = (eid_res, (0, element_id))
        icase += 2

        results = zone.nodal_results
        if is_results and len(results):
            for iresult, result_name in enumerate(result_names):
                if results.shape[1] == 1:
                    nodal_data = results
                    assert len(result_names) == 1, result_names
                else:
                    nodal_data = results[:, iresult]

                node_res = GuiResult(ID,
                                     header=result_name,
                                     title=result_name,
                                     location='node',
                                     scalar=nodal_data)
                cases[icase] = (node_res, (0, result_name))

                results_form.append((result_name, icase, []))
                icase += 1
        form = [
            ('Geometry', None, geometry_form),
        ]
        if len(results_form):
            form.append(('Results', None, results_form))
        return form, cases, nids, eids
예제 #23
0
    def _fill_usm3d_case(self,
                         cases,
                         form,
                         bcs,
                         mapbc,
                         bcmap_to_bc_name,
                         loads,
                         is_geometry=True):
        """actually fills the sidebar"""
        self.scalarBar.VisibilityOff()

        subcasemap_id = 1
        icase = len(cases)
        itime = 0
        if is_geometry:
            assert self.element_ids is not None, self.element_ids
            assert len(self.element_ids) > 0, self.element_ids
            eid_res = GuiResult(subcasemap_id,
                                'ElementID',
                                'ElementID',
                                'centroid',
                                self.element_ids,
                                nlabels=None,
                                labelsize=None,
                                ncolors=None,
                                colormap='jet',
                                data_format='%i',
                                uname='GuiResult')

            region_res = GuiResult(
                subcasemap_id,
                'Patch',
                'Patch',
                'centroid',
                bcs,  # patch_id
                nlabels=None,
                labelsize=None,
                ncolors=None,
                colormap='jet',
                data_format='%i',
                uname='GuiResult')
            cases[icase] = (eid_res, (itime, 'ElementID'))
            cases[icase + 1] = (region_res, (itime, 'Patch'))
            form.append(('ElementID', icase, []))
            form.append(('Patch', icase + 1, []))
            icase += 2

        if bcs is not None:
            patch_id = bcs

            form += [
                ('BC', icase, []),
                ('Family', icase + 1, []),
            ]
            bc_value = np.zeros(bcs.shape, dtype='int32')
            family = np.zeros(bcs.shape, dtype='int32')
            mapbc_print = defaultdict(list)
            for region, mapi in sorted(iteritems(mapbc)):
                bcnum = mapi[0]
                familyi = mapi[1]
                mapbc_print[bcnum].append(region)
                try:
                    name = bcmap_to_bc_name[bcnum]
                except KeyError:
                    name = '???'
                #self.log.info('Region=%i BC=%s name=%r' % (region, bcnum, name))
                ipatch = np.where(patch_id == region)[0]
                bc_value[ipatch] = bcnum
                family[ipatch] = familyi

            bc_res = GuiResult(subcasemap_id,
                               'BC',
                               'BC',
                               'centroid',
                               bc_value,
                               nlabels=None,
                               labelsize=None,
                               ncolors=None,
                               colormap='jet',
                               data_format='%i',
                               uname='GuiResult')
            family_res = GuiResult(subcasemap_id,
                                   'Family',
                                   'Family',
                                   'centroid',
                                   family,
                                   nlabels=None,
                                   labelsize=None,
                                   ncolors=None,
                                   colormap='jet',
                                   data_format='%i',
                                   uname='GuiResult')
            cases[icase] = (bc_res, (itime, 'BC'))
            cases[icase + 1] = (family_res, (itime, 'Family'))
            icase += 2

            for bcnum, regions in sorted(iteritems(mapbc_print)):
                try:
                    name = bcmap_to_bc_name[bcnum]
                except KeyError:
                    name = '???'
                self.log.info('BC=%s Regions=%s name=%r' %
                              (bcnum, regions, name))

            self.scalarBar.VisibilityOn()

        subcasemap_id = 2
        if len(loads):
            form0 = []
            for key, load in iteritems(loads):
                load_res = GuiResult(subcasemap_id,
                                     key,
                                     key,
                                     'node',
                                     load,
                                     nlabels=None,
                                     labelsize=None,
                                     ncolors=None,
                                     colormap='jet',
                                     data_format='%.3f',
                                     uname='GuiResult')
                cases[icase] = (load_res, (itime, key))
                formi = (key, icase, [])
                form0.append(formi)
                icase += 1

            if form0:
                form.append(('Results', None, form0))
        self.scalarBar.VisibilityOn()
        return form, cases
예제 #24
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)
예제 #25
0
    def fill_plot3d_geometry_case(self, cases, ID, nodes, elements, regions,
                                  loads):
        #print "regions**** = ",regions
        #nNodes = self.nnodes
        #nElements = self.nelements

        #result_names = ['Cp', 'Mach', 'U', 'V', 'W', 'E', 'rho',
        #'rhoU', 'rhoV', 'rhoW', 'rhoE']
        #nelements, three = elements.shape
        #print regions
        icase = 0
        itime = 0

        region_res = GuiResult(ID,
                               header='Region',
                               title='Region',
                               location='centroid',
                               scalar=regions)
        cases[icase] = region_res(nid_res, (itime, 'Region'))
        icase += 1

        # centroidal
        Xc = zeros(len(elements), 'float64')
        Yc = zeros(len(elements), 'float64')
        Zc = zeros(len(elements), 'float64')
        area = zeros(len(elements), 'float64')

        Xn = zeros(len(nodes), 'float64')
        Yn = zeros(len(nodes), 'float64')
        Zn = zeros(len(nodes), 'float64')

        for i, element in enumerate(elements):
            p1, p2, p3, p4 = element
            P1 = array(nodes[p1])
            P2 = array(nodes[p2])
            P3 = array(nodes[p3])
            P4 = array(nodes[p4])
            a = P3 - P1
            b = P4 - P2
            A = 0.5 * norm(cross(a, b))
            x, y, z = (P1 + P2 + P3 + P4) / 4.0
            Xc[i] = x
            Yc[i] = y
            Zc[i] = z
            area[i] = A
        for i, node in enumerate(nodes):
            Xn[i] = node[0]
            Yn[i] = node[1]
            Zn[i] = node[2]

        cases[(ID, icase, 'node_x', 1, 'node', '%.2f', '')] = Xn
        cases[(ID, icase + 1, 'node_y', 1, 'node', '%.2f', '')] = Yn
        cases[(ID, icase + 2, 'node_z', 1, 'node', '%.2f', '')] = Zn

        cases[(ID, icase + 3, 'centroid_x', 1, 'centroid', '%.2f', '')] = Xc
        cases[(ID, icase + 4, 'centroid_y', 1, 'centroid', '%.2f', '')] = Yc
        cases[(ID, icase + 5, 'centroid_z', 1, 'centroid', '%.2f', '')] = Zc

        cases[(ID, icase + 6, 'Area', 1, 'centroid', '%.2f', '')] = area
        icase += 7

        #print("load.keys() = ", loads.keys())
        #for key in result_names:
        #if key in loads:
        #nodal_data = loads[key]
        #cases[(ID, key, 1, 'node', '%.3f')] = nodal_data
        return cases
예제 #26
0
def _fill_cart3d_geometry_objects(cases, unused_id, nodes, elements, regions,
                                  model):
    """Creates the results form for Cart3d Geometry"""
    nelements = elements.shape[0]
    nnodes = nodes.shape[0]

    eids = arange(1, nelements + 1)
    nids = arange(1, nnodes + 1)
    area = model.get_area()
    cnormals = model.get_normals()
    cnnodes = cnormals.shape[0]
    assert cnnodes == nelements, len(cnnodes)

    inv_counter = _node_inverse_counter(model, nnodes)

    def data_map_func(data):
        res = np.zeros(nnodes, dtype='float32')
        for elem, datai in zip(model.elements, data):
            res[elem] += datai
        #print(res)

        #res = np.zeros(nnodes, dtype='float32')
        #res[model.elements] = data
        #print(res)
        #print('----')
        #print(inv_counter)
        ## neids * ??? = (3,nnodes)
        ##(3,) * ??? = (5,)
        ## eids * map -> node_ids
        ##results = np.zeros(nnodes, dtype='float32')
        #print(model.elements)
        #node_results = data[model.elements.ravel()]
        #assert node_results.shape == model.elements.shape
        #node_results_sum = node_results.sum(axis=1)
        #assert node_results_sum.shape == nnodes
        #return node_results_sum * inv_counter
        return res * inv_counter

    data_map_dict = {('centroid', 'Node'): data_map_func}

    #print('nnodes =', nnodes)
    #print('nelements =', nelements)
    #print('regions.shape =', regions.shape)
    subcase_id = 0
    labels = [
        'NodeID', 'ElementID', 'Region', 'Area', 'Normal X', 'Normal Y',
        'Normal Z'
    ]
    cart3d_geo = Cart3dGeometry(subcase_id,
                                labels,
                                nids,
                                eids,
                                regions,
                                area,
                                cnormals,
                                uname='Cart3dGeometry')

    normal_z = cnormals[:, 2]
    node_normal = data_map_func(normal_z)
    result_name = 'Normal Z-nodal'
    node_res = GuiResult(subcase_id,
                         header=result_name,
                         title=result_name,
                         location='node',
                         scalar=node_normal)

    cases = OrderedDict()
    cases[0] = (cart3d_geo, (0, 'NodeID'))
    cases[1] = (cart3d_geo, (0, 'ElementID'))
    cases[2] = (cart3d_geo, (0, 'Region'))
    cases[3] = (cart3d_geo, (0, 'Area'))
    cases[4] = (cart3d_geo, (0, 'NormalX'))
    cases[5] = (cart3d_geo, (0, 'NormalY'))
    cases[6] = (cart3d_geo, (0, 'NormalZ'))
    #cases[7] = (node_res, (0, 'NormalZ-nodal'))

    geometry_form = [
        ('NodeID', 0, []),
        ('ElementID', 1, []),
        ('Region', 2, []),
        ('Area', 3, []),
        ('Normal X', 4, []),
        ('Normal Y', 5, []),
        ('Normal Z', 6, []),
        #('Normal Z-nodal', 7, []),
    ]
    form = [
        ('Geometry', None, geometry_form),
    ]
    icase = len(geometry_form)
    return form, cases, icase, nids, eids, data_map_dict
예제 #27
0
    def _create_box(self, cart3d_filename, ID, form, cases, icase, regions):
        """creates the bounding box for boundary conditions"""
        dirname = os.path.dirname(os.path.abspath(cart3d_filename))
        input_c3d_filename = os.path.join(dirname, 'input.c3d')
        input_cntl_filename = os.path.join(dirname, 'input.cntl')
        mach = None
        alpha = None
        beta = None
        unused_gamma = None

        bcs = None
        if os.path.exists(input_cntl_filename):
            cntl = read_input_cntl(input_cntl_filename,
                                   log=self.gui.log,
                                   debug=self.gui.debug)
            mach, alpha, beta, unused_gamma = cntl.get_flow_conditions()
            (unused_bc_xmin, unused_bc_xmax, unused_bc_ymin, unused_bc_ymax,
             unused_bc_xmin, unused_bc_xmax,
             surfbcs) = cntl.get_boundary_conditions()
            #stack = False

            if surfbcs:
                bc_form = [
                    ('Rho', icase, []),
                    ('xVelocity', icase + 1, []),
                    ('yVelocity', icase + 2, []),
                    ('zVelocity', icase + 3, []),
                    ('Mach', icase + 4, []),
                    ('Pressure', icase + 5, []),
                ]
                icase += 5
                nelements = self.gui.nelements
                rho = np.full(nelements, np.nan, dtype='float32')
                xvel = np.full(nelements, np.nan, dtype='float32')
                yvel = np.full(nelements, np.nan, dtype='float32')
                zvel = np.full(nelements, np.nan, dtype='float32')
                #vel = np.full(nelements, np.nan, dtype='float32')
                pressure = np.full(nelements, np.nan, dtype='float32')

                uregions = set(unique(regions))
                surf_bc_regions = set(surfbcs.keys())
                invalid_regions = surf_bc_regions - uregions
                if len(invalid_regions) != 0:
                    assert len(invalid_regions) == 0, invalid_regions

                for bc_id, bc_values in sorted(iteritems(surfbcs)):
                    rhoi, xveli, yveli, zveli, pressi = bc_values
                    i = where(regions == bc_id)[0]
                    rho[i] = rhoi
                    xvel[i] = xveli
                    yvel[i] = yveli
                    zvel[i] = zveli
                    pressure[i] = pressi

                inan = np.where(rho == 0.0)
                rho[inan] = np.nan
                xvel[inan] = np.nan
                yvel[inan] = np.nan
                zvel[inan] = np.nan
                #vel[inan] = np.nan
                pressure[inan] = np.nan

                mach = sqrt(xvel**2 + yvel**2 + zvel**2)

                rho_res = GuiResult(ID,
                                    header='Rho',
                                    title='Rho',
                                    location='centroid',
                                    scalar=rho)
                xvel_res = GuiResult(ID,
                                     header='xVelocity',
                                     title='xVelocity',
                                     location='centroid',
                                     scalar=xvel)
                yvel_res = GuiResult(ID,
                                     header='yVelocity',
                                     title='yVelocity',
                                     location='centroid',
                                     scalar=yvel)
                zvel_res = GuiResult(ID,
                                     header='zVelocity',
                                     title='zVelocity',
                                     location='centroid',
                                     scalar=zvel)
                mach_res = GuiResult(ID,
                                     header='Mach',
                                     title='Mach',
                                     location='centroid',
                                     scalar=mach)
                pressure_res = GuiResult(ID,
                                         header='Pressure',
                                         title='Pressure',
                                         location='centroid',
                                         scalar=pressure)

                cases[icase] = (rho_res, (ID, 'Rho'))
                cases[icase + 1] = (xvel_res, (ID, 'xVelocity'))
                cases[icase + 2] = (yvel_res, (ID, 'yVelocity'))
                cases[icase + 3] = (zvel_res, (ID, 'zVelocity'))
                cases[icase + 4] = (mach_res, (ID, 'Mach'))
                cases[icase + 5] = (pressure_res, (ID, 'Pressure'))
                form.append(('Boundary Conditions', None, bc_form))
        else:
            self.gui.log.warning('input_cntl_filename doesnt exist = %s' %
                                 input_cntl_filename)

        if os.path.exists(input_c3d_filename):
            # put in one group

            # Planes
            # ----------
            # xmin, xmax
            # ymin, ymax
            # zmin, zmax
            nodes, elements = read_input_c3d(input_c3d_filename,
                                             stack=True,
                                             log=self.gui.log,
                                             debug=self.gui.debug)

            color = RED_FLOAT
            self.gui.set_quad_grid('box',
                                   nodes,
                                   elements,
                                   color,
                                   line_width=1,
                                   opacity=1.)

            #-------------------------------------------------------------------
            # put in multiple groups
            nodes, elements = read_input_c3d(input_c3d_filename,
                                             stack=False,
                                             log=self.gui.log,
                                             debug=self.gui.debug)

            inflow_nodes = []
            inflow_elements = []

            symmetry_nodes = []
            symmetry_elements = []

            colori = (1., 1., 0.)
            outflow_nodes = []
            outflow_elements = []

            farfield_nodes = []
            farfield_elements = []

            ifarfield = 0
            isymmetry = 0
            iinflow = 0
            ioutflow = 0

            nfarfield_nodes = 0
            nsymmetry_nodes = 0
            ninflow_nodes = 0
            noutflow_nodes = 0
            if bcs is None:
                bcs = [None] * len(nodes)
            for bcsi, nodesi, elementsi in zip(bcs, nodes, elements):
                # 0 = FAR FIELD
                # 1 = SYMMETRY
                # 2 = INFLOW  (specify all)
                # 3 = OUTFLOW (simple extrap)
                self.gui.log.info('bcsi = %s' % bcsi)
                nnodes = nodesi.shape[0]
                bc = bcsi
                if bc is None:  # fake case
                    continue
                elif isinstance(bc, integer_types):
                    if bc == 0:
                        farfield_nodes.append(nodesi)
                        farfield_elements.append(elementsi + nfarfield_nodes)
                        nfarfield_nodes += nnodes
                        ifarfield += 1
                    elif bc == 1:
                        symmetry_nodes.append(nodesi)
                        symmetry_elements.append(elementsi + nsymmetry_nodes)
                        nsymmetry_nodes += nnodes
                        isymmetry += 1
                    elif bc == 2:
                        inflow_nodes.append(nodesi)
                        inflow_elements.append(elementsi + ninflow_nodes)
                        ninflow_nodes += nnodes
                        iinflow += 1
                    elif bc == 3:
                        outflow_nodes.append(nodesi)
                        outflow_elements.append(elementsi + noutflow_nodes)
                        noutflow_nodes += nnodes
                        ioutflow += 1
                    else:
                        msg = 'bc=%s' % str(bc)
                        raise NotImplementedError(msg)
                elif isinstance(bc, dict):  # ???
                    if len(bc) == 0:
                        continue
                    # bc = {
                    #    2: [2.0, 3.0, 0.0, 0.0, 5.0],
                    #    3: [1.0, 1.5, 0.0, 0.0, 0.714285]
                    # }
                    continue
                    #msg = 'bc=%s' % str(bc)
                    #raise NotImplementedError(msg)
                else:
                    msg = 'bc=%s' % str(bc)
                    raise NotImplementedError(msg)

            if ifarfield:
                color = BLUE_FLOAT
                nodes = vstack(farfield_nodes)
                elements = vstack(farfield_elements)
                self.gui.set_quad_grid('farfield',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            if isymmetry:
                color = GREEN_FLOAT
                nodes = vstack(symmetry_nodes)
                elements = vstack(symmetry_elements)
                self.gui.set_quad_grid('symmetry',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            if iinflow:
                color = RED_FLOAT
                nodes = vstack(inflow_nodes)
                elements = vstack(inflow_elements)
                self.gui.set_quad_grid('inflow',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            if ioutflow:
                color = colori
                nodes = vstack(outflow_nodes)
                elements = vstack(outflow_elements)
                self.gui.set_quad_grid('outflow',
                                       nodes,
                                       elements,
                                       color,
                                       line_width=1,
                                       opacity=1.)

            #i = 0
            #for nodesi, elementsi in zip(nodes, elements):
            #self.set_quad_grid('box_%i' % i, nodesi, elementsi, color,
            #line_width=1, opacity=1.)
            #i += 1
        else:
            self.gui.log.warning('input_c3d_filename doesnt exist = %s' %
                                 input_c3d_filename)
        return mach, alpha, beta
예제 #28
0
    def _fill_fast_case(self,
                        form,
                        cases,
                        model,
                        nnodes,
                        nelements,
                        dimension_flag,
                        results=False):
        self.gui.scalarBar.VisibilityOff()

        icase = 0
        geometry_form = [
            ('NodeID', icase + 0, []),
            ('ElementID', icase + 1, []),
        ]
        res_id = 1
        nids = np.arange(1, nnodes + 1)
        eids = np.arange(1, nelements + 1)

        nid_res = GuiResult(res_id,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids)
        cases[icase] = (nid_res, (0, 'NodeID'))
        icase += 1

        eid_res = GuiResult(res_id,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=eids)
        cases[icase] = (eid_res, (0, 'ElementID'))
        icase += 1

        if dimension_flag == 2:
            geometry_form.append(('BC', icase + 2, []))
            bc_res = GuiResult(res_id,
                               header='BoundaryCondition',
                               title='BC',
                               location='centroid',
                               scalar=model.bcs)
            cases[icase] = (bc_res, (0, 'BoundaryCondition'))
            icase += 1

        #if results:
        #res_id = 1
        #if bcs is not None:
        #cases[(res_id, icase, 'Region', 1, 'centroid', '%i', '')] = bcs
        #icase += 1

        #mapbc_print = defaultdict(list)
        #for region, bcnum in sorted(iteritems(mapbc)):
        #mapbc_print[bcnum].append(region)
        #try:
        #name = bcmap_to_bc_name[bcnum]
        #except KeyError:
        #name = '???'
        ##self.log.info('Region=%i BC=%s name=%r' % (region, bcnum, name))

        #for bcnum, regions in sorted(iteritems(mapbc_print)):
        #try:
        #name = bcmap_to_bc_name[bcnum]
        #except KeyError:
        #name = '???'
        #self.log.info('BC=%s Regions=%s name=%r' % (bcnum, regions, name))
        #self.scalarBar.VisibilityOn()

        ##==============================
        #res_id = 2
        #if len(loads):
        #for key, load in iteritems(loads):
        #cases[(res_id, icase, key, 1, 'node', '%.3f')] = load
        #icase += 1
        #self.scalarBar.VisibilityOn()

        form.append(('Geometry', None, geometry_form))
        return cases, nids, eids
예제 #29
0
    def _fill_ugrid3d_case(self, base, cases, ID, nnodes, nelements, model):
        tag_filename = base + '.tags'
        mapbc_filename = base.split('.')[0] + '.mapbc'
        self.log.info('mapbc_filename = %r' % mapbc_filename)

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

        geometry_form = [
            #('Region', 0, []),
            ('ElementID', 0, []),
            ('NodeID', 1, []),
            ('SurfaceID', 2, []),
            #('normSpacing', 3, []),
            #('BL_thick', 4, []),
            #('ReconFlag', 5, []),
            #('GridBC', 6, []),
        ]

        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)
        nid_res = GuiResult(0,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids)
        surface_res = GuiResult(0,
                                header='SurfaceID',
                                title='SurfaceID',
                                location='centroid',
                                scalar=pids)

        icase = 0
        cases[icase] = (eid_res, (0, 'ElementID'))
        cases[icase + 1] = (nid_res, (0, 'NodeID'))
        cases[icase + 2] = (surface_res, (0, 'SurfaceID'))

        icase = 3
        if os.path.exists(tag_filename):
            #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(iteritems(data)):
                #self.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.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])
            recon_res = GuiResult(0,
                                  header='is_recon',
                                  title='is_recon',
                                  location='node',
                                  scalar=int_data[:, 1])
            rebuild_res = GuiResult(0,
                                    header='is_rebuild',
                                    title='is_rebuild',
                                    location='node',
                                    scalar=int_data[:, 2])
            fixed_res = GuiResult(0,
                                  header='is_fixed',
                                  title='is_fixed',
                                  location='node',
                                  scalar=int_data[:, 3])
            source_res = GuiResult(0,
                                   header='is_source',
                                   title='is_source',
                                   location='node',
                                   scalar=int_data[:, 4])
            trans_res = GuiResult(0,
                                  header='is_trans',
                                  title='is_trans',
                                  location='node',
                                  scalar=int_data[:, 5])
            delete_res = GuiResult(0,
                                   header='is_delete',
                                   title='is_delete',
                                   location='node',
                                   scalar=int_data[:, 6])
            nlayers_res = GuiResult(0,
                                    header='nlayers',
                                    title='nlayers',
                                    location='node',
                                    scalar=int_data[:, 7])

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

            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
        else:
            self.log.warning('tag_filename=%r could not be found' %
                             tag_filename)

        if os.path.exists(mapbc_filename):
            has_mapbc_data = True
            mapbc = open(mapbc_filename, 'r')
            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.log.info(line)
            mapbc_form.append(('Map BC', icase, []))

            mapbc_res = GuiResult(0,
                                  header='Map BC',
                                  title='Map BC',
                                  location='centroid',
                                  scalar=mapbcs)
            cases[icase + 9] = (mapbc_res, (0, 'Map BC'))
        else:
            self.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.log.info(form)
        return form, cases
예제 #30
0
    def _fill_openfoam_case(self, cases, ID, nodes, nelements, patches, names,
                            normals, is_surface_blockmesh):
        #nelements = elements.shape[0]
        nnodes = nodes.shape[0]

        #new = False
        results_form = []
        geometry_form = [
            #('Region', 0, []),
            ('ElementID', 0, []),
            ('NodeID', 1, []),
        ]

        eids = arange(nelements) + 1
        nids = arange(0, nnodes)
        eid_res = GuiResult(0,
                            header='ElementID',
                            title='ElementID',
                            location='centroid',
                            scalar=eids)
        nid_res = GuiResult(0,
                            header='NodeID',
                            title='NodeID',
                            location='node',
                            scalar=nids)

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

        if is_surface_blockmesh:
            if patches is not None:
                patch_res = GuiResult(0,
                                      header='Patch',
                                      title='Patch',
                                      location='centroid',
                                      scalar=patches)
                cases[icase] = (patch_res, (0, 'Patch'))
                formi = ('PatchType', icase, [])
                geometry_form.append(formi)
                icase += 1

            if names is not None:
                name_res = GuiResult(0,
                                     header='Name',
                                     title='Name',
                                     location='centroid',
                                     scalar=names)
                cases[icase] = (name_res, (0, 'Name'))
                formi = ('Names', icase, [])
                geometry_form.append(formi)
                icase += 1
            else:
                raise RuntimeError('names is None...')

        if normals is not None:
            nx_res = GuiResult(0,
                               header='NormalX',
                               title='NormalX',
                               location='node',
                               data_format='%.1f',
                               scalar=normals[:, 0])
            ny_res = GuiResult(0,
                               header='NormalY',
                               title='NormalY',
                               location='node',
                               data_format='%.1f',
                               scalar=normals[:, 1])
            nz_res = GuiResult(0,
                               header='NormalZ',
                               title='NormalZ',
                               location='node',
                               data_format='%.1f',
                               scalar=normals[:, 2])
            geometry_form.append(('NormalX', icase, []))
            geometry_form.append(('NormalY', icase, []))
            geometry_form.append(('NormalZ', icase, []))
            cases[icase] = (nx_res, (0, 'NormalX'))
            cases[icase + 1] = (ny_res, (0, 'NormalY'))
            cases[icase + 2] = (nz_res, (0, 'NormalZ'))
            icase += 3

        form = [
            ('Geometry', None, geometry_form),
        ]
        if len(results_form):
            form.append(('Results', None, results_form))
        return form, cases