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

main test-branch
Last change on this file since bb03188 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

  • Property mode set to 100644
File size: 1.7 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 all 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;
16$input int N;
17$assume(1 < M && M <= 4);
18$assume(1 < N && N <= 4);
19$input double x_data[M][N];
20
21//TypeAnalyzer Exception if we define $input AppCtx user;
22AppCtx user;
23$input double user2;
24user.param = user2;
25
26$input int xs, ys, xm, ym;
27DMDALocalInfo info;
28info.xs = xs;
29info.ys = ys;
30info.xm = xm;
31info.ym = ym;
32info.mx = N;
33info.my = M;
34
35$assume(ys >= 0 && ym >0 && ys+ym <= M);
36$assume(xs >= 0 && xm >0 && xs+xm <= N);
37
38$output double f_data[ym][xm];
39
40PetscErrorCode FormFunctionLocal(DMDALocalInfo *,PetscScalar **,PetscScalar **,AppCtx *);
41
42int main() {
43 PetscScalar **x, **f;
44
45 x = (double **)malloc(M*sizeof(double *));
46 for (int i = 0; i < M ; i++) {
47 x[i] = (double *)malloc(N*sizeof(double));
48 }
49
50 f = (double **)malloc(M*sizeof(double *));
51 for (int i = 0; i < M ; i++) {
52 f[i] = (double *)malloc(N*sizeof(double));
53 }
54
55 for (int i = 0; i < M ; i++)
56 for (int j = 0; j < N ; j++) {
57 x[i][j] = x_data[i][j];
58 }
59
60 $elaborate(info.xs);
61 $elaborate(info.ys);
62
63 FormFunctionLocal(&info, x, f, &user);
64
65 // store the portion of array to f_data
66 for (int i = 0; i < info.ym ; i++)
67 for (int j = 0; j < info.xm ; j++) {
68 f_data[i][j] = f[info.ys+i][info.xs+j];
69 }
70
71 for (int i = 0; i< M; i++) {
72 free(x[i]);
73 free(f[i]);
74 }
75 free(x);
76 free(f);
77}
Note: See TracBrowser for help on using the repository browser.