50 v(0) = p(0) + s*p(1) + s*p(2);
51 v(1) = p(1) + s*p(2) + s*p(0);
54 else if (p.
Size() == 2)
70 const double x = p(0), y = p(1);
72 return std::max(std::max(x - 0.25, -y), y - 1.0);
81 for (
int p = 0; p < np; p++)
84 fname << mesh_prefix <<
'.' << setfill(
'0') << setw(6) << p;
88 cerr <<
"Can not open mesh file: " << fname.str().c_str()
90 for (p--; p >= 0; p--)
96 mesh_array[p] =
new Mesh(meshin, 1, 0);
100 for (
int i = 0; i < mesh_array[p]->GetNE(); i++)
102 mesh_array[p]->GetElement(i)->SetAttribute(p+1);
104 for (
int i = 0; i < mesh_array[p]->GetNBE(); i++)
106 mesh_array[p]->GetBdrElement(i)->SetAttribute(p+1);
110 mesh =
new Mesh(mesh_array, np);
112 for (
int p = 0; p < np; p++)
114 delete mesh_array[np-1-p];
121 int main (
int argc,
char *argv[])
124 const char *mesh_file =
"../../data/beam-hex.mesh";
128 args.
AddOption(&mesh_file,
"-m",
"--mesh",
129 "Mesh file to visualize.");
131 "Load mesh from multiple processors.");
132 args.
AddOption(&refine,
"-ref",
"--refinement",
"-no-ref",
"--no-refinement",
133 "Prepare the mesh for refinement or not.");
142 cout <<
"Visualize and manipulate a serial mesh:\n"
143 <<
" mesh-explorer -m <mesh_file>\n"
144 <<
"Visualize and manipulate a parallel mesh:\n"
145 <<
" mesh-explorer -np <#proc> -m <mesh_prefix>\n" << endl
155 mesh =
new Mesh(mesh_file, 1, refine);
185 cout <<
"boundary attribs :";
190 cout <<
'\n' <<
"material attribs :";
196 cout <<
"mesh curvature : ";
203 cout <<
"NONE" << endl;
208 cout <<
"What would you like to do?\n"
211 "c) Change curvature\n"
216 "m) View materials\n"
219 "h) View element sizes, h\n"
220 "k) View element ratios, kappa\n"
221 "x) Print sub-element stats\n"
222 "f) Find physical point in reference space\n"
223 "p) Generate a partitioning\n"
224 "S) Save in MFEM format\n"
225 "V) Save in VTK format (only linear and quadratic meshes)\n"
226 #ifdef MFEM_USE_GZSTREAM
227 "Z) Save in MFEM format with compression\n"
242 "Choose type of refinement:\n"
243 "s) standard refinement with Mesh::UniformRefinement()\n"
244 "b) Mesh::UniformRefinement() (bisection for tet meshes)\n"
245 "u) uniform refinement with a factor\n"
246 "g) non-uniform refinement (Gauss-Lobatto) with a factor\n"
247 "l) refine locally using the region() function\n"
264 cout <<
"enter refinement factor --> " << flush;
267 if (ref_factor <= 1 || ref_factor > 32) {
break; }
270 Mesh *rmesh =
new Mesh(mesh, ref_factor, ref_type);
279 for (
int i = 0; i < mesh->
GetNE(); i++)
289 marked_elements.
Append(i);
304 cout <<
"enter new order for mesh curvature --> " << flush;
313 cout <<
"scaling factor ---> " << flush;
319 for (
int i = 0; i < mesh->
GetNV(); i++)
347 cout <<
"jitter factor ---> " << flush;
354 cerr <<
"The mesh should have nodes, introduce curvature first!\n";
370 for (
int i = 0; i < fespace->
GetNE(); i++)
373 for (
int j = 0; j < dofs.
Size(); j++)
381 for (
int i = 0; i < fespace->
GetNDofs(); i++)
383 for (
int d = 0; d <
dim; d++)
390 cout <<
"move boundary nodes? [y/n] ---> " << flush;
397 for (
int i = 0; i < fespace->
GetNBE(); i++)
400 for (
int j = 0; j < vdofs.
Size(); j++)
417 double min_det_J, max_det_J, min_det_J_z, max_det_J_z;
418 double min_kappa, max_kappa, max_ratio_det_J_z;
420 max_det_J = max_kappa = max_ratio_det_J_z = -
infinity();
421 cout <<
"subdivision factor ---> " << flush;
424 bad_elems_by_geom = 0;
425 for (
int i = 0; i < mesh->
GetNE(); i++)
440 double det_J = J.
Det();
444 min_det_J_z = fmin(min_det_J_z, det_J);
445 max_det_J_z = fmax(max_det_J_z, det_J);
447 min_kappa = fmin(min_kappa, kappa);
448 max_kappa = fmax(max_kappa, kappa);
451 fmax(max_ratio_det_J_z, max_det_J_z/min_det_J_z);
452 min_det_J = fmin(min_det_J, min_det_J_z);
453 max_det_J = fmax(max_det_J, max_det_J_z);
454 if (min_det_J_z <= 0.0)
457 bad_elems_by_geom[
geom]++;
460 cout <<
"\nbad elements = " << nz;
466 cout <<
"\nmin det(J) = " << min_det_J
467 <<
"\nmax det(J) = " << max_det_J
468 <<
"\nglobal ratio = " << max_det_J/min_det_J
469 <<
"\nmax el ratio = " << max_ratio_det_J_z
470 <<
"\nmin kappa = " << min_kappa
471 <<
"\nmax kappa = " << max_kappa << endl;
477 cout <<
"\npoint in physical space ---> " << flush;
478 for (
int i = 0; i < sdim; i++)
480 cin >> point_mat(i,0);
488 cout <<
"point in reference space:";
489 if (elem_ids[0] == -1)
491 cout <<
" NOT FOUND!\n";
495 cout <<
" element " << elem_ids[0] <<
", ip =";
496 cout <<
" " << ips[0].x;
499 cout <<
" " << ips[0].y;
502 cout <<
" " << ips[0].z;
510 if (mk ==
'm' || mk ==
'b' || mk ==
'e' || mk ==
'v' || mk ==
'h' ||
511 mk ==
'k' || mk ==
'p')
519 for (
int i = 0; i < mesh->
GetNE(); i++)
524 if (mk ==
'b' || mk ==
'v')
533 double a = double(rand()) / (double(RAND_MAX) + 1.);
534 int el0 = (int)floor(a * mesh->
GetNE());
535 cout <<
"Generating coloring starting with element " << el0+1
536 <<
" / " << mesh->
GetNE() << endl;
538 for (
int i = 0; i < coloring.
Size(); i++)
540 attr(i) = coloring[i];
542 cout <<
"Number of colors: " << attr.
Max() + 1 << endl;
543 for (
int i = 0; i < mesh->
GetNE(); i++)
546 attr(i) = part[i] = i;
556 for (
int i = 0; i < mesh->
GetNE(); i++)
566 attr(i) = -pow(-attr(i), 1.0/
double(dim));
570 attr(i) = pow(attr(i), 1.0/
double(dim));
572 h_min = min(h_min, attr(i));
573 h_max = max(h_max, attr(i));
575 cout <<
"h_min = " << h_min <<
", h_max = " << h_max << endl;
581 for (
int i = 0; i < mesh->
GetNE(); i++)
593 int *partitioning = NULL, n;
594 cout <<
"What type of partitioning?\n"
596 "0) METIS_PartGraphRecursive (sorted neighbor lists)\n"
597 "1) METIS_PartGraphKway (sorted neighbor lists)"
599 "2) METIS_PartGraphVKway (sorted neighbor lists)\n"
600 "3) METIS_PartGraphRecursive\n"
601 "4) METIS_PartGraphKway\n"
602 "5) METIS_PartGraphVKway\n"
609 cout <<
"Enter nx: " << flush;
610 cin >> nxyz[0]; n = nxyz[0];
613 cout <<
"Enter ny: " << flush;
614 cin >> nxyz[1]; n *= nxyz[1];
617 cout <<
"Enter nz: " << flush;
618 cin >> nxyz[2]; n *= nxyz[2];
625 int part_method = pk -
'0';
626 if (part_method < 0 || part_method > 5)
630 cout <<
"Enter number of processors: " << flush;
636 const char part_file[] =
"partitioning.txt";
637 ofstream opart(part_file);
638 opart <<
"number_of_elements " << mesh->
GetNE() <<
'\n'
639 <<
"number_of_processors " << n <<
'\n';
640 for (
int i = 0; i < mesh->
GetNE(); i++)
642 opart << partitioning[i] <<
'\n';
644 cout <<
"Partitioning file: " << part_file << endl;
648 for (
int i = 0; i < mesh->
GetNE(); i++)
650 proc_el[partitioning[i]]++;
652 int min_el = proc_el[0], max_el = proc_el[0];
653 for (
int i = 1; i < n; i++)
655 if (min_el > proc_el[i])
659 if (max_el < proc_el[i])
664 cout <<
"Partitioning stats:\n"
666 << setw(12) <<
"minimum"
667 << setw(12) <<
"average"
668 << setw(12) <<
"maximum"
669 << setw(12) <<
"total" <<
'\n';
671 << setw(12) << min_el
672 << setw(12) << double(mesh->
GetNE())/n
673 << setw(12) << max_el
674 << setw(12) << mesh->
GetNE() << endl;
681 for (
int i = 0; i < mesh->
GetNE(); i++)
683 attr(i) = part[i] = partitioning[i];
685 delete [] partitioning;
688 char vishost[] =
"localhost";
693 sol_sock.precision(14);
696 sol_sock <<
"fem2d_gf_data_keys\n";
699 mesh->
Print(sol_sock);
706 mesh->
Print(sol_sock);
707 for (
int i = 0; i < mesh->
GetNE(); i++)
718 sol_sock <<
"RjlmAb***********";
730 sol_sock <<
"fem3d_gf_data_keys\n";
731 if (mk ==
'b' || mk ==
'v' || mk ==
'h' || mk ==
'k')
733 mesh->
Print(sol_sock);
740 mesh->
Print(sol_sock);
741 for (
int i = 0; i < mesh->
GetNE(); i++)
766 cout <<
"Unable to connect to "
767 << vishost <<
':' << visport << endl;
774 const char mesh_file[] =
"mesh-explorer.mesh";
775 ofstream omesh(mesh_file);
778 cout <<
"New mesh file: " << mesh_file << endl;
783 const char mesh_file[] =
"mesh-explorer.vtk";
784 ofstream omesh(mesh_file);
787 cout <<
"New VTK mesh file: " << mesh_file << endl;
790 #ifdef MFEM_USE_GZSTREAM
793 const char mesh_file[] =
"mesh-explorer.mesh.gz";
797 cout <<
"New mesh file: " << mesh_file << endl;
int GetNPoints() const
Returns the number of the points in the integration rule.
int Size() const
Logical size of the array.
virtual void Print(std::ostream &out=mfem::out) const
int * CartesianPartitioning(int nxyz[])
int GetNDofs() const
Returns number of degrees of freedom.
Class for an integration rule - an Array of IntegrationPoint.
const double * GetVertex(int i) const
Return pointer to vertex i's coordinates.
Class for grid function - Vector with associated FE space.
int DofToVDof(int dof, int vd, int ndofs=-1) const
Mesh * read_par_mesh(int np, const char *mesh_prefix)
static void PrintElementsByGeometry(int dim, const Array< int > &num_elems_by_geom, std::ostream &out)
Auxiliary method used by PrintCharacteristics().
void JacToPerfJac(int GeomType, const DenseMatrix &J, DenseMatrix &PJ) const
int * GeneratePartitioning(int nparts, int part_method=1)
void PrintWithPartitioning(int *partitioning, std::ostream &out, int elem_attr=0) const
Prints the mesh with boundary elements given by the boundary of the subdomains, so that the boundary ...
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
Data type dense matrix using column-major storage.
int Size() const
Returns the size of the vector.
void Transform(void(*f)(const Vector &, Vector &))
int GetNE() const
Returns number of elements.
void PrintHelp(std::ostream &out) const
void Randomize(int seed=0)
Set random values in the vector.
const IntegrationPoint & GetCenter(int GeomType)
Return the center of the given Geometry::Type, GeomType.
int main(int argc, char *argv[])
Geometry::Type GetElementBaseGeometry(int i) const
void DeleteAll()
Delete whole array.
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
int GetNE() const
Returns number of elements in the mesh.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
int GetNBE() const
Returns number of boundary elements in the mesh.
int Append(const T &el)
Append element to array, resize if necessary.
void transformation(const Vector &p, Vector &v)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
virtual void GetElementDofs(int i, Array< int > &dofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
GeometryRefiner GlobGeometryRefiner
RefinedGeometry * Refine(Geometry::Type Geom, int Times, int ETimes=1)
FiniteElementSpace * FESpace()
double GetElementSize(int i, int type=0)
Get the size of the i-th element relative to the perfect reference element.
int SpaceDimension() const
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void PrintVTK(std::ostream &out)
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 SetSize(int nsize)
Change logical size of the array, keep existing entries.
void GetColumnReference(int c, Vector &col)
Nodes: x_i = i/(n-1), i=0,...,n-1.
NURBSExtension * NURBSext
Optional NURBS mesh extension.
int GetNV() const
Returns number of vertices. Vertices are only at the corners of elements, where you would expect them...
void PrintError(std::ostream &out) const
virtual const char * Name() const
void GetElementTransformation(int i, IsoparametricTransformation *ElTr)
double Max() const
Returns the maximal element of the vector.
const FiniteElementSpace * GetNodalFESpace() const
virtual void Finalize(bool refine=false, bool fix_orientation=false)
Finalize the construction of a general Mesh.
void PrintOptions(std::ostream &out) const
double CalcSingularvalue(const int i) const
Return the i-th singular value (decreasing order) of NxN matrix, N=1,2,3.
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
virtual int FindPoints(DenseMatrix &point_mat, Array< int > &elem_ids, Array< IntegrationPoint > &ips, bool warn=true, InverseElementTransformation *inv_trans=NULL)
Find the ids of the elements that contain the given points, and their corresponding reference coordin...
const FiniteElementCollection * FEColl() const
void GetNodes(Vector &node_coord) const
void GetElementColoring(Array< int > &colors, int el0=0)
void GetBdrElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom for i'th boundary element.
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
double region(const Vector &p)
int GetAttribute(int i) const
Return the attribute of element i.
Array< int > attributes
A list of all unique element attributes used by the Mesh.
void PrintCharacteristics(Vector *Vh=NULL, Vector *Vk=NULL, std::ostream &out=mfem::out)
Compute and print mesh characteristics such as number of vertices, number of elements, number of boundary elements, minimal and maximal element sizes, minimal and maximal element aspect ratios, etc.