コード例 #1
0
ファイル: vtutools.py プロジェクト: zhoubing34/multifluids
    class VtkType(elements.ElementType):
        """
    Class defining a VTK element type
    """

        _vtkTypeIdToElementTypeId = { \
            VTK_UNKNOWN:elements.ELEMENT_UNKNOWN, \
            VTK_EMPTY_CELL:elements.ELEMENT_EMPTY, \
            VTK_VERTEX:elements.ELEMENT_VERTEX, \
            VTK_LINE:elements.ELEMENT_LINE, VTK_QUADRATIC_LINE:elements.ELEMENT_QUADRATIC_LINE, \
            VTK_TRIANGLE:elements.ELEMENT_TRIANGLE, VTK_QUADRATIC_TRIANGLE:elements.ELEMENT_QUADRATIC_TRIANGLE, VTK_QUAD:elements.ELEMENT_QUAD, \
            VTK_TETRAHEDRON:elements.ELEMENT_TETRAHEDRON, VTK_QUADRATIC_TETRAHEDRON:elements.ELEMENT_QUADRATIC_TETRAHEDRON, VTK_HEXAHEDRON:elements.ELEMENT_HEXAHEDRON \
          }
        _elementTypeIdToVtkTypeId = utils.DictInverse(
            _vtkTypeIdToElementTypeId)

        def __init__(self, dim=None, nodeCount=None, vtkTypeId=None):
            if vtkTypeId is None:
                elements.ElementType.__init__(self,
                                              dim=dim,
                                              nodeCount=nodeCount)
            else:
                elements.ElementType.__init__(
                    self,
                    elementTypeId=self._vtkTypeIdToElementTypeId[vtkTypeId])

            self._UpdateVtkTypeId()
            self.RegisterEventHandler("elementTypeIdChange",
                                      self._UpdateVtkTypeId)

            return

        def _UpdateVtkTypeId(self):
            """
      Update the VTK type ID to reflect the element type ID
      """

            self._vtkTypeId = self._elementTypeIdToVtkTypeId[
                self._elementTypeId]

            return

        def GetVtkTypeId(self):
            return self._vtkTypeId

        def SetVtkTypeId(self, vtkTypeId):
            self.SetElementTypeId(self._vtkTypeIdToElementTypeId[vtkTypeId])

            return
コード例 #2
0
ファイル: gmshtools.py プロジェクト: staminazhu/fluidity
class GmshElementType(elements.ElementType):
    """
  Class defining a Gmsh element type
  """

    _gmshElementTypeIdToElementTypeId = { \
        GMSH_UNKNOWN:elements.ELEMENT_UNKNOWN, \
        GMSH_LINE:elements.ELEMENT_LINE, \
        GMSH_TRIANGLE:elements.ELEMENT_TRIANGLE, GMSH_QUAD:elements.ELEMENT_QUAD, \
        GMSH_TETRAHEDRON:elements.ELEMENT_TETRAHEDRON, GMSH_HEXAHEDRON:elements.ELEMENT_HEXAHEDRON, \
        GMSH_POINT:elements.ELEMENT_VERTEX
      }
    _elementTypeIdToGmshElementTypeId = utils.DictInverse(
        _gmshElementTypeIdToElementTypeId)

    def __init__(self, dim=None, nodeCount=None, gmshElementTypeId=None):
        if gmshElementTypeId is None:
            elements.ElementType.__init__(self, dim=dim, nodeCount=nodeCount)
        else:
            elements.ElementType.__init__(
                self,
                elementTypeId=self.
                _gmshElementTypeIdToElementTypeId[gmshElementTypeId])

        self._UpdateGmshElementTypeId()
        self.RegisterEventHandler("elementTypeIdChange",
                                  self._UpdateGmshElementTypeId)

        return

    def _UpdateGmshElementTypeId(self):
        """
    Update the Gmsh type ID to reflect the element type ID
    """

        self._gmshElementTypeId = self._elementTypeIdToGmshElementTypeId[
            self._elementTypeId]

        return

    def GetGmshElementTypeId(self):
        return self._gmshElementTypeId

    def SetGmshElementTypeId(self, gmshElementTypeId):
        self.SetElementTypeId(
            self._gmshElementTypeIdToElementTypeId[gmshElementTypeId])

        return
コード例 #3
0
ファイル: elements.py プロジェクト: zch1996/fluidity
class ElementType(events.Evented):
  """
  Class defining an element type
  """

  _elementTypeIdsMap = {
      (0, 0):ELEMENT_EMPTY, \
      (0, 1):ELEMENT_VERTEX, \
      (1, 2):ELEMENT_LINE, (1, 3):ELEMENT_QUADRATIC_LINE, \
      (2, 3):ELEMENT_TRIANGLE, (2, 6):ELEMENT_QUADRATIC_TRIANGLE, (2, 4):ELEMENT_QUAD, \
      (3, 4):ELEMENT_TETRAHEDRON, (3, 10):ELEMENT_QUADRATIC_TETRAHEDRON, (3, 8):ELEMENT_HEXAHEDRON \
    }
  _elementTypeIdsMapInverse = utils.DictInverse(_elementTypeIdsMap)

  _elementDegreeMap = {
      ELEMENT_EMPTY:0, \
      ELEMENT_VERTEX:0, \
      ELEMENT_LINE:1, ELEMENT_QUADRATIC_LINE:2, \
      ELEMENT_TRIANGLE:1, ELEMENT_QUADRATIC_TRIANGLE:2, ELEMENT_QUAD:1, \
      ELEMENT_TETRAHEDRON:1, ELEMENT_QUADRATIC_TETRAHEDRON:2, ELEMENT_HEXAHEDRON:1 \
    }

  _elementFamilyIdMap = {
      ELEMENT_EMPTY:ELEMENT_FAMILY_UNKNOWN, \
      ELEMENT_VERTEX:ELEMENT_FAMILY_SIMPLEX, \
      ELEMENT_LINE:ELEMENT_FAMILY_SIMPLEX, ELEMENT_QUADRATIC_LINE:ELEMENT_FAMILY_SIMPLEX, \
      ELEMENT_TRIANGLE:ELEMENT_FAMILY_SIMPLEX, ELEMENT_QUADRATIC_TRIANGLE:ELEMENT_FAMILY_SIMPLEX, ELEMENT_QUAD:ELEMENT_FAMILY_CUBIC, \
      ELEMENT_TETRAHEDRON:ELEMENT_FAMILY_SIMPLEX, ELEMENT_QUADRATIC_TETRAHEDRON:ELEMENT_FAMILY_SIMPLEX, ELEMENT_HEXAHEDRON:ELEMENT_FAMILY_CUBIC \
    }
    
  def __init__(self, dim = None, nodeCount = None, elementTypeId = None):
    events.Evented.__init__(self, ["elementTypeIdChange"])
    
    if dim is None:
      assert(nodeCount is None)
      assert(not elementTypeId is None)
      self.SetElementTypeId(elementTypeId)
    else:
      assert(not nodeCount is None)
      assert(elementTypeId is None)
      assert(dim >= 0)
      assert(nodeCount >= 0)
      self._SetElementTypeIdFromData(dim, nodeCount)
      self._dim, self._nodeCount = dim, nodeCount
      
    return
    
  def __str__(self):
    return "Element type: " + str(self.GetNodeCount()) + " nodes, " + str(self.GetDim()) + " dimensions"
    
  def _SetElementTypeIdFromData(self, dim, nodeCount):
    if (dim, nodeCount) in self._elementTypeIdsMap:
      self._elementTypeId = self._elementTypeIdsMap[(dim, nodeCount)]
    else:
      debug.deprint("Warning: Unknown element type with " + str(nodeCount) + " nodes in " + str(dim) + " dimensions")
      self._elementTypeId = ELEMENT_UNKNOWN
    
    self._RaiseEvent("elementTypeIdChange")
    
    return
    
  def GetElementTypeId(self):
    return self._elementTypeId
    
  def SetElementTypeId(self, elementTypeId):  
    self._dim, self._nodeCount = self._elementTypeIdsMapInverse[elementTypeId]
    self._elementTypeId = elementTypeId
    
    self._RaiseEvent("elementTypeIdChange")
    
    return
    
  def GetDim(self):
    return self._dim
    
  def SetDim(self, dim):
    self._SetElementTypeIdFromData(dim, self.GetNodeCount())
    assert(dim >= 0)
    self._dim = dim
    
    return
    
  def GetNodeCount(self):
    return self._nodeCount
    
  def SetNodeCount(self, nodeCount):
    self._SetElementTypeIdFromData(self.GetDim(), nodeCount)
    assert(nodeCount >= 0)
    self._nodeCount = nodeCount
    
    return
    
  def GetDegree(self):
    return self._elementDegreeMap[self.GetElementTypeId()]
    
  def GetElementFamilyId(self):
    return self._elementFamilyIdMap[self.GetElementTypeId()]