oomph-convert.TecplotZone Class Reference

Public Member Functions

def __init__ (self)
 
def nodesCount (self)
 

Static Public Member Functions

def parse (file, line)
 

Public Attributes

 edges
 
 nodes
 
 dimension
 
 cellType
 
 cellFormat
 
 cellsCount
 
 connectivities
 

Detailed Description

 This class handles Tecplot zone informations.

Constructor & Destructor Documentation

◆ __init__()

def oomph-convert.TecplotZone.__init__ (   self)
599  def __init__(self):
600  self.edges = list()
601  self.nodes = list()
602  self.dimension = list()
603  self.cellType = list()
604  self.cellFormat = list()
605  self.cellsCount = list()
606  self.connectivities = list()
607  """ List of :class:`TecplotZone`
608  """
609 

Member Function Documentation

◆ nodesCount()

def oomph-convert.TecplotZone.nodesCount (   self)
 :return: The number of nodes in this zone
610  def nodesCount(self):
611  """ :return: The number of nodes in this zone
612  """
613  return len(self.nodes)
614 

References oomph-convert.TecplotZone.nodes, and PQueueType.nodes.

◆ parse()

def oomph-convert.TecplotZone.parse (   file,
  line 
)
static
 Parse the zone of the given file starting from current position.

    :param file: A file open for reading
    :param line: The current position in the file as line number (used for error messages)
    :return: :class:`TecplotZone` if a zone has been found before the end of the file otherwise :const:`None`
    :return: The updated line position in input file
    :raise:  :class:`TecplotParsingError` on parsing error

    .. note:: This method will seek until it reach a Tecplot zone header.
616  def parse(file, line):
617  """ Parse the zone of the given file starting from current position.
618 
619  :param file: A file open for reading
620  :param line: The current position in the file as line number (used for error messages)
621  :return: :class:`TecplotZone` if a zone has been found before the end of the file otherwise :const:`None`
622  :return: The updated line position in input file
623  :raise: :class:`TecplotParsingError` on parsing error
624 
625  .. note:: This method will seek until it reach a Tecplot zone header.
626  """
627  #-----------------------------------------------------------------------
628  # Seek to the next Tecplot zone
629  #-----------------------------------------------------------------------
630 
631  while 1:
632  header = file.readline()
633  line += 1
634 
635  if not header:
636  # We reach the end of the file
637  return (None, line)
638 
639  if len(header) > 3 and header[0:4] == "ZONE":
640  # We got a zone !
641  break
642 
643  #-----------------------------------------------------------------------
644  # Create the zone
645  #-----------------------------------------------------------------------
646  zone = TecplotZone()
647 
648  # Read header informations
649  edges = header[len("ZONE"):].strip().split(",")
650 
651  # Assumption: Only two zone formats are possible.
652  # The first (format 1) is defined with a zone header of the type
653  # ZONE N=15, E=16, F=FEPOINT, ET=TRIANGLE
654  # In this case, edges = ['N=15', ' E=16', ' F=FEPOINT', ' ET=TRIANGLE']
655  # This zone has been coded for two ET keywords: TRIANGLE and TETRAHEDRON
656  # The second (format 2) is defined in terms of the IJK indexes and a
657  # typical zone reads
658  # ZONE I=5, J=5, K=5
659  # One index, I, indicates a line element, 2 indexes, I and J, indicate
660  # a 4 node quadrilateral element, and three indexes, I J and K, indicate
661  # a tetrahedral element.
662 
663  if "TRIANGLE" in header:
664 
665  # Define data
666  cell = 5 # VTK_TRIANGLE
667  dim = 2
668  format = 1
669  nodesCount = int(edges[0].strip().strip("N="))
670  cellsCount = int(edges[1].strip().strip("E="))
671 
672  # Append data to zone
673  zone.dimension.append(dim)
674  zone.cellType.append(cell)
675  zone.cellFormat.append(format)
676  zone.cellsCount.append(cellsCount)
677 
678  elif "TETRAHEDRON" in header:
679 
680  # Define data
681  cell = 10 # VTK_TETRAHEDRON
682  dim = 3
683  format = 1
684  nodesCount = int(edges[0].strip().strip("N="))
685  cellsCount = int(edges[1].strip().strip("E="))
686 
687  # Append data to zone
688  zone.dimension.append(dim)
689  zone.cellType.append(cell)
690  zone.cellFormat.append(format)
691  zone.cellsCount.append(cellsCount)
692 
693  else:
694 
695  if not len(edges) in range(1, 4):
696  raise TecplotParsingError("Invalid zone header",\
697  "wrong edges count! Try to convert with -p option",\
698  line,\
699  reminder=True)
700 
701  format = 2
702 
703  # define dimension of zone cell by counting the IJK indexes
704  dim = len(edges)
705 
706  if dim == 1:
707  cell = 3 # VTK_LINE
708  if dim == 2:
709  cell = 9 # VTK_QUAD
710  if dim == 3:
711  cell = 12 # VTK_HEXAHEDRON
712 
713  # append dimension and cell type/format to the zone
714  zone.dimension.append(dim)
715  zone.cellType.append(cell)
716  zone.cellFormat.append(format)
717 
718  # extract information from string
719  labels = ["I", "J", "K"]
720  for (index, edge) in enumerate(edges):
721  edge = edge.strip()
722  if len(edge) < 2 or edge[0] != labels[index]:
723  raise TecplotParsingError("Invalid zone header",\
724  "wrong edges format (%s). Try to convert with -p option" % edges,\
725  line,\
726  reminder=True)
727  try:
728  zone.edges.append(int(edge[2:]))
729  except:
730  raise TecplotParsingError("Invalid zone header",\
731  "wrong edge format (%s). Try to convert with -p option" % edge,\
732  line)
733 
734  #-------------------------------------------------------------------
735  # Node count in cell
736  #-------------------------------------------------------------------
737  nodesCount = 1
738  for edge in zone.edges:
739  nodesCount *= edge
740 
741  #-------------------------------------------------------------------
742  # Cell count in zone
743  #-------------------------------------------------------------------
744  cellsCount = 1
745  for edge in zone.edges:
746  cellsCount *= edge - 1
747  zone.cellsCount.append(cellsCount)
748 
749  #-----------------------------------------------------------------------
750  # Parse nodes
751  #-----------------------------------------------------------------------
752  for nodeIndex in range(nodesCount):
753  data = file.readline()
754  line += 1
755 
756  if not data or data.strip() == "":
757  data = file.readline() # ...in case of empty line
758 
759  data = data.strip().split(" ")
760  if len(data) < dim:
761  raise TecplotParsingError("Invalid zone", "not enough values for this node ! Try to convert with -p option", line)
762 
763  node = TecplotNode()
764  for i, value in enumerate(data):
765  try:
766  if i < dim:
767  node.coordinates[i] = float(value)
768  else:
769  node.fields.append(float(value))
770  except ValueError:
771  raise TecplotParsingError("Invalid zone", "wrong node values ! Try to convert with -p option", line)
772 
773  # Append this node to the zone
774  zone.nodes.append(node)
775 
776  #-----------------------------------------------------------------------
777  # Parse connectivities (format == 1)
778  #-----------------------------------------------------------------------
779  if format == 1:
780  for cellIndex in range(cellsCount):
781  data = file.readline()
782  line += 1
783 
784  if not data or data.strip() == "":
785  data = file.readline() # ...in case of empty line
786 
787  data = data.strip().split(" ")
788  if cell == 3: cellNodes = 2 # VTK_LINE
789  if cell == 5: cellNodes = 3 # VTK_TRIANGLE
790  if cell == 9: cellNodes = 4 # VTK_QUAD
791  if cell == 10: cellNodes = 4 # VTK_TETRAHEDRON
792  if cell == 12: cellNodes = 8 # VTK_HEXAHEDRON
793 
794  if len(data) != cellNodes:
795  raise TecplotParsingError("Invalid zone", "wrong connectivity list for this element!", line)
796 
797  # Append these connectivities to the zone
798  zone.connectivities.append(data)
799 
800  return (zone, line)
801 
802 #
return int(ret)+1
void split(const DoubleVector &in_vector, Vector< DoubleVector * > &out_vector_pt)
Definition: double_vector.cc:1413

References int(), and oomph::DoubleVectorHelpers.split().

Member Data Documentation

◆ cellFormat

oomph-convert.TecplotZone.cellFormat

◆ cellsCount

oomph-convert.TecplotZone.cellsCount

◆ cellType

oomph-convert.TecplotZone.cellType

◆ connectivities

oomph-convert.TecplotZone.connectivities

◆ dimension

oomph-convert.TecplotZone.dimension

◆ edges

oomph-convert.TecplotZone.edges

◆ nodes

oomph-convert.TecplotZone.nodes

The documentation for this class was generated from the following file: