fixed all errors with daniel
[cluster_expansion.git] / Lattice.cpp
blob9d162b76c7e561199a724ac31d08011e8a31f423
1 #include <stdexcept>
3 #include "Lattice.h"
4 #include "SimpleIni.h"
6 // FIXME: LatticeType should derive operator= from Array<Occupation, 2>
7 LatticeLayer& LatticeLayer::operator=(Occupation const& o) {
8 for (LatticeLayer::iterator i = this->begin(); i != this->end(); ++i)
9 this->operator()(i.position()) = o;
10 return *this;
13 ostream& operator<<(ostream& output, const LatticeLayer& layer)
15 for (int y = 0; y < layer.extent(secondDim); ++y) {
16 for (int x = 0; x < layer.extent(firstDim); ++x) {
17 switch (layer(x,y)) {
18 case empty: cout << "."; break;
19 case CO: cout << "C"; break;
20 case Pd: cout << "P"; break;
21 default: throw out_of_range("Invalid occupation");
24 output << endl;
27 return output;
30 void
31 Lattice::extendUnitCell(void)
33 extendUnitCell(adsorbates, UnitCellSizeX, UnitCellSizeY);
34 extendUnitCell(surface, UnitCellSizeX, UnitCellSizeY);
37 void
38 Lattice::extendUnitCell(LatticeLayer latticeLayer, int dimX, int dimY)
40 for (LatticeLayer::iterator i = latticeLayer.begin();
41 i != latticeLayer.end(); i++) {
42 int x = i.position()[0];
43 int y = i.position()[1];
44 latticeLayer(x, y) = latticeLayer(x % dimX, y % dimY);
49 void
50 Lattice::assessInteractions(Interactions &interactions)
52 for (LatticeLayer::iterator i = adsorbates.begin(); i != adsorbates.end(); i++) {
53 if (adsorbates(i.position()) == empty)
54 continue;
55 cout << "POS" << i.position() << endl;
56 for (Interactions::iterator interaction = interactions.begin();
57 interaction != interactions.end(); interaction++) {
58 cout << "checking " << interaction->name << ": ";
59 for (Directions::iterator direction = interaction->directions.begin();
60 direction != interaction->directions.end(); direction++) {
61 for (Directions::iterator symmetry_operation = _symmetryOperations.directions.begin();
62 symmetry_operation != _symmetryOperations.directions.end(); symmetry_operation++) {
64 int x = (i.position()[firstDim] + (int)((direction->x / UnitCellSizeX)*
65 (symmetry_operation->x * Longitude)) %
66 (UnitCellSizeX * Longitude) );
67 int y = (i.position()[secondDim] + (int)((direction->y / UnitCellSizeY)*
68 (symmetry_operation->y * Latitude)) %
69 (UnitCellSizeY * Latitude));
70 cout << "(" << x << "/" << y << ") ";
71 if (adsorbates(x, y) != empty) {
72 interaction->multiplicity++;
73 cout << "HIT ";
77 cout << endl;
83 ostream& operator<<(ostream& output, const Lattice& lattice)
85 output << "lattice: UnitCellSizeX = " << lattice.UnitCellSizeX
86 << ", UnitCellSizeY = " << lattice.UnitCellSizeY
87 << ", Latitude = " << lattice.Latitude
88 << ", Longitude = " << lattice.Longitude << endl
89 << "surface: " << endl << lattice.surface
90 << "adsorbates: " << endl << lattice.adsorbates;
92 return output;