2 * Determination of lateral interaction parameters on a c(2x2) square lattice
3 * using linear combinations to express each interaction and then counting
4 * them in terms of cluster-expansion coefficients
6 * Michael Rieger, FHI, 2008
16 #include <blitz/array.h> // http://www.oonumerics.org/blitz/
17 #include <random/uniform.h> // blitz Random Number Generator - Mersenne Twister type
18 #include "SimpleIni.h" // Ini File Parser
21 using namespace blitz
;
22 using namespace ranlib
;
33 Array
<Occupation
, 2> sites
;
34 int Latitude
, Longitude
;
35 int UnitCellSizeX
, UnitCellSizeY
;
38 void usage(const char *prog
)
40 fprintf(stderr
, "usage: %s ini-file\n", prog
);
44 void panic(char *msg
, ...)
49 fprintf(stderr
, "FATAL: ");
50 vfprintf(stderr
, msg
, vargs
);
51 fprintf(stderr
, "\n");
55 const char *str_SI_Error(SI_Error rc
)
58 case SI_OK
: return "no error";
59 case SI_UPDATED
: return "existing value updated";
60 case SI_INSERTED
: return "new value inserted";
61 case SI_FAIL
: return "generic failure";
62 case SI_NOMEM
: return "out of memory";
63 case SI_FILE
: return "file error";
64 default: return "(invalid error)";
68 void read_ini_structure(const char *input_file_name
, Lattice
&lattice
)
70 CSimpleIni
ini(false, true, false);
73 SI_Error rc
= ini
.LoadFile(input_file_name
);
75 panic("Failed loading ini file: %s", str_SI_Error(rc
));
78 const CSimpleIniA::TKeyVal
* section
= ini
.GetSection("UnitCell");
80 panic("Ini file is missing 'UnitCell' section.");
82 #define ASSIGN_KEY(section, key_name, key_member) \
83 tmp = ini.GetValue(section, key_name); \
85 panic("%s definition is missing '%s'", section, key_name); \
86 lattice.key_member = atoi(tmp)
88 ASSIGN_KEY("UnitCell", "SizeX", UnitCellSizeX
);
89 ASSIGN_KEY("UnitCell", "SizeY", UnitCellSizeY
);
90 ASSIGN_KEY("UnitCell", "Longitude", Longitude
);
91 ASSIGN_KEY("UnitCell", "Latitude", Latitude
);
94 if (lattice
.UnitCellSizeX
< 1 || lattice
.UnitCellSizeY
< 1 ||
95 lattice
.Longitude
< 1 || lattice
.Latitude
< 1)
96 panic("Unit cell has unreasonable size.");
98 lattice
.sites
.resize(lattice
.Longitude
* lattice
.UnitCellSizeX
,
99 lattice
.Latitude
* lattice
.UnitCellSizeY
);
100 lattice
.sites
= empty
;
103 section
= ini
.GetSection("Adsorbates");
105 panic("Ini file is missing 'Adsorbates' section. Maybe meaningful??");
107 CSimpleIniA::TNamesDepend CO_positions
;
108 ini
.GetAllValues("Adsorbates", "CO", CO_positions
);
109 for (CSimpleIniA::TNamesDepend::const_iterator i
= CO_positions
.begin();
110 i
!= CO_positions
.end(); ++i
) {
111 double x_frac
, y_frac
;
112 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 ||
113 x_frac
< 0 || x_frac
>= 1 ||
114 y_frac
< 0 || y_frac
>= 1)
115 panic("Skrewed coordinates in '%s'", i
->pItem
);
116 lattice
.sites((int)(lattice
.UnitCellSizeX
* x_frac
),
117 (int)(lattice
.UnitCellSizeY
* y_frac
)) = CO
;
120 // Replicate unit cell to full dimension
121 for (int x
= 0; x
< lattice
.Longitude
* lattice
.UnitCellSizeX
; ++x
)
122 for (int y
= 0; y
< lattice
.Latitude
* lattice
.UnitCellSizeY
; ++y
)
123 lattice
.sites(x
, y
) =
124 lattice
.sites((x
% lattice
.UnitCellSizeX
),
125 (y
% lattice
.UnitCellSizeY
));
128 int main(int argc
, char* argv
[])
133 read_ini_structure(argv
[1], lattice
);
135 cout
<< "lattice:" << endl
<< lattice
.sites
;