[cig-commits] r4624 - short/3D/PyLith/trunk/pylith/feassemble
baagaard at geodynamics.org
baagaard at geodynamics.org
Tue Sep 26 11:19:44 PDT 2006
Author: baagaard
Date: 2006-09-26 11:19:44 -0700 (Tue, 26 Sep 2006)
New Revision: 4624
Added:
short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py
short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py
short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py
short/3D/PyLith/trunk/pylith/feassemble/ReferenceCell.py
Modified:
short/3D/PyLith/trunk/pylith/feassemble/Quadrature.py
Log:
Started filling in use of FIAT for setting up basis functions and quadrature rules.
Added: short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py 2006-09-26 12:20:08 UTC (rev 4623)
+++ short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py 2006-09-26 18:19:44 UTC (rev 4624)
@@ -0,0 +1,83 @@
+#!/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.
+
+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.
+ """
+
+ # 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()
+ self.basis = numpy.array(basisFns.tabulate(quadpts)).transpose()
+
+ # Evaluate derivatives of basis functions at quadrature points
+ # ADD STUFF HERE
+
+ self._info.line("Basis:")
+ self._info.line(self.basis)
+ #print "Basis derivatives:"
+ #print 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
Added: short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py 2006-09-26 12:20:08 UTC (rev 4623)
+++ short/3D/PyLith/trunk/pylith/feassemble/FIATLagrange.py 2006-09-26 18:19:44 UTC (rev 4624)
@@ -0,0 +1,110 @@
+b#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/feassemble/FIATLagrange.py
+
+## @brief Python object for managing basis functions and quadrature
+## rules of a Lagrange reference finite-element cell using FIAT.
+
+from FIATCell import FIATCell
+
+import numpy
+
+def validateDimension(self, dim):
+ if dim < 1 or dim > 3:
+ raise ValueError("Dimension of Lagrange element must be 1, 2, or 3.")
+ return
+
+# FIATLagrange class
+class FIATLagrange(FIATCell):
+ """
+ Python object for managing basis functions and quadrature rules of a
+ Lagrange reference finite-element cell using FIAT.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(FIATCell.Inventory):
+ """Python object for managing FIATLagrange facilities and properties."""
+
+ ## @class Inventory
+ ## Python object for managing FIATLagrange facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b dimension Dimension of finite-element cell
+ ## @li \b degree Degree of finite-element cell
+ ## @li \b quad_order Order of quadrature rule
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ dimension = pyre.inventory.int("dimension", default=3,
+ validator=validateDimension)
+ dimension.meta['tip'] = "Dimension of finite-element cell."
+
+ degree = pyre.inventory.int("degree", default=1)
+ degree.meta['tip'] = "Degree of finite-element cell."
+
+ quadOrder = pyre.inventory.int("quad_order", default=1)
+ quadOrder.meta['tip'] = "Order of quadrature rule."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="fiatlagrange"):
+ """
+ Constructor.
+ """
+ FIATCell.__init__(self, name)
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ FIATCell._configure(self)
+ self.dimension = self.inventory.dimension
+ self.degree = self.inventory.degree
+ self.order = self.inventory.order
+ return
+
+
+ def _setupQuadrature(self):
+ """
+ Setup quadrature rule for reference cell.
+ """
+
+ # ADD STUFF HERE
+ raise NotImplementedError()
+
+ return
+
+
+ def _setupBasisFns(self):
+ """
+ Setup basis functions for reference cell.
+ """
+ from FIAT.Lagrange import Lagrange
+
+ # ADD STUFF HERE
+ raise NotImplementedError()
+
+ return
+
+
+
+# End of file
Added: short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py 2006-09-26 12:20:08 UTC (rev 4623)
+++ short/3D/PyLith/trunk/pylith/feassemble/FIATSimplex.py 2006-09-26 18:19:44 UTC (rev 4624)
@@ -0,0 +1,127 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/feassemble/FIATSimplex.py
+
+## @brief Python object for managing basis functions and quadrature
+## rules of a simplex reference finite-element cell using FIAT.
+
+from FIATCell import FIATCell
+
+import numpy
+
+def validateShape(self, shape):
+ name = shape.lower()
+ if not ("tetrahedron" == name or
+ "triangle" == name or
+ "line" == name):
+ raise ValueError("Unknown shape '%s' for reference finite-element " \
+ "cell.\n" \
+ "Known shapes: 'tetrahedron', 'triangle', 'line'" % \
+ name)
+ return
+
+# FIATSimplex class
+class FIATSimplex(FIATCell):
+ """
+ Python object for managing basis functions and quadrature rules of a
+ simplex reference finite-element cell using FIAT.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(FIATCell.Inventory):
+ """Python object for managing FIATSimplex facilities and properties."""
+
+ ## @class Inventory
+ ## Python object for managing FIATSimplex facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b shape Shape of finite-element cell
+ ## @li \b degree Degree of finite-element cell
+ ## @li \b quad_order Order of quadrature rule
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ shape = pyre.inventory.str("shape", default="tetrahedron",
+ validator=validateShape)
+ shape.meta['tip'] = "Shape of finite-element cell."
+
+ degree = pyre.inventory.int("degree", default=1)
+ degree.meta['tip'] = "Degree of finite-element cell."
+
+ quadOrder = pyre.inventory.int("quad_order", default=1)
+ quadOrder.meta['tip'] = "Order of quadrature rule."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="fiatsimplex"):
+ """
+ Constructor.
+ """
+ FIATCell.__init__(self, name)
+ return
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ FIATCell._configure(self)
+ self.shape = self.inventory.shape
+ self.degree = self.inventory.degree
+ self.order = self.inventory.order
+ return
+
+
+ def _setupQuadrature(self):
+ """
+ Setup quadrature rule for reference cell.
+ """
+ import FIAT.quadrature
+ return FIAT.quadrature.make_quadrature(self._getShape(), self.order)
+
+
+ def _setupBasisFns(self):
+ """
+ Setup basis functions for reference cell.
+ """
+ from FIAT.Lagrange import Lagrange
+ return Lagrange(self._getShape(), self.degree).function_space()
+
+
+ def _getShape(self):
+ """
+ Parse string into FIAT shape.
+ """
+ import FIAT.shapes
+ name = self.shape.lower()
+ if "tetrahedron" == name:
+ shape = FIAT.shapes.TETRAHEDRON
+ elif "triangle" == name:
+ shape = FIAT.shapes.TRIANGLE
+ elif "line" == name:
+ shape = FIAT.shapes.LINE
+ else:
+ raise ValueError("Unknown shape '%s' for reference finite-element " \
+ "cell.\n" \
+ "Known shapes: 'tetrahedron', 'triangle', 'line'" % \
+ name)
+ return shape
+
+
+# End of file
Modified: short/3D/PyLith/trunk/pylith/feassemble/Quadrature.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/Quadrature.py 2006-09-26 12:20:08 UTC (rev 4623)
+++ short/3D/PyLith/trunk/pylith/feassemble/Quadrature.py 2006-09-26 18:19:44 UTC (rev 4624)
@@ -10,17 +10,11 @@
# ----------------------------------------------------------------------
#
-## @file pyre/feassemble/Qudrature.py
+## @file pylith/feassemble/Qudrature.py
## @brief Python abstract base class for integrating over
## finite-elements using quadrature.
-# TODO
-#
-# Use FIAT to create numpy arrays containing basis functions and their
-# derivatives evaludated at the quadrature points and the coordinates
-# and weights of the quadrature points in the reference cell.
-
# DESIGN QUESTION
#
# The dimension of the space associated with the coordinates of
@@ -53,14 +47,18 @@
## @li \b jacobian_tolerance Minimum allowable determinant of Jacobian.
##
## \b Facilities
- ## @li None
+ ## @li \b cell Reference cell with basis functions and quadrature rules
import pyre.inventory
jacobianTol = pyre.inventory.float("jacobian_tolerance", default=1.0e-06)
jacobianTol.meta['tip'] = "Minimum allowable determinant of Jacobian."
+ from CellFIAT import CellFIAT
+ cell = pyre.inventory.facility("cell", factory=CellFIAT)
+ cell.meta['tip'] = "Reference cell with basis fns and quadrature rules."
+
# PUBLIC METHODS /////////////////////////////////////////////////////
def __init__(self, name="quadrature"):
@@ -77,6 +75,8 @@
"""
Initialize C++ quadrature object.
"""
+ self.cell.initialize()
+
# Set minimum allowable determinant of Jacobian
#self.cppHandle.jacobianTol = self.jacobianTol
@@ -93,6 +93,7 @@
"""
Component._configure(self)
self.jacobianTol = self.inventory.jacobianTol
+ self.cell = self.inventory.cell
return
Added: short/3D/PyLith/trunk/pylith/feassemble/ReferenceCell.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/ReferenceCell.py 2006-09-26 12:20:08 UTC (rev 4623)
+++ short/3D/PyLith/trunk/pylith/feassemble/ReferenceCell.py 2006-09-26 18:19:44 UTC (rev 4624)
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/feassemble/ReferenceCell.py
+
+## @brief Python abstract base class for managing basis functions and
+## quadrature rules of a reference finite-element cell.
+
+from pyre.components.Component import Component
+
+# ReferenceCell class
+class ReferenceCell(Component):
+ """
+ Python abstract base class for managing basis functions and
+ quadrature rules of a reference finite-element cell.
+ """
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="referencecell"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="referencecell")
+ self.basis = None
+ self.basisDeriv = None
+ self.quadrature = None
+ return
+
+ def initialize(self):
+ """
+ Initialize reference finite-element cell.
+ """
+ return
+
+
+# End of file
More information about the cig-commits
mailing list