upgrading copyright year from 2015 to 2016
[hkl.git] / tests / hkl-pseudoaxis-e6c-t.c
blob344347e9ffe9dc49b7ae22af570be5f6736ccc5d
1 /* This file is part of the hkl library.
3 * The hkl library is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * The hkl library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright (C) 2003-2016 Synchrotron SOLEIL
17 * L'Orme des Merisiers Saint-Aubin
18 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
22 #include "hkl.h"
23 #include <tap/basic.h>
24 #include <tap/hkl-tap.h>
26 #include "hkl-axis-private.h" /* temporary */
28 #define CHECK_AXIS_VALUE(geometry, axis, value) fabs((value) - hkl_parameter_value_get(hkl_geometry_axis_get(geometry, axis, NULL), HKL_UNIT_DEFAULT)) < HKL_EPSILON
31 static int hkl_geometry_list_check_geometry_unit(const HklGeometryList *self,
32 double mu,
33 double omega,
34 double chi,
35 double phi,
36 double gamma,
37 double delta)
39 const HklGeometryListItem *item;
40 int res = TRUE;
42 HKL_GEOMETRY_LIST_FOREACH(item, self){
43 const HklGeometry *geometry;
45 geometry = hkl_geometry_list_item_geometry_get(item);
47 res = TRUE;
48 res &= CHECK_AXIS_VALUE(geometry, "mu", mu * HKL_DEGTORAD);
49 res &= CHECK_AXIS_VALUE(geometry, "omega", omega * HKL_DEGTORAD);
50 res &= CHECK_AXIS_VALUE(geometry, "chi", chi * HKL_DEGTORAD);
51 res &= CHECK_AXIS_VALUE(geometry, "phi", phi * HKL_DEGTORAD);
52 res &= CHECK_AXIS_VALUE(geometry, "gamma", gamma * HKL_DEGTORAD);
53 res &= CHECK_AXIS_VALUE(geometry, "delta", delta * HKL_DEGTORAD);
55 if (res)
56 break;
58 return res;
61 static void getter(void)
63 int res = TRUE;
64 HklEngineList *engines;
65 HklEngine *engine;
66 const HklFactory *factory;
67 HklGeometry *geometry;
68 HklDetector *detector;
69 HklSample *sample;
71 factory = hkl_factory_get_by_name("E6C", NULL);
72 geometry = hkl_factory_create_new_geometry(factory);
73 sample = hkl_sample_new("test");
75 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
77 engines = hkl_factory_create_new_engine_list(factory);
78 hkl_engine_list_init(engines, geometry, detector, sample);
80 engine = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
82 /* geometry -> pseudo */
83 res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., 0., 0., 60.));
84 res &= DIAG(check_pseudoaxes_v(engine, 0., 0., 1.));
86 res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., 90., 0., 60.));
87 res &= DIAG(check_pseudoaxes_v(engine, 1., 0., 0.));
89 res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., -90., 0., 60.));
90 res &= DIAG(check_pseudoaxes_v(engine, -1., 0., 0.));
92 res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., 180., 0., 60.));
93 res &= DIAG(check_pseudoaxes_v(engine, 0., 0., -1.));
95 res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 45., 0., 135., 0., 90.));
96 res &= DIAG(check_pseudoaxes_v(engine, 1., 0., -1.));
98 ok(res == TRUE, "getter");
100 hkl_engine_list_free(engines);
101 hkl_detector_free(detector);
102 hkl_sample_free(sample);
103 hkl_geometry_free(geometry);
106 static void degenerated(void)
108 int res = TRUE;
109 HklEngineList *engines;
110 HklEngine *engine;
111 const darray_string *modes;
112 const char **mode;
113 const HklFactory *factory;
114 HklGeometry *geometry;
115 HklDetector *detector;
116 HklSample *sample;
117 static double hkl[] = {0, 0, 1};
119 factory = hkl_factory_get_by_name("E6C", NULL);
120 geometry = hkl_factory_create_new_geometry(factory);
121 sample = hkl_sample_new("test");
123 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
125 engines = hkl_factory_create_new_engine_list(factory);
126 hkl_engine_list_init(engines, geometry, detector, sample);
128 engine = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
129 modes = hkl_engine_modes_names_get(engine);
131 darray_foreach(mode, *modes) {
132 const darray_string *parameters;
133 HklGeometryList *geometries;
134 size_t n_params;
136 res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
137 parameters = hkl_engine_parameters_names_get(engine);
138 n_params = darray_size(*parameters);
139 if (n_params){
140 double params[n_params];
142 hkl_engine_parameters_values_get(engine, params, n_params, HKL_UNIT_DEFAULT);
143 params[0] = 0;
144 res &= DIAG(hkl_engine_parameters_values_set(engine, params, n_params, HKL_UNIT_DEFAULT, NULL));
147 /* studdy this degenerated case */
148 geometries = hkl_engine_pseudo_axis_values_set(engine,
149 hkl, ARRAY_SIZE(hkl),
150 HKL_UNIT_DEFAULT, NULL);
151 if (geometries){
152 const HklGeometryListItem *item;
154 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
155 hkl_geometry_set(geometry,
156 hkl_geometry_list_item_geometry_get(item));
157 res &= DIAG(check_pseudoaxes(engine, hkl, 3));
159 hkl_geometry_list_free(geometries);
163 ok(res == TRUE, "degenerated");
165 hkl_engine_list_free(engines);
166 hkl_detector_free(detector);
167 hkl_sample_free(sample);
168 hkl_geometry_free(geometry);
171 static void q2(void)
173 int res = TRUE;
174 HklEngineList *engines;
175 HklEngine *engine;
176 const char **mode;
177 const darray_string *modes;
178 const HklFactory *factory;
179 HklGeometry *geometry;
180 HklDetector *detector;
181 HklSample *sample;
183 factory = hkl_factory_get_by_name("E6C", NULL);
184 geometry = hkl_factory_create_new_geometry(factory);
185 sample = hkl_sample_new("test");
187 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
189 engines = hkl_factory_create_new_engine_list(factory);
190 hkl_engine_list_init(engines, geometry, detector, sample);
192 engine = hkl_engine_list_engine_get_by_name(engines, "q2", NULL);
193 modes = hkl_engine_modes_names_get(engine);
195 /* the init part */
196 res &= DIAG(hkl_geometry_set_values_v(geometry, HKL_UNIT_USER, NULL, 0., 30., 0., 0., 0., 60.));
197 res &= DIAG(hkl_engine_initialized_set(engine, TRUE, NULL));
199 darray_foreach(mode, *modes){
200 double q, alpha;
202 res &= DIAG(hkl_engine_current_mode_set(engine, *mode, NULL));
203 for(q=0.1; q<1.; q += 0.1)
204 for(alpha = -M_PI; alpha<M_PI; alpha += M_PI/180.){
205 double values[] = {q, alpha};
206 HklGeometryList *geometries;
208 geometries = hkl_engine_pseudo_axis_values_set(engine,
209 values, ARRAY_SIZE(values),
210 HKL_UNIT_DEFAULT, NULL);
211 if(geometries){
212 const HklGeometryListItem *item;
214 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
215 hkl_geometry_set(geometry, hkl_geometry_list_item_geometry_get(item));
216 res &= DIAG(check_pseudoaxes(engine, values, 2));
218 hkl_geometry_list_free(geometries);
223 ok(res == TRUE, "q2");
225 hkl_engine_list_free(engines);
226 hkl_detector_free(detector);
227 hkl_sample_free(sample);
228 hkl_geometry_free(geometry);
231 static void petra3(void)
233 static double hkl_v[] = {1, 1, 0};
234 static double hkl_p[] = {0, 0, 1, 90 * HKL_DEGTORAD};
235 static double psi_p[] = {0, 0, 1};
236 int res = TRUE;
237 HklEngineList *engines;
238 HklEngine *hkl;
239 HklEngine *psi;
240 const HklFactory *factory;
241 HklGeometry *geometry;
242 HklGeometryList *geometries;
243 HklDetector *detector;
244 HklSample *sample;
245 HklLattice *lattice;
246 HklMatrix *U;
248 factory = hkl_factory_get_by_name("E6C", NULL);
249 geometry = hkl_factory_create_new_geometry(factory);
250 res &= DIAG(hkl_geometry_wavelength_set(geometry, 2.033, HKL_UNIT_DEFAULT, NULL));
252 sample = hkl_sample_new("test");
253 lattice = hkl_lattice_new(7.813, 7.813, 7.813,
254 90*HKL_DEGTORAD, 90*HKL_DEGTORAD, 90*HKL_DEGTORAD,
255 NULL);
256 hkl_sample_lattice_set(sample, lattice);
257 hkl_lattice_free(lattice);
259 U = hkl_matrix_new_euler(-112.5 * HKL_DEGTORAD,
260 -87.84 * HKL_DEGTORAD,
261 157.48 * HKL_DEGTORAD);
262 hkl_sample_U_set(sample, U, NULL);
263 hkl_matrix_free(U);
265 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
267 engines = hkl_factory_create_new_engine_list(factory);
268 hkl_engine_list_init(engines, geometry, detector, sample);
270 /* set the psi pseudo axis */
271 psi = hkl_engine_list_engine_get_by_name(engines, "psi", NULL);
272 /* set the mode parameters 0, 0, 1 */
273 res &= DIAG(hkl_engine_parameters_values_set(psi, psi_p, ARRAY_SIZE(psi_p), HKL_UNIT_DEFAULT, NULL));
275 /* Compute the hkl [1, 1, 0] in psi_constant_vertical mode with */
276 /* h2,k2,l2= [0, 0,1] and psi = 90 */
277 /* set the hkl pseudo axis in psi_constant_vertical */
278 hkl = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
279 res &= DIAG(hkl_engine_current_mode_set(hkl, "psi_constant_vertical", NULL));
280 /* set the mode parameters 0, 0, 1, 90. */
281 res &= DIAG(hkl_engine_parameters_values_set(hkl, hkl_p, ARRAY_SIZE(hkl_p), HKL_UNIT_DEFAULT, NULL));
282 geometries = hkl_engine_pseudo_axis_values_set(hkl, hkl_v, ARRAY_SIZE(hkl_v),
283 HKL_UNIT_DEFAULT, NULL);
284 if(geometries){
285 const HklGeometryListItem *item;
287 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
288 double PSI = hkl_p[3];
289 double current;
291 hkl_geometry_set(geometry,
292 hkl_geometry_list_item_geometry_get(item));
293 res &= DIAG(hkl_engine_initialized_set(psi, TRUE, NULL));
294 res &= DIAG(hkl_engine_pseudo_axis_values_get(psi, &current, 1,
295 HKL_UNIT_DEFAULT, NULL));
296 res &= DIAG(fabs(PSI - current) < HKL_EPSILON);
298 hkl_geometry_list_free(geometries);
301 ok(res == TRUE, "petra3");
303 hkl_engine_list_free(engines);
304 hkl_detector_free(detector);
305 hkl_sample_free(sample);
306 hkl_geometry_free(geometry);
309 /* Problem observed with the psi_constant_vertical mode */
310 static void petra3_2(void)
312 int res = TRUE;
313 HklEngineList *engines;
314 HklEngine *hkl;
315 HklEngine *psi;
316 const HklFactory *factory;
317 const HklGeometryListItem *item;
318 HklGeometry *geometry;
319 HklGeometryList *geometries;
320 HklDetector *detector;
321 HklSample *sample;
322 HklLattice *lattice;
323 HklMatrix *U;
324 double PSI;
325 double hkl_p[4];
326 double psi_p[3];
328 /* Wavelength 1.0332035 */
329 /* Mode psi_constant_vertical */
330 /* UB11 0.000 UB12 1.232 UB13 0.000 */
331 /* UB21 0.000 UB22 -0.000 UB23 1.232 */
332 /* UB31 1.232 UB32 -0.000 UB33 -0.000 */
333 /* Ux -90 Uy 6.84979352816457e-15 Uz -90 */
334 /* A 5.1 B 5.1 C 5.1 */
335 /* Alpha 90 Beta 90 Gamma 90 */
337 factory = hkl_factory_get_by_name("E6C", NULL);
338 geometry = hkl_factory_create_new_geometry(factory);
339 res &= DIAG(hkl_geometry_wavelength_set(geometry, 1.0332035, HKL_UNIT_DEFAULT, NULL));
341 sample = hkl_sample_new("test");
342 lattice = hkl_lattice_new(5.1, 5.1, 5.1,
343 90*HKL_DEGTORAD, 90*HKL_DEGTORAD, 90*HKL_DEGTORAD,
344 NULL);
345 hkl_sample_lattice_set(sample, lattice);
346 hkl_lattice_free(lattice);
347 U = hkl_matrix_new_euler(-90.0 * HKL_DEGTORAD,
348 0.0 * HKL_DEGTORAD,
349 -90.0 * HKL_DEGTORAD);
350 hkl_sample_U_set(sample, U, NULL);
351 hkl_matrix_free(U);
353 detector = hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D);
355 engines = hkl_factory_create_new_engine_list(factory);
356 hkl_engine_list_init(engines, geometry, detector, sample);
358 /* set the hkl pseudo axis in psi_constant_vertical */
359 hkl = hkl_engine_list_engine_get_by_name(engines, "hkl", NULL);
360 res &= DIAG(hkl_engine_current_mode_set(hkl, "psi_constant_vertical", NULL));
361 /* set the psi pseudo engine to read the psi value */
362 psi = hkl_engine_list_engine_get_by_name(engines, "psi", NULL);
364 /* PsiRef 0 1 0 */
365 /* freeze 0; ca 0 0 2 */
366 /* for hkl */
367 hkl_p[0] = 0;
368 hkl_p[1] = 1;
369 hkl_p[2] = 0;
370 hkl_p[3] = PSI = 0;
371 res &= DIAG(hkl_engine_parameters_values_set(hkl, hkl_p, ARRAY_SIZE(hkl_p), HKL_UNIT_DEFAULT, NULL));
372 /* for psi */
373 psi_p[0] = 0;
374 psi_p[1] = 1;
375 psi_p[2] = 0;
376 res &= DIAG(hkl_engine_parameters_values_set(psi, psi_p, ARRAY_SIZE(psi_p), HKL_UNIT_DEFAULT, NULL));
378 /* freeze 0; ca 0 0 2 */
379 geometries = hkl_engine_set_values_v(hkl, 0., 0., 2.);
381 /* del th chi phi */
382 /* 23.37668 11.68835 90 -90 */
383 /* gamma mu */
384 /* -2.384186e-09 -1.182388e-14 */
385 /* the -90 value of phi is problematic, the right value is 0 */
386 if(geometries){
387 res &= DIAG(hkl_geometry_list_check_geometry_unit(geometries, 0., 11.688393153063114, 90., 0., 0., 23.376786185344031));
389 /* check that all solution gives the right psi */
390 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
391 double current;
393 hkl_geometry_set(geometry, hkl_geometry_list_item_geometry_get(item));
394 res &= DIAG(hkl_engine_initialized_set(psi, TRUE, NULL));
395 res &= DIAG(hkl_engine_pseudo_axis_values_get(psi, &current, 1,
396 HKL_UNIT_DEFAULT, NULL));
397 res &= DIAG(fabs(PSI - current) < HKL_EPSILON);
399 hkl_geometry_list_free(geometries);
402 /* freeze 45; ca 0 0 2 */
403 hkl_p[3] = PSI = 45.0 * HKL_DEGTORAD;
404 res &= DIAG(hkl_engine_parameters_values_set(hkl, hkl_p, ARRAY_SIZE(hkl_p), HKL_UNIT_DEFAULT, NULL));
405 geometries = hkl_engine_set_values_v(hkl, 0., 0., 2.);
407 /* del th chi phi */
408 /* 23.3768 11.68831 90 -135 */
409 /* gamma mu */
410 /* -2.384186e-09 -1.182388e-14 */
411 /* -135 n'est pas bon il faudrait plutôt -45 */
412 if(geometries){
413 res &= DIAG(hkl_geometry_list_check_geometry_unit(geometries, 0., 11.688393153063114, 90., -45., 0., 23.376786185344031));
415 /* check that all solution gives the right psi */
416 HKL_GEOMETRY_LIST_FOREACH(item, geometries) {
417 double current;
419 hkl_geometry_set(geometry, hkl_geometry_list_item_geometry_get(item));
420 res &= DIAG(hkl_engine_initialized_set(psi, TRUE, NULL));
421 res &= DIAG(hkl_engine_pseudo_axis_values_get(psi, &current, 1,
422 HKL_UNIT_DEFAULT, NULL));
423 res &= DIAG(fabs(PSI - current) < HKL_EPSILON);
425 hkl_geometry_list_free(geometries);
428 /* PsiRef 1 1 0 */
429 /* freeze 0; ca 0 0 2 */
430 hkl_p[0] = 1;
431 hkl_p[1] = 1;
432 hkl_p[2] = 0;
433 hkl_p[3] = PSI = 0;
434 /* for hkl */
435 res &= DIAG(hkl_engine_parameters_values_set(hkl, hkl_p, ARRAY_SIZE(hkl_p), HKL_UNIT_DEFAULT, NULL));
436 geometries = hkl_engine_set_values_v(hkl, 0., 0., 2.);
438 /* for psi */
439 psi_p[0] = 1;
440 psi_p[1] = 1;
441 psi_p[2] = 0;
442 res &= DIAG(hkl_engine_parameters_values_set(psi, psi_p, ARRAY_SIZE(psi_p), HKL_UNIT_DEFAULT, NULL));
444 /* del th chi phi */
445 /* 23.37681 11.68839 90 -90 */
446 /* gamma mu */
447 /* -2.384186e-09 -1.182388e-14 */
448 /* phi is wrong it should be -45 */
449 if(geometries){
450 res &= DIAG(hkl_geometry_list_check_geometry_unit(geometries, 0, 11.688393153063114, 90, -45, 0, 23.376786185344031));
452 /* check that all solution gives the right psi */
453 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
454 double current;
456 hkl_geometry_set(geometry, hkl_geometry_list_item_geometry_get(item));
457 res &= DIAG(hkl_engine_initialized_set(psi, TRUE, NULL));
458 res &= DIAG(hkl_engine_pseudo_axis_values_get(psi, &current, 1,
459 HKL_UNIT_DEFAULT, NULL));
460 res &= DIAG(fabs(PSI - current) < HKL_EPSILON);
462 hkl_geometry_list_free(geometries);
465 /* freeze 45; ca 0 0 2 */
466 hkl_p[3] = PSI = 45 * HKL_DEGTORAD;
467 /* for hkl */
468 res &= DIAG(hkl_engine_parameters_values_set(hkl, hkl_p, ARRAY_SIZE(hkl_p), HKL_UNIT_DEFAULT, NULL));
469 geometries = hkl_engine_set_values_v(hkl, 0., 0., 2.);
471 /* del th chi phi */
472 /* 23.37666 11.68837 90 -135 */
473 /* gamma mu */
474 /* -2.384186e-09 -1.182388e-14 */
475 /* phi is wrong it should be -90 */
476 if(geometries){
477 res &= DIAG(hkl_geometry_list_check_geometry_unit(geometries, 0, 11.688393153063114, 90, -90, 0, 23.376786185344031));
479 /* check that all solution gives the right psi */
480 HKL_GEOMETRY_LIST_FOREACH(item, geometries){
481 double current;
483 hkl_geometry_set(geometry, hkl_geometry_list_item_geometry_get(item));
484 res &= DIAG(hkl_engine_initialized_set(psi, TRUE, NULL));
485 res &= DIAG(hkl_engine_pseudo_axis_values_get(psi, &current, 1,
486 HKL_UNIT_DEFAULT, NULL));
487 res &= DIAG(fabs(PSI - current) < HKL_EPSILON);
489 hkl_geometry_list_free(geometries);
492 ok(res == TRUE, __func__);
494 hkl_engine_list_free(engines);
495 hkl_detector_free(detector);
496 hkl_sample_free(sample);
497 hkl_geometry_free(geometry);
500 int main(void)
502 plan(5);
504 getter();
505 degenerated();
506 q2();
507 petra3();
508 petra3_2();
510 return 0;