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-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
27 #include "hkl-pseudoaxis-common-readonly-private.h"
38 static int _bissector_func(const gsl_vector
*x
, void *params
, gsl_vector
*f
)
40 const double omega
= x
->data
[0];
41 const double tth
= x
->data
[3];
43 CHECK_NAN(x
->data
, x
->size
);
45 RUBh_minus_Q(x
->data
, params
, f
->data
);
46 f
->data
[3] = tth
- 2 * fmod(omega
,M_PI
);
51 static const HklFunction bissector_func
= {
52 .function
= _bissector_func
,
56 static HklMode
*bissector(void)
58 static const char* axes
[] = {"omega", "chi", "phi", "tth"};
59 static const HklFunction
*functions
[] = {&bissector_func
};
60 static const HklModeAutoInfo info
= {
61 HKL_MODE_AUTO_INFO(__func__
, axes
, axes
, functions
),
64 return hkl_mode_auto_new(&info
,
69 static HklMode
*constant_omega(void)
71 static const char* axes_r
[] = {"omega", "chi", "phi", "tth"};
72 static const char* axes_w
[] = {"chi", "phi", "tth"};
73 static const HklFunction
*functions
[] = {&RUBh_minus_Q_func
};
74 static const HklModeAutoInfo info
= {
75 HKL_MODE_AUTO_INFO(__func__
, axes_r
, axes_w
, functions
),
78 return hkl_mode_auto_new(&info
,
83 static HklMode
*constant_chi(void)
85 static const char* axes_r
[] = {"omega", "chi", "phi", "tth"};
86 static const char* axes_w
[] = {"omega", "phi", "tth"};
87 static const HklFunction
*functions
[] = {&RUBh_minus_Q_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_phi(void)
99 static const char* axes_r
[] = {"omega", "chi", "phi", "tth"};
100 static const char* axes_w
[] = {"omega", "chi", "tth"};
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
*double_diffraction(void)
113 static const char* axes
[] = {"omega", "chi", "phi", "tth"};
114 static const HklFunction
*functions
[] = {&double_diffraction_func
};
115 static const HklModeAutoInfo info
= {
116 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes
, axes
,
117 functions
, double_diffraction_parameters
),
120 return hkl_mode_auto_new(&info
,
121 &hkl_mode_operations
,
125 static HklMode
*psi_constant(void)
127 static const char* axes
[] = {"omega", "chi", "phi", "tth"};
128 static const HklFunction
*functions
[] = {&psi_constant_vertical_func
};
129 static const HklModeAutoInfo info
= {
130 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes
, axes
,
131 functions
, psi_constant_parameters
),
134 return hkl_mode_auto_new(&info
,
135 &psi_constant_vertical_mode_operations
,
139 static HklEngine
*hkl_engine_e4c_hkl_new(HklEngineList
*engines
)
142 HklMode
*default_mode
;
144 self
= hkl_engine_hkl_new(engines
);
146 default_mode
= bissector();
147 hkl_engine_add_mode(self
, default_mode
);
148 hkl_engine_mode_set(self
, default_mode
);
150 hkl_engine_add_mode(self
, constant_omega());
151 hkl_engine_add_mode(self
, constant_chi());
152 hkl_engine_add_mode(self
, constant_phi());
153 hkl_engine_add_mode(self
, double_diffraction());
154 hkl_engine_add_mode(self
, psi_constant());
163 static HklMode
*psi(void)
165 static const char *axes
[] = {"omega", "chi", "phi", "tth"};
166 static const HklFunction
*functions
[] = {&psi_func
};
167 static const HklModeAutoInfo info
= {
168 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes
, axes
,
169 functions
, psi_parameters
),
172 return hkl_mode_psi_new(&info
);
175 static HklEngine
*hkl_engine_e4c_psi_new(HklEngineList
*engines
)
178 HklMode
*default_mode
;
180 self
= hkl_engine_psi_new(engines
);
182 default_mode
= psi();
183 hkl_engine_add_mode(self
, default_mode
);
184 hkl_engine_mode_set(self
, default_mode
);
193 static const char *e4c_incidence_axes
[] = {OMEGA
, CHI
, PHI
};
195 REGISTER_INCIDENCE_ENGINE(e4c
);
201 #define HKL_GEOMETRY_EULERIAN4C_VERTICAL_DESCRIPTION \
202 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
203 "+ 3 axes for the sample\n" \
205 " + **omega** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
206 " + **chi** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
207 " + **phi** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
209 "+ 1 axis for the detector\n" \
211 " + **tth** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
213 static const char* hkl_geometry_eulerian4C_vertical_axes
[] = {"omega", "chi", "phi", "tth"};
215 static HklGeometry
*hkl_geometry_new_eulerian4C_vertical(const HklFactory
*factory
)
217 HklGeometry
*self
= hkl_geometry_new(factory
);
220 h
= hkl_geometry_add_holder(self
);
221 hkl_holder_add_rotation_axis(h
, "omega", 0, -1, 0);
222 hkl_holder_add_rotation_axis(h
, "chi", 1, 0, 0);
223 hkl_holder_add_rotation_axis(h
, "phi", 0, -1, 0);
225 h
= hkl_geometry_add_holder(self
);
226 hkl_holder_add_rotation_axis(h
, "tth", 0, -1, 0);
231 static HklEngineList
*hkl_engine_list_new_eulerian4C_vertical(const HklFactory
*factory
)
233 HklEngineList
*self
= hkl_engine_list_new();
235 hkl_engine_e4c_hkl_new(self
);
236 hkl_engine_e4c_psi_new(self
);
237 hkl_engine_q_new(self
);
238 hkl_engine_e4c_incidence_new(self
);
243 REGISTER_DIFFRACTOMETER(eulerian4C_vertical
, "E4CV", HKL_GEOMETRY_EULERIAN4C_VERTICAL_DESCRIPTION
);
250 #define HKL_GEOMETRY_TYPE_SOLEIL_MARS_DESCRIPTION \
251 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
252 "+ 3 axes for the sample\n" \
254 " + **omega** : rotating around the :math:`\\vec{z}` direction (0, -1, 0)\n" \
255 " + **chi** : rotating around the :math:`\\vec{x}` direction (-1, 0, 0)\n" \
256 " + **phi** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
258 "+ 1 axis for the detector\n" \
260 " + **tth** : rotation around the :math:`\\vec{z}` direction (0, -1, 0)\n"
262 static const char* hkl_geometry_soleil_mars_axes
[] = {"omega", "chi", "phi", "tth"};
264 static HklGeometry
*hkl_geometry_new_soleil_mars(const HklFactory
*factory
)
266 HklGeometry
*self
= hkl_geometry_new(factory
);
269 h
= hkl_geometry_add_holder(self
);
270 hkl_holder_add_rotation_axis(h
, "omega", 0, -1, 0);
271 hkl_holder_add_rotation_axis(h
, "chi", -1, 0, 0);
272 hkl_holder_add_rotation_axis(h
, "phi", 0, 0, 1);
274 h
= hkl_geometry_add_holder(self
);
275 hkl_holder_add_rotation_axis(h
, "tth", 0, -1, 0);
280 static HklEngineList
*hkl_engine_list_new_soleil_mars(const HklFactory
*factory
)
282 HklEngineList
*self
= hkl_engine_list_new();
284 hkl_engine_e4c_hkl_new(self
);
285 hkl_engine_e4c_psi_new(self
);
286 hkl_engine_q_new(self
);
287 hkl_engine_e4c_incidence_new(self
);
292 REGISTER_DIFFRACTOMETER(soleil_mars
, "SOLEIL MARS", HKL_GEOMETRY_TYPE_SOLEIL_MARS_DESCRIPTION
);
298 #define HKL_GEOMETRY_TYPE_EULERIAN4C_HORIZONTAL_DESCRIPTION \
299 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
300 "+ 3 axes for the sample\n" \
302 " + **omega** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
303 " + **chi** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
304 " + **phi** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
306 "+ 1 axis for the detector\n" \
308 " + **tth** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n"
310 static const char* hkl_geometry_eulerian4C_horizontal_axes
[] = {"omega", "chi", "phi", "tth"};
312 static HklGeometry
*hkl_geometry_new_eulerian4C_horizontal(const HklFactory
*factory
)
314 HklGeometry
*self
= hkl_geometry_new(factory
);
317 h
= hkl_geometry_add_holder(self
);
318 hkl_holder_add_rotation_axis(h
, "omega", 0, 0, 1);
319 hkl_holder_add_rotation_axis(h
, "chi", 1, 0, 0);
320 hkl_holder_add_rotation_axis(h
, "phi", 0, 0, 1);
322 h
= hkl_geometry_add_holder(self
);
323 hkl_holder_add_rotation_axis(h
, "tth", 0, 0, 1);
328 static HklEngineList
*hkl_engine_list_new_eulerian4C_horizontal(const HklFactory
*factory
)
330 HklEngineList
*self
= hkl_engine_list_new();
332 hkl_engine_e4c_hkl_new(self
);
333 hkl_engine_e4c_psi_new(self
);
334 hkl_engine_q_new(self
);
335 hkl_engine_e4c_incidence_new(self
);
340 REGISTER_DIFFRACTOMETER(eulerian4C_horizontal
, "E4CH", HKL_GEOMETRY_TYPE_EULERIAN4C_HORIZONTAL_DESCRIPTION
);