19.06.2015 Views

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

A FEniCS Tutorial - FEniCS Project

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

instance. In the latter case, a 4th argument is provided to describe which subdomain<br />

number that describes the relevant boundary.<br />

TestFunction(V): define a test function on a space V to be used in a variational<br />

form.<br />

TrialFunction(V): define a trial function on a space V to be used in a<br />

variational form to represent the unknown in a finite element problem.<br />

assemble(X): assemble a matrix, a right-hand side, or a functional, given a<br />

from X written with UFL syntax.<br />

assemble_system(a, L, bcs): assemble the matrix and the right-hand<br />

side from a bilinear (a) and linear (L) form written with UFL syntax. The<br />

bcs parameter holds one or more DirichletBC objects.<br />

LinearVariationalProblem(a, L, u, bcs): define a variational problem,<br />

given a bilinear (a) and linear (L) form, written with UFL syntax, and one or<br />

more DirichletBC objects stored in bcs.<br />

LinearVariationalSolver(problem): create solver object for a linear variational<br />

problem object (problem).<br />

solve(A, U, b): solve a linear system with A as coefficient matrix (Matrix<br />

object), U as unknown (Vector object), and b as right-hand side (Vector object).<br />

Usually, U = u.vector(), where u is a Function object representing the<br />

unknown finite element function of the problem, while A and b are computed<br />

by calls to assemble or assemble_system.<br />

plot(q): quick visualization of a mesh, function, or mesh function q, using<br />

the Viper component in <strong>FEniCS</strong>.<br />

interpolate(func, V): interpolate a formula or finite element function<br />

func onto the function space V.<br />

project(func, V): project a formula or finite element function func onto<br />

the function space V.<br />

7.3 User-Defined Functions<br />

When defining a function in terms of a mathematical expression inside a string<br />

formula, e.g.,<br />

myfunc = Expression(’sin(x[0])*cos(x[1])’)<br />

the expression contained in the first argument will be turned into a C++ functionandcompiledtogainefficiency.<br />

Therefore, thesyntaxusedintheexpression<br />

must be valid C++ syntax. Most Python syntax for mathematical expressions<br />

arealsovalidC++syntax, butpowerexpressionsmakeanexception: p**amust<br />

be written as pow(p,a) in C++ (this is also an alternative Python syntax). The<br />

following mathematical functions can be used directly in C++ expressions when<br />

defining Expression objects: cos, sin, tan, acos, asin, atan, atan2, cosh,<br />

sinh,tanh,exp,frexp,ldexp,log,log10,modf,pow,sqrt,ceil,fabs,floor,<br />

and fmod. Moreover, the number π is available as the symbol pi. All the listed<br />

functions are taken from the cmath C++ header file, and one may hence consult<br />

documentation of cmath for more information on the various functions.<br />

84

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

Saved successfully!

Ooh no, something went wrong!