Documentation is the directory of the documentation
[hkl.git] / test / mode_kappa4C_test.cpp
blobdeb91d4365250d82e4351fe008e00b011a00bb37
1 #include "mode_kappa4C_test.h"
3 CPPUNIT_TEST_SUITE_REGISTRATION( Mode_Kappa4C_Test );
5 void
6 Mode_Kappa4C_Test::setUp(void)
8 _geometry = new hkl::kappa4C::vertical::Geometry(50 * hkl::constant::math::degToRad);
9 hkl::eulerian4C::vertical::Geometry geometry;
11 _sample = new hkl::sample::MonoCrystal(*_geometry, "test");
12 hkl::Lattice lattice = _sample->lattice();
13 lattice.a().set_current(1.54);
14 lattice.b().set_current(1.54);
15 lattice.c().set_current(1.54);
16 lattice.alpha().set_current(90 * hkl::constant::math::degToRad);
17 lattice.beta().set_current(90 * hkl::constant::math::degToRad);
18 lattice.gamma().set_current(90 * hkl::constant::math::degToRad);
20 geometry.set_angles(30.*hkl::constant::math::degToRad,
21 0.*hkl::constant::math::degToRad,
22 90.*hkl::constant::math::degToRad,
23 60.*hkl::constant::math::degToRad);
24 _geometry->setFromGeometry(geometry, true);
25 _sample->reflections().add(hkl::svector(1., 0., 0.));
27 geometry.set_angles(30.*hkl::constant::math::degToRad,
28 0.*hkl::constant::math::degToRad,
29 180.*hkl::constant::math::degToRad,
30 60.*hkl::constant::math::degToRad);
31 _geometry->setFromGeometry(geometry, true);
32 _sample->reflections().add(hkl::svector(0., 1., 0.));
34 _sample->computeU(0, 1);
37 void
38 Mode_Kappa4C_Test::tearDown(void)
40 delete _sample;
41 delete _geometry;
44 void
45 Mode_Kappa4C_Test::Bissector(void)
47 hkl::smatrix UB = _sample->get_UB();
49 hkl::kappa4C::vertical::mode::Bissector mode("test", "test", *_geometry);
51 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(1., 0., 0., UB));
52 CPPUNIT_ASSERT_EQUAL(hkl::Value(120. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
53 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
54 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
55 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
57 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(-1., 0., 0., UB));
58 CPPUNIT_ASSERT_EQUAL(hkl::Value( 120. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
59 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
60 CPPUNIT_ASSERT_EQUAL(hkl::Value(-180. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
61 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
63 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(0., 1., 0., UB));
64 CPPUNIT_ASSERT_EQUAL(hkl::Value(120. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
65 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
66 CPPUNIT_ASSERT_EQUAL(hkl::Value( 90. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
67 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
69 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(0.,-1., 0., UB));
70 CPPUNIT_ASSERT_EQUAL(hkl::Value(120. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
71 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
72 CPPUNIT_ASSERT_EQUAL(hkl::Value(-90. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
73 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
75 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(0., 0., 1., UB));
76 CPPUNIT_ASSERT_EQUAL(hkl::Value( 62.954883 * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
77 CPPUNIT_ASSERT_EQUAL(hkl::Value( 134.755927 * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
78 CPPUNIT_ASSERT_EQUAL(hkl::Value(-147.045165 * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
79 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
81 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(0., 0., -1., UB));
82 CPPUNIT_ASSERT_EQUAL(hkl::Value( 177.0451647 * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
83 CPPUNIT_ASSERT_EQUAL(hkl::Value(-134.755927 * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
84 CPPUNIT_ASSERT_EQUAL(hkl::Value( -32.9548353 * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
85 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
87 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(1., 1., 0., UB));
88 CPPUNIT_ASSERT_EQUAL(hkl::Value(135. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
89 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
90 CPPUNIT_ASSERT_EQUAL(hkl::Value( 45. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
91 CPPUNIT_ASSERT_EQUAL(hkl::Value( 90. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
93 // random test
94 double h, k, l;
95 for (unsigned int i=0;i<1000;i++)
97 double h0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
98 double k0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
99 double l0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
102 mode.computeAngles(h0, k0, l0, UB);
103 _geometry->compute_HKL_consign(h, k, l, UB);
104 CPPUNIT_ASSERT_DOUBLES_EQUAL(h0, h, hkl::constant::math::epsilon);
105 CPPUNIT_ASSERT_DOUBLES_EQUAL(k0, k, hkl::constant::math::epsilon);
106 CPPUNIT_ASSERT_DOUBLES_EQUAL(l0, l, hkl::constant::math::epsilon);
108 catch (hkl::HKLException) {}
112 void
113 Mode_Kappa4C_Test::Delta_Theta(void)
115 hkl::smatrix UB = _sample->get_UB();
117 hkl::kappa4C::vertical::mode::Delta_Theta mode("test", "test", *_geometry);
118 mode.parameters()["delta theta"]->set_current(10 * hkl::constant::math::degToRad);
120 //CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(-1., 0., 0., UB));
121 mode.computeAngles(-1., 0., 0., UB);
122 CPPUNIT_ASSERT_EQUAL(hkl::Value( 130. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
123 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
124 CPPUNIT_ASSERT_EQUAL(hkl::Value(-190. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
125 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
127 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(0., 1., 0., UB));
128 CPPUNIT_ASSERT_EQUAL(hkl::Value(130. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
129 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
130 CPPUNIT_ASSERT_EQUAL(hkl::Value( 80. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
131 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
133 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(0.,-1., 0., UB));
134 CPPUNIT_ASSERT_EQUAL(hkl::Value( 130. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
135 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
136 CPPUNIT_ASSERT_EQUAL(hkl::Value(-100. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
137 CPPUNIT_ASSERT_EQUAL(hkl::Value( 60. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
139 CPPUNIT_ASSERT_NO_THROW(mode.computeAngles(1., 1., 0., UB));
140 CPPUNIT_ASSERT_EQUAL(hkl::Value(145. * hkl::constant::math::degToRad), _geometry->komega()->get_consign());
141 CPPUNIT_ASSERT_EQUAL(hkl::Value( 0. * hkl::constant::math::degToRad), _geometry->kappa()->get_consign());
142 CPPUNIT_ASSERT_EQUAL(hkl::Value( 35. * hkl::constant::math::degToRad), _geometry->kphi()->get_consign());
143 CPPUNIT_ASSERT_EQUAL(hkl::Value( 90. * hkl::constant::math::degToRad), _geometry->tth()->get_consign());
145 CPPUNIT_ASSERT_THROW(mode.computeAngles(0., 0., 1., UB), hkl::HKLException);
147 // random test
148 double h, k, l;
149 for (unsigned int i=0;i<1000;i++)
151 double h0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
152 double k0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
153 double l0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
156 mode.computeAngles(h0, k0, l0, UB);
157 _geometry->compute_HKL_consign(h, k, l, UB);
158 CPPUNIT_ASSERT_DOUBLES_EQUAL(h0, h, hkl::constant::math::epsilon);
159 CPPUNIT_ASSERT_DOUBLES_EQUAL(k0, k, hkl::constant::math::epsilon);
160 CPPUNIT_ASSERT_DOUBLES_EQUAL(l0, l, hkl::constant::math::epsilon);
162 catch (hkl::HKLException) {}
166 void
167 Mode_Kappa4C_Test::Constant_Omega(void)
169 hkl::smatrix UB = _sample->get_UB();
170 hkl::kappa4C::vertical::mode::Constant_Omega mode("test", "test", *_geometry);
171 double h, k, l;
173 for (unsigned int i=0;i<1000;i++)
175 double h0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
176 double k0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
177 double l0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
180 mode.computeAngles(h0, k0, l0, UB);
181 _geometry->compute_HKL_consign(h, k, l, UB);
182 CPPUNIT_ASSERT_DOUBLES_EQUAL(h0, h, hkl::constant::math::epsilon);
183 CPPUNIT_ASSERT_DOUBLES_EQUAL(k0, k, hkl::constant::math::epsilon);
184 CPPUNIT_ASSERT_DOUBLES_EQUAL(l0, l, hkl::constant::math::epsilon);
186 catch (hkl::HKLException) {}
190 void
191 Mode_Kappa4C_Test::Constant_Chi(void)
193 hkl::smatrix UB = _sample->get_UB();
194 hkl::kappa4C::vertical::mode::Constant_Chi mode("test", "test", *_geometry);
195 double h, k, l;
197 for (unsigned int i=0;i<1000;i++)
199 double h0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
200 double k0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
201 double l0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
204 mode.computeAngles(h0, k0, l0, UB);
205 _geometry->compute_HKL_consign(h, k, l, UB);
206 CPPUNIT_ASSERT_DOUBLES_EQUAL(h0, h, hkl::constant::math::epsilon);
207 CPPUNIT_ASSERT_DOUBLES_EQUAL(k0, k, hkl::constant::math::epsilon);
208 CPPUNIT_ASSERT_DOUBLES_EQUAL(l0, l, hkl::constant::math::epsilon);
210 catch (hkl::HKLException) {}
214 void
215 Mode_Kappa4C_Test::Constant_Phi(void)
217 hkl::smatrix UB = _sample->get_UB();
218 hkl::kappa4C::vertical::mode::Constant_Phi mode("test", "test", *_geometry);
219 double h, k, l;
221 for (unsigned int i=0;i<1000;i++)
223 double h0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
224 double k0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
225 double l0 = 4. * rand() / (RAND_MAX + 1.) - 2.;
228 mode.computeAngles(h0, k0, l0, UB);
229 _geometry->compute_HKL_consign(h, k, l, UB);
230 CPPUNIT_ASSERT_DOUBLES_EQUAL(h0, h, hkl::constant::math::epsilon);
231 CPPUNIT_ASSERT_DOUBLES_EQUAL(k0, k, hkl::constant::math::epsilon);
232 CPPUNIT_ASSERT_DOUBLES_EQUAL(l0, l, hkl::constant::math::epsilon);
234 catch (hkl::HKLException) {}
238 void
239 Mode_Kappa4C_Test::persistanceIO(void)
241 hkl::kappa4C::vertical::mode::Bissector bissector_ref("test", "test", *_geometry), bissector("test", "test", *_geometry);
242 hkl::kappa4C::vertical::mode::Delta_Theta delta_theta_ref("test", "test", *_geometry), delta_theta("test", "test", *_geometry);
243 hkl::kappa4C::vertical::mode::Constant_Omega constant_omega_ref("test", "test", *_geometry), constant_omega("test", "test", *_geometry);
244 hkl::kappa4C::vertical::mode::Constant_Chi constant_chi_ref("test", "test", *_geometry), constant_chi("test", "test", *_geometry);
245 hkl::kappa4C::vertical::mode::Constant_Phi constant_phi_ref("test", "test", *_geometry), constant_phi("test", "test", *_geometry);
246 std::stringstream flux;
248 bissector_ref.toStream(flux);
249 delta_theta_ref.toStream(flux);
250 constant_omega_ref.toStream(flux);
251 constant_chi_ref.toStream(flux);
252 constant_phi_ref.toStream(flux);
253 bissector.fromStream(flux);
254 delta_theta.fromStream(flux);
255 constant_omega.fromStream(flux);
256 constant_chi.fromStream(flux);
257 constant_phi.fromStream(flux);
259 CPPUNIT_ASSERT_EQUAL(bissector_ref, bissector);
260 CPPUNIT_ASSERT_EQUAL(delta_theta_ref, delta_theta);
261 CPPUNIT_ASSERT_EQUAL(constant_omega_ref, constant_omega);
262 CPPUNIT_ASSERT_EQUAL(constant_chi_ref, constant_chi);
263 CPPUNIT_ASSERT_EQUAL(constant_phi_ref, constant_phi);