### Nonlinear equation in 1D with periodic boundary condition

136

views

0

This post is about trying to solve the equation

\begin{equation}

0 = -\frac{\partial^2}{\partial x^2}u(x) +\varepsilon u(x) + u^3(x)

\end{equation}

on a one-dimensional torus. The correct solution should be \(u(x)=1\) for \(\varepsilon = -1\) and \(u(x)=0\) for \(\varepsilon = 1\), but I get \(u(x)=0\) in both cases. Where are the problems? Am I abusing FEniCS too much? Thanks!

Basic code is the following:

```
from __future__ import print_function
import matplotlib.pyplot as plt
import fenics as fenics
# Sub domain for periodic boundary condition
class PeriodicBoundary(fenics.SubDomain):
# Left boundary is "target domain" G
def inside(self, x, on_boundary):
return bool(x[0] < fenics.DOLFIN_EPS and x[0] > -fenics.DOLFIN_EPS and on_boundary)
# Map right boundary (H) to left boundary (G)
def map(self, x, y):
y[0] = x[0] - 1.0
# Create periodic boundary condition
pbc = PeriodicBoundary()
# Create mesh and define function space
mesh = fenics.UnitIntervalMesh(32)
V = fenics.FunctionSpace(mesh, 'P', 2, constrained_domain=pbc)
# Define variational problem
u = fenics.Function(V)
v = fenics.TestFunction(V)
f = fenics.Constant(0)
epsilon = -1.
F = fenics.dot(fenics.grad(u), fenics.grad(v)) * fenics.dx + epsilon * u * v * fenics.dx + (u ** 3) * v * fenics.dx - f * v * fenics.dx
# Compute solution
fenics.solve(F == 0, u, [])
# Plot solution
fenics.plot(u)
plt.xlim(0, 1)
plt.tight_layout()
plt.savefig('nonlinear_periodic.pdf')
```

Community: FEniCS Project

Have you tried a non-zero initial guess?

written
3 months ago by
Nate

Please login to add an answer/comment or follow this question.