testUnitCell.C 3.75 KB
 Francois Gygi committed Oct 02, 2003 1 2 3 4 5 //////////////////////////////////////////////////////////////////////////////// // // testUnitCell.C // ////////////////////////////////////////////////////////////////////////////////  Francois Gygi committed Mar 11, 2004 6 // $Id: testUnitCell.C,v 1.2 2004-03-11 21:52:31 fgygi Exp$  Francois Gygi committed Oct 02, 2003 7 8 9 10 11 12 13 14 15 16 17 18  #include "UnitCell.h" #include #include #include using namespace std; int main() { UnitCell cell; cout << " orthorhombic cell: " << endl;  Francois Gygi committed Mar 11, 2004 19  cell.set(D3vector(4.,0.,0.),D3vector(0.,5.,0.),D3vector(0.,0.,7.));  Francois Gygi committed Oct 02, 2003 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93  cout << cell << endl; D3vector v; const int n = 100000; const double d = 10.0; int count; count = 0; for ( int i = 0; i < n; i++ ) { // generate a random vector in a box of size d x d x d double x0 = drand48() - 0.5; double x1 = drand48() - 0.5; double x2 = drand48() - 0.5; v = d * D3vector(x0,x1,x2); if ( cell.in_ws(v) ) count++; cell.fold_in_ws(v); if ( !cell.in_ws(v) ) cout << v << endl; } cout << " volume ratio: " << cell.volume() / (d*d*d) << " computed: " << count/((double) n) << endl << endl;; cout << " FCC cell: " << endl; cell.set(D3vector(4,4,0),D3vector(0,4,4),D3vector(4,0,4)); cout << cell << endl; count = 0; for ( int i = 0; i < n; i++ ) { // generate a random vector in a box of size d x d x d double x0 = drand48() - 0.5; double x1 = drand48() - 0.5; double x2 = drand48() - 0.5; v = d * D3vector(x0,x1,x2); if ( cell.in_ws(v) ) count++; cell.fold_in_ws(v); if ( !cell.in_ws(v) ) cout << v << endl; } cout << " volume ratio: " << cell.volume() / (d*d*d) << " computed: " << count/((double) n) << endl << endl;; cout << " BCC cell: " << endl; cell.set(D3vector(4,4,-4),D3vector(-4, 4,4),D3vector(4,-4,4)); cout << cell << endl; count = 0; for ( int i = 0; i < n; i++ ) { // generate a random vector in a box of size d x d x d double x0 = drand48() - 0.5; double x1 = drand48() - 0.5; double x2 = drand48() - 0.5; v = d * D3vector(x0,x1,x2); if ( cell.in_ws(v) ) count++; cell.fold_in_ws(v); if ( !cell.in_ws(v) ) cout << v << endl; } cout << " volume ratio: " << cell.volume() / (d*d*d) << " computed: " << count/((double) n) << endl << endl;; cout << " Monoclinic cell: " << endl; cell.set(D3vector(4,0,0.1),D3vector(0.2, 4,0),D3vector(0.1,0.3,4)); cout << cell << endl;  Francois Gygi committed Mar 11, 2004 94 95 96 97 98 99  // Check matrix multiplication function double ztest[9]; cell.matmult3x3(cell.amat(),cell.amat_inv(),ztest); for ( int i = 0; i < 9; i++ ) cout << " ztest[" << i << "]=" << ztest[i] << endl;  Francois Gygi committed Oct 02, 2003 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135  count = 0; for ( int i = 0; i < n; i++ ) { // generate a random vector in a box of size d x d x d double x0 = drand48() - 0.5; double x1 = drand48() - 0.5; double x2 = drand48() - 0.5; v = d * D3vector(x0,x1,x2); if ( cell.in_ws(v) ) count++; cell.fold_in_ws(v); if ( !cell.in_ws(v) ) cout << v << endl; } cout << " volume ratio: " << cell.volume() / (d*d*d) << " computed: " << count/((double) n) << endl << endl; // test UnitCell::included_in function UnitCell rcell; rcell.set(D3vector(4,4,0),D3vector(0,4,4),D3vector(4,0,4)); cell.set(D3vector(4,5,0),D3vector(0,4,4),D3vector(4,0,4)); cout << " rcell: " << rcell << endl; cout << " cell: " << cell << endl; cout << " cell is"; if ( !rcell.encloses(cell) ) cout << " not"; cout << " included in rcell" << endl; rcell.set(D3vector(4,4,0),D3vector(0,4,4),D3vector(4,0,4)); cout << " rcell: " << rcell << endl; cell.set(D3vector(3.8,3.8,0),D3vector(0,3.8,3.8),D3vector(3.8,0,3.8)); cout << " cell: " << cell << endl; cout << " cell is"; if ( !rcell.encloses(cell) ) cout << " not"; cout << " included in rcell" << endl; }