Ejemplo n.º 1
0
  def test_initialize(self):
    """
    Test initialize().
    """
    cell = FIATSimplex()
    cell.inventory.dimension = 2
    cell.inventory.order = 1
    cell._configure()

    scalarType = None
    from pylith.utils.utils import sizeofPylithScalar
    if 8 == sizeofPylithScalar():
      scalarType = numpy.float64
    elif 4 == sizeofPylithScalar():
      scalarType = numpy.float32
    else:
      raise ValueError("Unknown size for PylithScalar.")

    verticesE = numpy.array([ [-1.0, -1.0],
                              [+1.0, -1.0],
                              [-1.0, +1.0] ])
    quadPtsE = numpy.array( [[-1.0/3.0, -1.0/3.0]], dtype=scalarType )
    quadWtsE = numpy.array( [2.0], dtype=scalarType )

    # Compute basis functions and derivatives at quadrature points
    basisE = numpy.zeros( (1, 3), dtype=scalarType)
    basisDerivE = numpy.zeros( (1, 3, 2), dtype=scalarType)
    iQuad = 0
    for x in quadPtsE:
      basisE[iQuad] = numpy.array([N0(x), N1(x), N2(x)], dtype=scalarType).reshape( (3,) )
      deriv = numpy.array([[N0p(x), N0q(x)], [N1p(x), N1q(x)], [N2p(x), N2q(x)]], dtype=scalarType)      
      basisDerivE[iQuad] = deriv.reshape((1, 3, 2))
      iQuad += 1

    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    quadrature.preinitialize(spaceDim=2)
    quadrature.initialize()

    self.assertEqual(2, quadrature.cellDim())
    self.assertEqual(2, quadrature.spaceDim())
    self.assertEqual(3, quadrature.numBasis())
    self.assertEqual(1, quadrature.numQuadPts())

    from pylith.utils.utils import TestArray_checkScalar

    self.failUnless(TestArray_checkScalar(basisE.ravel(), quadrature.basis()))
    self.failUnless(TestArray_checkScalar(basisDerivE.ravel(), quadrature.basisDerivRef()))
    self.failUnless(TestArray_checkScalar(quadPtsE.ravel(), quadrature.quadPtsRef()))
    self.failUnless(TestArray_checkScalar(quadWtsE.ravel(), quadrature.quadWts()))

    quadrature.initializeGeometry()
    return
Ejemplo n.º 2
0
 def test_sizeofPylithScalar(self):
   """
   Test sizeofPylithScalar().
   """
   from pylith.utils.utils import sizeofPylithScalar
   size = sizeofPylithScalar()
   self.failUnless(4 == size or 8 == size)
   return
Ejemplo n.º 3
0
 def test_sizeofPylithScalar(self):
     """
 Test sizeofPylithScalar().
 """
     from pylith.utils.utils import sizeofPylithScalar
     size = sizeofPylithScalar()
     self.failUnless(4 == size or 8 == size)
     return
Ejemplo n.º 4
0
 def _initialize(self, cell):
     """
 Initialize C++ quadrature object.
 """
     import numpy
     from pylith.utils.utils import sizeofPylithScalar
     size = sizeofPylithScalar()
     if 8 == size:
         ModuleQuadrature.initialize(self, cell.basis, cell.basisDeriv,
                                     cell.quadPts, cell.quadWts,
                                     cell.geometry.spaceDim())
     elif 4 == size:
         ModuleQuadrature.initialize(self, numpy.float32(cell.basis),
                                     numpy.float32(cell.basisDeriv),
                                     numpy.float32(cell.quadPts),
                                     numpy.float32(cell.quadWts),
                                     cell.geometry.spaceDim())
     else:
         raise ValueError("Unknown size for PylithScalar")
     return
Ejemplo n.º 5
0
 def _initialize(self, cell):
   """
   Initialize C++ quadrature object.
   """
   import numpy
   from pylith.utils.utils import sizeofPylithScalar
   size = sizeofPylithScalar()
   if 8 == size:
     ModuleQuadrature.initialize(self, cell.basis,
                                 cell.basisDeriv,
                                 cell.quadPts,
                                 cell.quadWts,
                             cell.geometry.spaceDim())
   elif 4 == size:
     ModuleQuadrature.initialize(self, numpy.float32(cell.basis),
                                 numpy.float32(cell.basisDeriv),
                                 numpy.float32(cell.quadPts),
                                 numpy.float32(cell.quadWts),
       cell.geometry.spaceDim())
   else:
       raise ValueError("Unknown size for PylithScalar")
   return
Ejemplo n.º 6
0
    def test_initialize(self):
        """
    Test initialize().
    """
        cell = FIATSimplex()
        cell.inventory.dimension = 2
        cell.inventory.order = 1
        cell._configure()

        scalarType = None
        from pylith.utils.utils import sizeofPylithScalar
        if 8 == sizeofPylithScalar():
            scalarType = numpy.float64
        elif 4 == sizeofPylithScalar():
            scalarType = numpy.float32
        else:
            raise ValueError("Unknown size for PylithScalar.")

        verticesE = numpy.array([[-1.0, -1.0], [+1.0, -1.0], [-1.0, +1.0]])
        quadPtsE = numpy.array([[-1.0 / 3.0, -1.0 / 3.0]], dtype=scalarType)
        quadWtsE = numpy.array([2.0], dtype=scalarType)

        # Compute basis functions and derivatives at quadrature points
        basisE = numpy.zeros((1, 3), dtype=scalarType)
        basisDerivE = numpy.zeros((1, 3, 2), dtype=scalarType)
        iQuad = 0
        for x in quadPtsE:
            basisE[iQuad] = numpy.array([N0(x), N1(x), N2(x)],
                                        dtype=scalarType).reshape((3, ))
            deriv = numpy.array(
                [[N0p(x), N0q(x)], [N1p(x), N1q(x)], [N2p(x), N2q(x)]],
                dtype=scalarType)
            basisDerivE[iQuad] = deriv.reshape((1, 3, 2))
            iQuad += 1

        quadrature = Quadrature()
        quadrature.inventory.cell = cell
        quadrature._configure()

        quadrature.preinitialize(spaceDim=2)
        quadrature.initialize()

        self.assertEqual(2, quadrature.cellDim())
        self.assertEqual(2, quadrature.spaceDim())
        self.assertEqual(3, quadrature.numBasis())
        self.assertEqual(1, quadrature.numQuadPts())

        from pylith.utils.utils import TestArray_checkScalar

        self.failUnless(
            TestArray_checkScalar(basisE.ravel(), quadrature.basis()))
        self.failUnless(
            TestArray_checkScalar(basisDerivE.ravel(),
                                  quadrature.basisDerivRef()))
        self.failUnless(
            TestArray_checkScalar(quadPtsE.ravel(), quadrature.quadPtsRef()))
        self.failUnless(
            TestArray_checkScalar(quadWtsE.ravel(), quadrature.quadWts()))

        quadrature.initializeGeometry()
        return