# Fenics: time-independent Sine-Gordon equation

Is there a code for the equation $$\frac{\partial^2u}{\partial x^2}+\frac{\partial^2u}{\partial y^2} = \sin(u)$$ or for the sine gordon equation in two dimensions because I want to change some boundary values to see the results?

• Hi @jessie, welcome to scicomp! The $\theta$-notation is a little weird, but other than that this looks very much like the Poisson equation -- the basic starting example for many numerical methods. Check out fenicsproject.org/documentation/dolfin/1.2.0/python/demo/pde/…. – Nico Schlömer May 22 '13 at 11:59
• I've taken the liberty to change the $\theta$ to $\partial$ according to standard notation, because I assumed that was just to avoid MathJax. Feel free to change back if that was incorrect. – Christian Clason May 22 '13 at 14:11
• Actually, it's not the Poisson equation since it's not linear in $u$ (it appears in the $\sin$ on the right-hand side). – Christian Clason May 22 '13 at 14:12
• @ChristianClason: Yes, but corresponding fixed point iteration $\Delta u_{n+1} = \sin(u_n)$ is Poisson equation - I don't say whether it converges or not. Similiarly applying Newton method would result in reaction-diffusion equation. – Jan Blechta May 22 '13 at 15:35

That's actually very easy to do in Dolfin:

from dolfin import *
# define mesh, function space (piecewise linear)
mesh = UnitSquareMesh(64,64)
V = FunctionSpace(mesh,'CG',1)
# inhomogeneous boundary conditions (otherwise the solution is trivial)
bc = DirichletBC(V, Constant(1.0), lambda x,on_boundary: on_boundary)
# define bi(non)linear form
# note that nonlinear problems need u to be a Function, not TestFunction
u = Function(V)
v = TestFunction(V)

There is also a nonlinear-poisson demo in the demo/undocumented directory, which also shows how to enter define more complicated nonlinear forms and thow to control the solver parameters.
• That just defines an anonymous function that returns True if the point x lies on the boundary; such a function (or a class implementing this function) is how FEniCS expects the part of the boundary where the condition should be imposed to be specified. – Christian Clason May 23 '13 at 16:44
• @jessie: lambda is python keyword - see docs.python.org/2/reference/expressions.html#lambda for description. – Jan Blechta May 23 '13 at 20:57