Esempio n. 1
0
    def test_shabp_2(self):
        """tests the flap"""
        log = SimpleLogger(level='info', encoding='utf-8')
        shabp_infilename = os.path.join(MODEL_PATH, 'flap',
                                        'flap_inviscid.mk5')
        shabp_outfilename = os.path.join(MODEL_PATH, 'flap', 'SHABP.OUT')

        #test.model.load_shabp_geometry(shabp_infilename)
        #test.on_load_geometry(shabp_infilename, geometry_format='shabp', raise_error=True)
        model = read_shabp(shabp_infilename,
                           read_special_routines=True,
                           log=log,
                           debug=None)

        #print(f'component_name_to_patch = {model.component_name_to_patch}')
        #print(f'patch_to_component_num = {model.patch_to_component_num}')
        #print(f'component_to_params = {model.component_to_params}')
        #print(f'component_num_to_name = {model.component_num_to_name}')
        #print(f'component_name_to_num = {model.component_name_to_num}')

        assert model.component_name_to_patch == {
            'COMP1': [1],
            'FLAP': [2]
        }, model.component_name_to_patch
        assert model.patch_to_component_num == {
            0: 1,
            1: 2
        }, model.patch_to_component_num
        assert model.component_to_params == {
            0: [3, 1, 1, 0, 0, 0.0, 1.0, 0.0, 1.0, 3.0, 3.0],
            1: [3, 1, 1, 0, 0, 0.0, 1.0, 0.0, 1.0, 3.0, 3.0]
        }, model.component_to_params
        assert model.component_num_to_name == {
            0: 'COMP1',
            1: 'FLAP'
        }, model.component_num_to_name
        assert model.component_name_to_num == {
            'COMP1': 0,
            'FLAP': 1
        }, model.component_name_to_num

        areas = model.get_area_by_patch()
        assert np.allclose(areas, [50., 124.6875]), areas

        areas = model.get_area_by_component()
        assert np.allclose(areas['COMP1'], 124.6875), areas
        assert np.allclose(areas['FLAP'], 50.0), areas

        areas, lengths = model.get_area_xlength_by_component()
        assert np.allclose(areas['COMP1'], 124.6875), areas
        assert np.allclose(areas['FLAP'], 50.0), areas
        assert np.allclose(lengths['COMP1'], 24.9375), lengths
        assert np.allclose(lengths['FLAP'], 34.9375), lengths

        out_model = ShabpOut(model, log=log)
        Cpd, unused_deltad = out_model.read_shabp_out(shabp_outfilename)
Esempio n. 2
0
    def test_shabp_1(self):
        """tests nose.mk5"""
        log = SimpleLogger(level='info', encoding='utf-8')
        shabp_filename = os.path.join(MODEL_PATH, 'nose', 'noseX_working.mk5')
        model = read_shabp(shabp_filename, log=log)

        npatches_expected = 1
        assert len(
            model.X
        ) == npatches_expected, f'npatches_expected={npatches_expected} len(model.X)={len(model.X)}'
        assert len(
            model.Y
        ) == npatches_expected, f'npatches_expected={npatches_expected} len(model.X)={len(model.Y)}'
        assert len(
            model.Z
        ) == npatches_expected, f'npatches_expected={npatches_expected} len(model.X)={len(model.Z)}'

        #print(f'component_name_to_patch = {model.component_name_to_patch}')
        #print(f'patch_to_component_num = {model.patch_to_component_num}')
        #print(f'component_to_params = {model.component_to_params}')
        #print(f'component_num_to_name = {model.component_num_to_name}')
        #print(f'component_name_to_num = {model.component_name_to_num}')
        assert model.component_name_to_patch == {
            'ellipse': [1]
        }, model.component_name_to_patch
        assert model.patch_to_component_num == {
            0: 1
        }, model.patch_to_component_num
        assert model.component_to_params == {
            0: [5, 5, 1, 0, 0, 0.0, 1.0, 0.0, 1.0, 3.0, 3.0]
        }, model.component_to_params
        assert model.component_num_to_name == {
            0: 'ellipse'
        }, model.component_num_to_name
        assert model.component_name_to_num == {
            'ellipse': 0
        }, model.component_name_to_num

        areas = model.get_area_by_patch()
        assert np.allclose(areas, [266.47640991]), areas

        areas = model.get_area_by_component()
        assert np.allclose(areas['ellipse'], 266.47640991), areas

        areas, lengths = model.get_area_xlength_by_component()
        assert np.allclose(areas['ellipse'], 266.47640991), areas
        assert np.allclose(lengths['ellipse'], 20.0), lengths
Esempio n. 3
0
    def test_shabp_results_1(self):
        log = get_logger(level='warning')
        test = ShabpGUI()
        test.log = log
        shabp_infilename = os.path.join(MODEL_PATH, 'flap',
                                        'flap_inviscid.mk5')
        shabp_outfilename = os.path.join(MODEL_PATH, 'flap', 'SHABP.OUT')

        #test.model.load_shabp_geometry(shabp_infilename)
        test.on_load_geometry(shabp_infilename,
                              geometry_format='shabp',
                              raise_error=True)
        unused_model = read_shabp(shabp_infilename, log=None, debug=None)
        #model.get_area_by_patch()
        #model.get_area_by_component()
        #model.get_area_xlength_by_component()
        test.on_load_results(shabp_outfilename)
Esempio n. 4
0
    def load_shabp_geometry(self, shabp_filename, name='main', plot=True):
        self.gui.eid_maps[name] = {}
        self.gui.nid_maps[name] = {}

        #key = self.case_keys[self.icase]
        #case = self.result_cases[key]

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

        self.model = read_shabp(shabp_filename,
                                log=self.gui.log,
                                debug=self.gui.debug)
        self.gui.model_type = 'shabp'  # model.model_type

        nodes, elements, patches, components, impact, shadow = self.model.get_points_elements_regions(
        )
        #for nid,node in enumerate(nodes):
        #print "node[%s] = %s" %(nid,str(node))

        nnodes = len(nodes)
        nelements = len(elements)
        self.gui.nnodes = nnodes
        self.gui.nelements = nelements
        #print("nnodes = ",self.nnodes)
        #print("nelements = ", self.nelements)

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

        points = vtk.vtkPoints()
        points.SetNumberOfPoints(nnodes)

        assert len(nodes) > 0
        mmax = amax(nodes, axis=0)
        mmin = amin(nodes, axis=0)
        dim_max = (mmax - mmin).max()
        self.gui.create_global_axes(dim_max)
        for nid, node in enumerate(nodes):
            points.InsertPoint(nid, *node)

        assert len(elements) > 0
        for eid, element in enumerate(elements):
            (p1, p2, p3, p4) = element
            elem = vtkQuad()
            elem.GetPointIds().SetId(0, p1)
            elem.GetPointIds().SetId(1, p2)
            elem.GetPointIds().SetId(2, p3)
            elem.GetPointIds().SetId(3, p4)
            grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):  # pragma: no cover
            grid.Update()

        # loadShabpResults - regions/loads
        self.gui.scalarBar.VisibilityOn()
        self.gui.scalarBar.Modified()

        self.gui.isubcase_name_map = {1: ['S/HABP', '']}
        cases = OrderedDict()
        ID = 1

        self.gui.log.debug("nNodes=%i nElements=%i" %
                           (self.gui.nnodes, self.gui.nelements))
        form, cases = self._fill_shabp_geometry_case(cases, ID, nodes,
                                                     elements, patches,
                                                     components, impact,
                                                     shadow)

        nelements = len(elements)
        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
        self.gui._finish_results_io2(form, cases)
Esempio n. 5
0
    def load_shabp_geometry(self,
                            shabp_filename,
                            dirname,
                            name='main',
                            plot=True):
        self.nid_map = {}

        #key = self.case_keys[self.icase]
        #case = self.result_cases[key]

        skip_reading = self._remove_old_geometry(shabp_filename)
        if skip_reading:
            return

        self.model = read_shabp(shabp_filename, log=self.log, debug=self.debug)
        self.model_type = 'shabp'  # model.model_type

        nodes, elements, patches, components, impact, shadow = self.model.getPointsElementsRegions(
        )
        #for nid,node in enumerate(nodes):
        #print "node[%s] = %s" %(nid,str(node))

        self.nNodes = len(nodes)
        self.nElements = len(elements)

        #print("nNodes = ",self.nNodes)
        #print("nElements = ", self.nElements)

        self.grid.Allocate(self.nElements, 1000)
        #self.gridResult.SetNumberOfComponents(self.nElements)

        points = vtk.vtkPoints()
        points.SetNumberOfPoints(self.nNodes)
        #self.gridResult.Allocate(self.nNodes, 1000)
        #vectorReselt.SetNumberOfComponents(3)
        #elem.SetNumberOfPoints(nNodes)
        if 0:
            fraction = 1. / nNodes  # so you can color the nodes by ID
            for nid, node in sorted(iteritems(nodes)):
                points.InsertPoint(nid - 1, *node)
                self.gridResult.InsertNextValue(nid * fraction)
                #print str(element)

                #elem = vtk.vtkVertex()
                #elem.GetPointIds().SetId(0, i)
                #self.aQuadGrid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())
                #vectorResult.InsertTuple3(0, 0.0, 0.0, 1.0)

        assert len(nodes) > 0
        mmax = amax(nodes, axis=0)
        mmin = amin(nodes, axis=0)
        dim_max = (mmax - mmin).max()
        self.create_global_axes(dim_max)
        for nid, node in enumerate(nodes):
            points.InsertPoint(nid, *node)

        assert len(elements) > 0
        for eid, element in enumerate(elements):
            (p1, p2, p3, p4) = element
            elem = vtkQuad()
            elem.GetPointIds().SetId(0, p1)
            elem.GetPointIds().SetId(1, p2)
            elem.GetPointIds().SetId(2, p3)
            elem.GetPointIds().SetId(3, p4)
            self.grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds())

        self.grid.SetPoints(points)
        #self.grid.GetPointData().SetScalars(self.gridResult)
        #print dir(self.grid) #.SetNumberOfComponents(0)
        #self.grid.GetCellData().SetNumberOfTuples(1);
        #self.grid.GetCellData().SetScalars(self.gridResult)
        self.grid.Modified()
        if hasattr(self.grid, 'Update'):
            self.grid.Update()

        # loadShabpResults - regions/loads
        self.scalarBar.VisibilityOn()
        self.scalarBar.Modified()

        self.iSubcaseNameMap = {1: ['S/HABP', '']}
        cases = {}
        ID = 1

        self.log.debug("nNodes=%i nElements=%i" %
                       (self.nNodes, self.nElements))
        form, cases = self._fill_shabp_geometry_case(cases, ID, nodes,
                                                     elements, patches,
                                                     components, impact,
                                                     shadow)
        self._finish_results_io2(form, cases)