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_lagrange3D(self):
    """
    Test setup of quadrature for Lagrange cells for a 3-D problem.
    """
    spaceDim = 3

    cell = FIATLagrange()
    cell.inventory.dimension = 3
    cell._configure()
    
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    quadrature.preinitialize(spaceDim)
    self.assertEqual(3, quadrature.cellDim())
    self.assertEqual(spaceDim, quadrature.spaceDim())
    self.assertEqual(8, quadrature.numBasis())
    return
Ejemplo n.º 3
0
  def test_simplex2D(self):
    """
    Test setup of quadrature for simplex cells for a 2-D problem.
    """
    spaceDim = 2

    cell = FIATSimplex()
    cell.inventory.dimension = 2
    cell._configure()
    
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()

    quadrature.preinitialize(spaceDim)
    self.assertEqual(2, quadrature.cellDim())
    self.assertEqual(spaceDim, quadrature.spaceDim())
    self.assertEqual(3, quadrature.numBasis())
    return
Ejemplo n.º 4
0
    def test_lagrange3D(self):
        """
    Test setup of quadrature for Lagrange cells for a 3-D problem.
    """
        spaceDim = 3

        cell = FIATLagrange()
        cell.inventory.dimension = 3
        cell._configure()

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

        quadrature.preinitialize(spaceDim)
        self.assertEqual(3, quadrature.cellDim())
        self.assertEqual(spaceDim, quadrature.spaceDim())
        self.assertEqual(8, quadrature.numBasis())
        return
Ejemplo n.º 5
0
    def test_simplex2D(self):
        """
    Test setup of quadrature for simplex cells for a 2-D problem.
    """
        spaceDim = 2

        cell = FIATSimplex()
        cell.inventory.dimension = 2
        cell._configure()

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

        quadrature.preinitialize(spaceDim)
        self.assertEqual(2, quadrature.cellDim())
        self.assertEqual(spaceDim, quadrature.spaceDim())
        self.assertEqual(3, quadrature.numBasis())
        return
Ejemplo n.º 6
0
  def test_initialize(self):
    """
    Test constructor.
    """
    spaceDim = 2
    
    from pylith.feassemble.FIATSimplex import FIATSimplex
    cell = FIATSimplex()
    cell.inventory.dimension = 2
    cell.inventory.degree = 2
    cell.inventory.order = 2
    cell._configure()

    from pylith.feassemble.Quadrature import Quadrature
    quadrature = Quadrature()
    quadrature.inventory.cell = cell
    quadrature._configure()
    quadrature.preinitialize(spaceDim)
    quadrature.initialize()

    filter = CellFilterAvg()
    filter._configure()
    filter.initialize(quadrature)
    return
Ejemplo n.º 7
0
    def test_initialize(self):
        """
    Test constructor.
    """
        spaceDim = 2

        from pylith.feassemble.FIATSimplex import FIATSimplex
        cell = FIATSimplex()
        cell.inventory.dimension = 2
        cell.inventory.degree = 2
        cell.inventory.order = 2
        cell._configure()

        from pylith.feassemble.Quadrature import Quadrature
        quadrature = Quadrature()
        quadrature.inventory.cell = cell
        quadrature._configure()
        quadrature.preinitialize(spaceDim)
        quadrature.initialize()

        filter = CellFilterAvg()
        filter._configure()
        filter.initialize(quadrature)
        return
Ejemplo n.º 8
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