source: CIVL/examples/compare/PETSc/ex2Driver.c@ 3073847

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

working version and cleaned up

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

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/* PETSc examples driver for ex2a.c, ex2b.c,ex2c.c,ex2d.c,
2 * https://repo.anl-external.org/repos/provesa/codes/mxm/
3 * simple examples run command: civl verify ex2Driver.c ex2a.c
4 * compare examples command: make
5 */
6
7#include <civlc.cvh>
8#include <stdlib.h>
9#include "petsc.h"
10
11typedef struct {
12 PassiveReal param; /* test problem parameter */
13} AppCtx;
14
15$input int M = 3;
16$input int N = 3;
17//$assume(M>=0 && M < 5);
18//$assume(N>=0 && N < 5);
19$input double x_data[M][N];
20
21AppCtx user;
22$input double user2;
23user.param = user2;
24
25$input int xs, ys, xm, ym;
26DMDALocalInfo info;
27info.xs = xs;
28info.ys = ys;
29info.xm = xm;
30info.ym = ym;
31info.mx = N;
32info.my = M;
33
34$assume(ys >= 0 && ym >0 && ys+ym <= M);
35$assume(xs >= 0 && xm >0 && xs+xm <= N);
36
37$output double f_data[ym][xm];
38
39PetscErrorCode FormFunctionLocal(DMDALocalInfo *,PetscScalar **,PetscScalar **,AppCtx *);
40
41int main() {
42 PetscScalar **x, **f;
43
44 x = (double **)malloc(M*sizeof(double *));
45 for (int i = 0; i < M ; i++) {
46 x[i] = (double *)malloc(N*sizeof(double));
47 }
48
49 f = (double **)malloc(M*sizeof(double *));
50 for (int i = 0; i < M ; i++) {
51 f[i] = (double *)malloc(N*sizeof(double));
52 }
53
54 for (int i = 0; i < M ; i++)
55 for (int j = 0; j < N ; j++) {
56 x[i][j] = x_data[i][j];
57 }
58
59 $elaborate(info.xs);
60 $elaborate(info.ys);
61
62 FormFunctionLocal(&info, x, f, &user);
63
64 for (int i = 0; i < info.ym ; i++)
65 for (int j = 0; j < info.xm ; j++) {
66 f_data[i][j] = f[info.ys+i][info.xs+j];
67 }
68
69 for (int i = 0; i< M; i++) {
70 free(x[i]);
71 free(f[i]);
72 }
73 free(x);
74 free(f);
75}
Note: See TracBrowser for help on using the repository browser.