Ejemplo n.º 1
0
def run():
    infileName = os.path.join(pkg_path, 'converters', 'panair', 'M100', 'M100.inp')
    model = PanairGrid(log=None, debug=True)
    model.read_panair(infileName)

    p3d_name = 'M100.plt'
    model.write_plot3d(p3d_name)
Ejemplo n.º 2
0
 def test_panair_io_02(self):
     model = PanairGrid(log=None, debug=False)
     msg = (
         '$circular sections - nacelle with composite panels\n'
         # =kn\n'
         '1.\n'
         # =kt\n'
         '1.\n'
         # =nopt                                                                 netname\n'
         '0.                                                                    cowlu\n'
         # =nm\n'
         '20.\n'
         # =xs(1)    ri(1)     xs(2)     ri(2)     xs(*)     ri(*)\n'
         '    2.0000    2.3000    1.5756    2.3000    1.1486    2.3000\n'
         '    0.7460    2.3030    0.4069    2.3286    0.1624    2.3790\n'
         '    0.0214    2.4542   -0.0200    2.5485    0.0388    2.6522\n'
         '    0.2056    2.7554    0.4869    2.8522    0.8883    2.9413\n'
         '    1.4250    3.0178    2.1188    3.0656    2.9586    3.0658\n'
         '    3.8551    3.0175    4.6715    2.9439    5.3492    2.8700\n'
         '    6.0000    2.7842    6.4687    2.7442\n'
         # =nn\n'
         '5.\n'
         # =th(1)    th(2)     th(3)     th(4)     th(5)\n'
         '-90.      -45.      0.        45.       90.\n')
     section = msg.split('\n')
     model._read_circular_section(section)
     model.write_panair('junk_circ.inp')
     os.remove('junk_circ.inp')
Ejemplo n.º 3
0
    def test_panair_io_03(self):
        """tests the SWB model"""
        log = get_logger(level='warning')
        in_filename = os.path.join(TEST_PATH, 'SWB', 'SWB.inp')
        #out_filename = os.path.join(TEST_PATH, 'M100', 'M100_out.inp')

        model = PanairGrid(log=log, debug=False)
        model.read_panair(in_filename)
        (points, elements, regions, kt, cp_nrom) = model.get_points_elements_regions()
        model.write_panair('junk_swb.inp')
        os.remove('junk_swb.inp')
Ejemplo n.º 4
0
def run():
    infilename = os.path.join(PKG_PATH, 'converters', 'panair', 'M100',
                              'M100.inp')
    model = PanairGrid(log=None, debug=True)
    model.read_panair(infilename)

    p3d_name = 'M100.plt'
    model.write_plot3d(p3d_name)
Ejemplo n.º 5
0
    def test_panair_io_01(self):
        log = get_logger(level='warning')
        in_filename = os.path.join(test_path, 'M100', 'M100.inp')
        out_filename = os.path.join(test_path, 'M100', 'M100_out.inp')
        #with open(infile_name, 'w') as f:
        #f.write(lines)

        model = PanairGrid(log=log, debug=False)
        model.read_panair(in_filename)
        #assert len(cart3d.points) == 7, 'npoints=%s' % len(cart3d.points)
        #assert len(cart3d.elements) == 6, 'nelements=%s' % len(cart3d.elements)
        #assert len(cart3d.regions) == 6, 'nregions=%s' % len(cart3d.regions)
        #assert len(cart3d.loads) == 0, 'nloads=%s' % len(cart3d.loads)
        model.write_panair(out_filename)
        (points, elements, regions, kt,
         cp_nrom) = model.get_points_elements_regions()
        os.remove(out_filename)
Ejemplo n.º 6
0
    def test_panair_io_01(self):
        in_filename = os.path.join(test_path, 'M100', 'M100.inp')
        out_filename = os.path.join(test_path, 'M100', 'M100_out.inp')
        #with open(infile_name, 'w') as f:
            #f.write(lines)

        model = PanairGrid(log=None, debug=False)
        model.read_panair(in_filename)
        #assert len(cart3d.points) == 7, 'npoints=%s' % len(cart3d.points)
        #assert len(cart3d.elements) == 6, 'nelements=%s' % len(cart3d.elements)
        #assert len(cart3d.regions) == 6, 'nregions=%s' % len(cart3d.regions)
        #assert len(cart3d.loads) == 0, 'nloads=%s' % len(cart3d.loads)
        model.write_panair(out_filename)
        (points, elements, regions, kt, cp_nrom) = model.get_points_elements_regions()
        os.remove(out_filename)
Ejemplo n.º 7
0
    def test_panair_io_01(self):
        """test the M100 model"""
        log = get_logger(level='warning')
        in_filename = os.path.join(TEST_PATH, 'M100', 'M100.inp')
        out_filename = os.path.join(TEST_PATH, 'M100', 'M100_out.inp')
        #with open(infile_name, 'w') as f:
        #f.write(lines)

        model = PanairGrid(log=log, debug=False)
        model.read_panair(in_filename)
        model.write_panair(out_filename)
        (points, elements, regions, kt,
         cp_nrom) = model.get_points_elements_regions()

        model.write_panair('junk_m100.inp')
        os.remove('junk_m100.inp')
        model.print_options()
        model.print_abutments()
        model.print_grid_summary()
        model.print_out_header()
        os.remove(out_filename)
Ejemplo n.º 8
0
    def load_panair_geometry(self,
                             panair_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(panair_filename)
        if skip_reading:
            return

        model = PanairGrid(log=self.log, debug=self.debug)
        self.model_type = model.model_type
        model.read_panair(panair_filename)

        nodes, elements, regions, kt, cp_norm = model.get_points_elements_regions(
        )
        #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, *point)
                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
        elem = vtkQuad()
        quad_type = elem.GetCellType()
        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(quad_type, 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()

        # loadPanairResults - regions/loads
        if plot:
            self.scalarBar.VisibilityOn()
            self.scalarBar.Modified()

        self.iSubcaseNameMap = {1: ['Panair', '']}
        cases = {}
        ID = 1

        #print "nElements = ", nElements
        loads = []
        form, cases = self._fill_panair_geometry_case(cases, ID, nodes,
                                                      elements, regions, kt,
                                                      cp_norm, loads)
        #if plot:
        self._finish_results_io2(form, cases)
Ejemplo n.º 9
0
    def load_panair_geometry(self, panair_filename, name='main', plot=True):
        model_name = name
        self.gui.nid_map = {}
        #key = self.case_keys[self.icase]
        #case = self.result_cases[key]

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

        model = PanairGrid(log=self.gui.log, debug=self.gui.debug)
        self.gui.model_type = model.model_type
        model.read_panair(panair_filename)
        self.gui.geom_model = model
        # get_wakes=True shows explicit wakes
        #
        # TODO: bad for results...what about just not adding it to the patches/bcs?
        nodes, elements, regions, kt, cp_norm = model.get_points_elements_regions(
            get_wakes=True)

        self.gui.nnodes = len(nodes)
        self.gui.nelements = len(elements)

        #print("nnodes = ",self.nnodes)
        #print("nelements = ", self.nelements)

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

        points = vtk.vtkPoints()
        points.SetNumberOfPoints(self.gui.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)
        points = numpy_to_vtk_points(nodes)

        assert len(elements) > 0
        elem = vtkQuad()
        quad_type = elem.GetCellType()
        create_vtk_cells_of_constant_element_type(grid, elements, quad_type)

        grid.SetPoints(points)
        grid.Modified()

        # loadPanairResults - regions/loads
        if plot:
            self.gui.scalar_bar_actor.VisibilityOn()
            self.gui.scalar_bar_actor.Modified()

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

        loads = []
        form, cases, node_ids, element_ids = self._fill_panair_geometry_case(
            cases, ID, nodes, elements, regions, kt, cp_norm, loads)
        self.gui.node_ids = node_ids
        self.gui.element_ids = element_ids

        #if plot:
        self.gui._finish_results_io2(model_name, form, cases)
Ejemplo n.º 10
0
    def write_panair(self, panair_filename, panair_case_filename):
        pan = PanairGrid()
        pan.mach = 0.5
        pan.is_end = True
        pan.ncases = 2
        pan.alphas = [0., 5.]

        i = 0
        pan.nNetworks = 1
        kt = 1
        cp_norm = 1
        for name, comps in sorted(self.components.items()):
            #panair_file.write('$ name = %r\n' % name)
            for comp in comps:
                str(comp)
                namei = name + str(i)
                # lifting_surface_xyz, lifting_surface_nx, lifting_surface_ny
                x = deepcopy(comp.xyz[:, 0])
                y = deepcopy(comp.xyz[:, 1])
                z = deepcopy(comp.xyz[:, 2])
                x = x.reshape((comp.nx, comp.ny))
                y = y.reshape((comp.nx, comp.ny))
                z = z.reshape((comp.nx, comp.ny))

                xyz = np.dstack([x, y, z])
                assert xyz.shape[2] == 3
                patch = PanairPatch(pan.nNetworks, namei, kt, cp_norm, xyz, self.log)
                pan.patches[i] = patch
                pan.nNetworks += 1
                i += 1

                if 'wing' in name.lower():  # make a wing cap
                    namei = 'cap%i' % i
                    #assert comp.lifting_surface_nx == 6, comp.lifting_surface_nx
                    assert comp.ny == 33, comp.ny
                    #print(x.shape)
                    xend = deepcopy(x[-1, :])
                    #print(xend)
                    yend = deepcopy(y[-1, :])
                    zend = deepcopy(z[-1, :])
                    imid = comp.ny // 2
                    x = np.zeros((imid+1, 2), dtype='float32')
                    y = np.zeros((imid+1, 2), dtype='float32')
                    z = np.zeros((imid+1, 2), dtype='float32')
                    #print(imid, xend[imid], xend.min())
                    xflip = list(xend[0:imid+1])
                    yflip = list(yend[0:imid+1])
                    zflip = list(zend[0:imid+1])
                    x[:, 0] = xflip[::-1]
                    y[:, 0] = yflip[::-1]
                    z[:, 0] = zflip[::-1]
                    x[:, 1] = xend[imid:]
                    y[:, 1] = yend[imid:]
                    z[:, 1] = zend[imid:]
                    #print(x)

                    #x = xend[0:imid:-1].extend(x[imid:])
                    #y = yend[0:imid:-1].extend(y[imid:])
                    #z = zend[0:imid:-1].extend(z[imid:])
                    #print(x)
                    x = x.reshape((2, imid+1))
                    y = y.reshape((2, imid+1))
                    z = z.reshape((2, imid+1))

                    #print(xend)
                    xyz = np.dstack([x, y, z])
                    assert xyz.shape[2] == 3
                    patch = PanairPatch(pan.nNetworks, namei, kt, cp_norm,
                                        xyz, self.log)
                    pan.patches[i] = patch
                    pan.nNetworks += 1
                    i += 1
                #i += 1
        pan.write_panair(panair_filename)
Ejemplo n.º 11
0
    def load_panair_geometry(self, panair_filename, name='main', plot=True):
        self.gui.nid_map = {}

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

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

        model = PanairGrid(log=self.gui.log, debug=self.gui.debug)
        self.gui.model_type = model.model_type
        model.read_panair(panair_filename)

        nodes, elements, regions, kt, cp_norm = model.get_points_elements_regions(
        )
        #for nid, node in enumerate(nodes):
        #print "node[%s] = %s" % (nid, str(node))

        self.gui.nnodes = len(nodes)
        self.gui.nelements = len(elements)

        #print("nnodes = ",self.nnodes)
        #print("nelements = ", self.nelements)

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

        points = vtk.vtkPoints()
        points.SetNumberOfPoints(self.gui.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
        elem = vtkQuad()
        quad_type = elem.GetCellType()
        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(quad_type, elem.GetPointIds())

        grid.SetPoints(points)
        grid.Modified()
        if hasattr(grid, 'Update'):
            grid.Update()

        # loadPanairResults - regions/loads
        if plot:
            self.gui.scalarBar.VisibilityOn()
            self.gui.scalarBar.Modified()

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

        #print "nElements = ", nElements
        loads = []
        form, cases, node_ids, element_ids = self._fill_panair_geometry_case(
            cases, ID, nodes, elements, regions, kt, cp_norm, loads)
        self.gui.node_ids = node_ids
        self.gui.element_ids = element_ids

        #if plot:
        self.gui._finish_results_io2(form, cases)
Ejemplo n.º 12
0
    def write_panair(self, panair_filename, panair_case_filename):
        #panair_file = open(panair_filename, 'wb')
        pan = PanairGrid()
        pan.mach = 0.5
        pan.isEnd = True
        pan.ncases = 2
        pan.alphas = [0., 5.]


        i = 0
        pan.nNetworks = 1
        kt = 1
        cpNorm = 1
        for name, comps in sorted(iteritems(self.components)):
            #panair_file.write('$ name = %r\n' % name)
            for comp in comps:
                namei = name + str(i)
                x = deepcopy(comp.lifting_surface_xyz[:, 0])
                y = deepcopy(comp.lifting_surface_xyz[:, 1])
                z = deepcopy(comp.lifting_surface_xyz[:, 2])
                x = x.reshape((comp.lifting_surface_nx, comp.lifting_surface_ny))
                y = y.reshape((comp.lifting_surface_nx, comp.lifting_surface_ny))
                z = z.reshape((comp.lifting_surface_nx, comp.lifting_surface_ny))
                patch = PanairPatch(pan.nNetworks, namei, kt, cpNorm, x, y, z, self.log)
                pan.patches[i] = patch
                pan.nNetworks += 1
                i += 1

                if 'wing' in name.lower():  # make a wing cap
                    namei = 'cap%i' % i
                    #assert comp.lifting_surface_nx == 6, comp.lifting_surface_nx
                    assert comp.lifting_surface_ny == 33, comp.lifting_surface_ny
                    #print(x.shape)
                    xend = deepcopy(x[-1, :])
                    print(xend)
                    yend = deepcopy(y[-1, :])
                    zend = deepcopy(z[-1, :])
                    imid = comp.lifting_surface_ny // 2
                    x = np.zeros((imid+1, 2), dtype='float32')
                    y = np.zeros((imid+1, 2), dtype='float32')
                    z = np.zeros((imid+1, 2), dtype='float32')
                    print(imid, xend[imid], xend.min())
                    xflip = list(xend[0:imid+1])
                    yflip = list(yend[0:imid+1])
                    zflip = list(zend[0:imid+1])
                    x[:, 0] = xflip[::-1]
                    y[:, 0] = yflip[::-1]
                    z[:, 0] = zflip[::-1]
                    x[:, 1] = xend[imid:]
                    y[:, 1] = yend[imid:]
                    z[:, 1] = zend[imid:]
                    print (x)

                    #x = xend[0:imid:-1].extend(x[imid:])
                    #y = yend[0:imid:-1].extend(y[imid:])
                    #z = zend[0:imid:-1].extend(z[imid:])
                    #print(x)
                    x = x.reshape((2, imid+1))
                    y = y.reshape((2, imid+1))
                    z = z.reshape((2, imid+1))

                    #print(xend)
                    patch = PanairPatch(pan.nNetworks, namei, kt, cpNorm, x.T, y.T, z.T, self.log)
                    pan.patches[i] = patch
                    pan.nNetworks += 1
                    i += 1
                #i += 1
        pan.write_panair(panair_filename)
Ejemplo n.º 13
0
    def load_panair_geometry(self, panair_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(panair_filename)
        if skip_reading:
            return

        model = PanairGrid(log=self.log, debug=self.debug)
        self.model_type = model.model_type
        model.read_panair(panair_filename)

        nodes, elements, regions, kt, cp_norm = model.get_points_elements_regions()
        #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, *point)
                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
        elem = vtkQuad()
        quad_type = elem.GetCellType()
        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(quad_type, 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()

        # loadPanairResults - regions/loads
        self. turn_text_on()
        if plot:
            self.scalarBar.VisibilityOn()
            self.scalarBar.Modified()

        self.iSubcaseNameMap = {1: ['Panair', '']}
        cases = {}
        ID = 1

        #print "nElements = ", nElements
        loads = []
        form, cases = self._fill_panair_geometry_case(cases, ID, nodes, elements, regions, kt, cp_norm, loads)
        #if plot:
        self._finish_results_io2(form, cases)