upgrading copyright year from 2015 to 2016
[hkl.git] / hkl / hkl-engine-e6c.c
blobd2788d33ba3c22e3f45a07ccfacc43ef6680e851
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 <gsl/gsl_sys.h> // for gsl_isnan
23 #include "hkl-factory-private.h" // for autodata_factories_, etc
24 #include "hkl-pseudoaxis-common-hkl-private.h" // for hkl_mode_operations, etc
25 #include "hkl-pseudoaxis-common-psi-private.h" // for hkl_engine_psi_new, etc
26 #include "hkl-pseudoaxis-common-q-private.h" // for hkl_engine_q2_new, etc
27 #include "hkl-pseudoaxis-common-tth-private.h" // for hkl_engine_tth2_new, etc
28 #include "hkl-pseudoaxis-common-readonly-private.h" // for hkl_engine_tth2_new, etc
30 #define MU "mu"
31 #define OMEGA "omega"
32 #define CHI "chi"
33 #define PHI "phi"
34 #define GAMMA "gamma"
35 #define DELTA "delta"
37 /***********************/
38 /* numerical functions */
39 /***********************/
41 static int _bissector_horizontal_func(const gsl_vector *x, void *params, gsl_vector *f)
43 const double mu = x->data[0];
44 const double omega = x->data[1];
45 const double gamma = x->data[4];
47 CHECK_NAN(x->data, x->size);
49 RUBh_minus_Q(x->data, params, f->data);
50 f->data[3] = fmod(omega, M_PI);
51 f->data[4] = gamma - 2 * fmod(mu, M_PI);
53 return GSL_SUCCESS;
56 static const HklFunction bissector_horizontal_func = {
57 .function = _bissector_horizontal_func,
58 .size = 5,
61 static int _bissector_vertical_func(const gsl_vector *x, void *params, gsl_vector *f)
63 const double omega = x->data[0];
64 const double tth = x->data[3];
66 CHECK_NAN(x->data, x->size);
68 RUBh_minus_Q(x->data, params, f->data);
69 f->data[3] = tth - 2 * fmod(omega,M_PI);
71 return GSL_SUCCESS;
74 static const HklFunction bissector_vertical_func = {
75 .function = _bissector_vertical_func,
76 .size = 4,
79 /************/
80 /* mode hkl */
81 /************/
83 static HklMode *bissector_vertical(void)
85 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
86 static const char* axes_w[] = {OMEGA, CHI, PHI, DELTA};
87 static const HklFunction *functions[] = {&bissector_vertical_func};
88 static const HklModeAutoInfo info = {
89 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
92 return hkl_mode_auto_new(&info,
93 &hkl_mode_operations,
94 TRUE);
97 static HklMode *constant_omega_vertical(void)
99 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
100 static const char* axes_w[] = {CHI, PHI, DELTA};
101 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
102 static const HklModeAutoInfo info = {
103 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
106 return hkl_mode_auto_new(&info,
107 &hkl_mode_operations,
108 TRUE);
111 static HklMode *constant_chi_vertical(void)
113 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
114 static const char* axes_w[] = {OMEGA, PHI, DELTA};
115 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
116 static const HklModeAutoInfo info = {
117 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
120 return hkl_mode_auto_new(&info,
121 &hkl_mode_operations,
122 TRUE);
125 static HklMode *constant_phi_vertical(void)
127 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
128 static const char* axes_w[] = {OMEGA, CHI, DELTA};
129 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
130 static const HklModeAutoInfo info = {
131 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
134 return hkl_mode_auto_new(&info,
135 &hkl_mode_operations,
136 TRUE);
139 static HklMode *lifting_detector_phi(void)
141 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
142 static const char* axes_w[] = {PHI, GAMMA, DELTA};
143 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
144 static const HklModeAutoInfo info = {
145 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
148 return hkl_mode_auto_new(&info,
149 &hkl_mode_operations,
150 TRUE);
153 static HklMode *lifting_detector_omega(void)
155 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
156 static const char* axes_w[] = {OMEGA, GAMMA, DELTA};
157 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
158 static const HklModeAutoInfo info = {
159 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
162 return hkl_mode_auto_new(&info,
163 &hkl_mode_operations,
164 TRUE);
167 static HklMode *lifting_detector_mu(void)
169 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
170 static const char* axes_w[] = {MU, GAMMA, DELTA};
171 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
172 static const HklModeAutoInfo info = {
173 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
176 return hkl_mode_auto_new(&info,
177 &hkl_mode_operations,
178 TRUE);
181 static HklMode *double_diffraction_vertical(void)
183 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
184 static const char* axes_w[] = {OMEGA, CHI, PHI, DELTA};
185 static const HklFunction *functions[] = {&double_diffraction_func};
186 static const HklModeAutoInfo info = {
187 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
188 functions, double_diffraction_parameters),
191 return hkl_mode_auto_new(&info,
192 &hkl_mode_operations,
193 TRUE);
196 static HklMode *bissector_horizontal(void)
198 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
199 static const char* axes_w[] = {MU, OMEGA, CHI, PHI, GAMMA};
200 static const HklFunction *functions[] = {&bissector_horizontal_func};
201 static const HklModeAutoInfo info = {
202 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
205 return hkl_mode_auto_new(&info,
206 &hkl_mode_operations,
207 TRUE);
210 static HklMode *double_diffraction_horizontal(void)
212 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
213 static const char* axes_w[] = {MU, CHI, PHI, GAMMA};
214 static const HklFunction *functions[] = {&double_diffraction_func};
215 static const HklModeAutoInfo info = {
216 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
217 functions, double_diffraction_parameters),
220 return hkl_mode_auto_new(&info,
221 &hkl_mode_operations,
222 TRUE);
225 static HklMode *psi_constant_vertical(void)
227 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
228 static const char* axes_w[] = {OMEGA, CHI, PHI, DELTA};
229 static const HklFunction *functions[] = {&psi_constant_vertical_func};
230 static const HklParameter parameters[] = { PSI_CONSTANT_PARAMETERS(1, 0, 0, 0) };
231 static const HklModeAutoInfo info = {
232 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w, functions, parameters),
235 return hkl_mode_auto_new(&info,
236 &psi_constant_vertical_mode_operations,
237 TRUE);
240 static HklMode *psi_constant_horizontal(void)
242 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
243 static const char* axes_w[] = {OMEGA, CHI, PHI, GAMMA};
244 static const HklFunction *functions[] = {&psi_constant_vertical_func};
245 static const HklModeAutoInfo info = {
246 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
247 functions, psi_constant_parameters),
250 return hkl_mode_auto_new(&info,
251 &psi_constant_vertical_mode_operations,
252 TRUE);
255 static HklMode *constant_mu_horizontal(void)
257 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
258 static const char* axes_w[] = {CHI, PHI, GAMMA};
259 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
260 static const HklModeAutoInfo info = {
261 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
264 return hkl_mode_auto_new(&info,
265 &hkl_full_mode_operations,
266 TRUE);
269 static HklEngine *hkl_engine_e6c_hkl_new(HklEngineList *engines)
271 HklEngine *self;
272 HklMode *default_mode;
274 self = hkl_engine_hkl_new(engines);
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 psi */
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 static HklEngine *hkl_engine_e6c_psi_new(HklEngineList *engines)
315 HklEngine *self;
316 HklMode *default_mode;
318 self = hkl_engine_psi_new(engines);
320 default_mode = psi_vertical();
321 hkl_engine_add_mode(self, default_mode);
322 hkl_engine_mode_set(self, default_mode);
324 return self;
327 /*****************/
328 /* mode readonly */
329 /*****************/
331 REGISTER_READONLY_INCIDENCE(hkl_engine_e6c_incidence_new,
332 P99_PROTECT({MU, OMEGA, CHI, PHI}),
333 surface_parameters_y);
335 REGISTER_READONLY_EMERGENCE(hkl_engine_e6c_emergence_new,
336 P99_PROTECT({MU, OMEGA, CHI, PHI, GAMMA, DELTA}),
337 surface_parameters_y);
339 /*******/
340 /* E6C */
341 /*******/
343 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
344 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
345 "+ 4 axes for the sample\n" \
346 "\n" \
347 " + **" MU "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
348 " + **" OMEGA "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
349 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
350 " + **" PHI "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
351 "\n" \
352 "+ 2 axes for the detector\n" \
353 "\n" \
354 " + **" GAMMA "** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
355 " + **" DELTA "** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
357 static const char* hkl_geometry_eulerian6C_axes[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
359 static HklGeometry *hkl_geometry_new_eulerian6C(const HklFactory *factory)
361 HklGeometry *self = hkl_geometry_new(factory);
362 HklHolder *h;
364 h = hkl_geometry_add_holder(self);
365 hkl_holder_add_rotation_axis(h, MU, 0, 0, 1);
366 hkl_holder_add_rotation_axis(h, OMEGA, 0, -1, 0);
367 hkl_holder_add_rotation_axis(h, CHI, 1, 0, 0);
368 hkl_holder_add_rotation_axis(h, PHI, 0, -1, 0);
370 h = hkl_geometry_add_holder(self);
371 hkl_holder_add_rotation_axis(h, GAMMA, 0, 0, 1);
372 hkl_holder_add_rotation_axis(h, DELTA, 0, -1, 0);
374 return self;
377 static HklEngineList *hkl_engine_list_new_eulerian6C(const HklFactory *factory)
379 HklEngineList *self = hkl_engine_list_new();
381 hkl_engine_e6c_hkl_new(self);
382 hkl_engine_e6c_psi_new(self);
383 hkl_engine_q2_new(self);
384 hkl_engine_qper_qpar_new(self);
385 hkl_engine_tth2_new(self);
386 hkl_engine_e6c_incidence_new(self);
387 hkl_engine_e6c_emergence_new(self);
389 return self;
392 REGISTER_DIFFRACTOMETER(eulerian6C, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION);