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);
79 double y = p.
Size() > 1 ?
p(1) : 0.0;
80 double z = p.
Size() > 2 ?
p(2) : 0.0;
85 const double r_big = 2.0;
86 const double r_small = 1.0;
87 return hypot(r_big - hypot(x, y), z) - r_small;
93 return hypot(hypot(x, y), z) - r;
104 for (
int p = 0;
p < np;
p++)
107 fname << mesh_prefix <<
'.' << setfill(
'0') << setw(6) <<
p;
111 cerr <<
"Can not open mesh file: " << fname.str().c_str()
113 for (p--; p >= 0; p--)
115 delete mesh_array[
p];
119 mesh_array[
p] =
new Mesh(meshin, 1, 0);
121 for (
int i = 0; i < mesh_array[
p]->GetNE(); i++)
125 for (
int i = 0; i < mesh_array[
p]->GetNBE(); i++)
127 bdr_partitioning.
Append(p);
130 mesh =
new Mesh(mesh_array, np);
132 for (
int p = 0;
p < np;
p++)
134 delete mesh_array[np-1-
p];
148 for (
int i = 0; i < mesh->
GetNBE(); i++)
153 for (
int j = 0; j < nv; j++)
159 for (
int i = 0; i < v2v.
Size(); i++)
173 for (
int i = 0; i < v2v.
Size(); i++)
185 for (
int i = 0; i < mesh->
GetNBE(); i++)
191 for (
int j = 0; j < nv; j++)
219 if (dynamic_cast<const H1_FECollection*>(fec))
233 for (
int i=0; i<mesh->
GetNBE(); i++)
236 mesh->
GetNodes()->GetSubVector(vdofs, v);
238 fes_copy->GetElementVDofs(i, bvdofs);
244 cout <<
"\nDiscontinuous nodes not yet supported" << endl;
256 for (
int be = 0; be < mesh->
GetNBE(); be++)
259 bdr_partitioning[be] = partitioning[e];
263 int main (
int argc,
char *argv[])
266 const char *mesh_file =
"../../data/beam-hex.mesh";
270 args.
AddOption(&mesh_file,
"-m",
"--mesh",
271 "Mesh file to visualize.");
273 "Load mesh from multiple processors.");
274 args.
AddOption(&refine,
"-ref",
"--refinement",
"-no-ref",
"--no-refinement",
275 "Prepare the mesh for refinement or not.");
284 cout <<
"Visualize and manipulate a serial mesh:\n"
285 <<
" mesh-explorer -m <mesh_file>\n"
286 <<
"Visualize and manipulate a parallel mesh:\n"
287 <<
" mesh-explorer -np <#proc> -m <mesh_prefix>\n" << endl
295 Mesh *bdr_mesh = NULL;
298 const bool use_par_mesh = np > 0;
305 mesh =
new Mesh(mesh_file, 1, refine);
309 bdr_partitioning = 0;
313 mesh =
read_par_mesh(np, mesh_file, partitioning, bdr_partitioning);
341 cout <<
"boundary attribs :";
346 cout <<
'\n' <<
"material attribs :";
352 cout <<
"mesh curvature : ";
359 cout <<
"NONE" << endl;
364 cout <<
"What would you like to do?\n"
366 "c) Change curvature\n"
371 "P) View partitioning\n"
372 "m) View materials\n"
374 "B) View boundary partitioning\n"
376 "h) View element sizes, h\n"
377 "k) View element ratios, kappa\n"
378 "J) View scaled Jacobian\n"
379 "l) Plot a function\n"
380 "x) Print sub-element stats\n"
381 "f) Find physical point in reference space\n"
382 "p) Generate a partitioning\n"
383 "o) Reorder elements\n"
384 "S) Save in MFEM format\n"
385 "V) Save in VTK format (only linear and quadratic meshes)\n"
388 "Z) Save in MFEM format with compression\n"
403 "Choose type of refinement:\n"
404 "s) standard refinement with Mesh::UniformRefinement()\n"
405 "b) Mesh::UniformRefinement() (bisection for tet meshes)\n"
406 "u) uniform refinement with a factor\n"
407 "g) non-uniform refinement (Gauss-Lobatto) with a factor\n"
408 "l) refine locally using the region() function\n"
425 cout <<
"enter refinement factor --> " << flush;
428 if (ref_factor <= 1 || ref_factor > 32) {
break; }
438 for (
int i = 0; i < mesh->
GetNE(); i++)
448 marked_elements.
Append(i);
463 cout <<
"enter new order for mesh curvature --> " << flush;
472 cout <<
"scaling factor ---> " << flush;
478 for (
int i = 0; i < mesh->
GetNV(); i++)
506 cout <<
"jitter factor ---> " << flush;
513 cerr <<
"The mesh should have nodes, introduce curvature first!\n";
529 for (
int i = 0; i < fespace->
GetNE(); i++)
532 for (
int j = 0; j < dofs.
Size(); j++)
540 for (
int i = 0; i < fespace->
GetNDofs(); i++)
542 for (
int d = 0; d <
dim; d++)
549 cout <<
"move boundary nodes? [y/n] ---> " << flush;
556 for (
int i = 0; i < fespace->
GetNBE(); i++)
559 for (
int j = 0; j < vdofs.
Size(); j++)
576 double min_det_J, max_det_J, min_det_J_z, max_det_J_z;
577 double min_kappa, max_kappa, max_ratio_det_J_z;
579 max_det_J = max_kappa = max_ratio_det_J_z = -
infinity();
580 cout <<
"subdivision factor ---> " << flush;
583 bad_elems_by_geom = 0;
585 const int max_to_print = 10;
586 for (
int i = 0; i < mesh->
GetNE(); i++)
601 double det_J = J.
Det();
605 min_det_J_z = fmin(min_det_J_z, det_J);
606 max_det_J_z = fmax(max_det_J_z, det_J);
608 min_kappa = fmin(min_kappa, kappa);
609 max_kappa = fmax(max_kappa, kappa);
612 fmax(max_ratio_det_J_z, max_det_J_z/min_det_J_z);
613 min_det_J = fmin(min_det_J, min_det_J_z);
614 max_det_J = fmax(max_det_J, max_det_J_z);
615 if (min_det_J_z <= 0.0)
617 if (nz < max_to_print)
621 cout <<
"det(J) < 0 = " << min_det_J_z <<
" in element "
622 << i <<
", centered at: ";
626 bad_elems_by_geom[
geom]++;
629 if (nz >= max_to_print)
631 cout <<
"det(J) < 0 for " << nz - max_to_print <<
" more elements "
634 cout <<
"\nbad elements = " << nz;
640 cout <<
"\nmin det(J) = " << min_det_J
641 <<
"\nmax det(J) = " << max_det_J
642 <<
"\nglobal ratio = " << max_det_J/min_det_J
643 <<
"\nmax el ratio = " << max_ratio_det_J_z
644 <<
"\nmin kappa = " << min_kappa
645 <<
"\nmax kappa = " << max_kappa << endl;
651 cout <<
"\npoint in physical space ---> " << flush;
652 for (
int i = 0; i < sdim; i++)
654 cin >> point_mat(i,0);
662 cout <<
"point in reference space:";
663 if (elem_ids[0] == -1)
665 cout <<
" NOT FOUND!\n";
669 cout <<
" element " << elem_ids[0] <<
", ip =";
670 cout <<
" " << ips[0].x;
673 cout <<
" " << ips[0].y;
676 cout <<
" " << ips[0].z;
685 cout <<
"What type of reordering?\n"
686 "g) Gecko edge-product minimization\n"
687 "h) Hilbert spatial sort\n"
700 int outer, inner, window, period;
701 cout <<
"Enter number of outer iterations (default 5): " << flush;
703 cout <<
"Enter number of inner iterations (default 4): " << flush;
705 cout <<
"Enter window size (default 4, beware of exponential cost): "
708 cout <<
"Enter period for window size increment (default 2): "
713 for (
int i = 0; i < outer; i++)
717 tentative, inner, window, period, seed,
true);
719 if (cost < best_cost)
721 ordering = tentative;
725 cout <<
"Final cost: " << best_cost << endl;
732 if (mk ==
'm' || mk ==
'b' || mk ==
'e' || mk ==
'v' || mk ==
'h' ||
733 mk ==
'k' || mk ==
'J' || mk ==
'p' || mk ==
'B' || mk ==
'P')
743 for (
int i = 0; i < mesh->
GetNE(); i++)
751 for (
int i = 0; i < mesh->
GetNE(); i++)
753 attr(i) = partitioning[i] + 1;
757 if (mk ==
'b' || mk ==
'B')
765 bdr_attr.
SetSpace(bdr_attr_fespace);
768 for (
int i = 0; i < bdr_mesh->
GetNE(); i++)
775 for (
int i = 0; i < bdr_mesh->
GetNE(); i++)
777 bdr_attr(i) = bdr_partitioning[i] + 1;
782 MFEM_WARNING(
"Unimplemented case.");
787 MFEM_WARNING(
"Unsupported mesh dimension.");
801 double a = double(rand()) / (double(RAND_MAX) + 1.);
802 int el0 = (int)floor(a * mesh->
GetNE());
803 cout <<
"Generating coloring starting with element " << el0+1
804 <<
" / " << mesh->
GetNE() << endl;
806 for (
int i = 0; i < coloring.
Size(); i++)
808 attr(i) = coloring[i];
810 cout <<
"Number of colors: " << attr.
Max() + 1 << endl;
811 for (
int i = 0; i < mesh->
GetNE(); i++)
823 for (
int i = 0; i < mesh->
GetNE(); i++)
833 attr(i) = -pow(-attr(i), 1.0/
double(dim));
837 attr(i) = pow(attr(i), 1.0/
double(dim));
839 h_min = min(h_min, attr(i));
840 h_max = max(h_max, attr(i));
842 cout <<
"h_min = " << h_min <<
", h_max = " << h_max << endl;
848 for (
int i = 0; i < mesh->
GetNE(); i++)
866 cout <<
"subdivision factor ---> " << flush;
868 for (
int i = 0; i < mesh->
GetNE(); i++)
887 for (
int k = 0; k < J.
Width(); k++)
895 attr(i) = fmin(sJ, attr(i));
902 cout <<
"What type of partitioning?\n"
904 "s) Simple 1D split of the element sequence\n"
905 "0) METIS_PartGraphRecursive (sorted neighbor lists)\n"
906 "1) METIS_PartGraphKway (sorted neighbor lists)"
908 "2) METIS_PartGraphVKway (sorted neighbor lists)\n"
909 "3) METIS_PartGraphRecursive\n"
910 "4) METIS_PartGraphKway\n"
911 "5) METIS_PartGraphVKway\n"
918 cout <<
"Enter nx: " << flush;
919 cin >> nxyz[0]; np = nxyz[0];
922 cout <<
"Enter ny: " << flush;
923 cin >> nxyz[1]; np *= nxyz[1];
926 cout <<
"Enter nz: " << flush;
927 cin >> nxyz[2]; np *= nxyz[2];
935 cout <<
"Enter number of processors: " << flush;
939 for (
int i = 0; i < mesh->
GetNE(); i++)
941 partitioning[i] = i * np / mesh->
GetNE();
947 int part_method = pk -
'0';
948 if (part_method < 0 || part_method > 5)
952 cout <<
"Enter number of processors: " << flush;
960 const char part_file[] =
"partitioning.txt";
961 ofstream opart(part_file);
962 opart <<
"number_of_elements " << mesh->
GetNE() <<
'\n'
963 <<
"number_of_processors " << np <<
'\n';
964 for (
int i = 0; i < mesh->
GetNE(); i++)
966 opart << partitioning[i] <<
'\n';
968 cout <<
"Partitioning file: " << part_file << endl;
972 for (
int i = 0; i < mesh->
GetNE(); i++)
974 proc_el[partitioning[i]]++;
976 int min_el = proc_el[0], max_el = proc_el[0];
977 for (
int i = 1; i < np; i++)
979 if (min_el > proc_el[i])
983 if (max_el < proc_el[i])
988 cout <<
"Partitioning stats:\n"
990 << setw(12) <<
"minimum"
991 << setw(12) <<
"average"
992 << setw(12) <<
"maximum"
993 << setw(12) <<
"total" <<
'\n';
995 << setw(12) << min_el
996 << setw(12) << double(mesh->
GetNE())/np
997 << setw(12) << max_el
998 << setw(12) << mesh->
GetNE() << endl;
1005 for (
int i = 0; i < mesh->
GetNE(); i++)
1007 attr(i) = partitioning[i] + 1;
1016 sol_sock.precision(14);
1019 sol_sock <<
"fem2d_gf_data_keys\n";
1022 mesh->
Print(sol_sock);
1029 mesh->
Print(sol_sock);
1030 for (
int i = 0; i < mesh->
GetNE(); i++)
1032 attr(i) = partitioning[i];
1040 attr.
Save(sol_sock);
1041 sol_sock <<
"RjlmAb***********";
1053 sol_sock <<
"fem3d_gf_data_keys\n";
1054 if (mk ==
'v' || mk ==
'h' || mk ==
'k' || mk ==
'J')
1056 mesh->
Print(sol_sock);
1058 else if (mk ==
'b' || mk ==
'B')
1060 bdr_mesh->
Print(sol_sock);
1061 bdr_attr.
Save(sol_sock);
1062 sol_sock <<
"mcaaA";
1064 sol_sock <<
"pppppp" <<
"pppppp" <<
"pppppp";
1071 mesh->
Print(sol_sock);
1072 for (
int i = 0; i < mesh->
GetNE(); i++)
1074 attr(i) = partitioning[i];
1082 if (mk !=
'b' && mk !=
'B')
1084 attr.
Save(sol_sock);
1100 cout <<
"Unable to connect to "
1101 << vishost <<
':' << visport << endl;
1103 delete attr_fespace;
1104 delete bdr_attr_fespace;
1112 cout <<
"Enter projection space order: " << flush;
1133 sol_sock.precision(14);
1134 sol_sock <<
"solution\n" << *mesh << level << flush;
1138 cout <<
"Unable to connect to "
1139 << vishost <<
':' << visport << endl;
1146 const char mesh_file[] =
"mesh-explorer.mesh";
1147 ofstream omesh(mesh_file);
1148 omesh.precision(14);
1150 cout <<
"New mesh file: " << mesh_file << endl;
1155 const char mesh_file[] =
"mesh-explorer.vtk";
1156 ofstream omesh(mesh_file);
1157 omesh.precision(14);
1159 cout <<
"New VTK mesh file: " << mesh_file << endl;
1162 #ifdef MFEM_USE_ZLIB
1165 const char mesh_file[] =
"mesh-explorer.mesh.gz";
1167 omesh.precision(14);
1169 cout <<
"New mesh file: " << mesh_file << endl;
1175 delete bdr_attr_fec;
int GetNPoints() const
Returns the number of the points in the integration rule.
bool Help() const
Return true if we are flagged to print the help message.
Geometry::Type GetGeometryType() const
double GetGeckoElementOrdering(Array< int > &ordering, int iterations=4, int window=4, int period=2, int seed=0, bool verbose=false, double time_limit=0)
int Size() const
Return the logical size of the array.
void SetSubVector(const Array< int > &dofs, const double value)
Set the entries listed in dofs to the given value.
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
int AddQuad(int v1, int v2, int v3, int v4, int attr=1)
virtual void GetVertices(Array< int > &v) const =0
Returns element's vertices.
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)
int GetNBE() const
Returns number of boundary elements.
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 ...
void NewNodes(GridFunction &nodes, bool make_owner=false)
Replace the internal node GridFunction with the given GridFunction.
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
double Norml2() const
Returns the l2 norm of the vector.
static Mesh MakeRefined(Mesh &orig_mesh, int ref_factor, int ref_type)
Create a refined (by any factor) version of orig_mesh.
int AddTriangle(int v1, int v2, int v3, int attr=1)
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
Print the help message.
void MakeOwner(FiniteElementCollection *fec_)
Make the GridFunction the owner of fec and fes.
virtual void GetElementDofs(int elem, Array< int > &dofs) const
Returns indices of degrees of freedom of element 'elem'.
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.
Mesh * read_par_mesh(int np, const char *mesh_prefix, Array< int > &partitioning, Array< int > &bdr_partitioning)
Nodes: x_i = i/(n-1), i=0,...,n-1.
Geometry::Type GetElementBaseGeometry(int i) const
void DeleteAll()
Delete the whole array.
Mesh * skin_mesh(Mesh *mesh)
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 AddVertex(double x, double y=0.0, double z=0.0)
double f(const Vector &xvec)
double GetElementSize(ElementTransformation *T, int type=0)
int GetNBE() const
Returns number of boundary elements in the mesh.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
int Append(const T &el)
Append element 'el' to array, resize if necessary.
void transformation(const Vector &p, Vector &v)
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
GeometryRefiner GlobGeometryRefiner
int GetAttribute() const
Return element's attribute.
void GetBdrElementAdjacentElement(int bdr_el, int &el, int &info) const
For the given boundary element, bdr_el, return its adjacent element and its info, i...
void GetHilbertElementOrdering(Array< int > &ordering)
Piecewise-constant discontinuous finite elements in 3D. This class is kept only for backward compatib...
void GetElementCenter(int i, Vector ¢er)
RefinedGeometry * Refine(Geometry::Type Geom, int Times, int ETimes=1)
Piecewise-constant discontinuous finite elements in 2D. This class is kept only for backward compatib...
FiniteElementSpace * FESpace()
L2_FECollection DG_FECollection
Declare an alternative name for L2_FECollection = DG_FECollection.
int SpaceDimension() const
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
bool is_open()
True if the socketstream is open, false otherwise.
void PrintVTK(std::ostream &out)
double p(const Vector &x, double t)
int AddSegment(int v1, int v2, int attr=1)
void Print(std::ostream &out=mfem::out, int width=8) const
Prints vector to stream out.
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 FinalizeTopology(bool generate_bdr=true)
Finalize the construction of the secondary topology (connectivity) data of a Mesh.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
void GetColumnReference(int c, Vector &col)
static FiniteElementCollection * New(const char *name)
Factory method: return a newly allocated FiniteElementCollection according to the given name...
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
Print the error message.
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 ReorderElements(const Array< int > &ordering, bool reorder_vertices=true)
void PrintOptions(std::ostream &out) const
Print the options.
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 GetNVertices() const =0
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
virtual void SetSpace(FiniteElementSpace *f)
Associate a new FiniteElementSpace with the GridFunction.
A general function coefficient.
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
Arbitrary order H1-conforming (continuous) finite elements.
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)
Abstract data type element.
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.
const Element * GetBdrElement(int i) const
void recover_bdr_partitioning(const Mesh *mesh, const Array< int > &partitioning, Array< int > &bdr_partitioning)
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.
bool Good() const
Return true if the command line options were parsed successfully.