39 void ApplyRule(vector<bool> *
b[], bitset<8> & r,
int ns,
int s);
42 int main(
int argc,
char *argv[])
47 bool visualization = 1;
51 "Number of steps of the 1D cellular automaton.");
53 "Elementary cellular automaton rule [0-255].");
54 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
56 "Enable or disable GLVis visualization.");
67 Mesh *mesh =
new Mesh(2 * ns - 1, ns, Element::QUADRILATERAL,
68 0, 2 * ns - 1, ns,
false);
80 vector<bool> * vbp[2];
81 vector<bool> vb0(len);
82 vector<bool> vb1(len);
87 for (
int i=0; i<len; i++)
105 char vishost[] =
"localhost";
107 sol_sock.
open(vishost, visport);
118 cout << endl <<
"Applying rule..." << flush;
119 for (
int s=1; s<ns; s++)
128 std::swap(vbp[0], vbp[1]);
133 sol_sock <<
"solution\n" << *mesh << x << flush;
138 sol_sock <<
"keys Ajl\n";
139 sol_sock <<
"view 0 180\n";
140 sol_sock <<
"zoom 2.2\n";
141 sol_sock <<
"palette 24\n";
147 cout <<
"done." << endl;
151 ofstream mesh_ofs(
"automata.mesh");
152 mesh_ofs.precision(8);
153 mesh->
Print(mesh_ofs);
154 ofstream sol_ofs(
"automata.gf");
155 sol_ofs.precision(8);
166 bool Rule(bitset<8> & r,
bool b0,
bool b1,
bool b2)
168 return r[(b0 ? 1 : 0) + (b1 ? 2 : 0) + (b2 ? 4 : 0)];
173 cout << endl <<
"Rule:" << endl;
174 for (
int i=7; i>=0; i--)
176 cout <<
" " << i/4 << (i/2)%2 << i%2;
179 for (
int i=7; i>=0; i--)
181 cout <<
" " <<
Rule(r,i%2,(i/2)%2,i/4) <<
" ";
186 void ApplyRule(vector<bool> *
b[], bitset<8> & r,
int ns,
int s)
188 for (
int i=0; i<2*ns-1; i++)
190 int i0 = (i + 2 * ns - 2) % (2 * ns - 1);
191 int i2 = (i + 1) % (2 * ns - 1);
192 (*b[1])[i] =
Rule(r, (*b[0])[i0], (*b[0])[i], (*b[0])[i2]);
198 for (
int i=0; i<2*ns-1; i++)
200 x[s*(2*ns-1)+i] = (
double)b[i];
virtual void Print(std::ostream &out=mfem::out) const
Class for grid function - Vector with associated FE space.
int main(int argc, char *argv[])
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void PrintRule(bitset< 8 > &r)
void PrintUsage(std::ostream &out) const
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
void ApplyRule(vector< bool > *b[], bitset< 8 > &r, int ns, int s)
void ProjectStep(const vector< bool > &b, GridFunction &x, int ns, int s)
void PrintOptions(std::ostream &out) const
bool Rule(bitset< 8 > &r, bool b0, bool b1, bool b2)
int open(const char hostname[], int port)
Arbitrary order "L2-conforming" discontinuous finite elements.