39void ApplyRule(vector<bool> *
b[], bitset<8> & r,
int ns,
int s);
42int 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.");
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++)
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);
165bool 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++)
void ProjectStep(const vector< bool > &b, GridFunction &x, int ns, int s)
bool Rule(bitset< 8 > &r, bool b0, bool b1, bool b2)
void ApplyRule(vector< bool > *b[], bitset< 8 > &r, int ns, int s)
void PrintRule(bitset< 8 > &r)
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Class for grid function - Vector with associated FE space.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Arbitrary order "L2-conforming" discontinuous finite elements.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, real_t sx=1.0, real_t sy=1.0, bool sfc_ordering=true)
Creates mesh for the rectangle [0,sx]x[0,sy], divided into nx*ny quadrilaterals if type = QUADRILATER...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
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...
bool Good() const
Return true if the command line options were parsed successfully.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.