| [6208c43] | 1 | /* PETSc examples driver for ex2a.c, ex2b.c,ex2c.c,ex2d.c,
|
|---|
| [f3bb9fb] | 2 | * https://repo.anl-external.org/repos/provesa/codes/mxm/
|
|---|
| [6208c43] | 3 | * simple examples run command: civl verify ex2Driver.c ex2a.c
|
|---|
| [95e3849] | 4 | * compare all examples command: make
|
|---|
| [f3bb9fb] | 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #include <civlc.cvh>
|
|---|
| 8 | #include <stdlib.h>
|
|---|
| 9 | #include "petsc.h"
|
|---|
| 10 |
|
|---|
| 11 | typedef struct {
|
|---|
| 12 | PassiveReal param; /* test problem parameter */
|
|---|
| 13 | } AppCtx;
|
|---|
| 14 |
|
|---|
| [f0b6251] | 15 | $input int M;
|
|---|
| 16 | $input int N;
|
|---|
| 17 | $assume(1 < M && M <= 4);
|
|---|
| 18 | $assume(1 < N && N <= 4);
|
|---|
| [6208c43] | 19 | $input double x_data[M][N];
|
|---|
| [12346a7] | 20 |
|
|---|
| [180518a] | 21 | //TypeAnalyzer Exception if we define $input AppCtx user;
|
|---|
| [6208c43] | 22 | AppCtx user;
|
|---|
| 23 | $input double user2;
|
|---|
| 24 | user.param = user2;
|
|---|
| 25 |
|
|---|
| 26 | $input int xs, ys, xm, ym;
|
|---|
| [12346a7] | 27 | DMDALocalInfo info;
|
|---|
| [6208c43] | 28 | info.xs = xs;
|
|---|
| 29 | info.ys = ys;
|
|---|
| 30 | info.xm = xm;
|
|---|
| 31 | info.ym = ym;
|
|---|
| 32 | info.mx = N;
|
|---|
| 33 | info.my = M;
|
|---|
| 34 |
|
|---|
| 35 | $assume(ys >= 0 && ym >0 && ys+ym <= M);
|
|---|
| 36 | $assume(xs >= 0 && xm >0 && xs+xm <= N);
|
|---|
| [12346a7] | 37 |
|
|---|
| [6208c43] | 38 | $output double f_data[ym][xm];
|
|---|
| [f3bb9fb] | 39 |
|
|---|
| 40 | PetscErrorCode FormFunctionLocal(DMDALocalInfo *,PetscScalar **,PetscScalar **,AppCtx *);
|
|---|
| 41 |
|
|---|
| 42 | int main() {
|
|---|
| 43 | PetscScalar **x, **f;
|
|---|
| 44 |
|
|---|
| [96f1f4c] | 45 | x = (double **)malloc(M*sizeof(double *));
|
|---|
| 46 | for (int i = 0; i < M ; i++) {
|
|---|
| 47 | x[i] = (double *)malloc(N*sizeof(double));
|
|---|
| [f3bb9fb] | 48 | }
|
|---|
| 49 |
|
|---|
| [96f1f4c] | 50 | f = (double **)malloc(M*sizeof(double *));
|
|---|
| 51 | for (int i = 0; i < M ; i++) {
|
|---|
| 52 | f[i] = (double *)malloc(N*sizeof(double));
|
|---|
| [f3bb9fb] | 53 | }
|
|---|
| 54 |
|
|---|
| [96f1f4c] | 55 | for (int i = 0; i < M ; i++)
|
|---|
| 56 | for (int j = 0; j < N ; j++) {
|
|---|
| [f3bb9fb] | 57 | x[i][j] = x_data[i][j];
|
|---|
| 58 | }
|
|---|
| [6208c43] | 59 |
|
|---|
| 60 | $elaborate(info.xs);
|
|---|
| 61 | $elaborate(info.ys);
|
|---|
| 62 |
|
|---|
| [5a9a4fc] | 63 | FormFunctionLocal(&info, x, f, &user);
|
|---|
| [83c9238] | 64 |
|
|---|
| [180518a] | 65 | // store the portion of array to f_data
|
|---|
| [6208c43] | 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];
|
|---|
| [83c9238] | 69 | }
|
|---|
| [6208c43] | 70 |
|
|---|
| 71 | for (int i = 0; i< M; i++) {
|
|---|
| [ecccf24] | 72 | free(x[i]);
|
|---|
| 73 | free(f[i]);
|
|---|
| 74 | }
|
|---|
| 75 | free(x);
|
|---|
| 76 | free(f);
|
|---|
| [f3bb9fb] | 77 | }
|
|---|