| 1 | /* ------------------------------------------------------------------------
|
|---|
| 2 |
|
|---|
| 3 | Solid Fuel Ignition (SFI) problem. This problem is modeled by
|
|---|
| 4 | the partial differential equation
|
|---|
| 5 |
|
|---|
| 6 | -Laplacian u - lambda*exp(u) = 0, 0 < x,y < 1,
|
|---|
| 7 |
|
|---|
| 8 | with boundary conditions
|
|---|
| 9 |
|
|---|
| 10 | u = 0 for x = 0, x = 1, y = 0, y = 1.
|
|---|
| 11 |
|
|---|
| 12 | A finite difference approximation with the usual 5-point stencil
|
|---|
| 13 | is used to discretize the boundary value problem to obtain a nonlinear
|
|---|
| 14 | system of equations.
|
|---|
| 15 | ------------------------------------------------------------------------- */
|
|---|
| 16 |
|
|---|
| 17 | #ifdef _CIVL
|
|---|
| 18 | #include <civlc.cvh>
|
|---|
| 19 | #endif
|
|---|
| 20 |
|
|---|
| 21 | #include "petsc.h"
|
|---|
| 22 |
|
|---|
| 23 | PetscErrorCode PetscLogFlops(double ){return 0;}
|
|---|
| 24 | PetscErrorCode CHKERRQ(PetscErrorCode ){return 0;}
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | typedef struct {
|
|---|
| 28 | PassiveReal param; /* test problem parameter */
|
|---|
| 29 | } AppCtx;
|
|---|
| 30 |
|
|---|
| 31 | /* ------------------------------------------------------------------- */
|
|---|
| 32 | #undef __FUNCT__
|
|---|
| 33 | #define __FUNCT__ "FormFunctionLocal"
|
|---|
| 34 | /*
|
|---|
| 35 | FormFunctionLocal - Evaluates nonlinear function, F(x) on local process patch
|
|---|
| 36 | */
|
|---|
| 37 | PetscErrorCode FormFunctionLocal(DMDALocalInfo *info,PetscScalar **x,PetscScalar **f,AppCtx *user)
|
|---|
| 38 | {
|
|---|
| 39 | PetscErrorCode ierr;
|
|---|
| 40 | PetscInt i,j;
|
|---|
| 41 | PetscReal lambda,hx,hy,hxdhy,hydhx,sc;
|
|---|
| 42 | PetscScalar u,uxx,uyy;
|
|---|
| 43 |
|
|---|
| 44 | PetscFunctionBegin;
|
|---|
| 45 |
|
|---|
| 46 | lambda = user->param;
|
|---|
| 47 | #ifdef _CIVL
|
|---|
| 48 | $assume(info->mx != 1);
|
|---|
| 49 | $assume(info->my != 1);
|
|---|
| 50 | #endif
|
|---|
| 51 | hx = 1.0/(PetscReal)(info->mx-1);
|
|---|
| 52 | hy = 1.0/(PetscReal)(info->my-1);
|
|---|
| 53 | sc = hx*hy*lambda;
|
|---|
| 54 | hxdhy = hx/hy;
|
|---|
| 55 | hydhx = hy/hx;
|
|---|
| 56 | /*
|
|---|
| 57 | Compute function over the locally owned part of the grid
|
|---|
| 58 | */
|
|---|
| 59 | for (j=info->ys; j<info->ys+info->ym; j++) {
|
|---|
| 60 | for (i=info->xs; i<info->xs+info->xm; i++) {
|
|---|
| 61 | if (i == 0 || j == 0 || i == info->mx-1 || j == info->my-1) {
|
|---|
| 62 | f[j][i] = 2.0*(hydhx+hxdhy)*x[j][i];
|
|---|
| 63 | } else {
|
|---|
| 64 | u = x[j][i];
|
|---|
| 65 | uxx = (2.0*u - x[j][i-1] - x[j][i+1])*hydhx;
|
|---|
| 66 | uyy = (2.0*u - x[j-1][i] - x[j+1][i])*hxdhy;
|
|---|
| 67 | f[j][i] = uxx + uyy - sc*PetscExpScalar(u);
|
|---|
| 68 | }
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | ierr = PetscLogFlops(11.0*info->ym*info->xm);CHKERRQ(ierr);
|
|---|
| 72 | PetscFunctionReturn(0);
|
|---|
| 73 | }
|
|---|