How to use analytical solutions?

code (Error control):

def u_ex(mod):
    return lambda x: mod.cos(2*mod.pi*x[0])*mod.cos(2*mod.pi*x[1])

https://jsdokken.com/dolfinxtutorial/chapter4/convergence.html)

So from what I gathered it the function is meant to make use of an analytical solution for u. There is also a description in Chapter 20 of dolfinx book where a different forumulation of analytical solution is shewn for Navier stokes where there is also an analytical solution for f, u and rho where the u_ex code shewn it here is said to be for poisson’s.

So then the first question I have is since in both cases a 2D representation is being used to display analytical solutions is there a different analytical formulation for a 3D problem?

Also I looked around for more information on how these analytical solutions get formulated. So far I found a bit of talk about them here:

Detailed Explanation of the Finite Element Method (FEM).

Is there a place to look to as a reference or manual how to develop analytic solutions like this for use with dolfinx for all the different types of problems that may arise?

Any introductory course on partial differential equations should equip you with the skills to form a manufactured solution.

As a classic example, consider the Poisson problem. Let \Omega = (0, 1)^2 such that we seek u: \Omega \rightarrow \mathbb{R} which satisfies

\begin{align} - \nabla^2 u &= f &&\text{in } \Omega, \\ u &= 0 &&\text{on } \partial \Omega, \end{align}

where f is to be determined.

First we must choose a function u which satisfies the boundary conditions and is at least twice differentiable u \in C^2(\Omega). Arbitrarily we choose the function

u = \sin(\pi x) \sin(\pi y).

Now we may determine f by inserting into the original equation

f = -\nabla^2 (\sin(\pi x) \sin(\pi y)) = 2 \pi^2 \sin(\pi x) \sin(\pi y).

And we’re done. We have our problem defined for the manufactured solution.

You can follow through the same process for the cube \Omega = (0, 1)^3 where you should see, for example,

\begin{align} u &= \sin(\pi x) \sin(\pi y) \sin(\pi z), \\ f &= 3 \pi^2 \sin(\pi x) \sin(\pi y) \sin(\pi z). \end{align}
2 Likes