// // main // int main(int argc, char *argv[]) { _F_ int res = ERR_SUCCESS; #ifdef WITH_PETSC PetscInitialize(&argc, &argv, (char *) PETSC_NULL, PETSC_NULL); #endif set_verbose(false); H1ShapesetLobattoHex shapeset; try { // I. linear independency if (!test_lin_indep(&shapeset)) throw ERR_FAILURE; // II. test zero fn. values if (!test_zero_values(&shapeset)) throw ERR_FAILURE; // III. continuity on boundaries if (!test_continuity(&shapeset)) throw ERR_FAILURE; // IV. gradients if (!test_gradients(&shapeset)) throw ERR_FAILURE; // V. computes gradients numericaly from fn values and compares if (!test_gradients_directly(&shapeset)) throw ERR_FAILURE; printf("Shapeset OK\n"); } catch (int e) { printf("Test failed\n"); res = e; } #ifdef WITH_PETSC PetscFinalize(); #endif TRACE_END; return res; }
int main(int argc, char *argv[]) { struct image image; const double incr_frac = 1.0/1000000.0; double incr_val; double ax, ay, az; double bx, by, bz; double cx, cy, cz; UnitCell *cell; Crystal *cr; struct quaternion orientation; int i; int fail = 0; int quiet = 0; int plot = 0; int c; gsl_rng *rng; const struct option longopts[] = { {"quiet", 0, &quiet, 1}, {"plot", 0, &plot, 1}, {0, 0, NULL, 0} }; while ((c = getopt_long(argc, argv, "", longopts, NULL)) != -1) { switch (c) { case 0 : break; case '?' : break; default : ERROR("Unhandled option '%c'\n", c); break; } } image.width = 1024; image.height = 1024; image.det = simple_geometry(&image); image.det->panels[0].res = 13333.3; image.det->panels[0].clen = 80e-3; image.det->panels[0].coffset = 0.0; image.lambda = ph_en_to_lambda(eV_to_J(8000.0)); image.div = 1e-3; image.bw = 0.01; image.filename = malloc(256); cr = crystal_new(); if ( cr == NULL ) { ERROR("Failed to allocate crystal.\n"); return 1; } crystal_set_mosaicity(cr, 0.0); crystal_set_profile_radius(cr, 0.005e9); crystal_set_image(cr, &image); cell = cell_new_from_parameters(10.0e-9, 10.0e-9, 10.0e-9, deg2rad(90.0), deg2rad(90.0), deg2rad(90.0)); rng = gsl_rng_alloc(gsl_rng_mt19937); for ( i=0; i<2; i++ ) { UnitCell *rot; double val; PartialityModel pmodel; if ( i == 0 ) { pmodel = PMODEL_SCSPHERE; STATUS("Testing SCSphere model:\n"); } else if ( i == 1 ) { pmodel = PMODEL_SCGAUSSIAN; STATUS("Testing SCGaussian model.\n"); } else { ERROR("WTF?\n"); return 1; } orientation = random_quaternion(rng); rot = cell_rotate(cell, orientation); crystal_set_cell(cr, rot); cell_get_reciprocal(rot, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz); incr_val = incr_frac * image.div; val = test_gradients(cr, incr_val, REF_DIV, "div", "div", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * crystal_get_profile_radius(cr); val = test_gradients(cr, incr_val, REF_R, "R", "R", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * ax; val = test_gradients(cr, incr_val, REF_ASX, "ax*", "x", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * bx; val = test_gradients(cr, incr_val, REF_BSX, "bx*", "x", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * cx; val = test_gradients(cr, incr_val, REF_CSX, "cx*", "x", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * ay; val = test_gradients(cr, incr_val, REF_ASY, "ay*", "y", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * by; val = test_gradients(cr, incr_val, REF_BSY, "by*", "y", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * cy; val = test_gradients(cr, incr_val, REF_CSY, "cy*", "y", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * az; val = test_gradients(cr, incr_val, REF_ASZ, "az*", "z", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * bz; val = test_gradients(cr, incr_val, REF_BSZ, "bz*", "z", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; incr_val = incr_frac * cz; val = test_gradients(cr, incr_val, REF_CSZ, "cz*", "z", pmodel, quiet, plot); if ( val < 0.99 ) fail = 1; } gsl_rng_free(rng); return fail; }