Commit da1538c2 authored by Sergey Kireev's avatar Sergey Kireev
Browse files

nle_cpp data file format fixed

parent d2a21f65
......@@ -22,6 +22,7 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
const int nsize; // size of N side
int nnsize; // number of cells in N
int nxsize; // X size of N
int ngroups; // number of groups, set by find_groups()
int minndes; // minimum number of neighbors to prevent desorb N
double en,el,enl,kT,mu,evap,cond,absn,desn,pgroup;
......@@ -41,7 +42,7 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
std::stringstream debug_message;
NLE_CA_base(const int nx,const int ny,const int ns = 1):ca(nx,ny),nsize(ns),nnsize(ns*ns),groups_found(false),maxgroupsize(0) {
NLE_CA_base(const int nx,const int ny,const int ns = 1):ca(nx,ny),nsize(ns),nnsize(ns*ns),nxsize(1024),groups_found(false),maxgroupsize(0) {
logfn_scc(std::string("NLE_CA_base<")+ca::dirs.name()+std::string(",")+ca::hood.name()+std::string(">"),"int,int,int");
en = 1.0;
el = 0.3;
......@@ -96,9 +97,9 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
void set_parameter_des(double val) { desn = val; }
void set_parameter_minndes(int val) { minndes = val; }
int xy2s(int i,int j) const { return (i+1) + (j+1)*1024; }
int s2x(int s) const { return s%1024-1; }
int s2y(int s) const { return s/1024-1; }
int xy2s(int x,int y) const { return x + y * nxsize + 1; }
int s2x(int s) const { return (s - 1) % nxsize; }
int s2y(int s) const { return (s - 1) / nxsize; }
bool isL(int s) const { return s == L; }
bool isE(int s) const { return s == E; }
......@@ -151,6 +152,17 @@ class NLE_CA_base : public CA2D<int,dirs_type,hood_type> {
virtual void fill_debug() { ca::fill(L); }
bool load_binary(const std::string &filename) {
ca::load_binary(filename);
if (!fix_loaded(1024)) {
std::cerr << "Error: Bad format of input file '" << filename << "'\n";
return false;
}
return true;
}
virtual bool fix_loaded(int base) { exit(-1); return false; }
virtual std::array<int,3> neighborhood(const int x,const int y) const {
int count_n = 0;
int count_l = 0;
......@@ -464,6 +476,7 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
using nle = NLE_CA_base<hood_vonNeumann,hood_type>;
using nle::nsize;
using nle::nnsize;
using nle::nxsize;
using nle::xN;
using nle::yN;
using nle::sN;
......@@ -478,6 +491,7 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
logfn_scc(std::string("NLE_sqr_CA<")+ca::hood.name()+std::string(">"),"");
const int ns = nsize;
nnsize = ns*ns;
nxsize = ns;
sN.resize(nnsize);
xN.resize(nnsize);
yN.resize(nnsize);
......@@ -502,7 +516,28 @@ class NLE_sqr_CA : public NLE_CA_base<hood_vonNeumann,hood_type> {
}
}
}
virtual bool fix_loaded(int base) { // return (i+1) + (j+1)*1024;
const int max_state = nle::xy2s(nsize,nsize);
bool need_fix = false;
for (int ix=0;ix<nx && !need_fix;ix++)
for (int iy=0;iy<ny;iy++)
if (ca::get(ix,iy) > max_state) { need_fix = true; break; }
if (need_fix)
for (int ix=0;ix<nx;ix++)
for (int iy=0;iy<ny;iy++) {
const int state = ca::get(ix,iy);
if (!nle::isL(state) && !nle::isE(state)) {
const int x = state % base - 1;
const int y = state / base - 1;
if (x < 0 || x >= nsize) return false;
if (y < 0 || y >= nsize) return false;
ca::get(ix,iy) = nle::xy2s(x,y);
}
}
return true;
}
virtual bool may_move_NL(int bi,int bj,int dir) const {
for (int k=0;k<nsize;k++)
if (!nle::isL(ca::getfixd(bi+side[dir][k].x,bj+side[dir][k].y))) return false;
......@@ -1243,6 +1278,7 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
oppdir.resize(6);
const int ns = nsize;
nnsize = 3*ns*(ns-1)+1;
nxsize = 2*ns - 1;
sN.resize(nnsize);
xN.resize(nnsize);
yN.resize(nnsize);
......@@ -1531,6 +1567,28 @@ class NLE_hex_CA : public NLE_CA_base<hood_hex> {
}
}
bool fix_loaded(int base) { // x + y*nxsize + 1;
const int max_state = nle::xy2s(nxsize,nxsize);
bool need_fix = false;
for (int ix=0;ix<nx && !need_fix;ix++)
for (int iy=0;iy<ny;iy++)
if (ca::get(ix,iy) > max_state) { need_fix = true; break; }
if (need_fix) {
for (int ix=0;ix<nx;ix++)
for (int iy=0;iy<ny;iy++) {
const int state = ca::get(ix,iy);
if (!nle::isL(state) && !nle::isE(state)) {
const int x = state % base - 1;
const int y = state / base - 1;
if (x < 0 || x >= nxsize) return false;
if (y < 0 || y >= nxsize) return false;
ca::get(ix,iy) = nle::xy2s(x,y);
}
}
}
return true;
}
virtual bool may_move_NL(int bx,int by,int dir) const {
int d0 = (dir+ca::dirs.count-1)%ca::dirs.count;
for (int k=0;k<nsize-1;k++)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment