[cig-commits] r7038 - in short/3D/PyLith/trunk: pylith
pylith/feassemble unittests/pytests/feassemble
brad at geodynamics.org
brad at geodynamics.org
Fri Jun 1 14:55:17 PDT 2007
Author: brad
Date: 2007-06-01 14:55:17 -0700 (Fri, 01 Jun 2007)
New Revision: 7038
Added:
short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATLagrange.py
Removed:
short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py
Modified:
short/3D/PyLith/trunk/pylith/Makefile.am
short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py
short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py
short/3D/PyLith/trunk/pylith/feassemble/__init__.py
short/3D/PyLith/trunk/unittests/pytests/feassemble/Makefile.am
short/3D/PyLith/trunk/unittests/pytests/feassemble/testfeassemble.py
Log:
Added Python unit tests for FIATLagrange.
Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/pylith/Makefile.am 2007-06-01 21:55:17 UTC (rev 7038)
@@ -30,7 +30,7 @@
feassemble/Constraint.py \
feassemble/ElasticityExplicit.py \
feassemble/ElasticityImplicit.py \
- feassemble/FIATCell.py \
+ feassemble/FIATLagrange.py \
feassemble/FIATSimplex.py \
feassemble/Integrator.py \
feassemble/IntegratorElasticity.py \
Deleted: short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py 2007-06-01 21:55:17 UTC (rev 7038)
@@ -1,141 +0,0 @@
-#!/usr/bin/env python
-#
-# ----------------------------------------------------------------------
-#
-# Brad T. Aagaard
-# U.S. Geological Survey
-#
-# <LicenseText>
-#
-# ----------------------------------------------------------------------
-#
-
-## @file pylith/feassemble/FIATCell.py
-##
-## @brief Python object for managing basis functions and quadrature
-## rules of a reference finite-element cell using FIAT.
-##
-## Factory: reference_cell.
-
-from ReferenceCell import ReferenceCell
-
-import numpy
-
-# FIATCell class
-class FIATCell(ReferenceCell):
- """
- Python object for managing basis functions and quadrature rules of a
- reference finite-element cell using FIAT.
-
- Factory: reference_cell.
- """
-
- # PUBLIC METHODS /////////////////////////////////////////////////////
-
- def __init__(self, name="fiatcell"):
- """
- Constructor.
- """
- ReferenceCell.__init__(self, name)
- return
-
-
- def initialize(self):
- """
- Initialize reference finite-element cell.
- """
- quadrature = self._setupQuadrature()
- basisFns = self._setupBasisFns()
-
- # Evaluate basis functions at quadrature points
- quadpts = quadrature.get_points()
- basis = numpy.array(basisFns.tabulate(quadpts)).transpose()
- self.basis = numpy.reshape(basis.flatten(), basis.shape)
-
- # Evaluate derivatives of basis functions at quadrature points
- import FIAT.shapes
- dim = FIAT.shapes.dimension(basisFns.base.shape)
- basisDeriv = numpy.array([basisFns.deriv_all(d).tabulate(quadpts) \
- for d in range(dim)]).transpose()
- self.basisDeriv = numpy.reshape(basisDeriv.flatten(), basisDeriv.shape)
-
- self.quadPts = numpy.array(quadrature.get_points())
- self.quadWts = numpy.array(quadrature.get_weights())
-
- self.cellDim = dim
- self.numCorners = len(basisFns)
- self.numQuadPts = len(quadrature.get_weights())
-
- self._info.line("Basis (quad pts):")
- self._info.line(self.basis)
- self._info.line("Basis derivatives (quad pts):")
- self._info.line(self.basisDeriv)
- self._info.line("Quad pts:")
- self._info.line(quadrature.get_points())
- self._info.line("Quad wts:")
- self._info.line(quadrature.get_weights())
-
- self._info.log()
-
- return
-
-
- def initializeTensor(self, dim):
- """
- Initialize reference finite-element cell from a tensor product of 1D Lagrange elements.
- """
- quadrature = self._setupQuadrature()
- basisFns = self._setupBasisFns()
-
- # Evaluate basis functions at quadrature points
- quadpts = quadrature.get_points()
- basis = numpy.array(basisFns.tabulate(quadpts)).transpose()
- self.basis = numpy.reshape(basis.flatten(), basis.shape)
-
- # Evaluate derivatives of basis functions at quadrature points
- import FIAT.shapes
- dim = FIAT.shapes.dimension(basisFns.base.shape)
- basisDeriv = numpy.array([basisFns.deriv_all(d).tabulate(quadpts) \
- for d in range(dim)]).transpose()
- self.basisDeriv = numpy.reshape(basisDeriv.flatten(), basisDeriv.shape)
-
- self.quadPts = numpy.array(quadrature.get_points())
- self.quadWts = numpy.array(quadrature.get_weights())
-
- self.cellDim = dim
- self.numCorners = len(basisFns)
- self.numQuadPts = len(quadrature.get_weights())
-
- self._info.line("Basis (quad pts):")
- self._info.line(self.basis)
- self._info.line("Basis derivatives (quad pts):")
- self._info.line(self.basisDeriv)
- self._info.line("Quad pts:")
- self._info.line(quadrature.get_points())
- self._info.line("Quad wts:")
- self._info.line(quadrature.get_weights())
-
- self._info.log()
-
- return
-
-
- # PRIVATE METHODS ////////////////////////////////////////////////////
-
- def _setupQuadrature(self):
- """
- Setup quadrature rule for reference cell.
- """
- raise NotImplementedError()
- return
-
-
- def _setupBasisFns(self):
- """
- Setup basis functions for reference cell.
- """
- raise NotImplementedError()
- return
-
-
-# End of file
Modified: short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py 2007-06-01 21:55:17 UTC (rev 7038)
@@ -1,4 +1,4 @@
-b#!/usr/bin/env python
+#!/usr/bin/env python
#
# ----------------------------------------------------------------------
#
@@ -20,7 +20,7 @@
##
## Factory: reference_cell.
-from FIATCell import FIATCell
+from ReferenceCell import ReferenceCell
import numpy
@@ -30,7 +30,7 @@
return
# FIATLagrange class
-class FIATLagrange(FIATCell):
+class FIATLagrange(ReferenceCell):
"""
Python object for managing basis functions and quadrature rules of a
Lagrange reference finite-element cell using FIAT.
@@ -40,7 +40,7 @@
# INVENTORY //////////////////////////////////////////////////////////
- class Inventory(FIATCell.Inventory):
+ class Inventory(ReferenceCell.Inventory):
"""Python object for managing FIATLagrange facilities and properties."""
## @class Inventory
@@ -73,10 +73,48 @@
"""
Constructor.
"""
- FIATCell.__init__(self, name)
+ ReferenceCell.__init__(self, name)
return
+ def initialize(self):
+ """
+ Initialize reference finite-element cell from a tensor product of
+ 1-D Lagrange elements.
+ """
+ quadrature = self._setupQuadrature()
+ basisFns = self._setupBasisFns()
+
+ # Evaluate basis functions at quadrature points
+ quadpts = quadrature.get_points()
+ basis = numpy.array(basisFns.tabulate(quadpts)).transpose()
+ self.basis = numpy.reshape(basis.flatten(), basis.shape)
+
+ # Evaluate derivatives of basis functions at quadrature points
+ import FIAT.shapes
+ dim = FIAT.shapes.dimension(basisFns.base.shape)
+ basisDeriv = numpy.array([basisFns.deriv_all(d).tabulate(quadpts) \
+ for d in range(dim)]).transpose()
+ self.basisDeriv = numpy.reshape(basisDeriv.flatten(), basisDeriv.shape)
+
+ self.quadPts = numpy.array(quadrature.get_points())
+ self.quadWts = numpy.array(quadrature.get_weights())
+
+ self.numCorners = len(basisFns)
+ self.numQuadPts = len(quadrature.get_weights())
+
+ self._info.line("Basis (quad pts):")
+ self._info.line(self.basis)
+ self._info.line("Basis derivatives (quad pts):")
+ self._info.line(self.basisDeriv)
+ self._info.line("Quad pts:")
+ self._info.line(quadrature.get_points())
+ self._info.line("Quad wts:")
+ self._info.line(quadrature.get_weights())
+ self._info.log()
+ return
+
+
# PRIVATE METHODS ////////////////////////////////////////////////////
def _configure(self):
@@ -85,20 +123,11 @@
"""
import FIAT.shapes
- FIATCell._configure(self)
+ ReferenceCell._configure(self)
self.cellDim = self.inventory.dimension
self.degree = self.inventory.degree
self.order = self.inventory.order
- # CHANGE TO BE LINE/QUADRILATERAL/HEXEHEDRAL
- if self.cellDim == 1:
- self.shape = FIAT.shapes.LINE
- elif self.cellDim == 2:
- self.shape = FIAT.shapes.TRIANGLE
- elif self.cellDim == 3:
- self.shape = FIAT.shapes.TETRAHEDRON
- # END CHANGE
-
if self.order == -1:
self.order = 2*self.degree+1
return
Modified: short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py 2007-06-01 21:55:17 UTC (rev 7038)
@@ -17,7 +17,7 @@
##
## Factory: reference_cell.
-from FIATCell import FIATCell
+from ReferenceCell import ReferenceCell
import numpy
@@ -33,7 +33,7 @@
return name
# FIATSimplex class
-class FIATSimplex(FIATCell):
+class FIATSimplex(ReferenceCell):
"""
Python object for managing basis functions and quadrature rules of a
simplex reference finite-element cell using FIAT.
@@ -43,7 +43,7 @@
# INVENTORY //////////////////////////////////////////////////////////
- class Inventory(FIATCell.Inventory):
+ class Inventory(ReferenceCell.Inventory):
"""Python object for managing FIATSimplex facilities and properties."""
## @class Inventory
@@ -76,16 +76,55 @@
"""
Constructor.
"""
- FIATCell.__init__(self, name)
+ ReferenceCell.__init__(self, name)
return
+
+ def initialize(self):
+ """
+ Initialize reference finite-element cell.
+ """
+ quadrature = self._setupQuadrature()
+ basisFns = self._setupBasisFns()
+
+ # Evaluate basis functions at quadrature points
+ quadpts = quadrature.get_points()
+ basis = numpy.array(basisFns.tabulate(quadpts)).transpose()
+ self.basis = numpy.reshape(basis.flatten(), basis.shape)
+
+ # Evaluate derivatives of basis functions at quadrature points
+ import FIAT.shapes
+ dim = FIAT.shapes.dimension(basisFns.base.shape)
+ basisDeriv = numpy.array([basisFns.deriv_all(d).tabulate(quadpts) \
+ for d in range(dim)]).transpose()
+ self.basisDeriv = numpy.reshape(basisDeriv.flatten(), basisDeriv.shape)
+
+ self.quadPts = numpy.array(quadrature.get_points())
+ self.quadWts = numpy.array(quadrature.get_weights())
+
+ self.cellDim = dim
+ self.numCorners = len(basisFns)
+ self.numQuadPts = len(quadrature.get_weights())
+
+ self._info.line("Basis (quad pts):")
+ self._info.line(self.basis)
+ self._info.line("Basis derivatives (quad pts):")
+ self._info.line(self.basisDeriv)
+ self._info.line("Quad pts:")
+ self._info.line(quadrature.get_points())
+ self._info.line("Quad wts:")
+ self._info.line(quadrature.get_weights())
+ self._info.log()
+ return
+
+
# PRIVATE METHODS ////////////////////////////////////////////////////
def _configure(self):
"""
Set members based using inventory.
"""
- FIATCell._configure(self)
+ ReferenceCell._configure(self)
self.shape = self.inventory.shape
self.degree = self.inventory.degree
self.order = self.inventory.order
@@ -118,6 +157,7 @@
from FIAT.Lagrange import Lagrange
return Lagrange(self._getShape(), self.degree).Udual.pts
+
def _getShape(self):
"""
Parse string into FIAT shape.
Modified: short/3D/PyLith/trunk/pylith/feassemble/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/__init__.py 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/pylith/feassemble/__init__.py 2007-06-01 21:55:17 UTC (rev 7038)
@@ -16,7 +16,6 @@
__all__ = ['ElasticityExplicit',
'ElasticityImplicit',
- 'FIATCell',
'FIATLagrange',
'FIATSimplex',
'Integrator',
Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/Makefile.am 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/Makefile.am 2007-06-01 21:55:17 UTC (rev 7038)
@@ -20,6 +20,7 @@
check_SCRIPTS = testfeassemble.py
noinst_PYTHON = \
+ TestFIATLagrange.py \
TestFIATSimplex.py \
TestQuadrature.py \
TestIntegrator.py
Added: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATLagrange.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATLagrange.py 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATLagrange.py 2007-06-01 21:55:17 UTC (rev 7038)
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/feassemble/TestFIATLagrange.py
+
+## @brief Unit testing of FIATLagrange object.
+
+import unittest
+import numpy
+from pylith.utils.testarray import test_double
+
+# ----------------------------------------------------------------------
+def N0(p):
+ return (1-p[0])*(1-p[1])/4.0
+
+def N0p(p):
+ return -0.25
+
+def N0q(p):
+ return -0.25
+
+def N1(p):
+ return (1+p[0])*(1-p[1])/4.0
+
+def N1p(p):
+ return +0.25
+
+def N1q(p):
+ return -0.25
+
+def N2(p):
+ return (1+p[0])*(1+p[1])/4.0
+
+def N2p(p):
+ return +0.25
+
+def N2q(p):
+ return +0.25
+
+def N3(p):
+ return (1-p[0])*(1+p[1])/4.0
+
+def N3p(p):
+ return -0.25
+
+def N3q(p):
+ return +0.25
+
+# ----------------------------------------------------------------------
+class TestFIATLagrange(unittest.TestCase):
+ """
+ Unit testing of FIATLagrange object.
+ """
+
+
+ def test_initialize(self):
+ """
+ Test initialize().
+ """
+ from pylith.feassemble.FIATLagrange import FIATLagrange
+ cell = FIATLagrange()
+ cell.degree = 1
+ cell.order = 1
+ quadPtsE = numpy.array( [(-1.0/3**0.5, -1.0/3**0.5),
+ (+1.0/3**0.5, -1.0/3**0.5),
+ (-1.0/3**0.5, +1.0/3**0.5),
+ (+1.0/3**0.5, +1.0/3**0.5)],
+ dtype=numpy.float64 )
+ quadWtsE = numpy.array( [1.0, 1.0, 1.0, 1.0], dtype=numpy.float64 )
+
+ # Compute basis fns and derivatives at quadrature points
+ basis = numpy.zeros( (4, 4), dtype=numpy.float64)
+ basisDeriv = numpy.zeros( (4, 4, 2), dtype=numpy.float64)
+ iQuad = 0
+ for q in quadPtsE:
+ basis[iQuad] = numpy.array([N0(q), N1(q), N2(q), N3(q)],
+ dtype=numpy.float64).reshape( (4,) )
+ deriv = numpy.array([[N0p(q), N0q(q)],
+ [N1p(q), N1q(q)],
+ [N2p(q), N2q(q)],
+ [N3p(q), N3q(q)]],
+ dtype=numpy.float64)
+ basisDeriv[iQuad] = deriv.reshape((4, 2))
+ iQuad += 1
+
+ cell.initialize()
+
+ # Check basic attributes
+ self.assertEqual(2, cell.cellDim)
+ self.assertEqual(4, cell.numCorners)
+ self.assertEqual(4, cell.numQuadPts)
+
+ # Check arrays
+ test_double(self, quadPtsE, cell.quadPts)
+ test_double(self, quadWtsE, cell.quadWts)
+ test_double(self, basis, cell.basis)
+ test_double(self, basisDeriv, cell.basisDeriv)
+
+ return
+
+
+# End of file
Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/testfeassemble.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/testfeassemble.py 2007-06-01 21:54:23 UTC (rev 7037)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/testfeassemble.py 2007-06-01 21:55:17 UTC (rev 7038)
@@ -57,6 +57,9 @@
from TestFIATSimplex import TestFIATSimplex
suite.addTest(unittest.makeSuite(TestFIATSimplex))
+ from TestFIATLagrange import TestFIATLagrange
+ suite.addTest(unittest.makeSuite(TestFIATLagrange))
+
from TestQuadrature import TestQuadrature
suite.addTest(unittest.makeSuite(TestQuadrature))
More information about the cig-commits
mailing list