SyFi  0.3
test_sfc.test_form_argument_code.FormArgumentTestMixin Class Reference
Inheritance diagram for test_sfc.test_form_argument_code.FormArgumentTestMixin:
test_sfc.test_form_argument_code.SfcQuadratureFormArgumentTest test_sfc.test_form_argument_code.SfcSymbolicFormArgumentTest test_sfc.test_form_argument_code.UflacsFormArgumentTest

List of all members.

Public Member Functions

def assertAlmostEqualNumpy
def assertAssembledAlmostEqual
def xtest_constant_interval
def xtest_constant_triangle
def xtest_constant_tetrahedron
def xtest_constants_interval
def xtest_constants_triangle
def xtest_constants_tetrahedron
def xtest_vector_constant_interval
def xtest_vector_constant_triangle
def xtest_vector_constant_tetrahedron
def xtest_tensor_constant_interval
def xtest_tensor_constant_triangle
def xtest_tensor_constant_tetrahedron
def xtest_coefficients_interval
def xtest_coefficients_triangle
def xtest_coefficients_tetrahedron
def xtest_coefficients_quadrilateral
def xtest_coefficients_hexahedron
def test_code_snippets

Private Member Functions

def _test_constant
def _test_constant_quadrilateral
def _test_constant_hexahedron
def _test_constants
def _test_constants_quadrilateral
def _test_constants_hexahedron
def _test_vector_constant
def _test_vector_constant_quadrilateral
def _test_vector_constant_hexahedron
def _test_tensor_constant
def _test_tensor_constant_quadrilateral
def _test_tensor_constant_hexahedron
def _test_coefficients
def _test_coefficient

Detailed Description

Definition at line 145 of file test_form_argument_code.py.


Member Function Documentation

def test_sfc.test_form_argument_code.FormArgumentTestMixin._test_coefficient (   self,
  cell,
  family = "CG",
  degree = 1 
) [private]

Definition at line 269 of file test_form_argument_code.py.

References test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAssembledAlmostEqual().

Referenced by test_sfc.test_form_argument_code.FormArgumentTestMixin._test_coefficients().

00269 
00270     def _test_coefficient(self, cell, family="CG", degree=1):
00271         "Test that a single coefficient is handled correctly."
00272         D = cell2volume[cell]
00273         V = FiniteElement(family, cell, degree)
00274         c = Coefficient(V)
00275         a = c*dx
00276         coeffs = [1.2]
00277         expected = 1.2 * D
00278         self.assertAssembledAlmostEqual(a, cell, coeffs, expected)

Definition at line 183 of file test_form_argument_code.py.

References test_sfc.test_form_argument_code.FormArgumentTestMixin._test_constant().

00183 
00184     def _test_constant_hexahedron(self): # TODO: Not supported by dolfin yet
00185         self._test_constant(ufl.hexahedron)
00186 

Definition at line 187 of file test_form_argument_code.py.

References test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAssembledAlmostEqual().

Referenced by test_sfc.test_form_argument_code.FormArgumentTestMixin._test_constants_hexahedron(), test_sfc.test_form_argument_code.FormArgumentTestMixin._test_constants_quadrilateral(), test_sfc.test_form_argument_code.FormArgumentTestMixin.xtest_constants_interval(), test_sfc.test_form_argument_code.FormArgumentTestMixin.xtest_constants_tetrahedron(), and test_sfc.test_form_argument_code.FormArgumentTestMixin.xtest_constants_triangle().

00187 
00188     def _test_constants(self, cell):
00189         "Test that multiple constants are handled correctly."
00190         D = cell2volume[cell]
00191         c1 = Constant(cell)
00192         c2 = Constant(cell)
00193         c3 = Constant(cell)
00194         a = c1*c2*c3*dx
00195         coeffs = [2,3,5]
00196         expected = coeffs[0]*coeffs[1]*coeffs[2] * D
00197         self.assertAssembledAlmostEqual(a, cell, coeffs, expected)

Definition at line 207 of file test_form_argument_code.py.

References test_sfc.test_form_argument_code.FormArgumentTestMixin._test_constants().

00207 
00208     def _test_constants_hexahedron(self): # TODO: Not supported by dolfin yet
00209         self._test_constants(ufl.hexahedron)
00210 

Definition at line 233 of file test_form_argument_code.py.

References test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAssembledAlmostEqual().

Referenced by test_sfc.test_form_argument_code.FormArgumentTestMixin._test_tensor_constant_hexahedron(), test_sfc.test_form_argument_code.FormArgumentTestMixin._test_tensor_constant_quadrilateral(), test_sfc.test_form_argument_code.FormArgumentTestMixin.xtest_tensor_constant_interval(), test_sfc.test_form_argument_code.FormArgumentTestMixin.xtest_tensor_constant_tetrahedron(), and test_sfc.test_form_argument_code.FormArgumentTestMixin.xtest_tensor_constant_triangle().

00233 
00234     def _test_tensor_constant(self, cell):
00235         "Test that a tensor valued constant is handled correctly."
00236         D = cell2volume[cell]
00237         c = TensorConstant(cell)
00238         sh = c.shape()
00239         a = sum(c[i,j] for i in range(sh[0]) for j in range(sh[1]))*dx
00240         rows = ( (1.1,1.2,1.3)[:sh[0]],
00241                  (2.1,2.2,2.3)[:sh[0]],
00242                  (3.1,3.2,3.3)[:sh[0]] )[:sh[1]]
00243         coeffs = [rows]
00244         expected = D * sum(rows[i][j] for i in range(sh[0]) for j in range(sh[1]))
00245         self.assertAssembledAlmostEqual(a, cell, coeffs, expected)

def test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAlmostEqualNumpy (   self,
  actual,
  expected,
  eps = 1e-8 
)

Definition at line 147 of file test_form_argument_code.py.

Referenced by test_sfc.test_geometry_code.GeometryTestMixin.assertAssembledAlmostEqual(), and test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAssembledAlmostEqual().

00147 
00148     def assertAlmostEqualNumpy(self, actual, expected, eps=1e-8):
00149         self.assertEqual(actual.shape, expected.shape)
00150         mdiff = expected - actual
00151         vdiff = mdiff.reshape((product(mdiff.shape),))
00152         sdiff = numpy.dot(vdiff,vdiff)
00153         self.assertAlmostEqual(sdiff, 0.0, eps)

def test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAssembledAlmostEqual (   self,
  ufl_form,
  ufl_cell,
  coeffs,
  expected 
)
Test that the integral of 1.0 over a unit cell
equals the length/area/volume of the unit cell.

Definition at line 154 of file test_form_argument_code.py.

References test_sfc::cell_assembly.assemble_on_cell(), test_sfc.test_form_argument_code.FormArgumentTestMixin.assertAlmostEqualNumpy(), and test_sfc.test_tempdir_base.TempDirTestBase.options.

Referenced by test_sfc.test_form_argument_code.FormArgumentTestMixin._test_coefficient(), test_sfc.test_geometry_code.GeometryTestMixin._test_constant(), test_sfc.test_form_argument_code.FormArgumentTestMixin._test_constant(), test_sfc.test_form_argument_code.FormArgumentTestMixin._test_constants(), test_sfc.test_geometry_code.GeometryTestMixin._test_coordinates(), test_sfc.test_form_argument_code.FormArgumentTestMixin._test_tensor_constant(), test_sfc.test_form_argument_code.FormArgumentTestMixin._test_vector_constant(), and test_sfc.test_geometry_code.GeometryTestMixin._test_volume().

00154 
00155     def assertAssembledAlmostEqual(self, ufl_form, ufl_cell, coeffs, expected):
00156         """Test that the integral of 1.0 over a unit cell
00157         equals the length/area/volume of the unit cell."""
00158         ufc_form, module, formdata, prefix = sfc.jit(ufl_form, parameters=self.options)
00159         assembled = assemble_on_cell(ufc_form, ufl_cell, coeffs=coeffs)
00160         if isinstance(assembled, float):
00161             self.assertAlmostEqual(assembled, expected)
00162         else:
00163             self.assertAlmostEqualNumpy(assembled, expected)
00164 

Definition at line 293 of file test_form_argument_code.py.

00293 
00294     def test_code_snippets(self):
00295         print
00296         cell = ufl.triangle
00297 
00298         # Mock up a formrep object
00299         class Mock(object): pass
00300         formrep = Mock()
00301         formrep.geomrep = Mock()
00302         formrep.geomrep.sfc_cell = Mock()
00303         formrep.geomrep.sfc_cell.nsd = cell.d
00304 
00305         facg = FormArgumentCG(formrep, on_facet=False)
00306 
00307         S = FiniteElement("CG", cell, 1)
00308         u = Argument(S, count=1)
00309         f = Coefficient(S, count=2)
00310         print
00311         print facg.gen_argument_name(u, (), (), None)
00312         print facg.gen_argument_name(u, (0,), (), None)
00313         print facg.gen_coefficient_name(f, (), (), None)
00314         print facg.gen_coefficient_name(f, (0,), (), None)
00315         print
00316 
00317         V = VectorElement("CG", cell, 1)
00318         v = Argument(V, count=1)
00319         g = Coefficient(V, count=2)
00320         print
00321         print facg.gen_argument_name(v, (), (0,), None)
00322         print facg.gen_argument_name(v, (0,), (1,), None)
00323         print facg.gen_coefficient_name(g, (), (0,), None)
00324         print facg.gen_coefficient_name(g, (0,), (1,), None)
00325         print
00326 
00327         T = TensorElement("CG", cell, 1)
00328         w = Argument(T, count=1)
00329         h = Coefficient(T, count=2)
00330         print
00331         print facg.gen_argument_name(w, (), (0,1), None)
00332         print facg.gen_argument_name(w, (0,), (1,0), None)
00333         print facg.gen_coefficient_name(h, (), (0,1), None)
00334         print facg.gen_coefficient_name(h, (0,), (1,0), None)
00335         print
00336 
00337         print


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines