1 // File to test quaternion implementation.
2 #include "diffractometer_test.h"
4 CPPUNIT_TEST_SUITE_REGISTRATION( diffractometerTest
);
7 diffractometerTest::setUp()
9 m_epsilon
= mathematicalConstants::getEpsilon0();
10 m_degToRad
= mathematicalConstants::convertAnglesToRadians();
14 diffractometerTest::tearDown()
18 diffractometerTest::GetSetAxe()
20 Diffractometer
*d
= new Diffractometer_Eulerian4C();
22 CPPUNIT_ASSERT_THROW(d
->setAxeAngle("nu", 0.), HKLException
);
23 CPPUNIT_ASSERT_THROW(d
->getAxeAngle("nu"), HKLException
);
25 CPPUNIT_ASSERT_NO_THROW(d
->getAxeAngle("2theta"));
26 CPPUNIT_ASSERT_NO_THROW(d
->getAxeAngle("omega"));
27 CPPUNIT_ASSERT_NO_THROW(d
->getAxeAngle("chi"));
28 CPPUNIT_ASSERT_NO_THROW(d
->getAxeAngle("phi"));
30 CPPUNIT_ASSERT_NO_THROW(d
->setAxeAngle("2theta", 1.));
31 CPPUNIT_ASSERT_NO_THROW(d
->setAxeAngle("omega", 1.));
32 CPPUNIT_ASSERT_NO_THROW(d
->setAxeAngle("chi", 1.));
33 CPPUNIT_ASSERT_NO_THROW(d
->setAxeAngle("phi", 1.));
35 CPPUNIT_ASSERT_EQUAL(1., d
->getAxeAngle("2theta"));
36 CPPUNIT_ASSERT_EQUAL(1., d
->getAxeAngle("omega"));
37 CPPUNIT_ASSERT_EQUAL(1., d
->getAxeAngle("chi"));
38 CPPUNIT_ASSERT_EQUAL(1., d
->getAxeAngle("phi"));
44 diffractometerTest::CrystalPart()
46 Diffractometer
*d
= new Diffractometer_Eulerian4C();
48 CPPUNIT_ASSERT_THROW(d
->setCurrentCrystal("toto"),HKLException
);
49 CPPUNIT_ASSERT_NO_THROW(d
->addNewCrystal("crystal1"));
50 CPPUNIT_ASSERT_NO_THROW(d
->setCurrentCrystal("crystal1"));
51 CPPUNIT_ASSERT_THROW(d
->addNewCrystal("crystal1"), HKLException
);
53 CPPUNIT_ASSERT_THROW(d
->copyCrystalAsNew("toto", "crystal2"), HKLException
);
54 CPPUNIT_ASSERT_THROW(d
->copyCrystalAsNew("crystal1", "crystal1"), HKLException
);
55 CPPUNIT_ASSERT_NO_THROW(d
->copyCrystalAsNew("crystal1", "crystal2"));
56 CPPUNIT_ASSERT_NO_THROW(d
->setCurrentCrystal("crystal2"));
58 CPPUNIT_ASSERT_THROW(d
->delCrystal("toto"), HKLException
);
59 CPPUNIT_ASSERT_NO_THROW(d
->delCrystal("crystal1"));
65 diffractometerTest::GetSetLattice()
67 Diffractometer
*d
= new Diffractometer_Eulerian4C();
69 // je suis obligé de les initialiser sinon valgrind proteste lors
70 // de l'appel du premier setLattice
78 d
->addNewCrystal("crystal");
80 CPPUNIT_ASSERT_THROW(d
->getCrystalLattice("toto", &a
, &b
, &c
, &alpha
, &beta
, &gamma
), HKLException
);
81 CPPUNIT_ASSERT_THROW(d
->setCrystalLattice("toto", a
, b
, c
, alpha
, beta
, gamma
), HKLException
);
83 CPPUNIT_ASSERT_NO_THROW(d
->getCrystalLattice("crystal", &a
, &b
, &c
, &alpha
, &beta
, &gamma
));
84 CPPUNIT_ASSERT_NO_THROW(d
->setCrystalLattice("crystal", a
, b
, c
, alpha
, beta
, gamma
));
86 d
->setCrystalLattice("crystal", 1., 2., 3., 2., 1., 2.);
87 d
->getCrystalLattice("crystal", &a
, &b
, &c
, &alpha
, &beta
, &gamma
);
89 CPPUNIT_ASSERT_DOUBLES_EQUAL(1., a
, m_epsilon
);
90 CPPUNIT_ASSERT_DOUBLES_EQUAL(2., b
, m_epsilon
);
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(3., c
, m_epsilon
);
92 CPPUNIT_ASSERT_DOUBLES_EQUAL(2., alpha
, m_epsilon
);
93 CPPUNIT_ASSERT_DOUBLES_EQUAL(1., beta
, m_epsilon
);
94 CPPUNIT_ASSERT_DOUBLES_EQUAL(2., gamma
, m_epsilon
);
100 diffractometerTest::GetReciprocalLattice()
102 Diffractometer
*d
= new Diffractometer_Eulerian4C();
103 double a
, b
, c
, alpha
, beta
, gamma
;
105 d
->addNewCrystal("crystal");
107 CPPUNIT_ASSERT_THROW(d
->getCrystalReciprocalLattice("toto", &a
, &b
, &c
, &alpha
, &beta
, &gamma
), HKLException
);
109 CPPUNIT_ASSERT_NO_THROW(d
->getCrystalReciprocalLattice("crystal", &a
, &b
, &c
, &alpha
, &beta
, &gamma
));
111 d
->setCrystalLattice("crystal", 1., 2., 3., 90. * m_degToRad
, 90. * m_degToRad
, 90. * m_degToRad
);
112 d
->getCrystalReciprocalLattice("crystal", &a
, &b
, &c
, &alpha
, &beta
, &gamma
);
114 CPPUNIT_ASSERT_DOUBLES_EQUAL(1., a
, m_epsilon
);
115 CPPUNIT_ASSERT_DOUBLES_EQUAL(.5, b
, m_epsilon
);
116 CPPUNIT_ASSERT_DOUBLES_EQUAL(1./3., c
, m_epsilon
);
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(90. * m_degToRad
, alpha
, m_epsilon
);
118 CPPUNIT_ASSERT_DOUBLES_EQUAL(90. * m_degToRad
, beta
, m_epsilon
);
119 CPPUNIT_ASSERT_DOUBLES_EQUAL(90. * m_degToRad
, gamma
, m_epsilon
);
126 diffractometerTest::AddReflection()
128 Diffractometer
*d
= new Diffractometer_Eulerian4C();
130 d
->addNewCrystal("crystal");
132 CPPUNIT_ASSERT_THROW(d
->addCrystalReflection("toto", 0, 0, 1, Reflection::Best
, true), HKLException
);
133 CPPUNIT_ASSERT_NO_THROW(d
->addCrystalReflection("crystal", 0, 0, 1, Reflection::Best
, true));
139 diffractometerTest::DelReflection()
141 Diffractometer
*d
= new Diffractometer_Eulerian4C();
143 d
->addNewCrystal("crystal");
145 CPPUNIT_ASSERT_THROW(d
->delCrystalReflection("toto", 0), HKLException
);
147 d
->addCrystalReflection("crystal", 0, 0, 1, Reflection::Best
, true);
148 d
->addCrystalReflection("crystal", 0, 0, 1, Reflection::Best
, true);
150 CPPUNIT_ASSERT_NO_THROW(d
->delCrystalReflection("crystal", 1));
151 CPPUNIT_ASSERT_THROW(d
->delCrystalReflection("crystal", 1), HKLException
);
152 CPPUNIT_ASSERT_NO_THROW(d
->delCrystalReflection("crystal", 0));
153 CPPUNIT_ASSERT_THROW(d
->delCrystalReflection("crystal", 0), HKLException
);
160 diffractometerTest::GetReflection()
162 Diffractometer *d = new Diffractometer_Eulerian4C();
164 d->addNewCrystal("crystal");
165 d->setCrystal("crystal");
167 CPPUNIT_ASSERT_THROW(d->getReflection(0), HKLException);
168 CPPUNIT_ASSERT_THROW(d->getCrystalReflection("toto", 0), HKLException);
170 d->addReflection(0, 0, 1, Reflection::Best, true);
172 CPPUNIT_ASSERT_NO_THROW(d->getReflection(0));
173 CPPUNIT_ASSERT_NO_THROW(d->getCrystalReflection("crystal", 0));
180 diffractometerTest::ModePart()
182 Diffractometer
*d
= new Diffractometer_Eulerian4C();
184 CPPUNIT_ASSERT_NO_THROW(d
->setCurrentMode("Bissector"));
185 CPPUNIT_ASSERT_NO_THROW(d
->setCurrentMode("Delta Theta"));
186 CPPUNIT_ASSERT_NO_THROW(d
->setCurrentMode("Constant Omega"));
187 CPPUNIT_ASSERT_THROW(d
->setCurrentMode("toto"), HKLException
);
189 CPPUNIT_ASSERT_THROW(d
->setModeParameterValue("Bissector", "titi", 10.), HKLException
);
191 CPPUNIT_ASSERT_THROW(d
->getModeParameterValue("Constant Omega", "titi"), HKLException
);
192 CPPUNIT_ASSERT_NO_THROW(d
->setModeParameterValue("Constant Omega", "omega", 5.));
193 CPPUNIT_ASSERT_NO_THROW(d
->getModeParameterValue("Constant Omega", "omega"));
194 CPPUNIT_ASSERT_EQUAL(5., d
->getModeParameterValue("Constant Omega", "omega"));
201 diffractometerTest::ComputeU()
203 Diffractometer *d = new Diffractometer_Eulerian4C();
204 d->setWaveLength(1.54);
205 //d->setIncidentBeamDirection(1., 0., 0.);
207 d->addNewCrystal("crystal1");
208 d->setCurrentCrystal("crystal1");
210 CPPUNIT_ASSERT_THROW(d->computeU(), HKLException);
211 d->setCrystalLattice("crystal1",
213 90.*m_degToRad, 90.*m_degToRad, 90.*m_degToRad );
216 CPPUNIT_ASSERT_THROW(d->computeU(), HKLException);
218 d->setAxeAngle("2theta", 60.*m_degToRad);
219 d->setAxeAngle("omega", 30.*m_degToRad);
220 d->setAxeAngle("chi", 0.);
221 d->setAxeAngle("phi", 90.*m_degToRad);
222 d->addCrystalReflection("crystal1", 1., 0., 0., Reflection::Best, true);
224 CPPUNIT_ASSERT_THROW(d->computeU(), HKLException);
226 d->setAxeAngle("phi", 180.*m_degToRad);
227 d->addCrystalReflection("crystal1", 0., 1., 0., Reflection::Best, true);
229 CPPUNIT_ASSERT_NO_THROW(d->computeU());
231 smatrix M(1., 0., 0.,
235 CPPUNIT_ASSERT_EQUAL(M, d->getCurrentCrystal().get_U());
242 diffractometerTest::ComputeHKL()
244 Diffractometer
*d
= new Diffractometer_Eulerian4C();
247 d
->setWaveLength(1.54);
248 //d->setIncidentBeamDirection(1., 0., 0.);
250 d
->addNewCrystal("crystal1");
251 d
->setCurrentCrystal("crystal1");
252 d
->setCrystalLattice("crystal1", 1.54, 1.54, 1.54,
253 90.*m_degToRad
, 90.*m_degToRad
, 90.*m_degToRad
);
255 d
->setAxeAngle("2theta", 60.*m_degToRad
);
256 d
->setAxeAngle("omega", 30.*m_degToRad
);
257 d
->setAxeAngle("chi", 0.);
258 d
->setAxeAngle("phi", 90.*m_degToRad
);
259 d
->addCrystalReflection("crystal1", 1., 0., 0., Reflection::Best
, true);
261 d
->setAxeAngle("phi", 180.*m_degToRad
);
262 d
->addCrystalReflection("crystal1", 0., 1., 0., Reflection::Best
, true);
265 d
->computeHKL(&h
, &k
, &l
);
266 CPPUNIT_ASSERT_DOUBLES_EQUAL(0., h
, m_epsilon
);
267 CPPUNIT_ASSERT_DOUBLES_EQUAL(1., k
, m_epsilon
);
268 CPPUNIT_ASSERT_DOUBLES_EQUAL(0., l
, m_epsilon
);
270 d
->setAxeAngle("phi", 90.*m_degToRad
);
271 d
->computeHKL(&h
, &k
, &l
);
272 CPPUNIT_ASSERT_DOUBLES_EQUAL(1., h
, m_epsilon
);
273 CPPUNIT_ASSERT_DOUBLES_EQUAL(0., k
, m_epsilon
);
274 CPPUNIT_ASSERT_DOUBLES_EQUAL(0., l
, m_epsilon
);
276 d
->setAxeAngle("2theta", 180.*m_degToRad
);
277 d
->setAxeAngle("omega", 90.*m_degToRad
);
278 d
->computeHKL(&h
, &k
, &l
);
279 CPPUNIT_ASSERT_DOUBLES_EQUAL(2., h
, m_epsilon
);
280 CPPUNIT_ASSERT_DOUBLES_EQUAL(0., k
, m_epsilon
);
281 CPPUNIT_ASSERT_DOUBLES_EQUAL(0., l
, m_epsilon
);
287 diffractometerTest::ComputeAngles()
289 Diffractometer
*d
= new Diffractometer_Eulerian4C();
291 CPPUNIT_ASSERT_THROW(d
->computeAngles(1., 1., 1.), HKLException
);
293 d
->setCurrentMode("Bissector");
294 CPPUNIT_ASSERT_THROW(d
->computeAngles(1., 1., 1.), HKLException
);
296 d
->setWaveLength(1.);
297 //d->setIncidentBeamDirection(1., 0., 0.);
298 CPPUNIT_ASSERT_THROW(d
->computeAngles(1., 1., 1.), HKLException
);
299 CPPUNIT_ASSERT_THROW(d
->computeAngles(0., 0., 0.), HKLException
);
301 d
->addNewCrystal("crystal1");
302 d
->setCurrentCrystal("crystal1");
303 CPPUNIT_ASSERT_THROW(d
->computeAngles(1., 1., 1.), HKLException
);
305 d
->setCrystalLattice("crystal1", 1., 1., 1.,
306 90.*m_degToRad
, 90.*m_degToRad
, 90.*m_degToRad
);
308 d
->setAxeAngle("2theta", 60.*m_degToRad
);
309 d
->setAxeAngle("omega", 30.*m_degToRad
);
310 d
->setAxeAngle("chi", 0.);
311 d
->setAxeAngle("phi", 90.*m_degToRad
);
312 d
->addCrystalReflection("crystal1", 1., 0., 0., Reflection::Best
, true);
314 d
->setAxeAngle("phi", 180.*m_degToRad
);
315 d
->addCrystalReflection("crystal1", 0., 1., 0., Reflection::Best
, true);
318 CPPUNIT_ASSERT_NO_THROW(d
->computeAngles(1., 0., 0.));
320 CPPUNIT_ASSERT_DOUBLES_EQUAL(60*m_degToRad
, d
->getAxeAngle("2theta"), m_epsilon
);
321 CPPUNIT_ASSERT_DOUBLES_EQUAL(30*m_degToRad
, d
->getAxeAngle("omega"), m_epsilon
);
322 CPPUNIT_ASSERT_DOUBLES_EQUAL(0, d
->getAxeAngle("chi"), m_epsilon
);
323 CPPUNIT_ASSERT_DOUBLES_EQUAL(90*m_degToRad
, d
->getAxeAngle("phi"), m_epsilon
);
329 diffractometerTest::LPS()
331 Diffractometer
*d
= new Diffractometer_Eulerian4C();
333 d
->setCurrentMode("Bissector");
335 d
->setWaveLength(1.542);
336 //d->setIncidentBeamDirection(1., 0., 0.);
338 d
->addNewCrystal("orthorombique");
339 d
->setCurrentCrystal("orthorombique");
341 d
->setCrystalLattice("orthorombique",
343 90.*m_degToRad
, 90.*m_degToRad
, 90.*m_degToRad
);
345 d
->setAxeAngle("2theta", 30.391991*m_degToRad
);
346 d
->setAxeAngle("omega", 15.195995*m_degToRad
);
347 d
->setAxeAngle("chi", 90.*m_degToRad
);
348 d
->setAxeAngle("phi", 0.*m_degToRad
);
349 d
->addCrystalReflection("orthorombique", 0., 0., 1., Reflection::Best
, true);
351 d
->setAxeAngle("2theta", 10.445403*m_degToRad
);
352 d
->setAxeAngle("omega", 5.2227013*m_degToRad
);
353 d
->setAxeAngle("chi", 0.*m_degToRad
);
354 d
->setAxeAngle("phi", 0.*m_degToRad
);
355 d
->addCrystalReflection("orthorombique", 0., 1., 0., Reflection::Best
, true);
358 CPPUNIT_ASSERT_NO_THROW(d
->computeAngles(0., 1., 0.));
360 CPPUNIT_ASSERT_DOUBLES_EQUAL(10.445403*m_degToRad
, d
->getAxeAngle("2theta"), m_epsilon
);
361 CPPUNIT_ASSERT_DOUBLES_EQUAL(5.2227013*m_degToRad
, d
->getAxeAngle("omega"), m_epsilon
);
362 CPPUNIT_ASSERT_DOUBLES_EQUAL(0*m_degToRad
, d
->getAxeAngle("chi"), m_epsilon
);
363 CPPUNIT_ASSERT_DOUBLES_EQUAL(0*m_degToRad
, d
->getAxeAngle("phi"), m_epsilon
);