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 REGISTER_READONLY_INCIDENCE(hkl_engine_e4c_incidence_new
,
194 P99_PROTECT({OMEGA
, CHI
, PHI
}));
196 REGISTER_READONLY_EMERGENCE(hkl_engine_e4c_emergence_new
,
197 P99_PROTECT({OMEGA
, CHI
, PHI
, TTH
}));
203 #define HKL_GEOMETRY_EULERIAN4C_VERTICAL_DESCRIPTION \
204 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
205 "+ 3 axes for the sample\n" \
207 " + **" OMEGA "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
208 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
209 " + **" PHI "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
211 "+ 1 axis for the detector\n" \
213 " + **" TTH "** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
215 static const char* hkl_geometry_eulerian4C_vertical_axes
[] = {OMEGA
, CHI
, PHI
, TTH
};
217 static HklGeometry
*hkl_geometry_new_eulerian4C_vertical(const HklFactory
*factory
)
219 HklGeometry
*self
= hkl_geometry_new(factory
);
222 h
= hkl_geometry_add_holder(self
);
223 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, -1, 0);
224 hkl_holder_add_rotation_axis(h
, CHI
, 1, 0, 0);
225 hkl_holder_add_rotation_axis(h
, PHI
, 0, -1, 0);
227 h
= hkl_geometry_add_holder(self
);
228 hkl_holder_add_rotation_axis(h
, TTH
, 0, -1, 0);
233 static HklEngineList
*hkl_engine_list_new_eulerian4C_vertical(const HklFactory
*factory
)
235 HklEngineList
*self
= hkl_engine_list_new();
237 hkl_engine_e4c_hkl_new(self
);
238 hkl_engine_e4c_psi_new(self
);
239 hkl_engine_q_new(self
);
240 hkl_engine_e4c_incidence_new(self
);
245 REGISTER_DIFFRACTOMETER(eulerian4C_vertical
, "E4CV", HKL_GEOMETRY_EULERIAN4C_VERTICAL_DESCRIPTION
);
252 #define HKL_GEOMETRY_TYPE_SOLEIL_MARS_DESCRIPTION \
253 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
254 "+ 3 axes for the sample\n" \
256 " + **" OMEGA "** : rotating around the :math:`\\vec{z}` direction (0, -1, 0)\n" \
257 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (-1, 0, 0)\n" \
258 " + **" PHI "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
260 "+ 1 axis for the detector\n" \
262 " + **" TTH "** : rotation around the :math:`\\vec{z}` direction (0, -1, 0)\n"
264 static const char* hkl_geometry_soleil_mars_axes
[] = {OMEGA
, CHI
, PHI
, TTH
};
266 static HklGeometry
*hkl_geometry_new_soleil_mars(const HklFactory
*factory
)
268 HklGeometry
*self
= hkl_geometry_new(factory
);
271 h
= hkl_geometry_add_holder(self
);
272 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, -1, 0);
273 hkl_holder_add_rotation_axis(h
, CHI
, -1, 0, 0);
274 hkl_holder_add_rotation_axis(h
, PHI
, 0, 0, 1);
276 h
= hkl_geometry_add_holder(self
);
277 hkl_holder_add_rotation_axis(h
, TTH
, 0, -1, 0);
282 static HklEngineList
*hkl_engine_list_new_soleil_mars(const HklFactory
*factory
)
284 HklEngineList
*self
= hkl_engine_list_new();
286 hkl_engine_e4c_hkl_new(self
);
287 hkl_engine_e4c_psi_new(self
);
288 hkl_engine_q_new(self
);
289 hkl_engine_e4c_incidence_new(self
);
294 REGISTER_DIFFRACTOMETER(soleil_mars
, "SOLEIL MARS", HKL_GEOMETRY_TYPE_SOLEIL_MARS_DESCRIPTION
);
300 #define HKL_GEOMETRY_TYPE_EULERIAN4C_HORIZONTAL_DESCRIPTION \
301 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
302 "+ 3 axes for the sample\n" \
304 " + **" OMEGA "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
305 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
306 " + **" PHI "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
308 "+ 1 axis for the detector\n" \
310 " + **" TTH "** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n"
312 static const char* hkl_geometry_eulerian4C_horizontal_axes
[] = {OMEGA
, CHI
, PHI
, TTH
};
314 static HklGeometry
*hkl_geometry_new_eulerian4C_horizontal(const HklFactory
*factory
)
316 HklGeometry
*self
= hkl_geometry_new(factory
);
319 h
= hkl_geometry_add_holder(self
);
320 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, 0, 1);
321 hkl_holder_add_rotation_axis(h
, CHI
, 1, 0, 0);
322 hkl_holder_add_rotation_axis(h
, PHI
, 0, 0, 1);
324 h
= hkl_geometry_add_holder(self
);
325 hkl_holder_add_rotation_axis(h
, TTH
, 0, 0, 1);
330 static HklEngineList
*hkl_engine_list_new_eulerian4C_horizontal(const HklFactory
*factory
)
332 HklEngineList
*self
= hkl_engine_list_new();
334 hkl_engine_e4c_hkl_new(self
);
335 hkl_engine_e4c_psi_new(self
);
336 hkl_engine_q_new(self
);
337 hkl_engine_e4c_incidence_new(self
);
338 hkl_engine_e4c_emergence_new(self
);
343 REGISTER_DIFFRACTOMETER(eulerian4C_horizontal
, "E4CH", HKL_GEOMETRY_TYPE_EULERIAN4C_HORIZONTAL_DESCRIPTION
);