44static real_t cosa_ = cos(0.5 * M_PI / nstep_);
45static real_t sina_ = sin(0.5 * M_PI / nstep_);
55static int conf[][23] =
123static int NUM_CONFIGURATIONS = 13;
125void trans(
const int * conf,
Mesh & mesh);
129int main(
int argc,
char *argv[])
134 bool visualization =
true;
139 args.
AddOption(&cfg,
"-c",
"--configuration",
140 "Select one of 13 pre-programmed configurations: 0-12");
141 args.
AddOption(&myConf,
"-u",
"--user-cfg",
142 "User defined configuration consisting of "
143 "23 joint positions defined by the integers 0, 1, 2, or 3.");
144 args.
AddOption(&anim,
"-anim",
"--animation",
"-no-anim",
146 "Enable or disable GLVis animation.");
147 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
148 "--no-visualization",
149 "Enable or disable GLVis visualization.");
159 if (myConf.
Size() > 0)
163 if (myConf.
Size() != 23)
165 MFEM_ABORT(
"Invalid user-defined configuration of length "
171 if (!user && cfg >=0 && cfg < NUM_CONFIGURATIONS)
178 for (
int i=0; i<myConf.
Size(); i++)
180 if (myConf[i] < 0 || myConf[i] > 3)
182 MFEM_ABORT(
"Invalid entry \"" << myConf[i]
183 <<
"\"in configuration at position " << i);
187 if (!visualization) { anim =
false; }
190 Mesh mesh(3, 6 * 24, 24);
195 for (
int i=0; i<12; i++)
199 c[0] = i-6; c[1] = 0.0; c[2] = i-6;
200 c[3] = i-6; c[4] = 0.0; c[5] = i-5;
201 c[6] = i-5; c[7] = 0.0; c[8] = i-5;
207 c[1] = 1.0; c[4] = 1.0; c[7] = 1.0;
212 for (
int j=0; j<6; j++) { v[j] = 12 * i + j; }
216 c[0] = i-6; c[1] = 0.0; c[2] = i-5;
217 c[3] = i-5; c[4] = 0.0; c[5] = i-4;
218 c[6] = i-5; c[7] = 0.0; c[8] = i-5;
224 c[1] = 1.0; c[4] = 1.0; c[7] = 1.0;
229 for (
int j=0; j<6; j++) { v[j] = 12 * i + j + 6; }
240 for (
int i=0; i<24; i++) { color[i] = (i%2)?1.0:-1.0; }
245 oss <<
"snake-init.mesh";
246 ofstream ofs(oss.str().c_str());
261 sol_sock.precision(8);
262 sol_sock <<
"solution\n" << mesh << color <<
"keys Am\n"
263 <<
"palette 22\n" <<
"valuerange -1.5 1\n"
264 <<
"autoscale off\n" << flush;
267 if (myConf.
Size() > 0 && anim)
269 sol_sock <<
"pause\n" << flush;
270 cout <<
"GLVis visualization paused."
271 <<
" Press space (in the GLVis window) to resume it.\n";
276 sol_sock <<
"solution\n" << mesh << color;
279 sol_sock <<
"pause\n";
284 sol_sock <<
"autoscale on\n" <<
"valuerange -1.5 1\n" << flush;
295 oss <<
"snake-user.mesh";
299 oss <<
"snake-c" << cfg <<
".mesh";
303 oss <<
"snake-joined.mesh";
305 ofstream ofs(oss.str().c_str());
318 if (notch_ == 0) {
return; }
326 cVec[0] = -5.5 + joint_ / 2; cVec[1] = 0.5; cVec[2] = 0.0;
327 xVec.
Add(-1.0, cVec);
331 swap(xVec[0], xVec[1]);
339 swap(xVec[0], xVec[1]);
347 cVec[0] = 0.0; cVec[1] = 0.5; cVec[2] = -4.5 + joint_ / 2;
348 xVec.
Add(-1.0, cVec);
352 swap(xVec[1], xVec[2]);
360 swap(xVec[1], xVec[2]);
371 for (
int i=0; i<23; i++)
374 notch_ = new_conf[i];
378 for (
int k=0; k<6*(i+1); k++)
389 if (notch_ == 0) {
return; }
398 cVec[0] = -5.5 + joint_ / 2; cVec[1] = 0.5; cVec[2] = 0.0;
399 xVec.
Add(-1.0, cVec);
403 yVec[0] = cosa_ * xVec[0] - sina_ * xVec[1];
404 yVec[1] = sina_ * xVec[0] + cosa_ * xVec[1];
408 yVec[0] = cosa_ * xVec[0] - sina_ * xVec[1];
409 yVec[1] = sina_ * xVec[0] + cosa_ * xVec[1];
413 yVec[0] = cosa_ * xVec[0] + sina_ * xVec[1];
414 yVec[1] = -sina_ * xVec[0] + cosa_ * xVec[1];
418 add(yVec, 1.0, cVec, xVec);
422 cVec[0] = 0.0; cVec[1] = 0.5; cVec[2] = -4.5 + joint_ / 2;
423 xVec.
Add(-1.0, cVec);
428 yVec[1] = cosa_ * xVec[1] - sina_ * xVec[2];
429 yVec[2] = sina_ * xVec[1] + cosa_ * xVec[2];
433 yVec[1] = cosa_ * xVec[1] - sina_ * xVec[2];
434 yVec[2] = sina_ * xVec[1] + cosa_ * xVec[2];
438 yVec[1] = cosa_ * xVec[1] + sina_ * xVec[2];
439 yVec[2] = -sina_ * xVec[1] + cosa_ * xVec[2];
442 add(yVec, 1.0, cVec, xVec);
449 if (notch_ == 2 && step_ == 2 * nstep_) { joint_++; step_ = 0; }
450 if (notch_ != 2 && step_ == nstep_) { joint_++; step_ = 0; }
451 if (joint_ == 23) {
return false; }
452 notch_ = new_conf[joint_];
461 for (
int k=0; k<6*(joint_+1); k++)
void Assign(const T *)
Copy data from a pointer. 'Size()' elements are copied.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
T * GetData()
Returns the data.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
Class for grid function - Vector with associated FE space.
Arbitrary order "L2-conforming" discontinuous finite elements.
int AddWedge(int v1, int v2, int v3, int v4, int v5, int v6, int attr=1)
Adds a wedge to the mesh given by 6 vertices v1 through v6.
void FinalizeTopology(bool generate_bdr=true)
Finalize the construction of the secondary topology (connectivity) data of a Mesh.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
int AddVertex(real_t x, real_t y=0.0, real_t z=0.0)
const real_t * GetVertex(int i) const
Return pointer to vertex i's coordinates.
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.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
void MergeMeshNodes(Mesh *mesh, int logging)
Merges vertices which lie at the same location.
void add(const Vector &v1, const Vector &v2, Vector &v)
bool anim_step(const int *conf, Mesh &mesh)
void rotate_step(real_t *x)
void trans(const int *conf, Mesh &mesh)