SyFi 0.3
|
00001 #!/usr/bin/env python 00002 00003 __authors__ = "Martin Sandve Alnes" 00004 __date__ = "2008-09-04 -- 2008-10-17" 00005 00006 import unittest 00007 import os, sys, glob, shutil, commands 00008 00009 import ufl 00010 from ufl import * 00011 import SyFi 00012 import sfc as sfc 00013 00014 from cell_assembly import assemble_on_cell 00015 00016 00017 def num_integrals(form): 00018 return (form.num_cell_integrals(), form.num_exterior_facet_integrals(), form.num_interior_facet_integrals()) 00019 00020 00021 _test_temp_dir = "temp_dir" 00022 _done_test_temp_dir = "done_temp_dir" 00023 class QuadJitTest(unittest.TestCase): 00024 def __init__(self, *args, **kwargs): 00025 unittest.TestCase.__init__(self, *args, **kwargs) 00026 shutil.rmtree(_done_test_temp_dir, ignore_errors=True) 00027 os.mkdir(_done_test_temp_dir) 00028 00029 def setUp(self): 00030 #print "Running sfc jit test in testdir" 00031 #print "Imported SyFi from location", SyFi.__file__ 00032 #print "Imported sfc from location", sfc.__file__ 00033 self.options = sfc.default_options() 00034 self.options.compilation.cache_dir = os.path.abspath("test_cache") 00035 self.options.code.integral.integration_method = "quadrature" 00036 # Generate code in a clean directory: 00037 shutil.rmtree(_test_temp_dir, ignore_errors=True) 00038 os.mkdir(_test_temp_dir) 00039 os.chdir(_test_temp_dir) 00040 00041 def tearDown(self): 00042 dirs = glob.glob("*") 00043 os.chdir("..") 00044 for d in dirs: 00045 os.rename(os.path.join(_test_temp_dir, d), os.path.join(_done_test_temp_dir, d)) 00046 00047 def testSetup(self): 00048 pass 00049 00050 def testJitMass(self): 00051 "Test the mass matrix." 00052 element = FiniteElement("CG", "triangle", 1) 00053 v = TestFunction(element) 00054 u = TrialFunction(element) 00055 a = u*v*dx 00056 form = sfc.jit(a, options = self.options) 00057 self.assertTrue(form.rank() == 2) 00058 self.assertTrue(form.num_coefficients() == 0) 00059 self.assertTrue(num_integrals(form) == (1,0,0)) 00060 A = assemble_on_cell(form, "triangle", coeffs=[5.43]) 00061 # TODO: Assert correct result 00062 00063 00064 tests = [QuadJitTest] 00065 00066 if __name__ == "__main__": 00067 unittest.main() 00068