SyFi  0.3
test_dolfin_integration.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 __authors__ = "Martin Sandve Alnes"
00004 __date__ = "2012-05-16"
00005 
00006 from test_tempdir_base import CompatibilityTestCase
00007 import swiginac
00008 import SyFi
00009 import sfc
00010 from ufl import *
00011 from time import time
00012 import sys
00013 from dolfin import *
00014 
00015 def info(*args):
00016     print " ".join(map(str,args))
00017 
00018 class TestDolfinIntegration(CompatibilityTestCase):
00019 
00020     def setUp(self):
00021         SyFi.initSyFi(3)
00022         dolfin.parameters["form_compiler"]["name"] = "sfc"
00023 
00024     def tearDown(self):
00025         pass
00026 
00027     def test_dolfin_poisson(self):
00028         mesh = UnitSquare(32, 32)
00029         V = FunctionSpace(mesh, "CG", 1)
00030         bc = DirichletBC(V, Constant(0.0),
00031                          lambda x: x[0] < 1e-9 or x[0] > 1.0-1e-9)
00032         v = TestFunction(V)
00033         u = TrialFunction(V)
00034         f = Function(V)
00035         estr = "500.0 * exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)"
00036         f.interpolate(Expression(estr))
00037         a = dot(grad(v), grad(u))*dx
00038         L = v*f*dx
00039         w = Function(V)
00040         solve(a == L, w, bc)
00041 
00042         self.assertLess(w.vector().norm("l2") - 142.420764968, 1e-4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines