[hkl] prepare for common storage of pseudo_axes
[hkl.git] / hkl / hkl-engine-template.c
blobf556106668178ea740ddef38513d4ed18dafd048
1 /* COPY THIS FILE INTO hkl-engine-xxx.c and fill the XXX */
2 /* This file is part of the hkl library.
4 * The hkl library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * The hkl library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with the hkl library. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 2003-2015 Synchrotron SOLEIL
18 * L'Orme des Merisiers Saint-Aubin
19 * BP 48 91192 GIF-sur-YVETTE CEDEX
20 * Copyright (C) 2014 XXX copyright owner XXX
22 * Authors: Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>
23 * XXXX <xxx@xxx>
25 #include <gsl/gsl_sys.h> // for gsl_isnan
26 #include "hkl-factory-private.h" // for autodata_factories_, etc
27 #include "hkl-pseudoaxis-common-hkl-private.h" // for hkl_mode_operations, etc
28 #include "hkl-pseudoaxis-common-psi-private.h" // for hkl_engine_psi_new, etc
29 #include "hkl-pseudoaxis-common-q-private.h" // for hkl_engine_q2_new, etc
30 #include "hkl-pseudoaxis-common-tth-private.h" // for hkl_engine_tth2_new, etc
32 /**************/
33 /* Axes names */
34 /**************/
36 #define MU "mu"
37 #define OMEGA "omega"
38 #define CHI "chi"
39 #define PHI "phi"
40 #define GAMMA "gamma"
41 #define DELTA "delta"
43 /************/
44 /* Geometry */
45 /************/
47 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
48 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
49 "+ 4 axes for the sample\n" \
50 "\n" \
51 " + **"MU"** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
52 " + **"OMEGA"** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
53 " + **"CHI"** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
54 " + **"PHI"** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
55 "\n" \
56 "+ 2 axes for the detector\n" \
57 "\n" \
58 " + **"GAMMA"** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
59 " + **"DELTA"** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
61 static const char* hkl_geometry_eulerian6C_axes[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
63 static HklGeometry *hkl_geometry_new_eulerian6C(const HklFactory *factory)
65 HklGeometry *self = hkl_geometry_new(factory);
66 HklHolder *h;
68 h = hkl_geometry_add_holder(self);
69 hkl_holder_add_rotation_axis(h, MU, 0, 0, 1);
70 hkl_holder_add_rotation_axis(h, OMEGA, 0, -1, 0);
71 hkl_holder_add_rotation_axis(h, CHI, 1, 0, 0);
72 hkl_holder_add_rotation_axis(h, PHI, 0, -1, 0);
74 h = hkl_geometry_add_holder(self);
75 hkl_holder_add_rotation_axis(h, GAMMA, 0, 0, 1);
76 hkl_holder_add_rotation_axis(h, DELTA, 0, -1, 0);
78 return self;
81 /*********/
82 /* Modes */
83 /*********/
85 /* exemple of a lowlevel gsl function use to compute an hkl bissector
86 * vertical mode for an E6C diffractometer */
87 static int _bissector_vertical_func(const gsl_vector *x, void *params, gsl_vector *f)
89 const double omega = x->data[0];
90 const double tth = x->data[3];
92 /* this method check that all the x values are valid. Sometime
93 * the computation produce NAN values. In that case
94 * computation is skipped */
95 CHECK_NAN(x->data, x->size);
97 /* do the hkl computation which fill the f[0..2] values */
98 RUBh_minus_Q(x->data, params, f->data);
100 /* here a mode specific equation requiered due to the number
101 * of axes to fit (4 in this case) */
102 f->data[3] = tth - 2 * fmod(omega,M_PI);
104 return GSL_SUCCESS;
107 /* Declare the number of axes expected by the gsl low level
108 * function. So during the HklMode configuration there is a runtime
109 * check which ensure that the right number of axes are given to the
110 * HklMode. */
111 static const HklFunction bissector_vertical_func = {
112 .function = _bissector_vertical_func,
113 .size = 4,
116 /* exemple of a mode with 4 axes. In that case you need the previously
117 * defined function */
118 static HklMode *bissector_vertical(void)
120 /* axes_r is the axes list requiered to compute the pseudo axes values */
121 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
123 /* axes_w is the axes list use when you write the pseudo axes
124 * values. You move only thoses axes when you use this
125 * mode. */
126 static const char* axes_w[] = {OMEGA, CHI, PHI, DELTA};
128 /* here a list of functions use to solve the mode */
129 static const HklFunction *functions[] = {&bissector_vertical_func};
131 /* here just the description of the mode: name, axes_r, axes_w, functions */
132 static const HklModeAutoInfo info = {
133 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
136 /* instantiate a new mode */
137 return hkl_mode_auto_new(&info,
138 &hkl_mode_operations,
139 TRUE);
142 /* here an exemple of a three axes hkl mode, a convenience function is
143 * provided to do the computation (RUBh_minus_Q_func). This funtion
144 * takes only three axes. So writing a generic hkl mode with only
145 * three axes is really simple */
146 static HklMode *constant_omega_vertical(void)
148 static const char* axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
149 static const char* axes_w[] = {CHI, PHI, DELTA};
150 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
151 static const HklModeAutoInfo info = {
152 HKL_MODE_AUTO_INFO(__func__, axes_r, axes_w, functions),
155 return hkl_mode_auto_new(&info,
156 &hkl_mode_operations,
157 TRUE);
160 static HklMode* psi_vertical()
162 static const char *axes_r[] = {MU, OMEGA, CHI, PHI, GAMMA, DELTA};
163 static const char *axes_w[] = {OMEGA, CHI, PHI, DELTA};
164 static const HklFunction *functions[] = {&psi_func};
165 static const HklModeAutoInfo info = {
166 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__, axes_r, axes_w,
167 functions, psi_parameters),
170 return hkl_mode_psi_new(&info);
173 /***********/
174 /* Engines */
175 /***********/
177 static HklEngine *hkl_engine_e6c_hkl_new(HklEngineList *engines)
179 HklEngine *self;
180 HklMode *default_mode;
182 self = hkl_engine_hkl_new(engines);
184 default_mode = bissector_vertical();
185 hkl_engine_add_mode(self, default_mode);
186 hkl_engine_mode_set(self, default_mode);
188 hkl_engine_add_mode(self, constant_omega_vertical());
190 return self;
193 static HklEngine *hkl_engine_e6c_psi_new(HklEngineList *engines)
195 HklEngine *self;
196 HklMode *default_mode;
198 self = hkl_engine_psi_new(engines);
200 default_mode = psi_vertical();
201 hkl_engine_add_mode(self, default_mode);
202 hkl_engine_mode_set(self, default_mode);
204 return self;
207 /***************/
208 /* Engine list */
209 /***************/
211 static HklEngineList *hkl_engine_list_new_eulerian6C(const HklFactory *factory)
213 HklEngineList *self = hkl_engine_list_new();
215 hkl_engine_list_add(self, hkl_engine_e6c_hkl_new(self));
216 hkl_engine_list_add(self, hkl_engine_e6c_psi_new(self));
217 hkl_engine_list_add(self, hkl_engine_q2_new(self));
218 hkl_engine_list_add(self, hkl_engine_qper_qpar_new(self));
219 hkl_engine_list_add(self, hkl_engine_tth2_new(self));
221 return self;
224 /* Register the diffractometer into the factory */
225 REGISTER_DIFFRACTOMETER(eulerian6C, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION);