From 48b6589f85d06d5967868ba15425e15df43619a2 Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Mon, 7 Nov 2016 22:17:12 +0100 Subject: [PATCH] Some initial work on symbolic parameter functions --- python/dune/perftool/compile.py | 6 +++--- python/dune/perftool/pdelab/__init__.py | 4 ++++ python/dune/perftool/ufl/visitor.py | 8 +++++++- test/poisson/poisson.ufl | 9 +++++++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/python/dune/perftool/compile.py b/python/dune/perftool/compile.py index 7e09f2fe..ec456ec9 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 6bbde90c..9cdd9607 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 c1c9c865..18a65330 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 8c62dd3a..68c89a95 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] -- GitLab