Home - apusok/FD-PDE GitHub Wiki
FD-PDE Framework - Wiki
This wiki covers the FD-PDE Framework developed for magma dynamics and other applications in geodynamics. The FD-PDE framework is built on top of PETSc, which provides access to fast, parallel objects for vectors, grids (DMs), and non-linear solvers. Currently, FD-PDE framework supports 1-D and 2-D applications.
Note: use Safari or Firefox for best rendering of LaTeX equations in the tutorials, instead of Google Chrome.
Contents
Overview
The FD-PDE framework uses the finite difference staggered grid method for discretisation of partial differential equations (PDE) --- thus, providing easy access to PDE-type objects. It largely uses the DMStag object for staggered grids.
Finite difference (FD) discretization on staggered grids is a simple and stable discretization, has a low-order stencil (meaning it is fast and cheap to solve), and can deal efficiently with large variations in coefficients (i.e., viscosity). The FD-PDE framework here intends to provide access to parallel PDE objects discretized internally, in order to
- separate the USER input from the discretization of PDEs,
- allow the USER to focus on the physics, and less on numerical discretisation,
- allow for extensible development (easy additions later on),
- allow for a robust framework for testing,
- allow for customized, modular applications.
Staggered grid geometry and location of degrees of freedom (dofs) for a Stokes problem:
Notice that variables are not co-located on the grid (i.e., pressure P is located in volume center points, while velocity [Vx, Vy] is located on face center points). The DMStag object in PETSc allows easy access to the staggered grid layout:
The figure above shows the DMStag names of each location within one 2-D grid cell (note that a LEFT dof may be a RIGHT dof in the neighbouring cell etc.) — these names will show up a lot in every code. While each FD-PDE object has its own stencil, sometimes it is useful to create additional vectors/dms for variables located in other locations of the grid.
Code development in FD-PDE/PETSc
Compared to high-level programming languages such as python
and matlab
, programming in C requires careful memory operations (allocate, use, free) and correct pointer assignments --- these two are the most common source of errors. Exposure to errors, experience, but also good practice will improve your programming skills in C.
Tips
- Make sure every code compilation is without errors and warnings. If your code does not compile, it will not run. Why fix warnings as well? Warnings are future errors.
- Memory allocation: if you create something, you have to destroy it after usage. If you allocate memory, you need to free it later. Objects are destroyed in the same order as they are created. Use
-log_view
for default profilling with PETSc. - Build code (and run) from simple to complex. Have a non-syntax error? Simplify the problem.
- Check every operation, pointer assignment, and test every routine. There are existing debuggers (GDB, LLDB), but everyone agrees the best debugger is
PetscPrintf();
- Use the manual and example codes for both FD-PDE and PETSc to help you with code development.