2 * Determination of lateral interaction parameters on a c(2x2) square lattice
3 * using linear combinations to express each interaction and then counting them in terms of cluster-expansion
6 * Michael Rieger, FHI, 2008
13 #include <blitz/array.h> // http://www.oonumerics.org/blitz/
14 #include <random/uniform.h> // blitz Random Number Generator - Mersenne Twister type
15 #include "SimpleIni.h" // Ini File Parser
18 using namespace blitz
;
19 using namespace ranlib
;
21 Array
<int, 2> lattice
;
22 Array
<int, 2> CObr_pos
;
39 int read_ini_structure(const char *input_file_name
, int &lattice_size_x
, int &lattice_size_y
, int &nr_of_CObr
)
42 int unit_cell_x
,unit_cell_y
;
45 SI_Error rc
= ini
.LoadFile(input_file_name
);
46 if (rc
< 0) return false;
48 // getting cell dimensions from [cell] section in input file
49 unit_cell_x
= atoi(ini
.GetValue("cell", "unit_cell_x"));
50 std::cout
<< unit_cell_x
<< endl
;
51 unit_cell_y
= atoi(ini
.GetValue("cell", "unit_cell_y"));
52 std::cout
<< unit_cell_y
<< endl
;
54 // creating simulation lattice
55 lattice_size_x
= 4*unit_cell_x
;
56 lattice_size_y
= 4*unit_cell_y
;
57 std::cout
<< lattice_size_x
<< " " << lattice_size_y
<< endl
;
60 // output all of the items of the input file
61 CSimpleIniA::TNamesDepend sections
;
62 CSimpleIniA::TNamesDepend::const_iterator sections_iterator
;
63 ini
.GetAllSections(sections
);
66 CSimpleIniA::TNamesDepend::size_type sections_size
;
67 sections_size
= sections
.size();
69 nr_of_CObr
= int(sections_size
) - 1;
71 string key_word
= "cell";
74 for (sections_iterator
= sections
.begin(); sections_iterator
!= sections
.end(); sections_iterator
++)
76 printf("%s\n", sections_iterator
->pItem
);
77 std::cout
<< "direkt per cout " << sections_iterator
->pItem
<< endl
;
79 string section_name
= sections_iterator
->pItem
;
81 if (key_word
== section_name
)
82 printf("\t\t\t FOUND \n\n\n");
86 printf("nr of sections given by sections.size() %i\n", sections
.size());
89 // next step.. printing all keys of a section
91 CSimpleIniA::TNamesDepend::const_iterator section_iterator
;
92 section_iterator
= sections
.begin();
97 printf("second section name: - %s - contains the keys: \n", section_iterator
->pItem
);
102 CSimpleIniA::TNamesDepend keys
;
103 ini
.GetAllKeys(sections_iterator
->pItem
, keys
);
104 CSimpleIniA::TNamesDepend::const_iterator k
;
106 for (k
= keys
.begin(); k
!= keys
.end(); ++k
)
108 printf("%s\n", k
->pItem
);
109 string key_name
= k
->pItem
;
110 if (key_word
== key_name
)
112 printf("\t\t\t FOUND an X\n\n\n");
113 x
= atof(ini
.GetValue(section_iterator
->pItem
, k
->pItem
));
114 std::cout
<< "value is now (here): " << x
<< endl
;
118 printf("end of input file reading");
126 int fill_surface_atoms(Array
<int, 2> lattice
, occupation site_occupation
, int lattice_size_x
, int lattice_size_y
)
130 for (pos_x
= 0; pos_x
< lattice_size_x
; pos_x
= pos_x
+ 2) // for test... only every second x
132 for (pos_y
= 0; pos_y
< lattice_size_y
; pos_y
++)
134 lattice(pos_x
,pos_y
) = site_occupation
;
138 std::cout
<< lattice
<< endl
;
142 int get_and_fill_adorbates(const char *input_file_name
, Array
<int, 2> lattice
, Array
<int, 2> CObr_pos
, occupation atom
, int lattice_size_x
, int lattice_size_y
)
145 CSimpleIniA::TNamesDepend sections
;
146 CSimpleIniA::TNamesDepend keys
;
147 CSimpleIniA::TNamesDepend::const_iterator sections_iterator
;
150 SI_Error rc
= ini
.LoadFile(input_file_name
);
151 if (rc
< 0) return false;
153 //getting all sections, setting pointer to first CO section
154 ini
.GetAllSections(sections
);
155 sections_iterator
= sections
.begin();
158 string coord_x
, coord_y
, coord_read
;
165 while (sections_iterator
!= sections
.end())
167 std::cout
<< sections_iterator
->pItem
<< endl
;
169 ini
.GetAllKeys(sections_iterator
->pItem
, keys
);
173 for (CSimpleIniA::TNamesDepend::const_iterator key_iterator
= keys
.begin(); key_iterator
!= keys
.end(); ++key_iterator
)
176 std::cout
<< key_iterator
->pItem
<< endl
;
189 int main(int argc
, char* argv
[])
191 int lattice_size_x
, lattice_size_y
;
194 // subroutine to read all necessary input files
195 if (read_ini_structure(argv
[1], lattice_size_x
, lattice_size_y
, nr_of_CObr
))
197 std::cout
<< "\n\n filling surface atoms now\n" << std::endl
;
198 Array
<int, 2> lattice(lattice_size_x
,lattice_size_y
); // array constructor
199 Array
<int, 2> CObr_pos(nr_of_CObr
, max_directions
);
204 std::cout
<< lattice
;
205 std::cout
<< CObr_pos
;
208 // filling surface atoms
209 fill_surface_atoms(lattice
, Pd
, lattice_size_x
, lattice_size_y
);
211 get_and_fill_adorbates(argv
[1], lattice
, CObr_pos
, CO
, lattice_size_x
, lattice_size_y
);
217 std::cout
<< "sth wrong with input file reading" << std::endl
;