UnitCell.h 2.48 KB
Newer Older
Francois Gygi committed
1 2 3 4 5
////////////////////////////////////////////////////////////////////////////////
//
// UnitCell.h
//
////////////////////////////////////////////////////////////////////////////////
6
// $Id: UnitCell.h,v 1.4 2004-03-11 21:52:31 fgygi Exp $
Francois Gygi committed
7 8 9 10 11

#ifndef UNITCELL_H
#define UNITCELL_H

#include "D3vector.h"
12
#include <valarray>
Francois Gygi committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26
using namespace std;

class UnitCell
{
  private:

  D3vector a_[3];
  D3vector b_[3];
  double volume_;
  D3vector an_[13];
  D3vector bn_[13];
  double an2h_[13];
  double bn2h_[13];
  
27 28 29 30 31 32 33 34
  // 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];
  
Francois Gygi committed
35 36 37 38 39 40 41 42 43 44 45 46
  public:

  const D3vector& a(int i) const { return a_[i]; }
  const D3vector& b(int i) const { return b_[i]; }
  
  UnitCell(void) { set(D3vector(0,0,0),D3vector(0,0,0),D3vector(0,0,0)); }  
  explicit UnitCell(const D3vector& a0, const D3vector& a1, const D3vector& a2)
  { set(a0,a1,a2); }
  
  void set(const D3vector& a0, const D3vector& a1, const D3vector& a2);
  double volume(void) const { return volume_; }
  
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  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]; }
  
  // 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;
  
  // 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;
  void compute_deda(const valarray<double>& sigma, valarray<double>& deda) const;
  
Francois Gygi committed
66 67 68 69 70 71 72 73 74 75
  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;
  
  bool encloses(const UnitCell& c) const;
  bool contains(D3vector v) const;
  
  void print(ostream& os) const;  
  bool operator==(const UnitCell& c) const;
76
  bool operator!=(const UnitCell& c) const;
Francois Gygi committed
77 78 79
};
ostream& operator << ( ostream& os, const UnitCell& cell );
#endif