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-2015 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
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
);
56 static const HklFunction bissector_horizontal_func
= {
57 .function
= _bissector_horizontal_func
,
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
);
74 static const HklFunction bissector_vertical_func
= {
75 .function
= _bissector_vertical_func
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
269 static HklEngine
*hkl_engine_e6c_hkl_new(HklEngineList
*engines
)
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());
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
)
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
);
331 static const char *e6c_incidence_axes
[] = {MU
, OMEGA
, CHI
, PHI
};
333 REGISTER_INCIDENCE_ENGINE(e6c
);
339 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
340 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
341 "+ 4 axes for the sample\n" \
343 " + **mu** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
344 " + **omega** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
345 " + **chi** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
346 " + **phi** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
348 "+ 2 axes for the detector\n" \
350 " + **gamma** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
351 " + **delta** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
353 static const char* hkl_geometry_eulerian6C_axes
[] = {"mu", "omega", "chi", "phi", "gamma", "delta"};
355 static HklGeometry
*hkl_geometry_new_eulerian6C(const HklFactory
*factory
)
357 HklGeometry
*self
= hkl_geometry_new(factory
);
360 h
= hkl_geometry_add_holder(self
);
361 hkl_holder_add_rotation_axis(h
, "mu", 0, 0, 1);
362 hkl_holder_add_rotation_axis(h
, "omega", 0, -1, 0);
363 hkl_holder_add_rotation_axis(h
, "chi", 1, 0, 0);
364 hkl_holder_add_rotation_axis(h
, "phi", 0, -1, 0);
366 h
= hkl_geometry_add_holder(self
);
367 hkl_holder_add_rotation_axis(h
, "gamma", 0, 0, 1);
368 hkl_holder_add_rotation_axis(h
, "delta", 0, -1, 0);
373 static HklEngineList
*hkl_engine_list_new_eulerian6C(const HklFactory
*factory
)
375 HklEngineList
*self
= hkl_engine_list_new();
377 hkl_engine_e6c_hkl_new(self
);
378 hkl_engine_e6c_psi_new(self
);
379 hkl_engine_q2_new(self
);
380 hkl_engine_qper_qpar_new(self
);
381 hkl_engine_tth2_new(self
);
382 hkl_engine_e6c_incidence_new(self
);
387 REGISTER_DIFFRACTOMETER(eulerian6C
, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION
);