Documentation is the directory of the documentation
[hkl.git] / test / affinement_simplex_test.cpp
blob51a1e1e328bc532d3ff47e5bc0a36e7cbc1b0abf
1 #include "affinement_simplex_test.h"
2 #include "sample_monocrystal.h"
3 #include "reflectionlist.h"
5 CPPUNIT_TEST_SUITE_REGISTRATION( Affinement_SimplexTest );
7 void
8 Affinement_SimplexTest::setUp(void)
10 // initialisation de la source
11 _geometry = new hkl::eulerian4C::vertical::Geometry;
12 _geometry->get_source().setWaveLength(1.54);
14 // initialisation du sample
15 _sample = hkl::SampleFactory(*_geometry).create("test", hkl::SAMPLE_MONOCRYSTAL);
16 hkl::Lattice & lattice = _sample->lattice();
17 lattice.a().set_current(1.);
18 lattice.b().set_current(5.);
19 lattice.c().set_current(4.);
20 lattice.alpha().set_current(90 * hkl::constant::math::degToRad);
21 lattice.beta().set_current(90 * hkl::constant::math::degToRad);
22 lattice.gamma().set_current(90 * hkl::constant::math::degToRad);
24 // Reflection 1
25 _geometry->get_axe("tth")->set_current(60.*hkl::constant::math::degToRad);
26 _geometry->get_axe("omega")->set_current(30.*hkl::constant::math::degToRad);
27 _geometry->get_axe("chi")->set_current(0.*hkl::constant::math::degToRad);
28 _geometry->get_axe("phi")->set_current(90.*hkl::constant::math::degToRad);
29 _sample->reflections().add(hkl::svector(1., 0., 0.));
31 // Reflection 2
32 _geometry->get_axe("tth")->set_current(60*hkl::constant::math::degToRad);
33 _geometry->get_axe("omega")->set_current(30.*hkl::constant::math::degToRad);
34 _geometry->get_axe("chi")->set_current(90.*hkl::constant::math::degToRad);
35 _geometry->get_axe("phi")->set_current(0.*hkl::constant::math::degToRad);
36 _sample->reflections().add(hkl::svector(0., 1., 0.));
38 // Reflection 3
39 _geometry->get_axe("tth")->set_current(60.*hkl::constant::math::degToRad);
40 _geometry->get_axe("omega")->set_current(30.*hkl::constant::math::degToRad);
41 _geometry->get_axe("chi")->set_current(0.*hkl::constant::math::degToRad);
42 _geometry->get_axe("phi")->set_current(0.*hkl::constant::math::degToRad);
43 _sample->reflections().add(hkl::svector(0., 0., 1.));
45 // Reflection 4
46 _geometry->get_axe("tth")->set_current(60.*hkl::constant::math::degToRad);
47 _geometry->get_axe("omega")->set_current(60.*hkl::constant::math::degToRad);
48 _geometry->get_axe("chi")->set_current(60.*hkl::constant::math::degToRad);
49 _geometry->get_axe("phi")->set_current(60.*hkl::constant::math::degToRad);
50 _sample->reflections().add(hkl::svector(0.625, 0.75, -0.216506350946));
52 // Reflection 5
53 _geometry->get_axe("tth")->set_current(60.*hkl::constant::math::degToRad);
54 _geometry->get_axe("omega")->set_current(45.*hkl::constant::math::degToRad);
55 _geometry->get_axe("chi")->set_current(45.*hkl::constant::math::degToRad);
56 _geometry->get_axe("phi")->set_current(45.*hkl::constant::math::degToRad);
57 _sample->reflections().add(hkl::svector(0.665975615037, 0.683012701892, 0.299950211252));
60 void
61 Affinement_SimplexTest::tearDown(void)
63 delete _sample;
64 delete _geometry;
67 void
68 Affinement_SimplexTest::Fit(void)
70 hkl::smatrix U_ref(1., 0., 0.,
71 0., 1., 0.,
72 0., 0., 1.);
74 for (unsigned int i=0;i<30;i++)
76 CPPUNIT_ASSERT_NO_THROW(_simplex.set_nb_max_iterations(800));
77 CPPUNIT_ASSERT_NO_THROW(_simplex.fit(*_sample));
78 CPPUNIT_ASSERT_NO_THROW(_simplex.fit(*_sample));
79 CPPUNIT_ASSERT_NO_THROW(_simplex.fit(*_sample));
80 CPPUNIT_ASSERT_NO_THROW(_simplex.set_nb_max_iterations(2500));
81 CPPUNIT_ASSERT_NO_THROW(_simplex.fit(*_sample));
84 hkl::Lattice lattice_ref = hkl::Lattice(1.54, 1.54, 1.54,
85 90 * hkl::constant::math::degToRad,
86 90 * hkl::constant::math::degToRad,
87 90 * hkl::constant::math::degToRad);
88 CPPUNIT_ASSERT_EQUAL(U_ref, dynamic_cast<hkl::sample::MonoCrystal *>(_sample)->get_U());
89 CPPUNIT_ASSERT_EQUAL(lattice_ref, _sample->lattice());
92 void
93 Affinement_SimplexTest::Fit2(void)
97 // initialisation de la source
98 _geometry->get_source().setWaveLength(1.5418);
100 //crystal.setLattice(4.81, 8.47, 2.941, 90.*hkl::constant::math::degToRad, 90.*hkl::constant::math::degToRad, 90. * hkl::constant::math::degToRad);
101 crystal.setLattice(1, 1, 5, 60.*hkl::constant::math::degToRad, 80.*hkl::constant::math::degToRad, 100. * hkl::constant::math::degToRad);
103 //crystal["a"].set_flagFit(false);
104 //crystal["b"].set_flagFit(false);
105 //crystal["c"].set_flagFit(false);
106 //crystal["alpha"].set_flagFit(false);
107 //crystal["beta"].set_flagFit(false);
108 //crystal["gamma"].set_flagFit(false);
110 // Reflection 1
111 _geometry->get_axe("tth").set_value(30.398*hkl::constant::math::degToRad);
112 _geometry->get_axe("omega").set_value(11.709*hkl::constant::math::degToRad);
113 _geometry->get_axe("chi").set_value(87.607*hkl::constant::math::degToRad);
114 _geometry->get_axe("phi").set_value(0.265*hkl::constant::math::degToRad);
115 crystal.addReflection(Reflection<geometry::eulerian4C::Vertical>(_geometry, 0., 0., 1., 0, true));
117 // Reflection 2
118 _geometry->get_axe("tth").set_value(21.001*hkl::constant::math::degToRad);
119 _geometry->get_axe("omega").set_value(10.322*hkl::constant::math::degToRad);
120 _geometry->get_axe("chi").set_value(-2.139*hkl::constant::math::degToRad);
121 _geometry->get_axe("phi").set_value(0.023*hkl::constant::math::degToRad);
122 crystal.addReflection(Reflection<geometry::eulerian4C::Vertical>(_geometry, 0., 2., 0., 0, true));
124 // Reflection 3
125 _geometry->get_axe("tth").set_value(54.046*hkl::constant::math::degToRad);
126 _geometry->get_axe("omega").set_value(26.872*hkl::constant::math::degToRad);
127 _geometry->get_axe("chi").set_value(34.938*hkl::constant::math::degToRad);
128 _geometry->get_axe("phi").set_value(57.295*hkl::constant::math::degToRad);
129 crystal.addReflection(Reflection<geometry::eulerian4C::Vertical>(_geometry, -2, 2., 1., 0, true));
131 // Reflection 4
132 _geometry->get_axe("tth").set_value(37.333*hkl::constant::math::degToRad);
133 _geometry->get_axe("omega").set_value(18.51*hkl::constant::math::degToRad);
134 _geometry->get_axe("chi").set_value(53.966*hkl::constant::math::degToRad);
135 _geometry->get_axe("phi").set_value(54.505*hkl::constant::math::degToRad);
136 crystal.addReflection(Reflection<geometry::eulerian4C::Vertical>(_geometry, -1, 1., 1., 0, true));
138 _simplex.set_nb_max_iterations(5000);
139 Crystal<geometry::eulerian4C::Vertical> crystal1(crystal);
140 _simplex.fit(crystal);
141 _simplex.fit(crystal);
142 _simplex.fit(crystal);
143 _simplex.set_nb_max_iterations(15000);
144 _simplex.fit(crystal);
145 //std::cout << crystal1;
146 //std::cout << crystal;
147 //std::cout << crystal.get_U()*crystal.get_B();
151 void
152 Affinement_SimplexTest::persistanceIO(void)
154 hkl::affinement::Simplex simplex_ref, simplex;
155 hkl::affinement::Simplex simplex1_ref, simplex1;
156 stringstream flux;
158 // Modification of the default parameters to be sure
159 // that serialization is ok.
160 simplex_ref.set_nb_max_iterations(1500);
162 simplex_ref.toStream(flux);
163 simplex1_ref.toStream(flux);
164 simplex.fromStream(flux);
165 simplex1.fromStream(flux);
167 CPPUNIT_ASSERT_EQUAL(simplex_ref, simplex);
168 CPPUNIT_ASSERT_EQUAL(simplex1_ref, simplex1);