source: CIVL/examples/compare/PETSc/ex2b.c@ 3820281

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 3820281 was 3820281, checked in by Si Li <sili@…>, 10 years ago

inlucde petsc.h header, correct syntax error

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

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