| 1 | /* PETSc example driver for ex2a.c, ex2b.c,ex2c.c,ex2d.c,
|
|---|
| 2 | * https://repo.anl-external.org/repos/provesa/codes/mxm/
|
|---|
| 3 | * command: civl verify ex2Driver.c ex2a.c
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #include <civlc.cvh>
|
|---|
| 7 | #include <stdlib.h>
|
|---|
| 8 | #include "petsc.h"
|
|---|
| 9 |
|
|---|
| 10 | typedef struct {
|
|---|
| 11 | PassiveReal param; /* test problem parameter */
|
|---|
| 12 | } AppCtx;
|
|---|
| 13 |
|
|---|
| 14 | $input int M = 5;
|
|---|
| 15 | $input int N = 5;
|
|---|
| 16 | //$assume(M>=0 && M < 5);
|
|---|
| 17 | //$assume(N>=0 && N < 5);
|
|---|
| 18 | $input PetscScalar x_data[M][N];
|
|---|
| 19 | $output PetscScalar f_data[M][N];
|
|---|
| 20 | $input AppCtx user;
|
|---|
| 21 |
|
|---|
| 22 | $input int xs, ys;
|
|---|
| 23 | DMDALocalInfo info;
|
|---|
| 24 | info.xs=xs;
|
|---|
| 25 | info.ys=ys;
|
|---|
| 26 |
|
|---|
| 27 | $assume(info.ys >=0 && info.ys+info.ym < M);
|
|---|
| 28 | $assume(info.xs >=0 && info.xs+info.xm < N);
|
|---|
| 29 |
|
|---|
| 30 | PetscErrorCode FormFunctionLocal(DMDALocalInfo *,PetscScalar **,PetscScalar **,AppCtx *);
|
|---|
| 31 |
|
|---|
| 32 | int main() {
|
|---|
| 33 | PetscScalar **x, **f;
|
|---|
| 34 |
|
|---|
| 35 | x = (double **)malloc(M*sizeof(double *));
|
|---|
| 36 | for (int i = 0; i < M ; i++) {
|
|---|
| 37 | x[i] = (double *)malloc(N*sizeof(double));
|
|---|
| 38 | //x[i] = $havoc(&x[i])
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | f = (double **)malloc(M*sizeof(double *));
|
|---|
| 42 | for (int i = 0; i < M ; i++) {
|
|---|
| 43 | f[i] = (double *)malloc(N*sizeof(double));
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | for (int i = 0; i < M ; i++)
|
|---|
| 47 | for (int j = 0; j < N ; j++) {
|
|---|
| 48 | x[i][j] = x_data[i][j];
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | FormFunctionLocal(&info, x, f, &user);
|
|---|
| 52 |
|
|---|
| 53 | for (int i = 0; i < M ; i++)
|
|---|
| 54 | for (int j = 0; j < N ; j++) {
|
|---|
| 55 | f_data[i][j] = f[i][j];
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | for(int i = 0; i< M; i++) {
|
|---|
| 59 | free(x[i]);
|
|---|
| 60 | free(f[i]);
|
|---|
| 61 | }
|
|---|
| 62 | free(x);
|
|---|
| 63 | free(f);
|
|---|
| 64 | }
|
|---|