Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
obbox_test.c
Go to the documentation of this file.
1 #include <stddef.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <float.h>
5 #include <string.h>
6 #include "c99.h"
7 #include "types.h"
8 #include "name.h"
9 #include "fail.h"
10 #include "mem.h"
11 #include "poly.h"
12 #include "lob_bnd.h"
13 #include "obbox.h"
14 #include "rand_elt_test.h"
15 
16 #define REPEAT 20
17 
18 #define N 100
19 #define NR 7
20 #define MR (4*NR)
21 #define NS 8
22 #define MS (4*NS)
23 #define NT 9
24 #define MT (4*NT)
25 
26 #define TOL 0.00001
27 
28 static const unsigned nr[3]={NR,NS,NT}, mr[3]={MR,MS,MT};
29 
30 static double zr[NR], zs[NS], zt[NT];
31 static double x[NR*NS*NT*N], y[NR*NS*NT*N], z[NR*NS*NT*N];
32 static double tx[3][NR*NS*NT];
33 static const double *const elx[3]={x,y,z};
34 
35 static struct obbox_2 ob2[N*NT];
36 static struct obbox_3 ob3[N];
37 
38 static struct dbl_range dbl_range_expand(struct dbl_range b, double tol)
39 {
40  double a = (b.min+b.max)/2, l = (b.max-b.min)*(1+tol)/2;
41  struct dbl_range m;
42  m.min = a-l, m.max = a+l;
43  return m;
44 }
45 
46 int main()
47 {
48  int failure=0;
49  unsigned i;
50 
51  double *lob_bnd_data_r = tmalloc(double,
53  *lob_bnd_data_s = lob_bnd_data_r + lob_bnd_size(NR,MR),
54  *lob_bnd_data_t = lob_bnd_data_s + lob_bnd_size(NS,MS);
55 
56  lobatto_nodes(zr,NR); lob_bnd_setup(lob_bnd_data_r,NR,MR);
57  lobatto_nodes(zs,NS); lob_bnd_setup(lob_bnd_data_s,NS,MS);
58  lobatto_nodes(zt,NT); lob_bnd_setup(lob_bnd_data_t,NT,MT);
59 
60  /* 2-D */
61  for(i=0;i<REPEAT;++i) {
62  unsigned n; double *x_ = x, *y_ = y;
63  for(n=0;n<N && n<6;++n, x_+=NR*NS*NT, y_+=NR*NS*NT)
64  bubble_elt(x_,y_,z, zr,NR, zs,NS, zt,NT, n);
65  for(n=N-6;n;--n, x_+=NR*NS*NT, y_+=NR*NS*NT)
66  rand_elt_2(x_,y_, zr,NR, zs,NS);
67  obbox_calc_2(ob2, elx, nr,NT*N, mr, TOL);
68  x_=x, y_=y;
69  for(n=0;n<N*NT;++n, x_+=NR*NS, y_+=NR*NS) {
70  const struct obbox_2 *ob = &ob2[n];
71  struct dbl_range xr,yr, tr[2];
72  static double work[2*MR*(NS+MS+1)];
73  unsigned j;
74  for(j=0;j<NR*NS;++j) {
75  const double dx=x_[j]-ob->c0[0], dy=y_[j]-ob->c0[1];
76  tx[0][j] = ob->A[0]*dx+ob->A[1]*dy;
77  tx[1][j] = ob->A[2]*dx+ob->A[3]*dy;
78  if( (x_[j]-ob->x[0].min)*(ob->x[0].max-x_[j]) < 0
79  || (y_[j]-ob->x[1].min)*(ob->x[1].max-y_[j]) < 0 )
80  failure=1,
81  printf("%d %d (%g,%g) not in [%g,%g] x [%g,%g]\n", n, j,
82  x_[j],y_[j], ob->x[0].min,ob->x[0].max, ob->x[1].min,ob->x[1].max);
83  if( (tx[0][j]+1)*(1-tx[0][j]) < 0
84  || (tx[1][j]+1)*(1-tx[1][j]) < 0 )
85  failure=1,
86  printf("%d %d (%g,%g) not in [-1,1]^2\n", n, j,
87  tx[0][j],tx[1][j]);
88  if(failure) break;
89  }
90 
91  xr = dbl_range_expand(lob_bnd_2(lob_bnd_data_r,NR,MR,
92  lob_bnd_data_s,NS,MS, x_, work), TOL);
93  yr = dbl_range_expand(lob_bnd_2(lob_bnd_data_r,NR,MR,
94  lob_bnd_data_s,NS,MS, y_, work), TOL);
95 
96  for(j=0;j<2;++j) tr[j] = dbl_range_expand(
97  lob_bnd_2(lob_bnd_data_r,NR,MR, lob_bnd_data_s,NS,MS, tx[j], work)
98  , TOL);
99 
100  if( ob->x[0].min < xr.min - DBL_EPSILON*128
101  || ob->x[0].max > xr.max + DBL_EPSILON*128 ) failure = 1;
102  if( ob->x[1].min < yr.min - DBL_EPSILON*128
103  || ob->x[1].max > yr.max + DBL_EPSILON*128 ) failure = 1;
104 
105  for(j=0;j<2;++j)
106  if( tr[j].min > -1 + DBL_EPSILON*128
107  || tr[j].max < 1 - DBL_EPSILON*128 ) failure = 1;
108 
109  if((i==0&&n==0) || failure) {
110  printf("x: [%g,%g] in [%g,%g]\n", ob->x[0].min, ob->x[0].max,
111  xr.min, xr.max);
112  printf("y: [%g,%g] in [%g,%g]\n", ob->x[1].min, ob->x[1].max,
113  yr.min, yr.max);
114  for(j=0;j<2;++j)
115  printf("r %d: [%g,%g]\n", j, tr[j].min, tr[j].max);
116  }
117  if(failure) break;
118  }
119  if(failure) break;
120  printf("."); fflush(stdout);
121  }
122  printf("\n");
123 
124  /* 3-D */
125  for(i=0;!failure && i<REPEAT;++i) {
126  unsigned n; double *x_ = x, *y_ = y, *z_ = z;
127  for(n=0;n<N && n<6;++n, x_+=NR*NS*NT, y_+=NR*NS*NT, z_+=NR*NS*NT)
128  bubble_elt(x_,y_,z_, zr,NR, zs,NS, zt,NT, n);
129  for(n=N-6;n;--n, x_+=NR*NS*NT, y_+=NR*NS*NT, z_+=NR*NS*NT)
130  rand_elt_3(x_,y_,z_, zr,NR, zs,NS, zt,NT);
131  obbox_calc_3(ob3, elx, nr,N, mr, TOL);
132  x_=x, y_=y, z_=z;
133  for(n=0;n<N;++n, x_+=NR*NS*NT, y_+=NR*NS*NT, z_+=NR*NS*NT) {
134  const struct obbox_3 *ob = &ob3[n];
135  struct dbl_range xr,yr,zr, tr[3];
136  static double work[2*MR*MS*(NT+MT+1)];
137  unsigned j;
138  for(j=0;j<NR*NS*NT;++j) {
139  const double dx=x_[j]-ob->c0[0], dy=y_[j]-ob->c0[1], dz=z_[j]-ob->c0[2];
140  tx[0][j] = ob->A[0]*dx+ob->A[1]*dy+ob->A[2]*dz;
141  tx[1][j] = ob->A[3]*dx+ob->A[4]*dy+ob->A[5]*dz;
142  tx[2][j] = ob->A[6]*dx+ob->A[7]*dy+ob->A[8]*dz;
143  if( (x_[j]-ob->x[0].min)*(ob->x[0].max-x_[j]) < 0
144  || (y_[j]-ob->x[1].min)*(ob->x[1].max-y_[j]) < 0
145  || (z_[j]-ob->x[2].min)*(ob->x[2].max-z_[j]) < 0 )
146  failure=1,
147  printf("%d %d (%g,%g,%g) not in [%g,%g] x [%g,%g] x [%g,%g]\n", n, j,
148  x_[j],y_[j],z_[j], ob->x[0].min,ob->x[0].max,
149  ob->x[1].min,ob->x[1].max, ob->x[2].min,ob->x[2].max);
150  if( (tx[0][j]+1)*(1-tx[0][j]) < 0
151  || (tx[1][j]+1)*(1-tx[1][j]) < 0
152  || (tx[2][j]+1)*(1-tx[2][j]) < 0 )
153  failure=1,
154  printf("%d %d (%g,%g,%g) not in [-1,1]^3\n", n, j,
155  tx[0][j],tx[1][j],tx[2][j]);
156  if(failure) break;
157  }
158 
159  xr = dbl_range_expand(lob_bnd_3(lob_bnd_data_r,NR,MR,
160  lob_bnd_data_s,NS,MS,
161  lob_bnd_data_t,NT,MT, x_, work), TOL);
162  yr = dbl_range_expand(lob_bnd_3(lob_bnd_data_r,NR,MR,
163  lob_bnd_data_s,NS,MS,
164  lob_bnd_data_t,NT,MT, y_, work), TOL);
165  zr = dbl_range_expand(lob_bnd_3(lob_bnd_data_r,NR,MR,
166  lob_bnd_data_s,NS,MS,
167  lob_bnd_data_t,NT,MT, z_, work), TOL);
168 
169  for(j=0;j<3;++j) tr[j] = dbl_range_expand(
170  lob_bnd_3(lob_bnd_data_r,NR,MR, lob_bnd_data_s,NS,MS,
171  lob_bnd_data_t,NT,MT, tx[j], work)
172  , TOL);
173 
174  if( ob->x[0].min < xr.min - DBL_EPSILON*128
175  || ob->x[0].max > xr.max + DBL_EPSILON*128 ) failure = 1;
176  if( ob->x[1].min < yr.min - DBL_EPSILON*128
177  || ob->x[1].max > yr.max + DBL_EPSILON*128 ) failure = 1;
178  if( ob->x[2].min < zr.min - DBL_EPSILON*128
179  || ob->x[2].max > zr.max + DBL_EPSILON*128 ) failure = 1;
180 
181  for(j=0;j<3;++j)
182  if( tr[j].min > -1 + DBL_EPSILON*128
183  || tr[j].max < 1 - DBL_EPSILON*128 ) failure = 1;
184 
185  if((i==0&&n==0) || failure) {
186  printf("x: [%g,%g] in [%g,%g]\n", ob->x[0].min, ob->x[0].max,
187  xr.min, xr.max);
188  printf("y: [%g,%g] in [%g,%g]\n", ob->x[1].min, ob->x[1].max,
189  yr.min, yr.max);
190  printf("z: [%g,%g] in [%g,%g]\n", ob->x[2].min, ob->x[2].max,
191  zr.min, zr.max);
192  for(j=0;j<3;++j)
193  printf("r %d: [%g,%g]\n", j, tr[j].min, tr[j].max);
194  }
195  if(failure) break;
196  }
197  if(failure) break;
198  printf("."); fflush(stdout);
199  }
200  printf("\n");
201 
202  free(lob_bnd_data_r);
203 
204  printf("Tests %s\n", failure?"failed":"successful");
205 
206  return failure;
207 }
double A[9]
Definition: obbox.c:19
#define MT
Definition: obbox_test.c:24
#define tmalloc(type, count)
Definition: mem.h:91
#define lob_bnd_3
Definition: lob_bnd.c:19
void bubble_elt(double *x, double *y, double *z, const double *zr, unsigned nr, const double *zs, unsigned ns, const double *zt, unsigned nt, int type)
static double zt[NT]
Definition: obbox_test.c:30
static struct obbox_2 ob2[N *NT]
Definition: obbox_test.c:35
static double tx[3][NR *NS *NT]
Definition: obbox_test.c:32
n
Definition: xxt_test.m:73
double max
Definition: lob_bnd.c:21
static double zr[NR]
Definition: obbox_test.c:30
void rand_elt_2(double *x, double *y, const double *zr, unsigned nr, const double *zs, unsigned ns)
Definition: rand_elt_test.c:70
Definition: obbox.c:19
#define MR
Definition: obbox_test.c:20
#define TOL
Definition: obbox_test.c:26
void rand_elt_3(double *x, double *y, double *z, const double *zr, unsigned nr, const double *zs, unsigned ns, const double *zt, unsigned nt)
static const double *const elx[3]
Definition: obbox_test.c:33
struct dbl_range x[3]
Definition: obbox.c:20
static struct obbox_3 ob3[N]
Definition: obbox_test.c:36
struct dbl_range x[2]
Definition: obbox.c:17
int main()
Definition: obbox_test.c:46
#define N
Definition: obbox_test.c:18
#define NT
Definition: obbox_test.c:23
#define obbox_calc_2
Definition: obbox.c:13
#define NS
Definition: obbox_test.c:21
#define lob_bnd_2
Definition: lob_bnd.c:18
#define NR
Definition: obbox_test.c:19
#define REPEAT
Definition: obbox_test.c:16
double A[4]
Definition: obbox.c:16
for i
Definition: xxt_test.m:74
static unsigned lob_bnd_size(unsigned n, unsigned m)
Definition: lob_bnd.h:64
double c0[3]
Definition: obbox.c:19
static struct dbl_range dbl_range_expand(struct dbl_range b, double tol)
Definition: obbox_test.c:38
#define obbox_calc_3
Definition: obbox.c:14
static double zs[NS]
Definition: obbox_test.c:30
static double x[NR *NS *NT *N]
Definition: obbox_test.c:31
static const unsigned mr[3]
Definition: obbox_test.c:28
double min
Definition: lob_bnd.c:21
Definition: obbox.c:16
#define lob_bnd_setup
Definition: lob_bnd.c:13
double c0[2]
Definition: obbox.c:16
static double work[TNR *NS]
#define lobatto_nodes
Definition: poly.c:15
establishes some macros to establish naming conventions
static double y[NR *NS *NT *N]
Definition: obbox_test.c:31
#define MS
Definition: obbox_test.c:22
static const unsigned nr[3]
Definition: obbox_test.c:28
static double z[NR *NS *NT *N]
Definition: obbox_test.c:31