From a670d325edde9b4580ef31afaad988456660c4ff Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 26 Sep 2012 12:18:19 +0200 Subject: Finish transformation_check --- tests/transformation_check.c | 94 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 19 deletions(-) diff --git a/tests/transformation_check.c b/tests/transformation_check.c index 771e44fe..80324795 100644 --- a/tests/transformation_check.c +++ b/tests/transformation_check.c @@ -35,41 +35,97 @@ #include +static int check_transformation(UnitCell *cell, UnitCellTransformation *tfn) +{ + UnitCell *cnew, *cback; + UnitCellTransformation *inv; + double a[9], b[9]; + int i; + int fail = 0; + + cnew = cell_transform(cell, tfn); + + cback = cell_transform_inverse(cnew, tfn); + + cell_get_cartesian(cell, &a[0], &a[1], &a[2], + &a[3], &a[4], &a[5], + &a[6], &a[7], &a[8]); + cell_get_cartesian(cback, &b[0], &b[1], &b[2], + &b[3], &b[4], &b[5], + &b[6], &b[7], &b[8]); + for ( i=0; i<9; i++ ) { + if ( !within_tolerance(a[i], b[i], 0.1) ) { + fail = 1; + STATUS("%e %e\n", a[i], b[i]); + } + } + + if ( fail ) { + ERROR("Original cell not recovered after transformation:\n"); + cell_print(cell); + tfn_print(tfn); + inv = tfn_inverse(tfn); + tfn_print(inv); + cell_print(cback); + } + + return fail; +} + + int main(int argc, char *argv[]) { int fail = 0; - UnitCell *cell, *cnew, *cback; - UnitCellTransformation *tfn, *inv; + UnitCell *cell, *cref; + UnitCellTransformation *tfn; - cell = cell_new_from_parameters(50e-10, 55e-10, 70e-10, + cref = cell_new_from_parameters(50e-10, 55e-10, 70e-10, deg2rad(67.0), deg2rad(70.0), deg2rad(77.0)); + if ( cref == NULL ) return 1; + + cell = cell_rotate(cref, random_quaternion()); if ( cell == NULL ) return 1; + cell_free(cref); + /* Permutation of axes */ tfn = tfn_identity(); if ( tfn == NULL ) return 1; - tfn_combine(tfn, tfn_vector(0,1,0), - tfn_vector(1,0,0), - tfn_vector(0,0,1)); + tfn_vector(0,0,1), + tfn_vector(1,0,0)); + fail += check_transformation(cell, tfn); + tfn_free(tfn); + /* Doubling of cell in one direction */ + tfn = tfn_identity(); + if ( tfn == NULL ) return 1; + tfn_combine(tfn, tfn_vector(2,0,0), + tfn_vector(0,1,0), + tfn_vector(0,0,1)); + fail += check_transformation(cell, tfn); + tfn_free(tfn); - cell_print(cell); - tfn_print(tfn); + /* Diagonal supercell */ + tfn = tfn_identity(); + if ( tfn == NULL ) return 1; + tfn_combine(tfn, tfn_vector(1,1,0), + tfn_vector(0,1,0), + tfn_vector(0,0,1)); + fail += check_transformation(cell, tfn); + tfn_free(tfn); - cnew = cell_transform(cell, tfn); - cell_print(cnew); + /* Crazy */ + tfn = tfn_identity(); + if ( tfn == NULL ) return 1; + tfn_combine(tfn, tfn_vector(1,1,0), + tfn_vector(0,1,0), + tfn_vector(0,1,1)); + fail += check_transformation(cell, tfn); + tfn_free(tfn); - cback = cell_transform_inverse(cnew, tfn); - inv = tfn_inverse(tfn); - tfn_print(inv); - cell_print(cback); - - cell_get_cartesian(cell, &ax1, &ay1, &az1, - &by1, &by1, &bz1, - &cx1, &cy1, &cz1); - cell_get_cartesian(cback, &ax, &ay, &az, &by, &by, &bz, &cx, &cy, &cz); + cell_free(cell); return fail; } -- cgit v1.2.3