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-2019, 2021, 2023 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
,
28 size_t n_values
, double values
[n_values
],
32 const darray_string
*modes
= hkl_engine_modes_names_get(engine
);
35 /* pseudo -> geometry */
36 darray_foreach(mode
, *modes
){
37 double min
, max
, mean
;
38 const darray_string
*parameters
;
41 if (FALSE
== hkl_engine_current_mode_set(engine
, *mode
, NULL
))
44 parameters
= hkl_engine_parameters_names_get(engine
);
45 n_params
= darray_size(*parameters
);
47 double params
[n_params
];
49 hkl_engine_parameters_values_get(engine
,
53 if(FALSE
== hkl_engine_parameters_values_set(engine
,
55 HKL_UNIT_DEFAULT
, NULL
))
60 min
= 1000; /* arbitrary value always greater than the real min */
62 struct timeval debut
, fin
, dt
;
64 HklGeometryList
*solutions
;
66 if(FALSE
== hkl_geometry_set_values_v(geometry
, HKL_UNIT_USER
, NULL
, 0., 0., 0., 0., 10., 10.))
68 gettimeofday(&debut
, NULL
);
69 solutions
= hkl_engine_pseudo_axis_values_set(engine
, values
, n_values
, HKL_UNIT_DEFAULT
, NULL
);
70 if (NULL
!= solutions
)
71 hkl_geometry_list_free(solutions
);
72 gettimeofday(&fin
, NULL
);
73 timersub(&fin
, &debut
, &dt
);
74 t
= dt
.tv_sec
* 1000. + dt
.tv_usec
/ 1000.;
75 min
= t
< min
? t
: min
;
76 max
= t
> max
? t
: max
;
79 fprintf(stdout
, "\"%s\" \"%s\" \"%s\" (%zd/%zd) iterations %f / %f / %f [min/mean/max] ms each\n",
80 hkl_geometry_name_get(geometry
),
81 hkl_engine_name_get(engine
),
82 *mode
, n
, i
, min
, mean
/n
, max
);
86 static void hkl_test_bench_run_v(HklEngineList
*engines
, HklGeometry
*geometry
,
87 char const *name
, int n
, size_t n_values
, ...)
91 HklEngine
*engine
= hkl_engine_list_engine_get_by_name(engines
, name
, NULL
);
92 double values
[n_values
];
94 va_start(ap
, n_values
);
95 for(i
=0; i
<n_values
; ++i
)
96 values
[i
] = va_arg(ap
, double);
99 hkl_test_bench_run_real(engine
, geometry
, n_values
, values
, n
);
102 static void hkl_test_bench_k6c(int n
)
104 const HklFactory
*factory
;
105 HklEngineList
*engines
;
107 HklDetector
*detector
;
110 factory
= hkl_factory_get_by_name("K6C", NULL
);
112 geom
= hkl_factory_create_new_geometry(factory
);
114 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
116 sample
= hkl_sample_new("test");
118 engines
= hkl_factory_create_new_engine_list(factory
);
119 hkl_engine_list_init(engines
, geom
, detector
, sample
);
121 hkl_test_bench_run_v(engines
, geom
, "hkl", n
, 3, 1., 0., 0.);
122 hkl_test_bench_run_v(engines
, geom
, "eulerians", n
, 3, 0., 90*HKL_DEGTORAD
, 0.);
123 hkl_test_bench_run_v(engines
, geom
, "psi", n
, 1, 10.*HKL_DEGTORAD
);
124 hkl_test_bench_run_v(engines
, geom
, "q2", n
, 2, 1., 10.*HKL_DEGTORAD
);
125 hkl_test_bench_run_v(engines
, geom
, "qper_qpar", n
, 2, 1., 1.);
127 hkl_engine_list_free(engines
);
128 hkl_sample_free(sample
);
129 hkl_detector_free(detector
);
130 hkl_geometry_free(geom
);
133 static void hkl_test_bench_eulerians(void)
135 HklEngineList
*engines
;
138 const darray_string
*modes
;
139 const HklFactory
*factory
;
140 HklGeometry
*geometry
;
141 HklDetector
*detector
;
144 factory
= hkl_factory_get_by_name("K6C", NULL
);
146 geometry
= hkl_factory_create_new_geometry(factory
);
147 detector
= hkl_detector_factory_new(HKL_DETECTOR_TYPE_0D
);
149 sample
= hkl_sample_new("test");
150 engines
= hkl_factory_create_new_engine_list(factory
);
151 hkl_engine_list_init(engines
, geometry
, detector
, sample
);
153 engine
= hkl_engine_list_engine_get_by_name(engines
, "eulerians", NULL
);
154 modes
= hkl_engine_modes_names_get(engine
);
156 darray_foreach(mode
, *modes
){
157 static double values
[3] = {0, 90 * HKL_DEGTORAD
, 0};
158 HklGeometryList
*solutions
;
160 if(FALSE
== hkl_engine_current_mode_set(engine
, *mode
, NULL
))
163 /* studdy this degenerated case */
164 solutions
= hkl_engine_pseudo_axis_values_set(engine
,
165 values
, ARRAY_SIZE(values
),
166 HKL_UNIT_DEFAULT
, NULL
);
168 const HklGeometryListItem
*item
;
170 HKL_GEOMETRY_LIST_FOREACH(item
, solutions
){
171 hkl_geometry_set(geometry
,
172 hkl_geometry_list_item_geometry_get(item
));
173 if(FALSE
== hkl_engine_pseudo_axis_values_get(engine
, values
, ARRAY_SIZE(values
),
174 HKL_UNIT_DEFAULT
, NULL
))
177 hkl_geometry_list_free(solutions
);
181 hkl_engine_list_free(engines
);
182 hkl_sample_free(sample
);
183 hkl_detector_free(detector
);
184 hkl_geometry_free(geometry
);
187 int main(int argc
, char **argv
)
198 hkl_test_bench_k6c(n
);
199 hkl_test_bench_eulerians();
201 ok(TRUE
== TRUE
, __func__
);