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

main
Last change on this file 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
RevLine 
[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
11typedef 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]22AppCtx user;
23$input double user2;
24user.param = user2;
25
26$input int xs, ys, xm, ym;
[12346a7]27DMDALocalInfo info;
[6208c43]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);
[12346a7]37
[6208c43]38$output double f_data[ym][xm];
[f3bb9fb]39
40PetscErrorCode FormFunctionLocal(DMDALocalInfo *,PetscScalar **,PetscScalar **,AppCtx *);
41
42int 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}
Note: See TracBrowser for help on using the repository browser.