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-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 REGISTER_READONLY_INCIDENCE(hkl_engine_e4c_incidence_new
,
194 P99_PROTECT({OMEGA
, CHI
, PHI
}),
195 surface_parameters_y
);
197 REGISTER_READONLY_EMERGENCE(hkl_engine_e4c_emergence_new
,
198 P99_PROTECT({OMEGA
, CHI
, PHI
, TTH
}),
199 surface_parameters_y
);
205 #define HKL_GEOMETRY_EULERIAN4C_VERTICAL_DESCRIPTION \
206 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
207 "+ 3 axes for the sample\n" \
209 " + **" OMEGA "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
210 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
211 " + **" PHI "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
213 "+ 1 axis for the detector\n" \
215 " + **" TTH "** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
217 static const char* hkl_geometry_eulerian4C_vertical_axes
[] = {OMEGA
, CHI
, PHI
, TTH
};
219 static HklGeometry
*hkl_geometry_new_eulerian4C_vertical(const HklFactory
*factory
)
221 HklGeometry
*self
= hkl_geometry_new(factory
);
224 h
= hkl_geometry_add_holder(self
);
225 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, -1, 0);
226 hkl_holder_add_rotation_axis(h
, CHI
, 1, 0, 0);
227 hkl_holder_add_rotation_axis(h
, PHI
, 0, -1, 0);
229 h
= hkl_geometry_add_holder(self
);
230 hkl_holder_add_rotation_axis(h
, TTH
, 0, -1, 0);
235 static HklEngineList
*hkl_engine_list_new_eulerian4C_vertical(const HklFactory
*factory
)
237 HklEngineList
*self
= hkl_engine_list_new();
239 hkl_engine_e4c_hkl_new(self
);
240 hkl_engine_e4c_psi_new(self
);
241 hkl_engine_q_new(self
);
242 hkl_engine_e4c_incidence_new(self
);
247 REGISTER_DIFFRACTOMETER(eulerian4C_vertical
, "E4CV", HKL_GEOMETRY_EULERIAN4C_VERTICAL_DESCRIPTION
);
254 #define HKL_GEOMETRY_TYPE_SOLEIL_MARS_DESCRIPTION \
255 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
256 "+ 3 axes for the sample\n" \
258 " + **" OMEGA "** : rotating around the :math:`\\vec{z}` direction (0, -1, 0)\n" \
259 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (-1, 0, 0)\n" \
260 " + **" PHI "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
262 "+ 1 axis for the detector\n" \
264 " + **" TTH "** : rotation around the :math:`\\vec{z}` direction (0, -1, 0)\n"
266 static const char* hkl_geometry_soleil_mars_axes
[] = {OMEGA
, CHI
, PHI
, TTH
};
268 static HklGeometry
*hkl_geometry_new_soleil_mars(const HklFactory
*factory
)
270 HklGeometry
*self
= hkl_geometry_new(factory
);
273 h
= hkl_geometry_add_holder(self
);
274 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, -1, 0);
275 hkl_holder_add_rotation_axis(h
, CHI
, -1, 0, 0);
276 hkl_holder_add_rotation_axis(h
, PHI
, 0, 0, 1);
278 h
= hkl_geometry_add_holder(self
);
279 hkl_holder_add_rotation_axis(h
, TTH
, 0, -1, 0);
284 static HklEngineList
*hkl_engine_list_new_soleil_mars(const HklFactory
*factory
)
286 HklEngineList
*self
= hkl_engine_list_new();
288 hkl_engine_e4c_hkl_new(self
);
289 hkl_engine_e4c_psi_new(self
);
290 hkl_engine_q_new(self
);
291 hkl_engine_e4c_incidence_new(self
);
296 REGISTER_DIFFRACTOMETER(soleil_mars
, "SOLEIL MARS", HKL_GEOMETRY_TYPE_SOLEIL_MARS_DESCRIPTION
);
302 #define HKL_GEOMETRY_TYPE_EULERIAN4C_HORIZONTAL_DESCRIPTION \
303 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
304 "+ 3 axes for the sample\n" \
306 " + **" OMEGA "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
307 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
308 " + **" PHI "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
310 "+ 1 axis for the detector\n" \
312 " + **" TTH "** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n"
314 static const char* hkl_geometry_eulerian4C_horizontal_axes
[] = {OMEGA
, CHI
, PHI
, TTH
};
316 static HklGeometry
*hkl_geometry_new_eulerian4C_horizontal(const HklFactory
*factory
)
318 HklGeometry
*self
= hkl_geometry_new(factory
);
321 h
= hkl_geometry_add_holder(self
);
322 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, 0, 1);
323 hkl_holder_add_rotation_axis(h
, CHI
, 1, 0, 0);
324 hkl_holder_add_rotation_axis(h
, PHI
, 0, 0, 1);
326 h
= hkl_geometry_add_holder(self
);
327 hkl_holder_add_rotation_axis(h
, TTH
, 0, 0, 1);
332 static HklEngineList
*hkl_engine_list_new_eulerian4C_horizontal(const HklFactory
*factory
)
334 HklEngineList
*self
= hkl_engine_list_new();
336 hkl_engine_e4c_hkl_new(self
);
337 hkl_engine_e4c_psi_new(self
);
338 hkl_engine_q_new(self
);
339 hkl_engine_e4c_incidence_new(self
);
340 hkl_engine_e4c_emergence_new(self
);
345 REGISTER_DIFFRACTOMETER(eulerian4C_horizontal
, "E4CH", HKL_GEOMETRY_TYPE_EULERIAN4C_HORIZONTAL_DESCRIPTION
);