Debian Codegraph @

demo/undocumented/gmg-poisson/cpp/Poisson.ufl

raw
1 # UFL input for the Poisson equation
2 # ==================================
3 #
4 # The first step is to define the variational problem at hand. We define
5 # the variational problem in UFL terms in a separate form file
6 # :download:`Poisson.ufl`. We begin by defining the finite element::
7
8 from ufl_legacy import (Coefficient, ds, dx, FiniteElement,
9 inner, grad,
10 triangle, TestFunction, TrialFunction)
11
12 element = FiniteElement("Lagrange", triangle, 1)
13
14 # The first argument to :py:class:`FiniteElement` is the finite element
15 # family, the second argument specifies the domain, while the third
16 # argument specifies the polynomial degree. Thus, in this case, our
17 # element ``element`` consists of first-order, continuous Lagrange basis
18 # functions on triangles (or in order words, continuous piecewise linear
19 # polynomials on triangles).
20 #
21 # Next, we use this element to initialize the trial and test functions
22 # (:math:`u` and :math:`v`) and the coefficient functions (:math:`f` and
23 # :math:`g`)::
24
25 u = TrialFunction(element)
26 v = TestFunction(element)
27 #f = Coefficient(element)
28 #g = Coefficient(element)
29
30 # Finally, we define the bilinear and linear forms according to the
31 # variational formulation of the equations::
32
33 a = inner(grad(u), grad(v))*dx
34 L = v*dx #+ g*v*ds
35
36 # Before the form file can be used in the C++ program, it must be
37 # compiled using FFC by running (on the command-line):
38 #
39 # .. code-block:: sh
40 #
41 # ffc -l dolfin Poisson.ufl