SyFi  0.3
test_jit_volumes.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 __authors__ = "Martin Sandve Alnes"
00004 __date__ = "2008-09-04 -- 2012-05-16"
00005 
00006 import unittest
00007 import os, sys, glob, shutil, commands
00008 
00009 import ufl
00010 
00011 from ufl import FiniteElement
00012 from ufl import VectorElement
00013 from ufl import TensorElement
00014 from ufl import MixedElement
00015 
00016 from ufl import Argument
00017 from ufl import TestFunction
00018 from ufl import TrialFunction
00019 
00020 from ufl import Coefficient
00021 from ufl import Constant
00022 
00023 from ufl import dx, ds
00024 
00025 import SyFi
00026 import sfc as sfc
00027 
00028 from test_tempdir_base import TempDirTestBase
00029 from cell_assembly import assemble_on_cell, cell2volume, num_integrals
00030 
00031 class VolumeTest(TempDirTestBase):
00032     def __init__(self, *args, **kwargs):
00033         TempDirTestBase.__init__(self, *args, **kwargs)
00034 
00035     def setUp(self):
00036         TempDirTestBase.setUp(self)
00037 
00038     def tearDown(self):
00039         TempDirTestBase.tearDown(self)
00040 
00041     def testSetup(self):
00042         "Just see that setUp and tearDown works."
00043         pass
00044 
00045     def _testJitVolume(self, polygon):
00046         """Test that the integral of 1.0 over a unit cell
00047         equals the length/area/volume of the unit cell."""
00048         c = Constant(polygon)
00049         a = c*dx
00050         form, module, formdata, prefix = sfc.jit(a, parameters = self.options)
00051 
00052         self.assertTrue(form.rank() == 0)
00053         self.assertTrue(form.num_coefficients() == 1)
00054         self.assertTrue(num_integrals(form) == (1,0,0))
00055         A = assemble_on_cell(form, polygon, coeffs=[1.0])
00056         self.assertAlmostEqual(A, cell2volume[polygon])
00057 
00058     def testJitVolumeInterval(self):
00059         self._testJitVolume("interval")
00060 
00061     def testJitVolumeTriangle(self):
00062         self._testJitVolume("triangle")
00063 
00064     def xtestJitVolumeTetrahedron(self): # FIXME: Failing!
00065         self._testJitVolume("tetrahedron")
00066 
00067     def _testJitVolumeQuadrilateral(self): # Not supported by dolfin yet
00068         self._testJitVolume("quadrilateral")
00069 
00070     def _testJitVolumeHexahedron(self): # Not supported by dolfin yet
00071         self._testJitVolume("hexahedron")
00072 
00073     def _testJitConstant(self, polygon, degree):
00074         """Test that the integral of a constant coefficient over a unit
00075         cell mesh equals the constant times the volume of the unit cell."""
00076         element = FiniteElement("CG", polygon, degree)
00077         f = Coefficient(element)
00078         a = f*dx
00079         form, module, formdata, prefix = sfc.jit(a, parameters = self.options)
00080 
00081         self.assertTrue(form.rank() == 0)
00082         self.assertTrue(form.num_coefficients() == 1)
00083         self.assertTrue(num_integrals(form) == (1,0,0))
00084         const = 1.23
00085         A = assemble_on_cell(form, polygon, coeffs=[const])
00086         self.assertAlmostEqual(A, const*cell2volume[polygon])
00087 
00088     def testJitConstantInterval(self):
00089         polygon = "interval"
00090         self._testJitConstant(polygon, 1)
00091         self._testJitConstant(polygon, 2)
00092 
00093     def testJitConstantTriangle(self):
00094         polygon = "triangle"
00095         self._testJitConstant(polygon, 1)
00096         self._testJitConstant(polygon, 2)
00097 
00098     def xtestJitConstantTetrahedron(self): # FIXME: Failing!
00099         polygon = "tetrahedron"
00100         self._testJitConstant(polygon, 1)
00101         self._testJitConstant(polygon, 2)
00102 
00103     def _testJitConstantQuadrilateral(self): # Not supported by dolfin yet
00104         polygon = "quadrilateral"
00105         self._testJitConstant(polygon, 1)
00106         self._testJitConstant(polygon, 2)
00107 
00108     def _testJitConstantHexahedron(self): # Not supported by dolfin yet
00109         polygon = "hexahedron"
00110         self._testJitConstant(polygon, 1)
00111         self._testJitConstant(polygon, 2)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines