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>
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 const HklFactory
*factory
;
34 HklGeometry
*geometry
;
35 HklDetector
*detector
;
37 static double hkl
[] = {0, 1, 0};
39 factory
= hkl_factory_get_by_name("K6C", NULL
);
40 geometry
= hkl_factory_create_new_geometry(factory
);
41 sample
= hkl_sample_new("test");
43 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
45 engines
= hkl_factory_create_new_engine_list(factory
);
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
;
55 res
&= DIAG(hkl_engine_current_mode_set(engine
, *mode
, NULL
));
56 parameters
= hkl_engine_parameters_names_get(engine
);
57 if (!strcasecmp(*mode
, "constant_chi_vertical")){
58 size_t n_params
= darray_size(*parameters
);
59 double params
[n_params
];
61 hkl_engine_parameters_values_get(engine
,
65 res
&= DIAG(hkl_engine_parameters_values_set(engine
,
67 HKL_UNIT_DEFAULT
, NULL
));
69 if (!strcasecmp(*mode
, "constant_incidence")){
70 size_t n_params
= darray_size(*parameters
);
71 double params
[n_params
];
73 hkl_engine_parameters_values_get(engine
,
77 res
&= DIAG(hkl_engine_parameters_values_set(engine
,
79 HKL_UNIT_DEFAULT
, NULL
));
82 /* studdy this degenerated case */
83 geometries
= hkl_engine_pseudo_axis_values_set(engine
,
85 HKL_UNIT_DEFAULT
, NULL
);
87 const HklGeometryListItem
*item
;
89 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
90 hkl_geometry_set(geometry
, hkl_geometry_list_item_geometry_get(item
));
91 res
&= DIAG(check_pseudoaxes(engine
, hkl
, ARRAY_SIZE(hkl
)));
93 hkl_geometry_list_free(geometries
);
97 ok(res
== TRUE
, "degenerated");
99 hkl_engine_list_free(engines
);
100 hkl_detector_free(detector
);
101 hkl_sample_free(sample
);
102 hkl_geometry_free(geometry
);
105 static void eulerians(void)
108 HklEngineList
*engines
;
110 const darray_string
*modes
;
112 const HklGeometryListItem
*item
;
113 const HklFactory
*factory
;
114 HklGeometry
*geometry
;
115 HklDetector
*detector
;
118 factory
= hkl_factory_get_by_name("K6C", NULL
);
119 geometry
= hkl_factory_create_new_geometry(factory
);
120 sample
= hkl_sample_new("test");
122 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
124 engines
= hkl_factory_create_new_engine_list(factory
);
125 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
127 engine
= hkl_engine_list_engine_get_by_name(engines
, "eulerians", NULL
);
128 modes
= hkl_engine_modes_names_get(engine
);
130 darray_foreach(mode
, *modes
){
131 const darray_string
*parameters
;
132 HklGeometryList
*geometries
;
135 res
&= DIAG(hkl_engine_current_mode_set(engine
, *mode
, NULL
));
136 parameters
= hkl_engine_parameters_names_get(engine
);
137 n_params
= darray_size(*parameters
);
139 double params
[n_params
];
141 hkl_engine_parameters_values_get(engine
,
145 res
&= DIAG(hkl_engine_parameters_values_set(engine
,
147 HKL_UNIT_DEFAULT
, NULL
));
150 /* studdy this degenerated case */
151 geometries
= hkl_engine_set_values_v(engine
, 0., 90. * HKL_DEGTORAD
, 0.);
153 res
&= DIAG(hkl_geometry_list_n_items_get(geometries
) == 2);
155 /* first solution = -180, -90, 180 */
156 item
= hkl_geometry_list_items_first_get(geometries
);
157 hkl_geometry_set(geometry
,
158 hkl_geometry_list_item_geometry_get(item
));
159 res
&= DIAG(check_pseudoaxes_v(engine
, -180. * HKL_DEGTORAD
, -90. * HKL_DEGTORAD
, 180. * HKL_DEGTORAD
));
161 /* second solution = 0, 90, 0 */
162 item
= hkl_geometry_list_items_next_get(geometries
, item
);
163 hkl_geometry_set(geometry
,
164 hkl_geometry_list_item_geometry_get(item
));
165 res
&= DIAG(check_pseudoaxes_v(engine
, 0., 90. * HKL_DEGTORAD
, 0.));
167 /* no more solution */
168 res
&= DIAG(hkl_geometry_list_items_next_get(geometries
, item
) == NULL
);
170 hkl_geometry_list_free(geometries
);
174 ok(res
== TRUE
, "eulerians");
176 hkl_engine_list_free(engines
);
177 hkl_detector_free(detector
);
178 hkl_sample_free(sample
);
179 hkl_geometry_free(geometry
);
185 HklEngineList
*engines
;
187 const darray_string
*modes
;
189 const HklFactory
*factory
;
190 HklGeometry
*geometry
;
191 HklDetector
*detector
;
194 factory
= hkl_factory_get_by_name("K6C", NULL
);
195 geometry
= hkl_factory_create_new_geometry(factory
);
196 sample
= hkl_sample_new("test");
198 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
200 engines
= hkl_factory_create_new_engine_list(factory
);
201 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
203 engine
= hkl_engine_list_engine_get_by_name(engines
, "q2", NULL
);
204 modes
= hkl_engine_modes_names_get(engine
);
207 res
&= DIAG(hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 0., 30., 0., 0., 0., 60.));
208 res
&= DIAG(hkl_engine_initialized_set(engine
, TRUE
, NULL
));
210 darray_foreach(mode
, *modes
){
213 res
&= DIAG(hkl_engine_current_mode_set(engine
, *mode
, NULL
));
214 for(q
=0.1; q
<1.; q
+= 0.1)
215 for(alpha
= -M_PI
; alpha
<M_PI
; alpha
+= M_PI
/180.){
216 double values
[] = {q
, alpha
};
217 HklGeometryList
*geometries
;
219 geometries
= hkl_engine_pseudo_axis_values_set(engine
,
220 values
, ARRAY_SIZE(values
),
221 HKL_UNIT_DEFAULT
, NULL
);
223 const HklGeometryListItem
*item
;
225 HKL_GEOMETRY_LIST_FOREACH(item
, geometries
){
226 hkl_geometry_set(geometry
,
227 hkl_geometry_list_item_geometry_get(item
));
228 res
&= DIAG(check_pseudoaxes(engine
, values
, 2));
230 hkl_geometry_list_free(geometries
);
235 ok(res
== TRUE
, "q2");
237 hkl_engine_list_free(engines
);
238 hkl_detector_free(detector
);
239 hkl_sample_free(sample
);
240 hkl_geometry_free(geometry
);
244 static void m15110(void)
247 HklEngineList
*engines
;
249 const HklFactory
*factory
;
250 HklGeometry
*geometry
;
251 HklDetector
*detector
;
254 factory
= hkl_factory_get_by_name("K6C", NULL
);
255 geometry
= hkl_factory_create_new_geometry(factory
);
256 sample
= hkl_sample_new("test");
258 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
260 engines
= hkl_factory_create_new_engine_list(factory
);
261 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
263 engine
= hkl_engine_list_engine_get_by_name(engines
, "psi", NULL
);
265 /* the init part must succed */
266 res
&= DIAG(hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 0., 62.95, 134.75, 0., 0., 60.));
267 res
&= DIAG(hkl_engine_initialized_set(engine
, TRUE
, NULL
));
269 hkl_engine_list_free(engines
);
270 hkl_detector_free(detector
);
271 hkl_sample_free(sample
);
272 hkl_geometry_free(geometry
);
274 ok(res
== TRUE
, "m15110");