예제 #1
0
    def writePointSet(self, name, fileName):
        """
        Write a given point set to a tecplot file

        Parameters
        ----------
        name : str
             The name of the point set to write to a file

        fileName : str
           Filename for tecplot file. Should have no extension, an
           extension will be added
        """
        coords = self.update(name)
        fileName = fileName + "_%s.dat" % name
        f = openTecplot(fileName, 3)
        writeTecplot1D(f, name, coords)
        closeTecplot(f)
예제 #2
0
    def writeTecplot(self,
                     fileName,
                     vols=True,
                     coef=True,
                     orig=False,
                     volLabels=False,
                     edgeLabels=False,
                     nodeLabels=False):
        """Write a tecplot visualization of the pyBlock object.

        Parameters
        ----------
        fileName : str
            Filename of tecplot file. Should have a .dat extension

        vols : bool. Default is True
            Flag to write interpolated volumes

        coef : bool. Default is True
            Flag to write spline control points

        orig : bool. Default is True
            Flag to write original data (if it exists)

        volLabels: bool. Default is True
            Flag to write volume labels in a separate tecplot file; filename
            is derived from the supplied fileName.

        edgeLabels: bool. Default is False
            Flag to write edge labels in a separate tecplot file; filename
            is derived from the supplied fileName.

        nodeLabels: bool. Default is False
            Flag to write node labels in a separate tecplot file; filename
            is derived from the supplied fileName.
        """

        # Open File and output header
        f = openTecplot(fileName, 3)

        if vols:
            for ivol in range(self.nVol):
                self.vols[ivol].computeData()
                writeTecplot3D(f, "interpolated", self.vols[ivol].data)
        if orig:
            for ivol in range(self.nVol):
                writeTecplot3D(f, "orig_data", self.vols[ivol].X)

        if coef:
            for ivol in range(self.nVol):
                writeTecplot3D(f, "control_pts", self.vols[ivol].coef)

        # ---------------------------------------------
        #    Write out labels:
        # ---------------------------------------------
        if volLabels:
            # Split the filename off
            dirName, fileName = os.path.split(fileName)
            fileBaseName, _ = os.path.splitext(fileName)
            labelFilename = dirName + "./" + fileBaseName + ".vol_labels.dat"
            f2 = open(labelFilename, "w")
            for ivol in range(self.nVol):
                midu = self.vols[ivol].nCtlu // 2
                midv = self.vols[ivol].nCtlv // 2
                midw = self.vols[ivol].nCtlw // 2
                textString = 'TEXT CS=GRID3D, X=%f, Y=%f, Z=%f, T="V%d"\n' % (
                    self.vols[ivol].coef[midu, midv, midw, 0],
                    self.vols[ivol].coef[midu, midv, midw, 1],
                    self.vols[ivol].coef[midu, midv, midw, 2],
                    ivol,
                )
                f2.write("%s" % (textString))
            f2.close()

        if edgeLabels:
            # Split the filename off
            dirName, fileName = os.path.split(fileName)
            fileBaseName, _ = os.path.splitext(fileName)
            labelFilename = dirName + "./" + fileBaseName + ".edge_labels.dat"
            f2 = open(labelFilename, "w")
            for ivol in range(self.nVol):
                for iedge in range(12):
                    pt = self.vols[ivol].edgeCurves[iedge](0.5)
                    edgeID = self.topo.edgeLink[ivol][iedge]
                    textString = 'TEXT CS=GRID3D X=%f, Y=%f, Z=%f, T="E%d"\n' % (
                        pt[0], pt[1], pt[2], edgeID)
                    f2.write("%s" % (textString))
            f2.close()

        if nodeLabels:
            # First we need to figure out where the corners actually *are*
            nNodes = len(np.unique(self.topo.nodeLink.flatten()))
            nodeCoord = np.zeros((nNodes, 3))

            for i in range(nNodes):
                # Try to find node i
                for ivol in range(self.nVol):
                    for inode in range(8):
                        if self.topo.nodeLink[ivol][inode] == i:
                            coordinate = self.vols[ivol].getValueCorner(inode)

                nodeCoord[i] = coordinate

            # Split the filename off
            dirName, fileName = os.path.split(fileName)
            fileBaseName, _ = os.path.splitext(fileName)
            labelFilename = dirName + "./" + fileBaseName + ".node_labels.dat"
            f2 = open(labelFilename, "w")
            for i in range(nNodes):
                textString = 'TEXT CS=GRID3D, X=%f, Y=%f, Z=%f, T="n%d"\n' % (
                    nodeCoord[i][0],
                    nodeCoord[i][1],
                    nodeCoord[i][2],
                    i,
                )
                f2.write("%s" % (textString))
            f2.close()

        closeTecplot(f)
예제 #3
0
파일: pyNetwork.py 프로젝트: mdolab/pygeo
    def writeTecplot(self, fileName, orig=False, curves=True, coef=True, curveLabels=False, nodeLabels=False):
        """Write the pyNetwork Object to Tecplot .dat file

        Parameters
        ----------
        fileName : str
            File name for tecplot file. Should have .dat extension
        curves : bool
            Flag to write discrete approximation of the actual curve
        coef : bool
            Flag to write b-spline coefficients
        curveLabels : bool
            Flag to write a separate label file with the curve indices
        nodeLabels : bool
            Flag to write a separate node label file with the node indices
        """

        f = openTecplot(fileName, 3)
        if curves:
            for icurve in range(self.nCurve):
                self.curves[icurve].computeData()
                writeTecplot1D(f, "interpolated", self.curves[icurve].data)
        if coef:
            for icurve in range(self.nCurve):
                writeTecplot1D(f, "coef", self.curves[icurve].coef)
        if orig:
            for icurve in range(self.nCurve):
                writeTecplot1D(f, "coef", self.curves[icurve].X)

        #    Write out The Curve and Node Labels
        dirName, fileName = os.path.split(fileName)
        fileBaseName, _ = os.path.splitext(fileName)

        if curveLabels:
            # Split the filename off
            labelFilename = dirName + "./" + fileBaseName + ".curve_labels.dat"
            f2 = open(labelFilename, "w")
            for icurve in range(self.nCurve):
                mid = np.floor(self.curves[icurve].nCtl / 2)
                textString = 'TEXT CS=GRID3D, X=%f,Y=%f,Z=%f,ZN=%d,T="S%d"\n' % (
                    self.curves[icurve].coef[mid, 0],
                    self.curves[icurve].coef[mid, 1],
                    self.curves[icurve].coef[mid, 2],
                    icurve + 1,
                    icurve,
                )
                f2.write("%s" % (textString))
            f2.close()

        if nodeLabels:
            # First we need to figure out where the corners actually *are*
            nNodes = len(np.unique(self.topo.nodeLink.flatten()))
            nodeCoord = np.zeros((nNodes, 3))
            for i in range(nNodes):
                # Try to find node i
                for icurve in range(self.nCurve):
                    if self.topo.nodeLink[icurve][0] == i:
                        coordinate = self.curves[icurve].getValueCorner(0)
                        break
                    elif self.topo.nodeLink[icurve][1] == i:
                        coordinate = self.curves[icurve].getValueCorner(1)
                        break
                    elif self.topo.nodeLink[icurve][2] == i:
                        coordinate = self.curves[icurve].getValueCorner(2)
                        break
                    elif self.topo.nodeLink[icurve][3] == i:
                        coordinate = self.curves[icurve].getValueCorner(3)
                        break
                nodeCoord[i] = coordinate

            # Split the filename off
            labelFilename = dirName + "./" + fileBaseName + ".node_labels.dat"
            f2 = open(labelFilename, "w")

            for i in range(nNodes):
                textString = 'TEXT CS=GRID3D, X=%f, Y=%f, Z=%f, T="n%d"\n' % (
                    nodeCoord[i][0],
                    nodeCoord[i][1],
                    nodeCoord[i][2],
                    i,
                )
                f2.write("%s" % (textString))
            f2.close()

        closeTecplot(f)
예제 #4
0
파일: pyGeo.py 프로젝트: mdolab/pygeo
    def writeTecplot(
        self,
        fileName,
        orig=False,
        surfs=True,
        coef=True,
        directions=False,
        surfLabels=False,
        edgeLabels=False,
        nodeLabels=False,
    ):

        """Write the pyGeo Object to Tecplot dat file

        Parameters
        ----------
        fileName : str
            File name for tecplot file. Should have .dat extension
        surfs : bool
            Flag to write discrete approximation of the actual surface
        coef: bool
            Flag to write b-spline coefficients
        directions : bool
            Flag to write surface direction visualization
        surfLabels : bool
            Flag to write file with surface labels
        edgeLabels : bool
            Flag to write file with edge labels
        nodeLabels : bool
            Falg to write file with node labels
        """

        f = openTecplot(fileName, 3)

        # Write out the Interpolated Surfaces
        if surfs:
            for isurf in range(self.nSurf):
                self.surfs[isurf].computeData()
                writeTecplot2D(f, "interpolated", self.surfs[isurf].data)

        # Write out the Control Points
        if coef:
            for isurf in range(self.nSurf):
                writeTecplot2D(f, "control_pts", self.surfs[isurf].coef)

        # Write out the Original Data
        if orig:
            for isurf in range(self.nSurf):
                writeTecplot2D(f, "control_pts", self.surfs[isurf].X)

        # Write out The Surface Directions
        if directions:
            for isurf in range(self.nSurf):
                self.surfs[isurf].writeDirections(f, isurf)

        # Write out The Surface, Edge and Node Labels
        dirName, fileName = os.path.split(fileName)
        fileBaseName, _ = os.path.splitext(fileName)

        if surfLabels:
            # Split the filename off
            labelFilename = dirName + "./" + fileBaseName + ".surf_labels.dat"
            f2 = open(labelFilename, "w")
            for isurf in range(self.nSurf):
                midu = np.floor(self.surfs[isurf].nCtlu / 2)
                midv = np.floor(self.surfs[isurf].nCtlv / 2)
                textString = 'TEXT CS=GRID3D, X=%f, Y=%f, Z=%f, ZN=%d, T="S%d"\n' % (
                    self.surfs[isurf].coef[midu, midv, 0],
                    self.surfs[isurf].coef[midu, midv, 1],
                    self.surfs[isurf].coef[midu, midv, 2],
                    isurf + 1,
                    isurf,
                )
                f2.write("%s" % (textString))
            f2.close()

        if edgeLabels:
            # Split the filename off
            labelFilename = dirName + "./" + fileBaseName + "edge_labels.dat"
            f2 = open(labelFilename, "w")
            for iedge in range(self.topo.nEdge):
                surfaces = self.topo.getSurfaceFromEdge(iedge)
                pt = self.surfs[surfaces[0][0]].edgeCurves[surfaces[0][1]](0.5)
                textString = 'TEXT CS=GRID3D X=%f, Y=%f, Z=%f, T="E%d"\n' % (pt[0], pt[1], pt[2], iedge)
                f2.write("%s" % (textString))
            f2.close()

        if nodeLabels:
            # First we need to figure out where the corners actually *are*
            nNodes = len(geo_utils.unique(self.topo.nodeLink.flatten()))
            nodeCoord = np.zeros((nNodes, 3))
            for i in range(nNodes):
                # Try to find node i
                for isurf in range(self.nSurf):
                    if self.topo.nodeLink[isurf][0] == i:
                        coordinate = self.surfs[isurf].getValueCorner(0)
                        break
                    elif self.topo.nodeLink[isurf][1] == i:
                        coordinate = self.surfs[isurf].getValueCorner(1)
                        break
                    elif self.topo.nodeLink[isurf][2] == i:
                        coordinate = self.surfs[isurf].getValueCorner(2)
                        break
                    elif self.topo.nodeLink[isurf][3] == i:
                        coordinate = self.surfs[isurf].getValueCorner(3)
                        break
                nodeCoord[i] = coordinate

            # Split the filename off
            labelFilename = dirName + "./" + fileBaseName + ".node_labels.dat"
            f2 = open(labelFilename, "w")

            for i in range(nNodes):
                textString = 'TEXT CS=GRID3D, X=%f, Y=%f, Z=%f, T="n%d"\n' % (
                    nodeCoord[i][0],
                    nodeCoord[i][1],
                    nodeCoord[i][2],
                    i,
                )
                f2.write("%s" % (textString))
            f2.close()

        # Close out the file
        closeTecplot(f)