23 #define INITD(a,b,c) {a,b,c}
24 #define MULD(a,b,c) ((a)*(b)*(c))
25 #define INDEXD(a,na, b,nb, c) (((c)*(nb)+(b))*(na)+(a))
26 #define findpts_data findpts_data_3
27 #define findpts_setup findpts_setup_3
28 #define findpts_free findpts_free_3
29 #define findpts findpts_3
30 #define findpts_eval findpts_eval_3
32 #define INITD(a,b,c) {a,b}
33 #define MULD(a,b,c) ((a)*(b))
34 #define INDEXD(a,na, b,nb, c) ((b)*(na)+(a))
35 #define findpts_data findpts_data_2
36 #define findpts_setup findpts_setup_2
37 #define findpts_free findpts_free_2
38 #define findpts findpts_2
39 #define findpts_eval findpts_eval_2
46 #define NEL MULD(K,K,K)
51 #define NEWT_TOL 1024*DBL_EPSILON
52 #define LOC_HASH_SIZE NEL*MULD(NR,NS,NT)
53 #define GBL_HASH_SIZE NEL*MULD(NR,NS,NT)
79 double lr0[
D], lr1[
D], lr2[
D];
81 for(d=0;d<
D;++d) lr0[d]=r[d]*(r[d]-1)/2,
82 lr1[d]=(1+r[d])*(1-r[d]),
83 lr2[d]=r[d]*(r[d]+1)/2;
84 #define EVALR(base) ( coef [base ]*lr0[0] \
85 +coef [base+ 1]*lr1[0] \
86 +coef [base+ 2]*lr2[0] )
87 #define EVALS(base) ( EVALR(base )*lr0[1] \
88 +EVALR(base+ 3)*lr1[1] \
89 +EVALR(base+ 6)*lr2[1] )
90 #define EVALT(base) ( EVALS(base )*lr0[2] \
91 +EVALS(base+ 9)*lr1[2] \
92 +EVALS(base+18)*lr2[2] )
94 # define EVAL() EVALS(0)
96 # define EVAL() EVALT(0)
109 const uint pn = ceil(pow(
np,1.0/
D));
110 const uint pi=
id%pn, pj=(
id/pn)%pn;
112 const uint pk=(
id/pn)/pn;
114 const double pfac = 1.0/pn;
115 const double pbase[
D] =
INITD(-1+2*pfac*pi, -1+2*pfac*pj, -1+2*pfac*pk);
116 const double fac = 1.0/
K;
117 const double z3[3] = {-1,0,1};
125 if(
id==0) printf(
"Global division: %u^%d\n",(
unsigned)pn,
D);
129 for(kj=0;kj<
K;++kj)
for(ki=0;ki<
K;++ki) {
132 double r[
D], base[
D] =
INITD(-1+2*fac*ki,-1+2*fac*kj,-1+2*fac*kk);
135 for(k=0;k<
NT;++k) { r[2]=pbase[2]+pfac*(1+base[2]+fac*(1+
zt[k]));
137 for(j=0;j<
NS;++j) { r[1]=pbase[1]+pfac*(1+base[1]+fac*(1+
zs[j]));
138 for(i=0;i<
NR;++
i) { r[0]=pbase[0]+pfac*(1+base[0]+fac*(1+
zr[
i]));
151 const uint pn = ceil(pow(
np,1.0/
D));
152 const uint pi=
id%pn, pj=(
id/pn)%pn;
154 const uint pk=(
id/pn)/pn;
156 const double pfac = 1.0/pn;
157 const double pbase[
D] =
INITD(-1+2*pfac*pi, -1+2*pfac*pj, -1+2*pfac*pk);
158 const double fac = 1.0/
K, step = 2.0/(
K*(
TN-1));
169 for(kj=0;kj<
K;++kj)
for(ki=0;ki<
K;++ki) {
171 double r[
D], base[
D] =
INITD(-1+2*fac*ki,-1+2*fac*kj,-1+2*fac*kk);
174 for(k=0;k<
TN;++k) { r[2] = pbase[2]+pfac*(1+base[2]+step*k);
176 for(j=0;j<
TN;++j) { r[1] = pbase[1]+pfac*(1+base[1]+step*j);
177 for(i=0;i<
TN;++
i) { r[0] = pbase[0]+pfac*(1+base[0]+step*
i);
192 printf(
"%u: %u shuffled points\n",
id,(
unsigned)
testp.
n);
198 double dist2max=0, ed2max=0;
202 printf(
"code=%u, proc=%u, el=%u, dist2=%g, r=(%.17g,%.17g"
230 if(pt->
code==2) ++notfound;
233 unsigned d;
for(d=0;d<
D;++d) dx=pt->
x[d]-pt->
ex[d], ed2+=dx*dx;
234 dist2max=pt->
dist2>dist2max?pt->
dist2:dist2max;
235 ed2max=ed2>ed2max?ed2:ed2max;
239 double distmax=sqrt(dist2max), edmax=sqrt(ed2max);
242 printf(
"%u: maximum distance = %g (adv), %g (eval);"
243 " %u/%u points not found\n",
244 (
unsigned)
id, distmax, edmax,
245 (
unsigned)notfound, (
unsigned)
testp.
n);
246 distmax = comm_reduce_double(comm,gs_max,&distmax,1);
247 edmax = comm_reduce_double(comm,gs_max,&edmax ,1);
248 notfound = comm_reduce_sint(comm,gs_add,(
sint*)¬found,1);
249 total = comm_reduce_slong(comm,gs_add,&total,1);
251 printf(
"maximum distance = %g (adv), %g (eval);"
252 " %u/%lu points not found\n",
254 (
unsigned)notfound, (
unsigned long)total);
260 const double *x_base[
D];
267 if(
id==0) printf(
"Initializing mesh\n");
271 if(
id==0) printf(
"calling findpts_setup\n");
275 if(
id==0) printf(
"calling findpts\n");
276 x_base[0]=pt->
x, x_base[1]=pt->
x+1;
285 x_base , x_stride,
testp.
n, fd);
287 if(
id==0) printf(
"calling findpts_eval (%u)\n",d);
299 int main(
int narg,
char *arg[])
305 MPI_Init(&narg,&arg);
306 world = MPI_COMM_WORLD;
static const double *const elx[D]
int main(int narg, char *arg[])
static double quad_eval(const double coef[MULD(3, 3, 3)], const double r[D])
void rand_elt_2(double *x, double *y, const double *zr, unsigned nr, const double *zs, unsigned ns)
static void test_mesh(void)
static void comm_free(struct comm *c)
static void rand_mesh(void)
static double x3[D][MULD(3, 3, 3)]
static const unsigned nr[D]
static struct array testp
static void test(const struct comm *const comm)
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)
#define INDEXD(a, na, b, nb, c)
#define array_init(T, a, max)
#define sarray_transfer(T, A, proc_field, set_src, cr)
static void print_ptdata(const struct comm *const comm)
establishes some macros to establish naming conventions
static const unsigned mr[D]
static void comm_init(struct comm *c, comm_ext ce)