From 6472ff2d8e5b08f1da978ba8413eca556f3d57b6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 26 Oct 2020 14:36:30 +0100 Subject: cellcompare_check: Factorise code and reduce to 1 repetition of each Otherwise it takes far too long. --- tests/cellcompare_check.c | 270 +++++++++++++++++++++------------------------- 1 file changed, 123 insertions(+), 147 deletions(-) diff --git a/tests/cellcompare_check.c b/tests/cellcompare_check.c index dea3eead..fa9bf869 100644 --- a/tests/cellcompare_check.c +++ b/tests/cellcompare_check.c @@ -207,192 +207,168 @@ static int check_crcp(UnitCell *cell, UnitCell *cref, double *tols, } -static void yaro_test() +static int test_plain_rotation(UnitCell *cref, gsl_rng *rng, + double *tols) { UnitCell *cell; - UnitCell *reference; - UnitCell *cmatch; - //float tols[] = {5, 5, 5, 1.5}; - double dtols[] = {0.05, 0.05, 0.05, deg2rad(5.0), deg2rad(5.0), deg2rad(5.0)}; - - cell = cell_new_from_parameters(63.24e-10, 63.94e-10, 64.61e-10, - deg2rad(89.98), deg2rad(89.82), deg2rad(119.87)); - cell_set_unique_axis(cell, 'c'); - cell_set_lattice_type(cell, L_HEXAGONAL); - cell_set_centering(cell, 'P'); - - reference = cell_new_from_parameters(64.7e-10, 64.7e-10, 65.2e-10, - deg2rad(90.0), deg2rad(90.0), deg2rad(120.0)); - cell_set_unique_axis(reference, 'c'); - cell_set_lattice_type(reference, L_HEXAGONAL); - cell_set_centering(reference, 'P'); - - STATUS("The cell:\n"); - cell_print(cell); - STATUS("The reference:\n"); - cell_print(reference); - //cmatch = match_cell(cell, reference, 0, tols, 1); - //STATUS("The match:\n"); - //cell_print(cmatch); - //cell_free(cmatch); - RationalMatrix *m = NULL; - cmatch = compare_reindexed_cell_parameters(cell, reference, dtols, &m); - STATUS("The new match:\n"); - cell_print(cmatch); - STATUS("The matrix:\n"); - rtnl_mtx_print(m); - cell_free(cmatch); - rtnl_mtx_free(m); + cell = cell_rotate(cref, random_quaternion(rng)); + if ( cell == NULL ) return 1; + + if ( check_ccp(cell, cref, tols, 1) ) return 1; + if ( check_ccpao(cell, cref, tols, 0) ) return 1; + if ( check_cpcpao(cell, cref, tols, 0) ) return 1; + if ( check_cdcp(cell, cref, tols, NULL, 1) ) return 1; + if ( check_crcp(cell, cref, tols, NULL, 1) ) return 1; cell_free(cell); - cell_free(reference); -} + return 0; +} -extern IntegerMatrix *reduce_g6(struct g6 g, double epsrel); -int main(int argc, char *argv[]) +static int test_permutation_no_rotation(UnitCell *cref, gsl_rng *rng, + double *tols) { - UnitCell *cell, *cref; - gsl_rng *rng; - int i; - const int ntrial = 5; - double tols[] = { 0.01, 0.01, 0.01, - deg2rad(1.0), deg2rad(1.0), deg2rad(1.0) }; + IntegerMatrix *tr; + UnitCell *cell; - rng = gsl_rng_alloc(gsl_rng_mt19937); + tr = random_permutation(rng); + cell = cell_transform_intmat(cref, tr); - yaro_test(); + if ( check_ccp(cell, cref, tols, intmat_is_identity(tr)) ) return 1; + if ( check_ccpao(cell, cref, tols, intmat_is_identity(tr)) ) return 1; + if ( check_cpcpao(cell, cref, tols, 1) ) return 1; + if ( check_cdcp(cell, cref, tols, NULL, 1) ) return 1; + if ( check_crcp(cell, cref, tols, NULL, 1) ) return 1; - cref = cell_new_from_parameters(3e-10, 5.196e-10, 2e-10, - deg2rad(103.9166666), - deg2rad(109.4666666), - deg2rad(134.8833333)); - cell_set_centering(cref, 'P'); - if ( cref == NULL ) return 1; + cell_free(cell); + intmat_free(tr); - /* Just rotate cell */ - for ( i=0; i