Based on this post over at the Computational Science StackExchange, I had left myself a note here to write a post on how easy it is to make divergence-free fields for use as manufactured solutions for testing incompressible Navier-Stokes solvers, but since the original poster went ahead and asked the question directly, I answered it.
Some background might be in order. The incompressible Navier-Stokes equations are often written:
$$
\begin{align}
\frac{\partial\boldsymbol{u}}{\partial t} + \boldsymbol{u}\cdot\nabla\boldsymbol{u} &= -\frac{1}{\rho}\nabla p + \nu\nabla^2\boldsymbol{u} + \boldsymbol{f} \\
\nabla \cdot \boldsymbol{u} &= 0
\end{align}
$$
These are the classical equations of fluid mechanics for fluids that don't compress very much (like water). This condition is represented by the second equation above and is the force behind making them somewhat tricky to solve (analytically and numerically). The other thing that makes these equations tricky to solve, is the non-linear term in the first equation: \( \boldsymbol{u}\cdot\nabla\boldsymbol{u} \).
When we computer jocks want test the validity of our programs for approximating these equations, we would really like to have some known correct answers to compare our numerical solutions to. Unfortunately, the non-linearity and incompressibility condition conspire to make it hard to come up with a good set of exact solutions to compare to. It is, in fact, an open problem with a substantial prize behind it to determine whether such solutions even exist, or if they do, under what conditions.
The Method of Manufactured Solutions (PDF) is a technique for generating exact solutions to compare your numerical method results to. With MMS, you pick (virtually) any function you like \(\boldsymbol{u}\), substitute it into the governing equations, and solve for the \(\boldsymbol{f}\) that makes that \(\boldsymbol{u}\) a solution. Since \(\boldsymbol{f}\) was a tunable knob in your code that allowed you to solve different kinds of problems, it's a place for making adjustments for testing it, too.
This method works great when every equation you want to solve has a convenient forcing term like \(\boldsymbol{f}\), but as we can see above, not every equation does. Sometimes you get lucky though, and you can create a solution that satisfies the homogenous equation exactly and can be plugged into the other equation to find the right forcing term.
In this case, the choice is to either pick your favorite (sufficiently differentiable) vector field, and take its curl, or pick your two favorite scalar functions and take the cross product of their gradients. That is, either take
$$
\boldsymbol{u} = \nabla \times \boldsymbol{A}
$$
or$$
\boldsymbol{u} = \nabla g \times \nabla h
$$
and crank it all through.
I highly recommend a symbolic manipulation program for this, though. There's lots of room for mistakes.
No comments:
Post a Comment