[hkl] factorize the double_diffraction_parameters (with description)
[hkl.git] / hkl / hkl-engine-e6c.c
blobe045fa071a94293028769dcfd2288080dbd72830
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 HklParameter parameters[] = {
242 {HKL_PARAMETER_DEFAULTS, .name = "h2", .range = {.min=-1, .max=1}, ._value = 1,},
243 {HKL_PARAMETER_DEFAULTS, .name = "k2", .range = {.min=-1, .max=1}, ._value = 0,},
244 {HKL_PARAMETER_DEFAULTS, .name = "l2", .range = {.min=-1, .max=1}, ._value = 0,},
245 {HKL_PARAMETER_DEFAULTS_ANGLE, .name = "psi"},
247 static const HklModeAutoInfo info = {
248 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w, functions, parameters),
251 return hkl_mode_auto_new(&info,
252 &psi_constant_vertical_mode_operations,
253 TRUE);
256 static HklMode *constant_mu_horizontal(void)
258 static const char* axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
259 static const char* axes_w[] = {"chi", "phi", "gamma"};
260 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
261 static const HklModeAutoInfo info = {
262 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
265 return hkl_mode_auto_new(&info,
266 &hkl_full_mode_operations,
267 TRUE);
270 /***********************/
271 /* E6C PseudoAxeEngine */
272 /***********************/
274 static HklEngine *hkl_engine_e6c_hkl_new(void)
276 HklEngine *self;
277 HklMode *default_mode;
279 self = hkl_engine_hkl_new();
281 default_mode = bissector_vertical();
282 hkl_engine_add_mode(self, default_mode);
283 hkl_engine_mode_set(self, default_mode);
285 hkl_engine_add_mode(self, constant_omega_vertical());
286 hkl_engine_add_mode(self, constant_chi_vertical());
287 hkl_engine_add_mode(self, constant_phi_vertical());
288 hkl_engine_add_mode(self, lifting_detector_phi());
289 hkl_engine_add_mode(self, lifting_detector_omega());
290 hkl_engine_add_mode(self, lifting_detector_mu());
291 hkl_engine_add_mode(self, double_diffraction_vertical());
292 hkl_engine_add_mode(self, bissector_horizontal());
293 hkl_engine_add_mode(self, double_diffraction_horizontal());
294 hkl_engine_add_mode(self, psi_constant_vertical());
295 hkl_engine_add_mode(self, psi_constant_horizontal());
296 hkl_engine_add_mode(self, constant_mu_horizontal());
298 return self;
301 /********/
302 /* mode */
303 /********/
305 static HklMode* psi_vertical()
307 static const char *axes_r[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
308 static const char *axes_w[] = {"omega", "chi", "phi", "delta"};
309 static const HklFunction *functions[] = {&psi_func};
310 static const HklParameter parameters[] = {
311 {HKL_PARAMETER_DEFAULTS, .name = "h1", .range = {.min=-1, .max=1}, ._value=1,},
312 {HKL_PARAMETER_DEFAULTS, .name = "k1", .range = {.min=-1, .max=1}, ._value=1,},
313 {HKL_PARAMETER_DEFAULTS, .name = "l1", .range = {.min=-1, .max=1}, ._value=1,},
315 static const HklModeAutoInfo info = {
316 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w, functions, parameters),
319 return hkl_mode_psi_new(&info);
322 /**********************/
323 /* pseudo axis engine */
324 /**********************/
326 static HklEngine *hkl_engine_e6c_psi_new(void)
328 HklEngine *self;
329 HklMode *default_mode;
331 self = hkl_engine_psi_new();
333 default_mode = psi_vertical();
334 hkl_engine_add_mode(self, default_mode);
335 hkl_engine_mode_set(self, default_mode);
337 return self;
340 /*******/
341 /* E6C */
342 /*******/
344 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
345 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
346 "+ 4 axes for the sample\n" \
347 "\n" \
348 " + **mu** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
349 " + **omega** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
350 " + **chi** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
351 " + **phi** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
352 "\n" \
353 "+ 2 axes for the detector\n" \
354 "\n" \
355 " + **gamma** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
356 " + **delta** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
358 static const char* hkl_geometry_eulerian6C_axes[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
360 static HklGeometry *hkl_geometry_new_eulerian6C(const HklFactory *factory)
362 HklGeometry *self = hkl_geometry_new(factory);
363 HklHolder *h;
365 h = hkl_geometry_add_holder(self);
366 hkl_holder_add_rotation_axis(h, "mu", 0, 0, 1);
367 hkl_holder_add_rotation_axis(h, "omega", 0, -1, 0);
368 hkl_holder_add_rotation_axis(h, "chi", 1, 0, 0);
369 hkl_holder_add_rotation_axis(h, "phi", 0, -1, 0);
371 h = hkl_geometry_add_holder(self);
372 hkl_holder_add_rotation_axis(h, "gamma", 0, 0, 1);
373 hkl_holder_add_rotation_axis(h, "delta", 0, -1, 0);
375 return self;
378 static HklEngineList *hkl_engine_list_new_eulerian6C(const HklFactory *factory)
380 HklEngineList *self = hkl_engine_list_new();
382 hkl_engine_list_add(self, hkl_engine_e6c_hkl_new());
383 hkl_engine_list_add(self, hkl_engine_e6c_psi_new());
384 hkl_engine_list_add(self, hkl_engine_q2_new());
385 hkl_engine_list_add(self, hkl_engine_qper_qpar_new());
387 return self;
390 REGISTER_DIFFRACTOMETER(eulerian6C, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION);