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 = Mesh::MakeCartesian2D(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++)
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);
165 bool Rule(bitset<8> & r,
bool b0,
bool b1,
bool b2)
167 return r[(b0 ? 1 : 0) + (b1 ? 2 : 0) + (b2 ? 4 : 0)];
172 cout << endl <<
"Rule:" << endl;
173 for (
int i=7; i>=0; i--)
175 cout <<
" " << i/4 << (i/2)%2 << i%2;
178 for (
int i=7; i>=0; i--)
180 cout <<
" " <<
Rule(r,i%2,(i/2)%2,i/4) <<
" ";
187 for (
int i=0; i<2*ns-1; i++)
189 int i0 = (i + 2 * ns - 2) % (2 * ns - 1);
190 int i2 = (i + 1) % (2 * ns - 1);
191 (*b[1])[i] =
Rule(r, (*b[0])[i0], (*b[0])[i], (*b[0])[i2]);
197 for (
int i=0; i<2*ns-1; i++)
199 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.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintRule(bitset< 8 > &r)
void PrintUsage(std::ostream &out) const
Print the usage message.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
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)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
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
Print the options.
bool Rule(bitset< 8 > &r, bool b0, bool b1, bool b2)
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
Arbitrary order "L2-conforming" discontinuous finite elements.
bool Good() const
Return true if the command line options were parsed successfully.