From 3ee6e5ad168f192ff356dcfb42a6f94d15b36cfd Mon Sep 17 00:00:00 2001 From: Janik Zikovsky <zikovskyjl@ornl.gov> Date: Mon, 28 Nov 2011 13:38:06 -0500 Subject: [PATCH] Refs #3991: hklFromQ fixed. Made RecalculateFromGstar private in OL --- .../MantidGeometry/Crystal/OrientedLattice.h | 7 ++++ .../inc/MantidGeometry/Crystal/UnitCell.h | 3 +- .../Geometry/src/Crystal/OrientedLattice.cpp | 14 +++++++ .../Geometry/src/Crystal/UnitCell.cpp | 10 ----- .../Geometry/test/OrientedLatticeTest.h | 39 ++++--------------- .../Framework/Geometry/test/UnitCellTest.h | 5 --- 6 files changed, 30 insertions(+), 48 deletions(-) diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h index 92d21822592..868ce473d14 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/OrientedLattice.h @@ -58,6 +58,8 @@ namespace Geometry Kernel::V3D getuVector(); Kernel::V3D getvVector(); + Mantid::Kernel::V3D hklFromQ(Mantid::Kernel::V3D Q) const; + Kernel::DblMatrix setUFromVectors(const Kernel::V3D &u, const Kernel::V3D &v); void saveNexus(::NeXus::File * file, const std::string & group) const; @@ -66,6 +68,11 @@ namespace Geometry private: Kernel::DblMatrix U; Kernel::DblMatrix UB; + + /** Make recalculateFromGstar private. */ + void recalculateFromGstar(Kernel::DblMatrix& NewGstar) + { UnitCell::recalculateFromGstar(NewGstar); } + }; } // namespace Mantid } // namespace Geometry diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h index a95e7328ebe..108c0f376c9 100644 --- a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/UnitCell.h @@ -121,11 +121,10 @@ namespace Geometry double dstar(double h,double k, double l) const; double d(const Kernel::V3D & hkl) const; double dstar(const Kernel::V3D & hkl) const; - Kernel::V3D hklFromQ(Kernel::V3D Q) const; double recAngle(double h1, double k1, double l1, double h2, double k2, double l2, const int angleunit=angDegrees) const; double volume()const; double recVolume() const; - void recalculateFromGstar(Kernel::Matrix<double>& NewGstar); + virtual void recalculateFromGstar(Kernel::Matrix<double>& NewGstar); private: /// Lattice parameter a,b,c,alpha,beta,gamma (in \f$ \mbox{ \AA } \f$ and radians) diff --git a/Code/Mantid/Framework/Geometry/src/Crystal/OrientedLattice.cpp b/Code/Mantid/Framework/Geometry/src/Crystal/OrientedLattice.cpp index ba8e9a1ce7b..cba32990207 100644 --- a/Code/Mantid/Framework/Geometry/src/Crystal/OrientedLattice.cpp +++ b/Code/Mantid/Framework/Geometry/src/Crystal/OrientedLattice.cpp @@ -123,6 +123,20 @@ namespace Geometry else throw std::invalid_argument("determinant of UB is not greater than 0"); } + + /** Calculate the hkl corresponding to a given Q-vector + * @param Q :: Q-vector in $AA^-1 in the sample frame + * @return a V3D with H,K,L + */ + V3D OrientedLattice::hklFromQ(V3D Q) const + { + DblMatrix UBinv = this->getUB(); + UBinv.Invert(); + V3D out = UBinv*Q; //transform back to HKL + return out; + } + + /** gets a vector along beam direction when goniometers are at 0. Note, this vector is not unique, but all vectors can be obtaineb by multiplying with a scalar @return u :: V3D vector along beam direction*/ diff --git a/Code/Mantid/Framework/Geometry/src/Crystal/UnitCell.cpp b/Code/Mantid/Framework/Geometry/src/Crystal/UnitCell.cpp index 9fc4065b0fe..a413fa5df0d 100644 --- a/Code/Mantid/Framework/Geometry/src/Crystal/UnitCell.cpp +++ b/Code/Mantid/Framework/Geometry/src/Crystal/UnitCell.cpp @@ -370,16 +370,6 @@ namespace Geometry } - /** Calculate the hkl corresponding to a given Q-vector - * @param Q :: Q-vector in $AA^-1 in the sample frame - * @return a V3D with H,K,L - */ - V3D UnitCell::hklFromQ(V3D Q) const - { - V3D out = Binv*Q; //transform back to HKL - return out; - } - /// Calculate the angle in degrees or radians between two reciprocal vectors (h1,k1,l1) and (h2,k2,l2) double UnitCell::recAngle(double h1, double k1, double l1, double h2, double k2, double l2, const int angleunit) const { diff --git a/Code/Mantid/Framework/Geometry/test/OrientedLatticeTest.h b/Code/Mantid/Framework/Geometry/test/OrientedLatticeTest.h index 96ef2d31f05..46500402fa9 100644 --- a/Code/Mantid/Framework/Geometry/test/OrientedLatticeTest.h +++ b/Code/Mantid/Framework/Geometry/test/OrientedLatticeTest.h @@ -33,39 +33,16 @@ public: TS_ASSERT_DELTA(u2.a(),3,1e-10); } - /// test more advanced calculations - /// the new Gstar shold yield a=2.5, b=6, c=8, alpha=93, beta=88, gamma=97. - void test_Advanced() + void test_hklFromQ() { - DblMatrix newGstar(3,3); - newGstar[0][0]=0.162546756312; - newGstar[0][1]=0.00815256992072; - newGstar[0][2]=-0.00145274558861; - newGstar[1][0]=newGstar[0][1]; - newGstar[1][1]=0.028262965555; - newGstar[1][2]=0.00102046431298; - newGstar[2][0]=newGstar[0][2]; - newGstar[2][1]=newGstar[1][2]; - newGstar[2][2]=0.0156808990098; - OrientedLattice u; - u.recalculateFromGstar(newGstar); - TS_ASSERT_DELTA(u.a(),2.5,1e-10); - TS_ASSERT_DELTA(u.b(),6,1e-10); - TS_ASSERT_DELTA(u.c(),8,1e-10); - TS_ASSERT_DELTA(u.alpha(),93,1e-10); - TS_ASSERT_DELTA(u.beta(),88,1e-10); - TS_ASSERT_DELTA(u.gamma(),97,1e-10); - - // get the some elements of the B matrix - TS_ASSERT_DELTA(u.getB()[0][0],0.403170877311,1e-10); - TS_ASSERT_DELTA(u.getB()[2][0],0.0,1e-10); - TS_ASSERT_DELTA(u.getB()[0][2],-0.00360329991666,1e-10); - TS_ASSERT_DELTA(u.getB()[2][2],0.125,1e-10); - // d spacing for direct lattice at (1,1,1) (will automatically check dstar) - TS_ASSERT_DELTA(u.d(1.,1.,1.),2.1227107587,1e-10); - // angle - TS_ASSERT_DELTA(u.recAngle(1,1,1,1,0,0,angRadians),0.471054990614,1e-10); + DblMatrix UB(3,3,true); + u.setUB(UB); + + // Convert to and from HKL + V3D hkl = u.hklFromQ(V3D(1.0, 2.0, 3.0)); + double dstar = u.dstar(hkl[0], hkl[1], hkl[2]); + TS_ASSERT_DELTA( dstar, sqrt(1+4.0+9.0), 1e-4); // The d-spacing after a round trip matches the Q we put in } diff --git a/Code/Mantid/Framework/Geometry/test/UnitCellTest.h b/Code/Mantid/Framework/Geometry/test/UnitCellTest.h index 638cd5cfdad..abf18556124 100644 --- a/Code/Mantid/Framework/Geometry/test/UnitCellTest.h +++ b/Code/Mantid/Framework/Geometry/test/UnitCellTest.h @@ -63,11 +63,6 @@ public: TS_ASSERT_DELTA(u.d(V3D(1.,1.,1.)),2.1227107587,1e-10); // angle TS_ASSERT_DELTA(u.recAngle(1,1,1,1,0,0,angRadians),0.471054990614,1e-10); - - // Convert to and from HKL - V3D hkl = u.hklFromQ(V3D(1.0, 2.0, 3.0)); - double dstar = u.dstar(hkl[0], hkl[1], hkl[2]); - TS_ASSERT_DELTA( dstar, sqrt(1+4.0+9.0), 1e-4); // The d-spacing after a round trip matches the Q we put in } void test_Advanced() -- GitLab