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-2010 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>
24 #include <tap/basic.h>
27 static void hkl_test_bench_run_real(HklEngine
*engine
, HklGeometry
*geometry
, size_t n
)
32 /* pseudo -> geometry */
33 darray_foreach(mode
, engine
->modes
){
34 double min
, max
, mean
;
36 hkl_engine_select_mode(engine
, *mode
);
37 if (darray_size((*mode
)->parameters
))
38 hkl_parameter_set_value(darray_item((*mode
)->parameters
, 0), 1, NULL
);
41 min
= 1000; /* arbitrary value always greater than the real min */
43 struct timeval debut
, fin
, dt
;
46 hkl_geometry_set_values_unit_v(geometry
, 0, 0, 0, 0, 10, 10);
47 gettimeofday(&debut
, NULL
);
48 hkl_engine_set(engine
, NULL
);
49 gettimeofday(&fin
, NULL
);
50 timersub(&fin
, &debut
, &dt
);
51 t
= dt
.tv_sec
* 1000. + dt
.tv_usec
/ 1000.;
52 min
= t
< min
? t
: min
;
53 max
= t
> max
? t
: max
;
56 fprintf(stdout
, "\"%s\" \"%s\" \"%s\" (%d/%d) iterations %f / %f / %f [min/mean/max] ms each\n",
57 geometry
->config
->name
, engine
->info
->name
,
58 (*mode
)->info
->name
, n
, i
, min
, mean
/n
, max
);
62 static void hkl_test_bench_run_v(HklEngineList
*engines
, HklGeometry
*geometry
,
63 char const *name
, int n
, ...)
68 engine
= hkl_engine_list_get_by_name(engines
, name
);
71 /* TODO replace with a specialise HklParameterList */
72 for(uint i
=0; i
<darray_size(engine
->pseudo_axes
); ++i
)
73 hkl_parameter_set_value(darray_item(engine
->pseudo_axes
, i
),
74 va_arg(ap
, double), NULL
);
77 hkl_test_bench_run_real(engine
, geometry
, n
);
80 static void hkl_test_bench_k6c(int n
)
82 HklEngineList
*engines
;
84 const HklGeometryConfig
*config
;
86 HklDetector
*detector
;
91 config
= hkl_geometry_factory_get_config_from_type(HKL_GEOMETRY_TYPE_KAPPA6C
);
92 geom
= hkl_geometry_factory_new(config
, 50 * HKL_DEGTORAD
);
94 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
97 sample
= hkl_sample_new("test", HKL_SAMPLE_TYPE_MONOCRYSTAL
);
99 engines
= hkl_engine_list_factory(config
);
100 hkl_engine_list_init(engines
, geom
, detector
, sample
);
102 hkl_test_bench_run_v(engines
, geom
, "hkl", n
, 1., 0., 0.);
103 hkl_test_bench_run_v(engines
, geom
, "eulerians", n
, 0., 90*HKL_DEGTORAD
, 0.);
104 hkl_test_bench_run_v(engines
, geom
, "psi", n
, 10.*HKL_DEGTORAD
);
105 hkl_test_bench_run_v(engines
, geom
, "q2", n
, 1., 10.*HKL_DEGTORAD
);
106 hkl_test_bench_run_v(engines
, geom
, "qper_qpar", n
, 1., 1.);
108 hkl_engine_list_free(engines
);
109 hkl_sample_free(sample
);
110 hkl_detector_free(detector
);
111 hkl_geometry_free(geom
);
114 static void hkl_test_bench_eulerians(void)
116 HklEngineList
*engines
;
119 const HklGeometryConfig
*config
;
121 HklDetector
*detector
;
124 config
= hkl_geometry_factory_get_config_from_type(HKL_GEOMETRY_TYPE_KAPPA6C
);
125 geom
= hkl_geometry_factory_new(config
, 50 * HKL_DEGTORAD
);
126 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
128 sample
= hkl_sample_new("test", HKL_SAMPLE_TYPE_MONOCRYSTAL
);
129 engines
= hkl_engine_list_factory(config
);
130 hkl_engine_list_init(engines
, geom
, detector
, sample
);
132 engine
= hkl_engine_list_get_by_name(engines
, "eulerians");
134 darray_foreach(mode
, engine
->modes
){
135 static double eulerians
[] = {0, 90 * HKL_DEGTORAD
, 0};
137 hkl_engine_select_mode(engine
, *mode
);
139 /* studdy this degenerated case */
140 hkl_parameter_list_set_values(&engine
->pseudo_axes
, eulerians
, 3, NULL
);
141 if (hkl_engine_set(engine
, NULL
)) {
142 const HklGeometryList
*geometries
= hkl_engine_list_geometries(engines
);
143 HklGeometryListItem
*item
;
145 list_for_each(&geometries
->items
, item
, node
){
146 static double null
[] = {0, 0, 0};
148 hkl_parameter_list_set_values(&engine
->pseudo_axes
, null
, 3, NULL
);
149 hkl_geometry_init_geometry(engine
->geometry
,
151 hkl_engine_get(engine
, NULL
);
156 hkl_engine_list_free(engines
);
157 hkl_sample_free(sample
);
158 hkl_detector_free(detector
);
159 hkl_geometry_free(geom
);
162 int main(int argc
, char **argv
)
173 hkl_test_bench_k6c(n
);
174 hkl_test_bench_eulerians();
176 ok(HKL_TRUE
== HKL_TRUE
, __func__
);