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-2019, 2021 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>
23 #include <tap/basic.h>
24 #include <tap/hkl-tap.h>
26 static void degenerated(void)
29 HklEngineList
*engines
;
31 const darray_string
*modes
;
33 HklGeometry
*geometry
;
34 HklDetector
*detector
;
36 static double hkl
[] = {0, 1, 0};
37 Geometry gconf
= K4cv(1.54, VALUES(30., 0., 0., 60.));
38 struct Sample cu
= CU
;
40 geometry
= newGeometry(gconf
);
41 engines
= newEngines(gconf
);
42 sample
= newSample(cu
);
44 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
46 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
48 engine
= hkl_engine_list_engine_get_by_name(engines
, "hkl", NULL
);
49 modes
= hkl_engine_modes_names_get(engine
);
51 darray_foreach(mode
, *modes
) {
52 const darray_string
*parameters
;
53 HklGeometryList
*geometries
;
56 res
&= DIAG(hkl_engine_current_mode_set(engine
, *mode
, NULL
));
57 parameters
= hkl_engine_parameters_names_get(engine
);
58 n_params
= darray_size(*parameters
);
60 double params
[n_params
];
62 hkl_engine_parameters_values_get(engine
, params
, n_params
, HKL_UNIT_DEFAULT
);
64 res
&= DIAG(hkl_engine_parameters_values_set(engine
, params
, n_params
, HKL_UNIT_DEFAULT
, NULL
));
67 /* studdy this degenerated case */
68 geometries
= hkl_engine_pseudo_axis_values_set(engine
,
70 HKL_UNIT_DEFAULT
, NULL
);
72 const HklGeometryListItem
*item
;
74 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
75 hkl_geometry_set(geometry
,
76 hkl_geometry_list_item_geometry_get(item
));
77 res
&= DIAG(check_pseudoaxes(engine
, hkl
, 3));
79 hkl_geometry_list_free(geometries
);
83 ok(res
== TRUE
, "degenerated");
85 hkl_engine_list_free(engines
);
86 hkl_detector_free(detector
);
87 hkl_sample_free(sample
);
88 hkl_geometry_free(geometry
);
91 static void eulerians(void)
94 HklEngineList
*engines
;
96 const darray_string
*modes
;
98 HklGeometry
*geometry
;
99 HklDetector
*detector
;
101 static double eulerians
[] = {0., 90 * HKL_DEGTORAD
, 0.};
102 Geometry gconf
= K4cv(1.54, VALUES(0., 0., 0., 0.));
103 struct Sample cu
= CU
;
105 geometry
= newGeometry(gconf
);
106 engines
= newEngines(gconf
);
107 sample
= newSample(cu
);
109 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
111 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
113 engine
= hkl_engine_list_engine_get_by_name(engines
, "eulerians", NULL
);
114 modes
= hkl_engine_modes_names_get(engine
);
116 darray_foreach(mode
, *modes
){
117 const darray_string
*parameters
;
118 HklGeometryList
*geometries
;
121 res
&= DIAG(hkl_engine_current_mode_set(engine
, *mode
, NULL
));
122 parameters
= hkl_engine_parameters_names_get(engine
);
123 n_params
= darray_size(*parameters
);
125 double params
[n_params
];
127 hkl_engine_parameters_values_get(engine
, params
, n_params
, HKL_UNIT_DEFAULT
);
129 res
&= DIAG(hkl_engine_parameters_values_set(engine
, params
, n_params
, HKL_UNIT_DEFAULT
, NULL
));
132 /* studdy this degenerated case */
133 geometries
= hkl_engine_pseudo_axis_values_set(engine
,
134 eulerians
, ARRAY_SIZE(eulerians
),
135 HKL_UNIT_DEFAULT
, NULL
);
137 const HklGeometryListItem
*item
;
139 /* first solution = -180, -90, 180 */
140 item
= hkl_geometry_list_items_first_get(geometries
);
141 hkl_geometry_set(geometry
,
142 hkl_geometry_list_item_geometry_get(item
));
143 res
&= DIAG(check_pseudoaxes_v(engine
, -180. * HKL_DEGTORAD
, -90 * HKL_DEGTORAD
, 180. * HKL_DEGTORAD
));
145 /* second solution = 0, 90, 0 */
146 item
= hkl_geometry_list_items_next_get(geometries
,item
);
147 hkl_geometry_set(geometry
,
148 hkl_geometry_list_item_geometry_get(item
));
149 res
&= DIAG(check_pseudoaxes_v(engine
, 0., 90 * HKL_DEGTORAD
, 0.));
151 /* no more solution */
152 res
&= DIAG(hkl_geometry_list_items_next_get(geometries
, item
) == NULL
);
154 hkl_geometry_list_free(geometries
);
158 ok(res
== TRUE
, "eulerians");
160 hkl_engine_list_free(engines
);
161 hkl_detector_free(detector
);
162 hkl_sample_free(sample
);
163 hkl_geometry_free(geometry
);
169 HklEngineList
*engines
;
171 const darray_string
*modes
;
173 HklGeometry
*geometry
;
174 HklDetector
*detector
;
176 Geometry gconf
= K4cv(1.54, VALUES(30., 0., 0., 60.));
177 struct Sample cu
= CU
;
179 geometry
= newGeometry(gconf
);
180 engines
= newEngines(gconf
);
181 sample
= newSample(cu
);
183 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
185 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
187 engine
= hkl_engine_list_engine_get_by_name(engines
, "q", NULL
);
188 modes
= hkl_engine_modes_names_get(engine
);
191 res
&= DIAG(hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 30., 0., 0., 60.));
192 res
&= DIAG(hkl_engine_initialized_set(engine
, TRUE
, NULL
));
194 darray_foreach(mode
, *modes
){
197 res
&= DIAG(hkl_engine_current_mode_set(engine
, *mode
, NULL
));
198 for(q
=-1.; q
<1.; q
+= 0.1){
199 HklGeometryList
*geometries
= NULL
;
201 geometries
= hkl_engine_set_values_v(engine
, q
, NULL
);
202 if(NULL
!= geometries
){
203 const HklGeometryListItem
*item
;
205 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
206 hkl_geometry_set(geometry
,
207 hkl_geometry_list_item_geometry_get(item
));
208 res
&= DIAG(check_pseudoaxes_v(engine
, q
));
210 hkl_geometry_list_free(geometries
);
215 ok(res
== TRUE
, "q");
217 hkl_engine_list_free(engines
);
218 hkl_detector_free(detector
);
219 hkl_sample_free(sample
);
220 hkl_geometry_free(geometry
);