diff --git a/python/dune/perftool/compile.py b/python/dune/perftool/compile.py index 7e09f2fe96794c283ccfa61f06ce33af907e8006..ec456ec942f5477f6feb7b6d7cf52cce935d4d4a 100644 --- a/python/dune/perftool/compile.py +++ b/python/dune/perftool/compile.py @@ -45,9 +45,9 @@ def read_ufl(uflfile): try: exec("from dune.perftool.ufl.execution import *\n" + uflcode, namespace) except: - basename = os.path.splitext(os.path.basename(uflfile))[0] - basename = "{}_debug".format(basename) - pyname = "{}.py".format(basename) + name = splitext(basename(uflfile))[0] + name = "{}_debug".format(name) + pyname = "{}.py".format(name) print(pyname) pycode = "#!/usr/bin/env python\nfrom dune.perftool.ufl.execution import *\nset_level(DEBUG)\n" + uflcode with file(pyname, "w") as f: diff --git a/python/dune/perftool/pdelab/__init__.py b/python/dune/perftool/pdelab/__init__.py index 6bbde90cae5fffbb4cb34871340402f5b3ab1474..9cdd9607cd21ac6afe6e47f12efea7e5341e09dd 100644 --- a/python/dune/perftool/pdelab/__init__.py +++ b/python/dune/perftool/pdelab/__init__.py @@ -23,6 +23,7 @@ from dune.perftool.pdelab.parameter import (cell_parameter_function, intersection_parameter_function, ) from dune.perftool.pdelab.quadrature import (pymbolic_quadrature_weight, + pymbolic_quadrature_position_in_cell, quadrature_inames, ) from dune.perftool.pdelab.spaces import (lfs_inames, @@ -84,6 +85,9 @@ class PDELabInterface(object): # Geometry related generator functions # + def pymbolic_spatial_coordinate(self, restriction): + return pymbolic_quadrature_position_in_cell(restriction) + def name_facet_jacobian_determinant(self): return name_facet_jacobian_determinant() diff --git a/python/dune/perftool/ufl/visitor.py b/python/dune/perftool/ufl/visitor.py index c1c9c8659af11007ed2cd904a6a601920cf31aab..18a6533083119b84c4fdba2638a67ae761924251 100644 --- a/python/dune/perftool/ufl/visitor.py +++ b/python/dune/perftool/ufl/visitor.py @@ -235,12 +235,18 @@ class UFL2LoopyVisitor(ModifiedTerminalTracker): if isinstance(o.ufl_operands[0], JacobianDeterminant): return self.call(o.ufl_operands[0]) else: - return Call('abs', self.call(o.ufl_operands[0])) + return Call(Variable('abs'), (self.call(o.ufl_operands[0]),)) + + def exp(self, o): + return Call(Variable('exp'), (self.call(o.ufl_operands[0]),)) # # Handlers for geometric quantities # + def spatial_coordinate(self, o): + return self.interface.pymbolic_spatial_coordinate(self.restriction) + def facet_normal(self, o): # The normal must be restricted to be well-defined assert self.restriction is not Restriction.NONE diff --git a/test/poisson/poisson.ufl b/test/poisson/poisson.ufl index 8c62dd3a24d2f64a3aec350c2096fd65967498d8..68c89a95f0378127fa81a1f0605ab2ee546f28c4 100644 --- a/test/poisson/poisson.ufl +++ b/test/poisson/poisson.ufl @@ -1,8 +1,13 @@ -f = Expression("Dune::FieldVector<double,2> c(0.5); c-= x; return 4.*(1.-c.two_norm2())*std::exp(-1.*c.two_norm2());") +#f = Expression("Dune::FieldVector<double,2> c(0.5); c-= x; return 4.*(1.-c.two_norm2())*std::exp(-1.*c.two_norm2());") g = Expression("Dune::FieldVector<double,2> c(0.5); c-= x; return std::exp(-1.*c.two_norm2());") +cell = triangle -V = FiniteElement("CG", "triangle", 1, dirichlet_expression=g) +V = FiniteElement("CG", cell, 1, dirichlet_expression=g) u = TrialFunction(V) v = TestFunction(V) +x = SpatialCoordinate(cell) + +f = exp(-1*(x[0]-0.5)) + forms = [(inner(grad(u), grad(v)) - f*v)*dx]