UnitCell.h 3.24 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17
// UnitCell.h
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
18
// $Id: UnitCell.h,v 1.10 2008-09-15 14:59:58 fgygi Exp $
Francois Gygi committed
19 20 21 22 23

#ifndef UNITCELL_H
#define UNITCELL_H

#include "D3vector.h"
24
#include <iosfwd>
Francois Gygi committed
25 26 27 28 29 30 31 32 33 34 35 36

class UnitCell
{
  private:

  D3vector a_[3];
  D3vector b_[3];
  double volume_;
  D3vector an_[13];
  D3vector bn_[13];
  double an2h_[13];
  double bn2h_[13];
37

Francois Gygi committed
38 39
  double a_norm_[3], alpha_, beta_, gamma_;

40 41 42 43 44 45 46
  // 3x3 matrix forms
  double amat_[9];
  double bmat_[9];
  // 3x3 matrix form of inverse
  double amat_inv_[9];
  // 3x3 matrix form of inverse transpose
  double amat_inv_t_[9];
47

Francois Gygi committed
48 49 50 51
  public:

  const D3vector& a(int i) const { return a_[i]; }
  const D3vector& b(int i) const { return b_[i]; }
52 53

  UnitCell(void) { set(D3vector(0,0,0),D3vector(0,0,0),D3vector(0,0,0)); }
Francois Gygi committed
54 55
  explicit UnitCell(const D3vector& a0, const D3vector& a1, const D3vector& a2)
  { set(a0,a1,a2); }
56

Francois Gygi committed
57 58
  void set(const D3vector& a0, const D3vector& a1, const D3vector& a2);
  double volume(void) const { return volume_; }
Francois Gygi committed
59 60 61 62
  double a_norm(int i) const { return a_norm_[i]; }
  double alpha(void) const { return alpha_; }
  double beta(void) const { return beta_; }
  double gamma(void) const { return gamma_; }
63

64 65 66 67 68 69
  const double* amat(void) const { return &amat_[0]; }
  const double* bmat(void) const { return &bmat_[0]; }
  const double* amat_inv(void) const { return &amat_inv_[0]; }
  double amat(int ij) const { return amat_[ij]; }
  double bmat(int ij) const { return bmat_[ij]; }
  double amat_inv(int ij) const { return amat_inv_[ij]; }
70

71 72
  // 3x3 matrix vector multiply Z = X Y where X is a 3x3 matrix, Y,Z 3-vectors
  void vecmult3x3(const double* x, const double* y, double *z) const;
73

Francois Gygi committed
74
  // 3x3 sym matrix vector multiply Z = X Y where X is a sym 3x3 matrix,
75 76 77
  // Y,Z 3-vectors
  void vecsmult3x3(const double* x, const double* y, double *z) const;

78 79 80 81 82 83 84
  // 3x3 matrix matrix multiply Z = X Y where X, Y are 3x3 matrices
  void matmult3x3(const double* x, const double* y, double *z) const;
  // Z = X Y where X is a symmetric 3x3 matrix and Y a general 3x3 matrix
  // uses only the first 6 elements of array xs
  // where xs[0] = x00, xs[1] = x11, xs[2] = x22,
  // xs[3] = x10, xs[4] = x21, xs[5] = x20
  void smatmult3x3(const double* xs, const double* y, double *z) const;
85

Francois Gygi committed
86 87 88 89
  bool in_ws(const D3vector& v) const;
  void fold_in_ws(D3vector& v) const;
  bool in_bz(const D3vector& k) const;
  void fold_in_bz(D3vector& k) const;
90

Francois Gygi committed
91 92
  bool encloses(const UnitCell& c) const;
  bool contains(D3vector v) const;
93 94

  void print(std::ostream& os) const;
Francois Gygi committed
95
  bool operator==(const UnitCell& c) const;
96
  bool operator!=(const UnitCell& c) const;
Francois Gygi committed
97
};
98
std::ostream& operator << ( std::ostream& os, const UnitCell& cell );
Francois Gygi committed
99
#endif