Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
findpts_local_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 <math.h>
6 #include <string.h>
7 #include "c99.h"
8 #include "name.h"
9 #include "fail.h"
10 #include "mem.h"
11 #include "types.h"
12 #include "poly.h"
13 #include "obbox.h"
14 #include "findpts_el.h"
15 #include "findpts_local.h"
16 #include "rand_elt_test.h"
17 
18 #define D 3
19 
20 #if D==3
21 #define INITD(a,b,c) {a,b,c}
22 #define MULD(a,b,c) ((a)*(b)*(c))
23 #define INDEXD(a,na, b,nb, c) (((c)*(nb)+(b))*(na)+(a))
24 #define findpts_local_data findpts_local_data_3
25 #define findpts_local_setup findpts_local_setup_3
26 #define findpts_local_free findpts_local_free_3
27 #define findpts_local findpts_local_3
28 #elif D==2
29 #define INITD(a,b,c) {a,b}
30 #define MULD(a,b,c) ((a)*(b))
31 #define INDEXD(a,na, b,nb, c) ((b)*(na)+(a))
32 #define findpts_local_data findpts_local_data_2
33 #define findpts_local_setup findpts_local_setup_2
34 #define findpts_local_free findpts_local_free_2
35 #define findpts_local findpts_local_2
36 #endif
37 
38 #define NR 5
39 #define NS 8
40 #define NT 6
41 #define K 4
42 #define NEL MULD(K,K,K)
43 #define TN 4
44 
45 #define NPT_MAX 256
46 #define BBOX_TOL 0.01
47 #define NEWT_TOL 1024*DBL_EPSILON
48 #define MAX_HASH_SIZE NEL*MULD(NR,NS,NT)
49 
50 /*
51 #define NPT_MAX 256
52 #define BBOX_TOL 1.00
53 #define NEWT_TOL 1024*DBL_EPSILON
54 #define MAX_HASH_SIZE NEL*3
55 */
56 
57 static const unsigned nr[D] = INITD(NR,NS,NT);
58 static const unsigned mr[D] = INITD(4*NR,4*NS,4*NT);
59 static double zr[NR], zs[NS], zt[NT];
60 static double x3[D][MULD(3,3,3)];
61 static double mesh[D][NEL*MULD(NR,NS,NT)];
62 static const double *const elx[D] = INITD(mesh[0],mesh[1],mesh[2]);
63 
64 static double testx[NEL*MULD(TN,TN,TN)*D];
65 struct pt_data { double r[D], dist2; uint code, el; };
66 static struct pt_data testp[NEL*MULD(TN,TN,TN)];
67 
68 static double quad_eval(const double coef[MULD(3,3,3)], const double r[D])
69 {
70  double lr0[D], lr1[D], lr2[D];
71  unsigned d;
72  for(d=0;d<D;++d) lr0[d]=r[d]*(r[d]-1)/2,
73  lr1[d]=(1+r[d])*(1-r[d]),
74  lr2[d]=r[d]*(r[d]+1)/2;
75  #define EVALR(base) ( coef [base ]*lr0[0] \
76  +coef [base+ 1]*lr1[0] \
77  +coef [base+ 2]*lr2[0] )
78  #define EVALS(base) ( EVALR(base )*lr0[1] \
79  +EVALR(base+ 3)*lr1[1] \
80  +EVALR(base+ 6)*lr2[1] )
81  #define EVALT(base) ( EVALS(base )*lr0[2] \
82  +EVALS(base+ 9)*lr1[2] \
83  +EVALS(base+18)*lr2[2] )
84  #if D==2
85  # define EVAL() EVALS(0)
86  #elif D==3
87  # define EVAL() EVALT(0)
88  #endif
89 
90  return EVAL();
91 
92  #undef EVAL
93  #undef EVALT
94  #undef EVALS
95  #undef EVALR
96 }
97 
98 static void rand_mesh(void)
99 {
100  const double fac = 1.0/K;
101  const double z3[3] = {-1,0,1};
102  unsigned ki,kj;
103  #if D==3
104  unsigned kk;
105  rand_elt_3(x3[0],x3[1],x3[2], z3,3,z3,3,z3,3);
106  #elif D==2
107  rand_elt_2(x3[0],x3[1], z3,3,z3,3);
108  #endif
109  #if D==3
110  for(kk=0;kk<K;++kk)
111  #endif
112  for(kj=0;kj<K;++kj) for(ki=0;ki<K;++ki) {
113  unsigned off = INDEXD(ki,K, kj,K, kk)*MULD(NR,NS,NT);
114  unsigned i,j;
115  double r[D], base[D] = INITD(-1+2*fac*ki,-1+2*fac*kj,-1+2*fac*kk);
116  #if D==3
117  unsigned k;
118  for(k=0;k<NT;++k) { r[2] = base[2]+fac*(1+zt[k]);
119  #endif
120  for(j=0;j<NS;++j) { r[1] = base[1]+fac*(1+zs[j]);
121  for(i=0;i<NR;++i) { r[0] = base[0]+fac*(1+zr[i]);
122  mesh[0][off+INDEXD(i,NR, j,NS, k)] = quad_eval(x3[0],r);
123  mesh[1][off+INDEXD(i,NR, j,NS, k)] = quad_eval(x3[1],r);
124  #if D==3
125  mesh[2][off+INDEXD(i,NR, j,NS, k)] = quad_eval(x3[2],r);
126  }
127  #endif
128  }}
129  }
130 }
131 
132 static void test_mesh(void)
133 {
134  const double fac = 1.0/K, step = 2.0/(K*(TN-1));
135  unsigned ki,kj;
136  #if D==3
137  unsigned kk;
138  for(kk=0;kk<K;++kk)
139  #endif
140  for(kj=0;kj<K;++kj) for(ki=0;ki<K;++ki) {
141  unsigned off = INDEXD(ki,K, kj,K, kk)*MULD(TN,TN,TN);
142  unsigned i,j;
143  double r[D], base[D] = INITD(-1+2*fac*ki,-1+2*fac*kj,-1+2*fac*kk);
144  #if D==3
145  unsigned k;
146  for(k=0;k<TN;++k) { r[2] = base[2]+step*k;
147  #endif
148  for(j=0;j<TN;++j) { r[1] = base[1]+step*j;
149  for(i=0;i<TN;++i) { r[0] = base[0]+step*i;
150  testx[(off+INDEXD(i,TN, j,TN, k))*D+0] = quad_eval(x3[0],r);
151  testx[(off+INDEXD(i,TN, j,TN, k))*D+1] = quad_eval(x3[1],r);
152  #if D==3
153  testx[(off+INDEXD(i,TN, j,TN, k))*D+2] = quad_eval(x3[2],r);
154  }
155  #endif
156  }}
157  }
158 }
159 
160 static void print_ptdata(void)
161 {
162  uint i,notfound=0;
163  double dist2max=0;
164  for(i=0;i<NEL*MULD(TN,TN,TN);++i) {
165  printf("code=%u, el=%u, dist2=%g, r=(%.17g,%.17g"
166  #if D==3
167  ",%.17g"
168  #endif
169  ")\n",
170  testp[i].code,testp[i].el,testp[i].dist2,
171  testp[i].r[0],testp[i].r[1]
172  #if D==3
173  ,testp[i].r[2]
174  #endif
175  );
176  dist2max=testp[i].dist2>dist2max?testp[i].dist2:dist2max;
177  if(testp[i].code==2) ++notfound;
178  }
179  printf("Maximum distance = %g\n%u points not found\n",
180  sqrt(dist2max), (unsigned)notfound);
181 }
182 
183 static void test(buffer *buf)
184 {
185  const double *const x_base[D]=INITD(testx,testx+1,testx+2);
186  const unsigned x_stride[D]=
187  INITD(D*sizeof(double),D*sizeof(double),D*sizeof(double));
188  struct findpts_local_data fld;
189  rand_mesh();
190  test_mesh();
192  NPT_MAX,NEWT_TOL);
193  findpts_local(&testp[0].code , sizeof(struct pt_data),
194  &testp[0].el , sizeof(struct pt_data),
195  testp[0].r , sizeof(struct pt_data),
196  &testp[0].dist2, sizeof(struct pt_data),
197  x_base, x_stride,
198  NEL*MULD(TN,TN,TN), &fld, buf);
199  findpts_local_free(&fld);
200  print_ptdata();
201 }
202 
203 int main()
204 {
207  test(&buf);
208  buffer_free(&buf);
209  return 0;
210 }
#define uint
Definition: types.h:70
#define buffer_free(b)
Definition: mem.h:158
static const unsigned mr[D]
double r[D]
#define MAX_HASH_SIZE
int main()
static double x3[D][MULD(3, 3, 3)]
static double zt[NT]
#define D
void rand_elt_2(double *x, double *y, const double *zr, unsigned nr, const double *zs, unsigned ns)
Definition: rand_elt_test.c:70
static void test(buffer *buf)
#define NT
#define NEL
#define NR
#define INDEXD(a, na, b, nb, c)
#define BBOX_TOL
cleaned
Definition: mesh_mod.F90:2
static double quad_eval(const double coef[MULD(3, 3, 3)], const double r[D])
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 void rand_mesh(void)
Definition: mem.h:111
static void test_mesh(void)
#define NS
#define findpts_local_free
#define INITD(a, b, c)
for i
Definition: xxt_test.m:74
static const unsigned nr[D]
#define NPT_MAX
static double testx[NEL *MULD(TN, TN, TN)*D]
#define K
#define TN
#define NEWT_TOL
#define null_buffer
Definition: mem.h:154
#define MULD(a, b, c)
static double zr[NR]
#define lobatto_nodes
Definition: poly.c:15
static struct pt_data testp[NEL *MULD(TN, TN, TN)]
establishes some macros to establish naming conventions
#define findpts_local
static double zs[NS]
static const double *const elx[D]
static void print_ptdata(void)
#define EVAL()
#define findpts_local_setup