77 enum DefType {INVALID, UNIFORM, SQUEEZE, SHEAR};
79 Deformation(
int dim, DefType dType,
const DeformationData & data)
92 const DeformationData & data_;
107int update_basis(vector<socketstream*> & sock,
const VisWinLayout & vwl,
109 Deformation::DefType dType,
const DeformationData & defData,
110 bool visualization,
int &onlySome,
int visport = 19916);
112int main(
int argc,
char *argv[])
129 Deformation::DefType dType = Deformation::INVALID;
130 DeformationData defData;
132 bool visualization =
true;
136 vector<socketstream*> sock;
139 args.
AddOption(&eInt,
"-e",
"--elem-type",
140 "Element Type: (1-Segment, 2-Triangle, 3-Quadrilateral, "
141 "4-Tetrahedron, 5-Hexahedron, 6-Wedge"
144 args.
AddOption(&bInt,
"-b",
"--basis-type",
145 "Basis Function Type (0-H1, 1-Nedelec, 2-Raviart-Thomas, "
146 "3-L2, 4-Fixed Order Cont.,\n\t5-Gaussian Discontinuous (2D),"
147 " 6-Crouzeix-Raviart, 7-Serendipity)");
148 args.
AddOption(&bOrder,
"-o",
"--order",
"Basis function order");
149 args.
AddOption(&vwl.nx,
"-nx",
"--num-win-x",
150 "Number of Viz windows in X");
151 args.
AddOption(&vwl.ny,
"-ny",
"--num-win-y",
152 "Number of Viz windows in y");
154 "Width of Viz windows");
156 "Height of Viz windows");
157 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
158 "--no-visualization",
159 "Enable or disable GLVis visualization.");
160 args.
AddOption(&onlySome,
"-only",
"--onlySome",
161 "Only view 10 dofs, starting with the specified one.");
162 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
172 if ( eInt > 0 && eInt < 7 )
207 bool print_char =
true;
213 cout <<
"Element Type: " <<
elemTypeStr(eType) << endl;
215 cout <<
"Basis function order: " << bOrder << endl;
216 cout <<
"Map Type: " <<
mapTypeStr(mType) << endl;
218 if (
update_basis(sock, vwl, eType, bType, bOrder, mType,
219 dType, defData, visualization, onlySome, visport) )
221 cerr <<
"Invalid combination of basis info (try again)" << endl;
224 if (!visualization) {
break; }
228 cout <<
"What would you like to do?\n"
230 "c) Close Windows and Quit\n"
231 "e) Change Element Type\n"
232 "b) Change Basis Type\n";
233 if ( bType ==
'h' || bType ==
'p' || bType ==
'n' || bType ==
'r' ||
234 bType ==
'l' || bType ==
'f' || bType ==
'g' || bType ==
's')
236 cout <<
"o) Change Basis Order\n";
239 if ( bType ==
'l' &&
false )
241 cout <<
"m) Change Map Type\n";
243 cout <<
"t) Transform Element\n";
244 cout <<
"--> " << flush;
254 for (
unsigned int i=0; i<sock.size(); i++)
256 *sock[i] <<
"keys q";
263 cout <<
"valid element types:\n";
273 "3) Quadrilateral\n";
281 "7) Pyramid (** not currently supported **)\n";
283 cout <<
"enter new element type --> " << flush;
285 if ( eInt <= 0 || eInt > 7 )
287 cout <<
"invalid element type \"" << eInt <<
"\"" << endl << flush;
297 dType = Deformation::INVALID;
305 cout <<
"invalid element type \"" << eInt <<
306 "\" for basis type \"" <<
basisTypeStr(bType) <<
"\"." << endl;
312 cout <<
"valid basis types:\n";
313 cout <<
"h) H1 Finite Element\n";
314 cout <<
"p) H1 Positive Finite Element\n";
317 cout <<
"s) H1 Serendipity Finite Element\n";
318 cout <<
"n) Nedelec Finite Element\n";
319 cout <<
"r) Raviart-Thomas Finite Element\n";
321 cout <<
"l) L2 Finite Element\n";
324 cout <<
"c) Crouzeix-Raviart Finite Element\n";
326 cout <<
"f) Fixed Order Continuous Finite Element\n";
329 cout <<
"g) Gauss Discontinuous Finite Element\n";
331 cout <<
"enter new basis type --> " << flush;
333 if (bChar ==
'h' || bChar ==
'p' || bChar ==
'l' || bChar ==
'f' ||
344 else if ( bType ==
'p' )
348 else if (bType ==
's')
352 else if ( bType ==
'n' )
356 else if ( bType ==
'r' )
360 else if ( bType ==
'l' )
368 else if ( bType ==
'c' )
373 else if ( bType ==
'f' )
375 if ( bOrder < 1 || bOrder > 3)
381 else if ( bType ==
'g' )
383 if ( bOrder < 1 || bOrder > 2)
393 cout <<
"invalid basis type \"" << bChar <<
"\"." << endl;
396 if (mk ==
'm' && bType ==
'l')
399 cout <<
"valid map types:\n"
402 cout <<
"enter new map type --> " << flush;
404 if (mInt >=0 && mInt <= 1)
411 cout <<
"invalid map type \"" << mInt <<
"\"." << endl;
417 int oMin = ( bType ==
'h' || bType ==
'p' || bType ==
'n' ||
418 bType ==
'f' || bType ==
'g' || bType ==
's')?1:0;
431 cout <<
"basis function order must be >= " << oMin;
434 cout <<
" and <= " << oMax;
437 cout <<
"enter new basis function order --> " << flush;
439 if ( oInt >= oMin && oInt <= (oMax>=0)?oMax:oInt )
446 cout <<
"invalid basis order \"" << oInt <<
"\"." << endl;
451 cout <<
"transformation options:\n";
452 cout <<
"r) reset to reference element\n";
453 cout <<
"u) uniform scaling\n";
456 cout <<
"c) compression\n";
457 cout <<
"s) shear\n";
459 cout <<
"enter transformation type --> " << flush;
464 dType = Deformation::INVALID;
468 cout <<
"enter scaling constant --> " << flush;
469 cin >> defData.uniformScale;
470 if ( defData.uniformScale > 0.0 )
472 dType = Deformation::UNIFORM;
475 else if (tk ==
'c' && !
elemIs1D(eType))
478 cout <<
"enter compression factor --> " << flush;
479 cin >> defData.squeezeFactor;
480 cout <<
"enter compression axis (0-" <<
dim-1 <<
") --> " << flush;
481 cin >> defData.squeezeAxis;
483 if ( defData.squeezeFactor > 0.0 &&
484 (defData.squeezeAxis >= 0 && defData.squeezeAxis <
dim))
486 dType = Deformation::SQUEEZE;
489 else if (tk ==
's' && !
elemIs1D(eType))
492 cout <<
"enter shear vector (components separated by spaces) --> "
495 for (
int i=0; i<
dim; i++)
497 cin >> defData.shearVec[i];
499 cout <<
"enter shear axis (0-" <<
dim-1 <<
") --> " << flush;
500 cin >> defData.shearAxis;
502 if ( defData.shearAxis >= 0 && defData.shearAxis <
dim )
504 dType = Deformation::SHEAR;
511 for (
unsigned int i=0; i<sock.size(); i++)
531 return "QUADRILATERAL";
533 return "TETRAHEDRON";
570 return "Continuous (H1)";
572 return "Continuous Positive (H1)";
574 return "Continuous Serendipity (H1)";
578 return "Raviart-Thomas";
580 return "Discontinuous (L2)";
582 return "Fixed Order Continuous";
584 return "Gaussian Discontinuous";
586 return "Crouzeix-Raviart";
595 return bType ==
'h' || bType ==
'p' || bType ==
'l' || bType ==
'c' ||
602 return bType ==
'h' || bType ==
'p' || bType ==
'n' || bType ==
'r' ||
603 bType ==
'l' || bType ==
'c' || bType ==
'f' || bType ==
'g' ||
610 return bType ==
'h' || bType ==
'p' || bType ==
'n' || bType ==
'r' ||
611 bType ==
'f' || bType ==
'l';
657 if ( dType_ == UNIFORM )
659 v *= data_.uniformScale;
670 v *= data_.uniformScale;
674 v[ data_.squeezeAxis ] /= data_.squeezeFactor;
675 v[(data_.squeezeAxis+1)%2] *= data_.squeezeFactor;
679 v.
Add(v[data_.shearAxis], data_.shearVec);
693 v *= data_.uniformScale;
697 v[ data_.squeezeAxis ] /= data_.squeezeFactor;
698 v[(data_.squeezeAxis+1)%2] *= sqrt(data_.squeezeFactor);
699 v[(data_.squeezeAxis+2)%2] *= sqrt(data_.squeezeFactor);
703 v.
Add(v[data_.shearAxis], data_.shearVec);
713 Deformation::DefType dType,
const DeformationData & defData,
714 bool visualization,
int &onlySome,
int visport)
723 cerr <<
"\nProblem with meshstream object\n" << endl;
727 mesh =
new Mesh(imesh, 1, 1);
730 if ( dType != Deformation::INVALID )
732 Deformation defCoef(
dim, dType, defData);
779 else if ( bOrder == 2 )
783 else if ( bOrder == 3 )
793 else if ( bOrder == 2 )
814 int offx = vwl.w+10,
offy = vwl.h+45;
816 for (
unsigned int i=0; i<sock.size(); i++)
818 *sock[i] <<
"keys q";
823 for (
int i=0; i<ndof; i++)
829 for (
int i=0; i<ndof; i++)
835 (*x[i])(-1-vdofs[i]) = -1.0;
839 (*x[i])(vdofs[i]) = 1.0;
845 if ( bType ==
'n' ) { exOrder++; }
846 if ( bType ==
'r' ) { exOrder += 2; }
847 while ( 1<<ref < bOrder + exOrder || ref == 0 )
852 for (
int i=0; i<ndof; i++)
860 if (ndof > 25 && onlySome == -1)
863 cout <<
"There are more than 25 windows to open.\n"
864 <<
"Only showing Dofs 1-10 to avoid crashing.\n"
865 <<
"Use the option -only N to show Dofs N to N+9 instead.\n";
868 for (
int i = 0; i < stopAt; i++)
870 if (i ==0 && onlySome > 0 && onlySome <ndof)
873 stopAt = min(ndof,onlySome+9);
877 oss <<
"DoF " << i + 1;
881 (i % vwl.nx) *
offx, ((i / vwl.nx) % vwl.ny) *
offy,
887 for (
int i=0; i<ndof; i++)
@ GaussLegendre
Open type.
Crouzeix-Raviart nonconforming elements in 2D.
Piecewise-(bi)cubic continuous finite elements.
Type
Constants for the classes derived from Element.
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...
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indices of degrees of freedom for the i'th element. The returned indices are offsets into an ...
virtual void Update(bool want_transform=true)
Reflect changes in the mesh: update number of DOFs, etc. Also, calculate GridFunction transformation ...
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
Version of LinearDiscont2DFECollection with dofs in the Gaussian points.
Version of QuadraticDiscont2DFECollection with dofs in the Gaussian points.
Class for grid function - Vector with associated FE space.
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Arbitrary order H1-conforming (continuous) finite elements with positive basis functions.
Arbitrary order H1-conforming (continuous) finite elements.
Class for integration point with weight.
Arbitrary order "L2-conforming" discontinuous finite elements.
Piecewise-(bi/tri)linear continuous finite elements.
int Dimension() const
Dimension of the reference space used within the elements.
void Transform(void(*f)(const Vector &, Vector &))
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Arbitrary order H(curl)-conforming Nedelec finite elements.
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.
Piecewise-(bi)quadratic continuous finite elements.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
Base class for vector Coefficients that optionally depend on time and space.
virtual void Eval(Vector &V, ElementTransformation &T, const IntegrationPoint &ip)=0
Evaluate the vector coefficient in the element described by T at the point ip, storing the result in ...
void SetSize(int s)
Resize the vector to size s.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
string elemTypeStr(const Element::Type &eType)
int update_basis(vector< socketstream * > &sock, const VisWinLayout &vwl, Element::Type e, char bType, int bOrder, int mType, Deformation::DefType dType, const DeformationData &defData, bool visualization, int &onlySome, int visport=19916)
string mapTypeStr(int mType)
bool elemIs2D(const Element::Type &eType)
string basisTypeStr(char bType)
bool basisIs2D(char bType)
bool basisIs3D(char bType)
bool elemIs3D(const Element::Type &eType)
bool basisIs1D(char bType)
bool elemIs1D(const Element::Type &eType)
void VisualizeField(socketstream &sock, const char *vishost, int visport, GridFunction &gf, const char *title, int x, int y, int w, int h, const char *keys, bool vec)
real_t u(const Vector &xvec)