From ab4b7140c160f84d9c0bc5ecfeb5efd51651d82e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 6 Sep 2017 14:48:29 +0200 Subject: tests/transformation_check: Check lots more things --- tests/transformation_check.c | 222 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 214 insertions(+), 8 deletions(-) (limited to 'tests/transformation_check.c') diff --git a/tests/transformation_check.c b/tests/transformation_check.c index 3affb652..2e7e7378 100644 --- a/tests/transformation_check.c +++ b/tests/transformation_check.c @@ -39,18 +39,152 @@ #include -static int check_transformation(UnitCell *cell, UnitCellTransformation *tfn) +#define MAX_REFLS (10*1024) + +static struct rvec *all_refls(UnitCell *cell, double max_r, int *n) +{ + double asx, asy, asz; + double bsx, bsy, bsz; + double csx, csy, csz; + double ax, ay, az; + double bx, by, bz; + double cx, cy, cz; + signed int h, k, l; + int hmax, kmax, lmax; + struct rvec *r; + int i = 0; + + r = malloc(sizeof(struct rvec)*MAX_REFLS); + if ( r == NULL ) return NULL; + + cell_get_cartesian(cell, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz); + + hmax = max_r * modulus(ax, ay, az); + kmax = max_r * modulus(bx, by, bz); + lmax = max_r * modulus(cx, cy, cz); + + cell_get_reciprocal(cell, &asx, &asy, &asz, + &bsx, &bsy, &bsz, + &csx, &csy, &csz); + + for ( h=-hmax; h<=hmax; h++ ) { + for ( k=-kmax; k<=kmax; k++ ) { + for ( l=-lmax; l<=lmax; l++ ) { + + if ( (h==0) && (k==0) && (l==0) ) continue; + if ( forbidden_reflection(cell, h, k, l) ) continue; + if ( 2.0*resolution(cell, h, k, l) > max_r ) continue; + + r[i].u = h*asx + k*bsx + l*csx; + r[i].v = h*asy + k*bsy + l*csy; + r[i].w = h*asz + k*bsz + l*csz; + i++; + + if ( i == MAX_REFLS ) { + ERROR("Too many reflections.\n"); + return NULL; + } + } + } + } + + *n = i; + return r; +} + + + +static int tolerance(double a, double b) +{ + if ( fabs(a-b) < 1e6 ) return 1; + return 0; +} + + +static int find_rvec(struct rvec *l, int n, struct rvec f) +{ + int i; + for ( i=0; i na ) return 1; + return 0; +} + + +static int check_transformation(UnitCell *cell, UnitCellTransformation *tfn, + int pred_test, UnitCell *ct) { UnitCell *cnew, *cback; UnitCellTransformation *inv; double a[9], b[9]; int i; int fail = 0; + struct rvec *vecs; + struct rvec *tvecs; + int na, nb; - cnew = cell_transform(cell, tfn); - + STATUS("-----------------------\n"); + if ( ct == NULL ) { + cnew = cell_transform(cell, tfn); + } else { + cnew = ct; + } cback = cell_transform_inverse(cnew, tfn); + cell_print(cell); + tfn_print(tfn); + cell_print(cnew); + + if ( pred_test ) { + /* Check that the two cells predict the same reflections */ + vecs = all_refls(cell, 1e9, &na); + tvecs = all_refls(cnew, 1e9, &nb); + if ( compare_rvecs(vecs, na, tvecs, nb) + || compare_rvecs(tvecs, nb, vecs, na) ) + { + ERROR("Transformed cell didn't predict the same reflections\n"); + //printf("---\n"); + //for ( i=0; i