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-2014 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>
25 #include <gsl/gsl_sys.h> // for gsl_isnan
26 #include "hkl-factory-private.h" // for autodata_factories_, etc
27 #include "hkl-pseudoaxis-common-q-private.h" // for hkl_engine_q2_new, etc
28 #include "hkl-pseudoaxis-common-hkl-private.h" // for hkl_mode_operations, etc
29 #include "hkl-pseudoaxis-common-psi-private.h" // for hkl_engine_psi_new, etc
46 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
47 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
48 "+ 4 axes for the sample\n" \
50 " + **"MU"** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
51 " + **"OMEGA"** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
52 " + **"CHI"** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
53 " + **"PHI"** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
55 "+ 2 axes for the detector\n" \
57 " + **"GAMMA"** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
58 " + **"DELTA"** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
60 static const char* hkl_geometry_eulerian6C_axes
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
62 static HklGeometry
*hkl_geometry_new_eulerian6C(const HklFactory
*factory
)
64 HklGeometry
*self
= hkl_geometry_new(factory
);
67 h
= hkl_geometry_add_holder(self
);
68 hkl_holder_add_rotation_axis(h
, MU
, 0, 0, 1);
69 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, -1, 0);
70 hkl_holder_add_rotation_axis(h
, CHI
, 1, 0, 0);
71 hkl_holder_add_rotation_axis(h
, PHI
, 0, -1, 0);
73 h
= hkl_geometry_add_holder(self
);
74 hkl_holder_add_rotation_axis(h
, GAMMA
, 0, 0, 1);
75 hkl_holder_add_rotation_axis(h
, DELTA
, 0, -1, 0);
84 /* exemple of a lowlevel gsl function use to compute an hkl bissector
85 * vertical mode for an E6C diffractometer */
86 static int _bissector_vertical_func(const gsl_vector
*x
, void *params
, gsl_vector
*f
)
88 const double omega
= x
->data
[0];
89 const double tth
= x
->data
[3];
91 /* this method check that all the x values are valid. Sometime
92 * the computation produce NAN values. In that case
93 * computation is skipped */
94 CHECK_NAN(x
->data
, x
->size
);
96 /* do the hkl computation which fill the f[0..2] values */
97 RUBh_minus_Q(x
->data
, params
, f
->data
);
99 /* here a mode specific equation requiered due to the number
100 * of axes to fit (4 in this case) */
101 f
->data
[3] = tth
- 2 * fmod(omega
,M_PI
);
106 /* Declare the number of axes expected by the gsl low level
107 * function. So during the HklMode configuration there is a runtime
108 * check which ensure that the right number of axes are given to the
110 static const HklFunction bissector_vertical_func
= {
111 .function
= _bissector_vertical_func
,
115 /* exemple of a mode with 4 axes. In that case you need the previously
116 * defined function */
117 static HklMode
*bissector_vertical(void)
119 /* axes_r is the axes list requiered to compute the pseudo axes values */
120 static const char* axes_r
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
122 /* axes_w is the axes list use when you write the pseudo axes
123 * values. You move only thoses axes when you use this
125 static const char* axes_w
[] = {OMEGA
, CHI
, PHI
, DELTA
};
127 /* here a list of functions use to solve the mode */
128 static const HklFunction
*functions
[] = {&bissector_vertical_func
};
130 /* here just the description of the mode: name, axes_r, axes_w, functions */
131 static const HklModeAutoInfo info
= {
132 HKL_MODE_AUTO_INFO(__func__
, axes_r
, axes_w
, functions
),
135 /* instantiate a new mode */
136 return hkl_mode_auto_new(&info
,
137 &hkl_mode_operations
,
141 /* here an exemple of a three axes hkl mode, a convenience function is
142 * provided to do the computation (RUBh_minus_Q_func). This funtion
143 * takes only three axes. So writing a generic hkl mode with only
144 * three axes is really simple */
145 static HklMode
*constant_omega_vertical(void)
147 static const char* axes_r
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
148 static const char* axes_w
[] = {CHI
, PHI
, DELTA
};
149 static const HklFunction
*functions
[] = {&RUBh_minus_Q_func
};
150 static const HklModeAutoInfo info
= {
151 HKL_MODE_AUTO_INFO(__func__
, axes_r
, axes_w
, functions
),
154 return hkl_mode_auto_new(&info
,
155 &hkl_mode_operations
,
159 static HklMode
* psi_vertical()
161 static const char *axes_r
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
162 static const char *axes_w
[] = {OMEGA
, CHI
, PHI
, DELTA
};
163 static const HklFunction
*functions
[] = {&psi_func
};
164 static const HklModeAutoInfo info
= {
165 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes_r
, axes_w
,
166 functions
, psi_parameters
),
169 return hkl_mode_psi_new(&info
);
176 static HklEngine
*hkl_engine_e6c_hkl_new(void)
179 HklMode
*default_mode
;
181 self
= hkl_engine_hkl_new();
183 default_mode
= bissector_vertical();
184 hkl_engine_add_mode(self
, default_mode
);
185 hkl_engine_mode_set(self
, default_mode
);
187 hkl_engine_add_mode(self
, constant_omega_vertical());
192 static HklEngine
*hkl_engine_e6c_psi_new(void)
195 HklMode
*default_mode
;
197 self
= hkl_engine_psi_new();
199 default_mode
= psi_vertical();
200 hkl_engine_add_mode(self
, default_mode
);
201 hkl_engine_mode_set(self
, default_mode
);
210 static HklEngineList
*hkl_engine_list_new_eulerian6C(const HklFactory
*factory
)
212 HklEngineList
*self
= hkl_engine_list_new();
214 hkl_engine_list_add(self
, hkl_engine_e6c_hkl_new());
215 hkl_engine_list_add(self
, hkl_engine_e6c_psi_new());
216 hkl_engine_list_add(self
, hkl_engine_q2_new());
217 hkl_engine_list_add(self
, hkl_engine_qper_qpar_new());
222 /* Register the diffractometer into the factory */
223 REGISTER_DIFFRACTOMETER(eulerian6C
, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION
);