This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to represent nabla**2 and nabla symbols in Fenics

+1 vote

Hi; I can't find a PDE example which has

$$ -au \nabla^2 - b(I)u*nabla +c = 0 $$

so that the first term is the second order differential in three dimensions of u, the second is an imaginary term of the first order differential of u times a constant b and the last is a constant c.

Is there an example in the list that is similar to this?

asked Jul 7, 2017 by SergioM FEniCS Novice (150 points)

1 Answer

+1 vote

You have written the equation in "strong form". The finite element method uses a "weak" or "variational" formulation. I suggest you look at a primer on FEM.

answered Jul 8, 2017 by chris_richardson FEniCS Expert (31,740 points)

Hi Chris, I have heard of the variational or "eak form before, but I am not sure how it looks like in Fenics terms. Is there an example that includes either of these terms?

Try this:
https://fenicsproject.org/pub/tutorial/pdf/fenics-tutorial-vol1.pdf

Your question is answered in Chapter 2.

Hi Nate. Thanks. I found this example on p 17 in chapter 2.

Create mesh and define function space
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, ’P’, 1)

Define boundary condition

u_D = Expression(’1 + x[0]x[0] + 2x[1]*x[1]’, degree=2)
def boundary(x, on_boundary):
return on_boundary
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

plot(u)
plot(mesh)

Save solution to file in VTK format

vtkfile = File(’poisson/solution.pvd’)
vtkfile << u
18
2 Fundamentals: Solving the Poisson equation

Compute error in L2 norm

error_L2 = errornorm(u_D, u, ’L2’)

Compute maximum error at vertices

vertex_values_u_D = u_D.compute_vertex_values(mesh)
vertex_values_u = u.compute_vertex_values(mesh)
import numpy as np
error_max = np.max(np.abs(vertex_values_u_D - vertex_values_u))

Print errors

print(’error_L2 =’, error_L2)
print(’error_max =’, error_max)

Hold plot

interactive()

How should it look like if I replace the PDE given here by $$ -au \nabla^2 - b(I)u*nabla +c = 0 $$ ?

Thanks!

Keep reading. It's clear that you're lacking the fundamentals of FEM analysis. Even if I were to state the weak formulation for you, that's only a tiny part of the process. The tutorial above is a good, gentle introduction.

...