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
);
47 static const HklFunction bissector_horizontal_func
= {
48 .function
= _bissector_horizontal_func
,
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
);
65 static const HklFunction bissector_vertical_func
= {
66 .function
= _bissector_vertical_func
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
[] = { PSI_CONSTANT_PARAMETERS(1, 0, 0, 0) };
222 static const HklModeAutoInfo info
= {
223 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes_r
, axes_w
, functions
, parameters
),
226 return hkl_mode_auto_new(&info
,
227 &psi_constant_vertical_mode_operations
,
231 static HklMode
*psi_constant_horizontal(void)
233 static const char* axes_r
[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
234 static const char* axes_w
[] = {"omega", "chi", "phi", "gamma"};
235 static const HklFunction
*functions
[] = {&psi_constant_vertical_func
};
236 static const HklModeAutoInfo info
= {
237 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes_r
, axes_w
,
238 functions
, psi_constant_parameters
),
241 return hkl_mode_auto_new(&info
,
242 &psi_constant_vertical_mode_operations
,
246 static HklMode
*constant_mu_horizontal(void)
248 static const char* axes_r
[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
249 static const char* axes_w
[] = {"chi", "phi", "gamma"};
250 static const HklFunction
*functions
[] = {&RUBh_minus_Q_func
};
251 static const HklModeAutoInfo info
= {
252 HKL_MODE_AUTO_INFO(__func__
, axes_r
, axes_w
, functions
),
255 return hkl_mode_auto_new(&info
,
256 &hkl_full_mode_operations
,
260 /***********************/
261 /* E6C PseudoAxeEngine */
262 /***********************/
264 static HklEngine
*hkl_engine_e6c_hkl_new(void)
267 HklMode
*default_mode
;
269 self
= hkl_engine_hkl_new();
271 default_mode
= bissector_vertical();
272 hkl_engine_add_mode(self
, default_mode
);
273 hkl_engine_mode_set(self
, default_mode
);
275 hkl_engine_add_mode(self
, constant_omega_vertical());
276 hkl_engine_add_mode(self
, constant_chi_vertical());
277 hkl_engine_add_mode(self
, constant_phi_vertical());
278 hkl_engine_add_mode(self
, lifting_detector_phi());
279 hkl_engine_add_mode(self
, lifting_detector_omega());
280 hkl_engine_add_mode(self
, lifting_detector_mu());
281 hkl_engine_add_mode(self
, double_diffraction_vertical());
282 hkl_engine_add_mode(self
, bissector_horizontal());
283 hkl_engine_add_mode(self
, double_diffraction_horizontal());
284 hkl_engine_add_mode(self
, psi_constant_vertical());
285 hkl_engine_add_mode(self
, psi_constant_horizontal());
286 hkl_engine_add_mode(self
, constant_mu_horizontal());
295 static HklMode
* psi_vertical()
297 static const char *axes_r
[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
298 static const char *axes_w
[] = {"omega", "chi", "phi", "delta"};
299 static const HklFunction
*functions
[] = {&psi_func
};
300 static const HklModeAutoInfo info
= {
301 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes_r
, axes_w
,
302 functions
, psi_parameters
),
305 return hkl_mode_psi_new(&info
);
308 /**********************/
309 /* pseudo axis engine */
310 /**********************/
312 static HklEngine
*hkl_engine_e6c_psi_new(void)
315 HklMode
*default_mode
;
317 self
= hkl_engine_psi_new();
319 default_mode
= psi_vertical();
320 hkl_engine_add_mode(self
, default_mode
);
321 hkl_engine_mode_set(self
, default_mode
);
330 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
331 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
332 "+ 4 axes for the sample\n" \
334 " + **mu** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
335 " + **omega** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
336 " + **chi** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
337 " + **phi** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
339 "+ 2 axes for the detector\n" \
341 " + **gamma** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
342 " + **delta** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
344 static const char* hkl_geometry_eulerian6C_axes
[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
346 static HklGeometry
*hkl_geometry_new_eulerian6C(const HklFactory
*factory
)
348 HklGeometry
*self
= hkl_geometry_new(factory
);
351 h
= hkl_geometry_add_holder(self
);
352 hkl_holder_add_rotation_axis(h
, "mu", 0, 0, 1);
353 hkl_holder_add_rotation_axis(h
, "omega", 0, -1, 0);
354 hkl_holder_add_rotation_axis(h
, "chi", 1, 0, 0);
355 hkl_holder_add_rotation_axis(h
, "phi", 0, -1, 0);
357 h
= hkl_geometry_add_holder(self
);
358 hkl_holder_add_rotation_axis(h
, "gamma", 0, 0, 1);
359 hkl_holder_add_rotation_axis(h
, "delta", 0, -1, 0);
364 static HklEngineList
*hkl_engine_list_new_eulerian6C(const HklFactory
*factory
)
366 HklEngineList
*self
= hkl_engine_list_new();
368 hkl_engine_list_add(self
, hkl_engine_e6c_hkl_new());
369 hkl_engine_list_add(self
, hkl_engine_e6c_psi_new());
370 hkl_engine_list_add(self
, hkl_engine_q2_new());
371 hkl_engine_list_add(self
, hkl_engine_qper_qpar_new());
376 REGISTER_DIFFRACTOMETER(eulerian6C
, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION
);