aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-10-26 14:36:30 +0100
committerThomas White <taw@physics.org>2020-10-26 14:36:30 +0100
commit6472ff2d8e5b08f1da978ba8413eca556f3d57b6 (patch)
treeeee4193782329ce5b75a66403b2fc1fb36a12ce3
parent882d05e8420ff0f2d7c48a6979bb355242f28a68 (diff)
cellcompare_check: Factorise code and reduce to 1 repetition of each
Otherwise it takes far too long.
-rw-r--r--tests/cellcompare_check.c270
1 files 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<ntrial; i++ ) {
+ return 0;
+}
- 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;
+static int test_rotation_and_permutation(UnitCell *cref, gsl_rng *rng,
+ double *tols)
+{
+ IntegerMatrix *tr;
+ UnitCell *cell;
+ UnitCell *cell2;
- cell_free(cell);
- progress_bar(i+1, ntrial, "Plain rotation");
- }
+ cell2 = cell_rotate(cref, random_quaternion(rng));
+ if ( cell2 == NULL ) return 1;
- /* Permute axes but don't rotate */
- for ( i=0; i<ntrial; i++ ) {
+ tr = random_permutation(rng);
+ cell = cell_transform_intmat(cell2, tr);
+ cell_free(cell2);
- IntegerMatrix *tr;
+ if ( check_ccp(cell, cref, tols, intmat_is_identity(tr)) ) 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;
- tr = random_permutation(rng);
- cell = cell_transform_intmat(cref, tr);
+ cell_free(cell);
+ intmat_free(tr);
- 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;
+ return 0;
+}
- cell_free(cell);
- intmat_free(tr);
- progress_bar(i+1, ntrial, "Axis permutation");
- }
- /* Rotate cell and permute axes */
- for ( i=0; i<ntrial; i++ ) {
+static int test_derivative_lattice(UnitCell *cref, gsl_rng *rng,
+ double *tols)
+{
+ RationalMatrix *tr;
+ UnitCell *cell;
- IntegerMatrix *tr;
- UnitCell *cell2;
+ cell = NULL;
+ tr = NULL;
+ do {
+ cell_free(cell);
+ rtnl_mtx_free(tr);
+ tr = random_derivative(rng);
+ cell = cell_transform_rational(cref, tr);
+ } while ( (cell_get_centering(cell) == '?')
+ || (cell_get_centering(cell) == 'H' ) );
+ /* H centering is no good because it needs a unique axis to
+ * be specified in order for uncentering in c_r_c_p to work.
+ * cell_transform_rational doesn't set the unique axis (yet?) */
+
+ if ( check_ccp(cell, cref, tols, rtnl_mtx_is_identity(tr)) ) return 1;
+ if ( check_ccpao(cell, cref, tols, rtnl_mtx_is_identity(tr)) ) return 1;
+ if ( check_cpcpao(cell, cref, tols, rtnl_mtx_is_perm(tr)) ) return 1;
+ if ( check_cdcp(cell, cref, tols, tr, 1) ) return 1;
+ /* check_crcp: Sometimes yes, hard to tell */
- cell2 = cell_rotate(cref, random_quaternion(rng));
- if ( cell2 == NULL ) return 1;
+ cell_free(cell);
+ rtnl_mtx_free(tr);
- tr = random_permutation(rng);
- cell = cell_transform_intmat(cell2, tr);
- cell_free(cell2);
+ return 0;
+}
- if ( check_ccp(cell, cref, tols, intmat_is_identity(tr)) ) 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);
- intmat_free(tr);
- progress_bar(i+1, ntrial, "Rotation with axis permutation");
- }
+static int test_derivative_lattice_rotation(UnitCell *cref, gsl_rng *rng,
+ double *tols)
+{
+ RationalMatrix *tr;
+ UnitCell *cell;
+ UnitCell *cell2;
- /* Derivative lattice */
- for ( i=0; i<ntrial; i++ ) {
-
- RationalMatrix *tr;
-
- cell = NULL;
- tr = NULL;
- do {
- cell_free(cell);
- rtnl_mtx_free(tr);
- tr = random_derivative(rng);
- cell = cell_transform_rational(cref, tr);
- } while ( (cell_get_centering(cell) == '?')
- || (cell_get_centering(cell) == 'H' ) );
- /* H centering is no good because it needs a unique axis to
- * be specified in order for uncentering in c_r_c_p to work.
- * cell_transform_rational doesn't set the unique axis (yet?) */
-
- if ( check_ccp(cell, cref, tols, rtnl_mtx_is_identity(tr)) ) return 1;
- if ( check_ccpao(cell, cref, tols, rtnl_mtx_is_identity(tr)) ) return 1;
- if ( check_cpcpao(cell, cref, tols, rtnl_mtx_is_perm(tr)) ) return 1;
- if ( check_cdcp(cell, cref, tols, tr, 1) ) return 1;
- /* check_crcp: Sometimes yes, hard to tell */
+ cell2 = cell_rotate(cref, random_quaternion(rng));
+ if ( cell2 == NULL ) return 1;
+ cell = NULL;
+ tr = NULL;
+ do {
cell_free(cell);
rtnl_mtx_free(tr);
- progress_bar(i+1, ntrial, "Derivative lattice");
- }
+ tr = random_derivative(rng);
+ cell = cell_transform_rational(cell2, tr);
+ } while ( (cell_get_centering(cell) == '?')
+ || (cell_get_centering(cell) == 'H' ) ); /* See above */
+ cell_free(cell2);
+
+ if ( check_ccp(cell, cref, tols, rtnl_mtx_is_identity(tr)) ) 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, tr, 1) ) return 1;
+ /* check_crcp: Sometimes yes, hard to tell */
+
+ cell_free(cell);
+ rtnl_mtx_free(tr);
+
+ return 0;
+}
- /* Derivative lattice and rotate */
- for ( i=0; i<ntrial; i++ ) {
- RationalMatrix *tr;
- UnitCell *cell2;
+extern IntegerMatrix *reduce_g6(struct g6 g, double epsrel);
- cell2 = cell_rotate(cref, random_quaternion(rng));
- if ( cell2 == NULL ) return 1;
+int main(int argc, char *argv[])
+{
+ UnitCell *cref;
+ gsl_rng *rng;
+ int fail = 0;
+ double tols[] = { 0.01, 0.01, 0.01,
+ deg2rad(1.0), deg2rad(1.0), deg2rad(1.0) };
- cell = NULL;
- tr = NULL;
- do {
- cell_free(cell);
- rtnl_mtx_free(tr);
- tr = random_derivative(rng);
- cell = cell_transform_rational(cell2, tr);
- } while ( (cell_get_centering(cell) == '?')
- || (cell_get_centering(cell) == 'H' ) ); /* See above */
- cell_free(cell2);
+ rng = gsl_rng_alloc(gsl_rng_mt19937);
- if ( check_ccp(cell, cref, tols, rtnl_mtx_is_identity(tr)) ) 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, tr, 1) ) return 1;
- /* check_crcp: Sometimes yes, hard to tell */
+ 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);
- rtnl_mtx_free(tr);
- progress_bar(i+1, ntrial, "Derivative lattice with rotation");
- }
+ fail += test_plain_rotation(cref, rng, tols);
+ fail += test_permutation_no_rotation(cref, rng, tols);
+ fail += test_rotation_and_permutation(cref, rng, tols);
+ fail += test_derivative_lattice(cref, rng, tols);
+ fail += test_derivative_lattice_rotation(cref, rng, tols);
cell_free(cref);
gsl_rng_free(rng);
- return 0;
+ return fail;
}