[hkl] factorize the psi_parameters for the psi engine.
[hkl.git] / hkl / hkl-engine-e6c.c
blob529ed471b623832f85d8b1b59fdfb26bb7706229
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-2014 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 <gsl/gsl_sys.h> // for gsl_isnan
23 #include "hkl-factory-private.h" // for autodata_factories_, etc
24 #include "hkl-pseudoaxis-common-q-private.h" // for hkl_engine_q2_new, etc
25 #include "hkl-pseudoaxis-common-hkl-private.h" // for hkl_mode_operations, etc
26 #include "hkl-pseudoaxis-common-psi-private.h" // for hkl_engine_psi_new, etc
28 /***********************/
29 /* numerical functions */
30 /***********************/
32 static int _bissector_horizontal_func(const gsl_vector *x, void *params, gsl_vector *f)
34 const double mu = x->data[0];
35 const double omega = x->data[1];
36 const double gamma = x->data[4];
38 CHECK_NAN(x->data, x->size);
40 RUBh_minus_Q(x->data, params, f->data);
41 f->data[3] = fmod(omega, M_PI);
42 f->data[4] = gamma - 2 * fmod(mu, M_PI);
44 return GSL_SUCCESS;
47 static const HklFunction bissector_horizontal_func = {
48 .function = _bissector_horizontal_func,
49 .size = 5,
52 static int _bissector_vertical_func(const gsl_vector *x, void *params, gsl_vector *f)
54 const double omega = x->data[0];
55 const double tth = x->data[3];
57 CHECK_NAN(x->data, x->size);
59 RUBh_minus_Q(x->data, params, f->data);
60 f->data[3] = tth - 2 * fmod(omega,M_PI);
62 return GSL_SUCCESS;
65 static const HklFunction bissector_vertical_func = {
66 .function = _bissector_vertical_func,
67 .size = 4,
70 /*********/
71 /* modes */
72 /*********/
74 static HklMode *bissector_vertical(void)
76 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
77 static const char* axes_w[] = {"omega", "chi", "phi", "delta"};
78 static const HklFunction *functions[] = {&bissector_vertical_func};
79 static const HklModeAutoInfo info = {
80 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
83 return hkl_mode_auto_new(&info,
84 &hkl_mode_operations,
85 TRUE);
88 static HklMode *constant_omega_vertical(void)
90 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
91 static const char* axes_w[] = {"chi", "phi", "delta"};
92 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
93 static const HklModeAutoInfo info = {
94 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
97 return hkl_mode_auto_new(&info,
98 &hkl_mode_operations,
99 TRUE);
102 static HklMode *constant_chi_vertical(void)
104 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
105 static const char* axes_w[] = {"omega", "phi", "delta"};
106 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
107 static const HklModeAutoInfo info = {
108 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
111 return hkl_mode_auto_new(&info,
112 &hkl_mode_operations,
113 TRUE);
116 static HklMode *constant_phi_vertical(void)
118 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
119 static const char* axes_w[] = {"omega", "chi", "delta"};
120 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
121 static const HklModeAutoInfo info = {
122 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
125 return hkl_mode_auto_new(&info,
126 &hkl_mode_operations,
127 TRUE);
130 static HklMode *lifting_detector_phi(void)
132 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
133 static const char* axes_w[] = {"phi", "gamma", "delta"};
134 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
135 static const HklModeAutoInfo info = {
136 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
139 return hkl_mode_auto_new(&info,
140 &hkl_mode_operations,
141 TRUE);
144 static HklMode *lifting_detector_omega(void)
146 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
147 static const char* axes_w[] = {"omega", "gamma", "delta"};
148 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
149 static const HklModeAutoInfo info = {
150 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
153 return hkl_mode_auto_new(&info,
154 &hkl_mode_operations,
155 TRUE);
158 static HklMode *lifting_detector_mu(void)
160 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
161 static const char* axes_w[] = {"mu", "gamma", "delta"};
162 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
163 static const HklModeAutoInfo info = {
164 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
167 return hkl_mode_auto_new(&info,
168 &hkl_mode_operations,
169 TRUE);
172 static HklMode *double_diffraction_vertical(void)
174 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
175 static const char* axes_w[] = {"omega", "chi", "phi", "delta"};
176 static const HklFunction *functions[] = {&double_diffraction_func};
177 static const HklModeAutoInfo info = {
178 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
179 functions, double_diffraction_parameters),
182 return hkl_mode_auto_new(&info,
183 &hkl_mode_operations,
184 TRUE);
187 static HklMode *bissector_horizontal(void)
189 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
190 static const char* axes_w[] = {"mu", "omega", "chi", "phi", "gamma"};
191 static const HklFunction *functions[] = {&bissector_horizontal_func};
192 static const HklModeAutoInfo info = {
193 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
196 return hkl_mode_auto_new(&info,
197 &hkl_mode_operations,
198 TRUE);
201 static HklMode *double_diffraction_horizontal(void)
203 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
204 static const char* axes_w[] = {"mu", "chi", "phi", "gamma"};
205 static const HklFunction *functions[] = {&double_diffraction_func};
206 static const HklModeAutoInfo info = {
207 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
208 functions, double_diffraction_parameters),
211 return hkl_mode_auto_new(&info,
212 &hkl_mode_operations,
213 TRUE);
216 static HklMode *psi_constant_vertical(void)
218 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
219 static const char* axes_w[] = {"omega", "chi", "phi", "delta"};
220 static const HklFunction *functions[] = {&psi_constant_vertical_func};
221 static const HklParameter parameters[] = {
222 {HKL_PARAMETER_DEFAULTS, .name = "h2", .range = {.min=-1, .max=1}, ._value = 1,},
223 {HKL_PARAMETER_DEFAULTS, .name = "k2", .range = {.min=-1, .max=1}, ._value = 0,},
224 {HKL_PARAMETER_DEFAULTS, .name = "l2", .range = {.min=-1, .max=1}, ._value = 0,},
225 {HKL_PARAMETER_DEFAULTS_ANGLE, .name = "psi"},
227 static const HklModeAutoInfo info = {
228 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w, functions, parameters),
231 return hkl_mode_auto_new(&info,
232 &psi_constant_vertical_mode_operations,
233 TRUE);
236 static HklMode *psi_constant_horizontal(void)
238 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
239 static const char* axes_w[] = {"omega", "chi", "phi", "gamma"};
240 static const HklFunction *functions[] = {&psi_constant_vertical_func};
241 static const HklModeAutoInfo info = {
242 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
243 functions, psi_constant_parameters),
246 return hkl_mode_auto_new(&info,
247 &psi_constant_vertical_mode_operations,
248 TRUE);
251 static HklMode *constant_mu_horizontal(void)
253 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
254 static const char* axes_w[] = {"chi", "phi", "gamma"};
255 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
256 static const HklModeAutoInfo info = {
257 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
260 return hkl_mode_auto_new(&info,
261 &hkl_full_mode_operations,
262 TRUE);
265 /***********************/
266 /* E6C PseudoAxeEngine */
267 /***********************/
269 static HklEngine *hkl_engine_e6c_hkl_new(void)
271 HklEngine *self;
272 HklMode *default_mode;
274 self = hkl_engine_hkl_new();
276 default_mode = bissector_vertical();
277 hkl_engine_add_mode(self, default_mode);
278 hkl_engine_mode_set(self, default_mode);
280 hkl_engine_add_mode(self, constant_omega_vertical());
281 hkl_engine_add_mode(self, constant_chi_vertical());
282 hkl_engine_add_mode(self, constant_phi_vertical());
283 hkl_engine_add_mode(self, lifting_detector_phi());
284 hkl_engine_add_mode(self, lifting_detector_omega());
285 hkl_engine_add_mode(self, lifting_detector_mu());
286 hkl_engine_add_mode(self, double_diffraction_vertical());
287 hkl_engine_add_mode(self, bissector_horizontal());
288 hkl_engine_add_mode(self, double_diffraction_horizontal());
289 hkl_engine_add_mode(self, psi_constant_vertical());
290 hkl_engine_add_mode(self, psi_constant_horizontal());
291 hkl_engine_add_mode(self, constant_mu_horizontal());
293 return self;
296 /********/
297 /* mode */
298 /********/
300 static HklMode* psi_vertical()
302 static const char *axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
303 static const char *axes_w[] = {"omega", "chi", "phi", "delta"};
304 static const HklFunction *functions[] = {&psi_func};
305 static const HklModeAutoInfo info = {
306 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
307 functions, psi_parameters),
310 return hkl_mode_psi_new(&info);
313 /**********************/
314 /* pseudo axis engine */
315 /**********************/
317 static HklEngine *hkl_engine_e6c_psi_new(void)
319 HklEngine *self;
320 HklMode *default_mode;
322 self = hkl_engine_psi_new();
324 default_mode = psi_vertical();
325 hkl_engine_add_mode(self, default_mode);
326 hkl_engine_mode_set(self, default_mode);
328 return self;
331 /*******/
332 /* E6C */
333 /*******/
335 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
336 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
337 "+ 4 axes for the sample\n" \
338 "\n" \
339 " + **mu** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
340 " + **omega** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
341 " + **chi** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
342 " + **phi** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
343 "\n" \
344 "+ 2 axes for the detector\n" \
345 "\n" \
346 " + **gamma** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
347 " + **delta** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
349 static const char* hkl_geometry_eulerian6C_axes[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
351 static HklGeometry *hkl_geometry_new_eulerian6C(const HklFactory *factory)
353 HklGeometry *self = hkl_geometry_new(factory);
354 HklHolder *h;
356 h = hkl_geometry_add_holder(self);
357 hkl_holder_add_rotation_axis(h, "mu", 0, 0, 1);
358 hkl_holder_add_rotation_axis(h, "omega", 0, -1, 0);
359 hkl_holder_add_rotation_axis(h, "chi", 1, 0, 0);
360 hkl_holder_add_rotation_axis(h, "phi", 0, -1, 0);
362 h = hkl_geometry_add_holder(self);
363 hkl_holder_add_rotation_axis(h, "gamma", 0, 0, 1);
364 hkl_holder_add_rotation_axis(h, "delta", 0, -1, 0);
366 return self;
369 static HklEngineList *hkl_engine_list_new_eulerian6C(const HklFactory *factory)
371 HklEngineList *self = hkl_engine_list_new();
373 hkl_engine_list_add(self, hkl_engine_e6c_hkl_new());
374 hkl_engine_list_add(self, hkl_engine_e6c_psi_new());
375 hkl_engine_list_add(self, hkl_engine_q2_new());
376 hkl_engine_list_add(self, hkl_engine_qper_qpar_new());
378 return self;
381 REGISTER_DIFFRACTOMETER(eulerian6C, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION);