upgrading copyright year from 2015 to 2016
[hkl.git] / hkl / hkl-engine-zaxis.c
blobd417d57be7381e93f8003de99a1ce81f157a3adb
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-hkl-private.h" // for RUBh_minus_Q, etc
25 #include "hkl-pseudoaxis-common-q-private.h" // for hkl_engine_q2_new, etc
26 #include "hkl-pseudoaxis-common-tth-private.h" // for hkl_engine_tth2_new, etc
27 #include "hkl-pseudoaxis-common-readonly-private.h" // for hkl_engine_tth2_new, etc
29 #define MU "mu"
30 #define OMEGA "omega"
31 #define DELTA "delta"
32 #define GAMMA "gamma"
34 /* #define DEBUG */
36 static HklMode* _zaxis()
38 static const char *axes_r[] = {MU, OMEGA, DELTA, GAMMA};
39 static const char *axes_w[] = {OMEGA, DELTA, GAMMA};
40 static const HklFunction *functions[] = {&RUBh_minus_Q_func};
41 static const HklModeAutoInfo info = {
42 HKL_MODE_AUTO_INFO("zaxis", axes_r, axes_w, functions),
45 return hkl_mode_auto_new(&info,
46 &hkl_full_mode_operations,
47 TRUE);
50 /* reflectivity */
52 static int _reflectivity_func(const gsl_vector *x, void *params, gsl_vector *f)
54 const double mu = x->data[0];
55 const double gamma = x->data[3];
57 CHECK_NAN(x->data, x->size);
59 RUBh_minus_Q(x->data, params, f->data);
60 f->data[3] = mu - gamma;
62 return GSL_SUCCESS;
65 static const HklFunction reflectivity_func = {
66 .function = _reflectivity_func,
67 .size = 4,
70 static HklMode* reflectivity()
72 static const char* axes[] = {MU, OMEGA, DELTA, GAMMA};
73 static const HklFunction *functions[] = {&reflectivity_func};
74 static const HklModeAutoInfo info = {
75 HKL_MODE_AUTO_INFO(__func__, axes, axes, functions),
78 return hkl_mode_auto_new(&info,
79 &hkl_full_mode_operations,
80 TRUE);
83 /**********************/
84 /* pseudo axis engine */
85 /**********************/
87 static HklEngine *hkl_engine_zaxis_hkl_new(HklEngineList *engines)
89 HklEngine *self;
90 HklMode *default_mode;
92 self = hkl_engine_hkl_new(engines);
94 default_mode = _zaxis();
95 hkl_engine_add_mode(self, default_mode);
96 hkl_engine_mode_set(self, default_mode);
98 hkl_engine_add_mode(self, reflectivity());
100 return self;
103 /*****************/
104 /* mode readonly */
105 /*****************/
107 REGISTER_READONLY_INCIDENCE(hkl_engine_zaxis_incidence_new,
108 P99_PROTECT({MU, OMEGA}),
109 surface_parameters_y);
111 REGISTER_READONLY_EMERGENCE(hkl_engine_zaxis_emergence_new,
112 P99_PROTECT({MU, OMEGA, DELTA, GAMMA}),
113 surface_parameters_y);
115 /*********/
116 /* ZAXIS */
117 /*********/
119 #define HKL_GEOMETRY_TYPE_ZAXIS_DESCRIPTION \
120 "For this geometry the **mu** axis is common to the sample and the detector.\n" \
121 "\n" \
122 "+ xrays source fix allong the :math:`\\vec{x}` direction (1, 0, 0)\n" \
123 "+ 2 axes for the sample\n" \
124 "\n" \
125 " + **" MU "** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
126 " + **" OMEGA "** : rotating around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
127 "\n" \
128 "+ 3 axis for the detector\n" \
129 "\n" \
130 " + **" MU "** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n" \
131 " + **" DELTA "** : rotation around the :math:`-\\vec{y}` direction (0, -1, 0)\n" \
132 " + **" GAMMA "** : rotation around the :math:`\\vec{z}` direction (0, 0, 1)\n"
134 static const char* hkl_geometry_zaxis_axes[] = {MU, OMEGA, DELTA, GAMMA};
136 static HklGeometry *hkl_geometry_new_zaxis(const HklFactory *factory)
138 HklGeometry *self = hkl_geometry_new(factory);
139 HklHolder *h;
141 h = hkl_geometry_add_holder(self);
142 hkl_holder_add_rotation_axis(h, MU, 0, 0, 1);
143 hkl_holder_add_rotation_axis(h, OMEGA, 0, -1, 0);
145 h = hkl_geometry_add_holder(self);
146 hkl_holder_add_rotation_axis(h, MU, 0, 0, 1);
147 hkl_holder_add_rotation_axis(h, DELTA, 0, -1, 0);
148 hkl_holder_add_rotation_axis(h, GAMMA, 0, 0, 1);
150 return self;
153 static HklEngineList *hkl_engine_list_new_zaxis(const HklFactory *factory)
155 HklEngineList *self = hkl_engine_list_new();
157 hkl_engine_zaxis_hkl_new(self);
158 hkl_engine_q2_new(self);
159 hkl_engine_qper_qpar_new(self);
160 hkl_engine_tth2_new(self);
161 hkl_engine_zaxis_incidence_new(self);
162 hkl_engine_zaxis_emergence_new(self);
164 return self;
167 REGISTER_DIFFRACTOMETER(zaxis, "ZAXIS", HKL_GEOMETRY_TYPE_ZAXIS_DESCRIPTION);