source: CIVL/examples/compare/PETSc/ex2a.c@ cc9073d

1.23 2.0 main test-branch
Last change on this file since cc9073d was c5569d1, checked in by Si Li <sili@…>, 10 years ago

minor change

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@3390 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 2.0 KB
Line 
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
23typedef struct {
24 PassiveReal param; /* test problem parameter */
25} AppCtx;
26
27/* ------------------------------------------------------------------- */
28#undef __FUNCT__
29#define __FUNCT__ "FormFunctionLocal"
30/*
31 FormFunctionLocal - Evaluates nonlinear function, F(x) on local process patch
32 */
33PetscErrorCode FormFunctionLocal(DMDALocalInfo *info,PetscScalar **x,PetscScalar **f,AppCtx *user)
34{
35 PetscErrorCode ierr;
36 PetscInt i,j;
37 PetscReal lambda,hx,hy,hxdhy,hydhx,sc;
38 PetscScalar u,uxx,uyy;
39
40 PetscFunctionBegin;
41
42 lambda = user->param;
43#ifdef _CIVL
44 $assume(info->mx != 1);
45 $assume(info->my != 1);
46#endif
47 hx = 1.0/(PetscReal)(info->mx-1);
48 hy = 1.0/(PetscReal)(info->my-1);
49 sc = hx*hy*lambda;
50 hxdhy = hx/hy;
51 hydhx = hy/hx;
52 /*
53 Compute function over the locally owned part of the grid
54 */
55 for (j=info->ys; j<info->ys+info->ym; j++) {
56 for (i=info->xs; i<info->xs+info->xm; i++) {
57 if (i == 0 || j == 0 || i == info->mx-1 || j == info->my-1) {
58 f[j][i] = 2.0*(hydhx+hxdhy)*x[j][i];
59 } else {
60 u = x[j][i];
61 uxx = (2.0*u - x[j][i-1] - x[j][i+1])*hydhx;
62 uyy = (2.0*u - x[j-1][i] - x[j+1][i])*hxdhy;
63 f[j][i] = uxx + uyy - sc*PetscExpScalar(u);
64 }
65 }
66 }
67 ierr = PetscLogFlops(11.0*info->ym*info->xm);CHKERRQ(ierr);
68 PetscFunctionReturn(0);
69}
Note: See TracBrowser for help on using the repository browser.