Mantid
Loading...
Searching...
No Matches
UnitCell.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
10#include "MantidGeometry/DllConfig.h"
11#include "MantidKernel/Matrix.h"
13#include "MantidKernel/Quat.h"
14#include "MantidKernel/V3D.h"
15#include <cmath>
16#include <iosfwd>
17#include <vector>
18
19namespace Mantid {
20namespace Geometry {
44class MANTID_GEOMETRY_DLL UnitCell {
45public:
46 // Default constructor. a = b = c = 1, alpha = beta = gamma = 90 degrees
47 UnitCell();
48 // a,b,c constructor
49 UnitCell(const double _a, const double _b, const double _c);
50 // a,b,c,alpha,beta,gamma constructor
51 UnitCell(const double _a, const double _b, const double _c, const double _alpha, const double _beta,
52 const double _gamma, const int angleunit = angDegrees);
53 // Destructor
54 virtual ~UnitCell() = default;
55
56 // Get and set lattice parameters
57 // Direct lattice parameters, angle in radians.
58 double a1() const;
59 double a2() const;
60 double a3() const;
61 double alpha1() const;
62 double alpha2() const;
63 double alpha3() const;
64 // Direct lattice parameters, angle in degrees.
65 double a(int nd) const; // get lattice parameter as function of index (0-2)
66 double a() const;
67 double b() const;
68 double c() const;
69 double alpha() const;
70 double beta() const;
71 double gamma() const;
72 // Reciprocal lattice parameters, angle in radians.
73 double b1() const;
74 double b2() const;
75 double b3() const;
76 double beta1() const;
77 double beta2() const;
78 double beta3() const;
79 // Reciprocal lattice parameters, angle in degrees.
80 double astar() const;
81 double bstar() const;
82 double cstar() const;
83 double alphastar() const;
84 double betastar() const;
85 double gammastar() const;
86 // Set lattice
87 void setModHKL(double _dh1, double _dk1, double _dl1, double _dh2, double _dk2, double _dl2, double _dh3, double _dk3,
88 double _dl3);
89 void setModHKL(const Kernel::DblMatrix &newModHKL);
90 void setErrorModHKL(const Kernel::DblMatrix &newErrorModHKL);
91 void setErrorModHKL(double _dh1err, double _dk1err, double _dl1err, double _dh2err, double _dk2err, double _dl2err,
92 double _dh3err, double _dk3err, double _dl3err);
93 void setModVec1(double _dh1, double _dk1, double _dl1);
94 void setModVec2(double _dh2, double _dk2, double _dl2);
95 void setModVec3(double _dh3, double _dk3, double _dl3);
96 void setModVec1(const Kernel::V3D &newModVec);
97 void setModVec2(const Kernel::V3D &newModVec);
98 void setModVec3(const Kernel::V3D &newModVec);
99 void setModerr(int i, double _dherr, double _dkerr, double _dlerr);
100 void setModerr1(double _dh1err, double _dk1err, double _dl1err);
101 void setModerr2(double _dh2err, double _dk2err, double _dl2err);
102 void setModerr3(double _dh3err, double _dk3err, double _dl3err);
103 void setMaxOrder(int MaxO);
104 void setCrossTerm(bool CT);
105
106 const Kernel::V3D getModVec(int j) const;
107 const Kernel::V3D getVecErr(int j) const;
108 const Kernel::DblMatrix &getModHKL() const;
109 double getdh(int j) const;
110 double getdk(int j) const;
111 double getdl(int j) const;
112
113 double getdherr(int j) const;
114 double getdkerr(int j) const;
115 double getdlerr(int j) const;
116 int getMaxOrder() const;
117 bool getCrossTerm() const;
118
119 void set(double _a, double _b, double _c, double _alpha, double _beta, double _gamma,
120 const int angleunit = angDegrees);
121 void seta(double _a);
122 void setb(double _b);
123 void setc(double _c);
124 void setalpha(double _alpha, const int angleunit = angDegrees);
125 void setbeta(double _beta, const int angleunit = angDegrees);
126 void setgamma(double _gamma, const int angleunit = angDegrees);
127 // Set errors
128 void setError(double _aerr, double _berr, double _cerr, double _alphaerr, double _betaerr, double _gammaerr,
129 const int angleunit = angDegrees);
130 void setErrora(double _aerr);
131 void setErrorb(double _berr);
132 void setErrorc(double _cerr);
133 void setErroralpha(double _alphaerr, const int angleunit = angDegrees);
134 void setErrorbeta(double _betaerr, const int angleunit = angDegrees);
135 void setErrorgamma(double _gammaerr, const int angleunit = angDegrees);
136 // Get errors in latice parameters
137 double errora() const;
138 double errorb() const;
139 double errorc() const;
140 double erroralpha(const int angleunit = angDegrees) const;
141 double errorbeta(const int angleunit = angDegrees) const;
142 double errorgamma(const int angleunit = angDegrees) const;
143 double errorvolume() const;
144 // Access private variables
145 const Kernel::DblMatrix &getG() const;
146 const Kernel::DblMatrix &getGstar() const;
147 const Kernel::DblMatrix &getB() const;
148 const Kernel::DblMatrix &getBinv() const;
149
150 // Calculate things about lattice and vectors
151 double d(double h, double k, double l) const;
152 double dstar(double h, double k, double l) const;
153 double d(const Kernel::V3D &hkl) const;
154 double dstar(const Kernel::V3D &hkl) const;
155 double recAngle(double h1, double k1, double l1, double h2, double k2, double l2,
156 const int angleunit = angDegrees) const;
157 double volume() const;
158 double recVolume() const;
159 virtual void recalculateFromGstar(const Kernel::Matrix<double> &NewGstar);
160 bool operator==(const UnitCell &other) const;
161 bool operator!=(const UnitCell &other) const;
162
163protected:
166 std::vector<double> da;
168 std::vector<double> ra;
170 std::vector<double> errorda;
192
196
198
200
202
204
205 // Private functions
206
207 void calculateG();
208 void calculateGstar();
209 void calculateReciprocalLattice();
210 void calculateB();
211
212 virtual void recalculate();
213};
214
215MANTID_GEOMETRY_DLL std::ostream &operator<<(std::ostream &out, const UnitCell &unitCell);
216
217MANTID_GEOMETRY_DLL UnitCell strToUnitCell(const std::string &unitCellString);
218MANTID_GEOMETRY_DLL std::string unitCellToStr(const UnitCell &unitCell);
219
220} // namespace Geometry
221} // namespace Mantid
Class to implement unit cell of crystals.
Definition: UnitCell.h:44
std::vector< double > errorda
Error in lattice parameters (in and radians)
Definition: UnitCell.h:170
Kernel::DblMatrix Binv
Inverse of the B matrix.
Definition: UnitCell.h:195
Kernel::DblMatrix errorModHKL
Definition: UnitCell.h:199
std::vector< double > da
Lattice parameter a,b,c,alpha,beta,gamma (in and radians)
Definition: UnitCell.h:166
std::vector< double > ra
Reciprocal lattice parameters (in and radians)
Definition: UnitCell.h:168
Kernel::DblMatrix G
Metric tensor.
Definition: UnitCell.h:177
Kernel::DblMatrix ModHKL
Definition: UnitCell.h:197
virtual ~UnitCell()=default
Kernel::DblMatrix Gstar
Reciprocal lattice tensor.
Definition: UnitCell.h:184
Kernel::DblMatrix B
B matrix for a right-handed coordinate system, in Busing-Levy convention.
Definition: UnitCell.h:191
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL UnitCell strToUnitCell(const std::string &unitCellString)
Definition: UnitCell.cpp:896
MANTID_GEOMETRY_DLL std::string unitCellToStr(const UnitCell &unitCell)
Definition: UnitCell.cpp:886
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
Definition: PointGroup.cpp:312
Helper class which provides the Collimation Length for SANS instruments.
constexpr bool operator==(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)
constexpr bool operator!=(const wide_integer< Bits, Signed > &lhs, const wide_integer< Bits2, Signed2 > &rhs)