Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
xxt_test2.c
Go to the documentation of this file.
1 #include <stddef.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include "c99.h"
7 #include "name.h"
8 #include "fail.h"
9 #include "types.h"
10 #include "comm.h"
11 #include "mem.h"
12 #include "crs.h"
13 
14 #define M 3
15 
16 int main(int narg, char* arg[])
17 {
18  uint n; ulong *xid;
19  uint nz; uint *Ai, *Aj; double *A;
20  uint i;
21  double *x, *b, *x2;
22 
23  struct crs_data *crs;
24  comm_ext world; int id,np;
25  struct comm comm;
26 #ifdef MPI
27  MPI_Init(&narg,&arg);
28  world = MPI_COMM_WORLD;
29  MPI_Comm_size(world,&np);
30 #else
31  world=0, np=1;
32 #endif
33 
34  comm_init(&comm,world);
35  id = comm.id;
36 
37  n=M+1; if(id==np-1) --n;
38  xid = tmalloc(ulong,n); x=tmalloc(double,3*n), b=x+n, x2=b+n;
39  for(i=0;i<n;++i) xid[i]=1+id*M+i;
40  nz=2*M; if(id==np-1) --nz;
41  Ai=tmalloc(uint,2*nz), Aj=Ai+nz;
42  A =tmalloc(double,nz);
43  for(i=0;i<M;++i) Ai[i]=i,Aj[i]=i,A[i]=2;
44  if(id==0) A[0]=1;
45  if(id==np-1) A[n-1]=1;
46  for(i=M;i<nz;++i) Ai[i]=i-M,Aj[i]=i-M+1,A[i]=-1;
47 
48  crs = crs_setup(n,xid, nz,Ai,Aj,A, 1, &comm);
49  crs_stats(crs);
50 
51  {
52  double tn = M*np, mean = 1*(tn+1)/2;
53  double avg = 1*(tn-1)*(tn+1)/12;
54  for(i=0;i<n;++i) x[i]=(xid[i]-mean)*(xid[i]-mean)-avg;
55  for(i=0;i<n;++i) b[i]=A[i]*x[i]
56  - (i>0 || id!=0 ? (xid[i]-1-mean)*(xid[i]-1-mean)-avg : 0)
57  - (i+1<n || id!=np-1 ? (xid[i]+1-mean)*(xid[i]+1-mean)-avg : 0);
58  if(id!=np-1) b[n-1]=0;
59  }
60  crs_solve(x2,crs,b);
61  crs_free(crs);
62  comm_free(&comm);
63 
64  { double dif=0;
65  for(i=0;i<n;++i) {
66  double d=fabs(x[i]-x2[i])/(.1+fabs(x[i]));
67  if(d>dif) dif=d;
68  }
69  printf("%d : max dif = %g\n",id,dif);
70  }
71  free(A); free(Ai); free(x); free(xid);
72 
73 #ifdef MPI
74  MPI_Finalize();
75 #endif
76 
77  if(id==0) printf("test successful\n");
78 
79  return 0;
80 }
81 
#define crs_stats
Definition: crs.h:10
#define uint
Definition: types.h:70
#define tmalloc(type, count)
Definition: mem.h:91
int main(int narg, char *arg[])
Definition: xxt_test2.c:16
n
Definition: xxt_test.m:73
#define x
#define crs_solve
Definition: crs.h:9
ulong A[NUM][SI]
Definition: sort_test.c:17
Definition: comm.h:85
static void comm_free(struct comm *c)
Definition: comm.h:176
#define crs_free
Definition: crs.h:11
const uint Ai[3][32]
Definition: xxt_test.c:80
int comm_ext
Definition: comm.h:69
#define ulong
Definition: types.h:75
#define M
Definition: xxt_test2.c:14
for i
Definition: xxt_test.m:74
const uint Aj[3][32]
Definition: xxt_test.c:85
#define crs_setup
Definition: crs.h:8
static uint id
Definition: findpts_test.c:63
uint id
Definition: comm.h:86
establishes some macros to establish naming conventions
static uint np
Definition: findpts_test.c:63
static void comm_init(struct comm *c, comm_ext ce)
Definition: comm.h:133
const uint nz[3]
Definition: xxt_test.c:78