13.07.2015 Views

UFL Specification and User Manual 0.3 - FEniCS Project

UFL Specification and User Manual 0.3 - FEniCS Project

UFL Specification and User Manual 0.3 - FEniCS Project

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>UFL</strong> <strong>Specification</strong> <strong>and</strong> <strong>User</strong> <strong>Manual</strong> <strong>0.3</strong>Martin S. Alnæs, Anders Loggformation rules for the types you wish to h<strong>and</strong>le.Shown here is maybe the simplest transformer possible:class Printer(Transformer):def __init__(self):Transformer.__init__(self)def expr(self, o, *oper<strong>and</strong>s):print "Visiting", str(o), "with oper<strong>and</strong>s:"print ", ".join(map(str,oper<strong>and</strong>s))return oelement = FiniteElement("CG", triangle, 1)v = TestFunction(element)u = TrialFunction(element)a = u*vp = Printer()p.visit(a)The call to visit will traverse a <strong>and</strong> call Printer.expr on all expressionnodes in post–order, with the argument oper<strong>and</strong>s holding the return valuesfrom visits to the oper<strong>and</strong>s of o. The output is:TODOImplementing expr above provides a default h<strong>and</strong>ler for any expression nodetype. For each subclass of Expr you can define a h<strong>and</strong>ler function to overridethe default by using the name of the type in underscore notation, e.g.basis function for BasisFunction. The constructor of Transformer <strong>and</strong>implementation of Transformer.visit h<strong>and</strong>les the mapping from type toh<strong>and</strong>ler function automatically.Here is a simple example to show how to override default behaviour:85

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!