| 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 |
|
|---|
| 11 | typedef 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;
|
|---|
| 22 | AppCtx user;
|
|---|
| 23 | $input double user2;
|
|---|
| 24 | user.param = user2;
|
|---|
| 25 |
|
|---|
| 26 | $input int xs, ys, xm, ym;
|
|---|
| 27 | DMDALocalInfo info;
|
|---|
| 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);
|
|---|
| 37 |
|
|---|
| 38 | $output double f_data[ym][xm];
|
|---|
| 39 |
|
|---|
| 40 | PetscErrorCode FormFunctionLocal(DMDALocalInfo *,PetscScalar **,PetscScalar **,AppCtx *);
|
|---|
| 41 |
|
|---|
| 42 | int 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 | }
|
|---|