Hi everyone,
I am new to FEniCS and currently I am trying to learn the basics on available examples.
When I was playing with the ft01 example (Poisson equation with Dirichlet conditions) I realized that when the number of mesh cells is increased even slightly from the default number, the solution is breaking down.
For n = 10 (number of cells in a horizontal and vertical direction) I received correct output:
but for higher numers, for example n = 15 the output is rather different and obviously not correct:
I have no idea why this strange behaviour occurs. Therefore the question is: Did I make an error when modifying the original code to run it in the Jupyter Lab or is something wrong with my installation of FEniCS?
The code I am running looks like this:
from __future__ import print_function
from fenics import *
import numpy as np
import matplotlib.pyplot as plt
def boundary(x, on_boundary):
return on_boundary
# Create mesh and define function space
n = 15
mesh = UnitSquareMesh(n, n)
V = FunctionSpace(mesh, 'CG', 1)
# Define boundary condition
u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)
bc = DirichletBC(V, u_D, boundary)
# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx
# Compute solution
u = Function(V)
solve(a == L, u, bc)
# Plot solution and mesh
plt.colorbar(plot(u))
plt.rcParams["figure.figsize"] = (5, 5)
The version of FEniCS: 2018.1.0
Installation: through Anaconda on Ubuntu on Windows. I run the code in Jupyter Lab.