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-2017 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-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
31 #include "hkl-pseudoaxis-common-readonly-private.h"
48 #define HKL_GEOMETRY_EULERIAN6C_DESCRIPTION \
49 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
50 "+ 4 axes for the sample\n" \
52 " + **" MU "** : rotating around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
53 " + **" OMEGA "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
54 " + **" CHI "** : rotating around the :math:`\\vec{x}` direction (1, 0, 0)\n" \
55 " + **" PHI "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
57 "+ 2 axes for the detector\n" \
59 " + **" GAMMA "** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
60 " + **" DELTA "** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n"
62 static const char* hkl_geometry_eulerian6C_axes
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
64 static HklGeometry
*hkl_geometry_new_eulerian6C(const HklFactory
*factory
)
66 HklGeometry
*self
= hkl_geometry_new(factory
);
69 h
= hkl_geometry_add_holder(self
);
70 hkl_holder_add_rotation_axis(h
, MU
, 0, 0, 1);
71 hkl_holder_add_rotation_axis(h
, OMEGA
, 0, -1, 0);
72 hkl_holder_add_rotation_axis(h
, CHI
, 1, 0, 0);
73 hkl_holder_add_rotation_axis(h
, PHI
, 0, -1, 0);
75 h
= hkl_geometry_add_holder(self
);
76 hkl_holder_add_rotation_axis(h
, GAMMA
, 0, 0, 1);
77 hkl_holder_add_rotation_axis(h
, DELTA
, 0, -1, 0);
86 /* exemple of a lowlevel gsl function use to compute an hkl bissector
87 * vertical mode for an E6C diffractometer */
88 static int _bissector_vertical_func(const gsl_vector
*x
, void *params
, gsl_vector
*f
)
90 const double omega
= x
->data
[0];
91 const double tth
= x
->data
[3];
93 /* this method check that all the x values are valid. Sometime
94 * the computation produce NAN values. In that case
95 * computation is skipped */
96 CHECK_NAN(x
->data
, x
->size
);
98 /* do the hkl computation which fill the f[0..2] values */
99 RUBh_minus_Q(x
->data
, params
, f
->data
);
101 /* here a mode specific equation requiered due to the number
102 * of axes to fit (4 in this case) */
103 f
->data
[3] = tth
- 2 * fmod(omega
,M_PI
);
108 /* Declare the number of axes expected by the gsl low level
109 * function. So during the HklMode configuration there is a runtime
110 * check which ensure that the right number of axes are given to the
112 static const HklFunction bissector_vertical_func
= {
113 .function
= _bissector_vertical_func
,
117 /* exemple of a mode with 4 axes. In that case you need the previously
118 * defined function */
119 static HklMode
*bissector_vertical(void)
121 /* axes_r is the axes list requiered to compute the pseudo axes values */
122 static const char* axes_r
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
124 /* axes_w is the axes list use when you write the pseudo axes
125 * values. You move only thoses axes when you use this
127 static const char* axes_w
[] = {OMEGA
, CHI
, PHI
, DELTA
};
129 /* here a list of functions use to solve the mode */
130 static const HklFunction
*functions
[] = {&bissector_vertical_func
};
132 /* here just the description of the mode: name, axes_r, axes_w, functions */
133 static const HklModeAutoInfo info
= {
134 HKL_MODE_AUTO_INFO(__func__
, axes_r
, axes_w
, functions
),
137 /* instantiate a new mode */
138 return hkl_mode_auto_new(&info
,
139 &hkl_mode_operations
,
143 /* here an exemple of a three axes hkl mode, a convenience function is
144 * provided to do the computation (RUBh_minus_Q_func). This funtion
145 * takes only three axes. So writing a generic hkl mode with only
146 * three axes is really simple */
147 static HklMode
*constant_omega_vertical(void)
149 static const char* axes_r
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
150 static const char* axes_w
[] = {CHI
, PHI
, DELTA
};
151 static const HklFunction
*functions
[] = {&RUBh_minus_Q_func
};
152 static const HklModeAutoInfo info
= {
153 HKL_MODE_AUTO_INFO(__func__
, axes_r
, axes_w
, functions
),
156 return hkl_mode_auto_new(&info
,
157 &hkl_mode_operations
,
161 static HklMode
* psi_vertical()
163 static const char *axes_r
[] = {MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
};
164 static const char *axes_w
[] = {OMEGA
, CHI
, PHI
, DELTA
};
165 static const HklFunction
*functions
[] = {&psi_func
};
166 static const HklModeAutoInfo info
= {
167 HKL_MODE_AUTO_INFO_WITH_PARAMS(__func__
, axes_r
, axes_w
,
168 functions
, psi_parameters
),
171 return hkl_mode_psi_new(&info
);
178 REGISTER_READONLY_INCIDENCE(hkl_engine_template_incidence_new
,
179 P99_PROTECT({MU
, OMEGA
, CHI
, PHI
}),
180 surface_parameters_y
);
182 REGISTER_READONLY_EMERGENCE(hkl_engine_template_emergence_new
,
183 P99_PROTECT({MU
, OMEGA
, CHI
, PHI
, GAMMA
, DELTA
}),
184 surface_parameters_y
);
190 static HklEngine
*hkl_engine_e6c_hkl_new(HklEngineList
*engines
)
193 HklMode
*default_mode
;
195 self
= hkl_engine_hkl_new(engines
);
197 default_mode
= bissector_vertical();
198 hkl_engine_add_mode(self
, default_mode
);
199 hkl_engine_mode_set(self
, default_mode
);
201 hkl_engine_add_mode(self
, constant_omega_vertical());
206 static HklEngine
*hkl_engine_e6c_psi_new(HklEngineList
*engines
)
209 HklMode
*default_mode
;
211 self
= hkl_engine_psi_new(engines
);
213 default_mode
= psi_vertical();
214 hkl_engine_add_mode(self
, default_mode
);
215 hkl_engine_mode_set(self
, default_mode
);
224 static HklEngineList
*hkl_engine_list_new_eulerian6C(const HklFactory
*factory
)
226 HklEngineList
*self
= hkl_engine_list_new();
228 hkl_engine_e6c_hkl_new(self
);
229 hkl_engine_e6c_psi_new(self
);
230 hkl_engine_q2_new(self
);
231 hkl_engine_qper_qpar_new(self
);
232 hkl_engine_tth2_new(self
);
233 hkl_engine_template_incidence_new(self
);
234 hkl_engine_template_emergence_new(self
);
239 /* Register the diffractometer into the factory */
240 REGISTER_DIFFRACTOMETER(eulerian6C
, "E6C", HKL_GEOMETRY_EULERIAN6C_DESCRIPTION
);