35 #include "../common/mfem-common.hpp"
51 v(0) =
p(0) + s*
p(1) + s*
p(2);
52 v(1) =
p(1) + s*
p(2) + s*
p(0);
55 else if (p.
Size() == 2)
71 const double x =
p(0), y =
p(1);
73 return std::max(std::max(x - 0.25, -y), y - 1.0);
80 double y = p.
Size() > 1 ?
p(1) : 0.0;
81 double z = p.
Size() > 2 ?
p(2) : 0.0;
86 const double r_big = 2.0;
87 const double r_small = 1.0;
88 return hypot(r_big - hypot(x, y), z) - r_small;
94 return hypot(hypot(x, y), z) - r;
105 for (
int p = 0;
p < np;
p++)
108 fname << mesh_prefix <<
'.' << setfill(
'0') << setw(6) <<
p;
112 cerr <<
"Can not open mesh file: " << fname.str().c_str()
114 for (p--; p >= 0; p--)
116 delete mesh_array[
p];
120 mesh_array[
p] =
new Mesh(meshin, 1, 0);
122 for (
int i = 0; i < mesh_array[
p]->GetNE(); i++)
126 for (
int i = 0; i < mesh_array[
p]->GetNBE(); i++)
128 bdr_partitioning.
Append(p);
131 mesh =
new Mesh(mesh_array, np);
133 for (
int p = 0;
p < np;
p++)
135 delete mesh_array[np-1-
p];
149 for (
int i = 0; i < mesh->
GetNBE(); i++)
154 for (
int j = 0; j < nv; j++)
160 for (
int i = 0; i < v2v.
Size(); i++)
174 for (
int i = 0; i < v2v.
Size(); i++)
186 for (
int i = 0; i < mesh->
GetNBE(); i++)
192 for (
int j = 0; j < nv; j++)
220 if (dynamic_cast<const H1_FECollection*>(fec))
234 for (
int i=0; i<mesh->
GetNBE(); i++)
237 mesh->
GetNodes()->GetSubVector(vdofs, v);
239 fes_copy->GetElementVDofs(i, bvdofs);
245 cout <<
"\nDiscontinuous nodes not yet supported" << endl;
257 for (
int be = 0; be < mesh->
GetNBE(); be++)
260 bdr_partitioning[be] = partitioning[e];
264 int main (
int argc,
char *argv[])
267 const char *mesh_file =
"../../data/beam-hex.mesh";
271 args.
AddOption(&mesh_file,
"-m",
"--mesh",
272 "Mesh file to visualize.");
274 "Load mesh from multiple processors.");
275 args.
AddOption(&refine,
"-ref",
"--refinement",
"-no-ref",
"--no-refinement",
276 "Prepare the mesh for refinement or not.");
285 cout <<
"Visualize and manipulate a serial mesh:\n"
286 <<
" mesh-explorer -m <mesh_file>\n"
287 <<
"Visualize and manipulate a parallel mesh:\n"
288 <<
" mesh-explorer -np <#proc> -m <mesh_prefix>\n" << endl
296 Mesh *bdr_mesh = NULL;
299 const bool use_par_mesh = np > 0;
306 mesh =
new Mesh(mesh_file, 1, refine);
310 bdr_partitioning = 0;
314 mesh =
read_par_mesh(np, mesh_file, partitioning, bdr_partitioning);
342 cout <<
"boundary attribs :";
347 cout <<
'\n' <<
"material attribs :";
353 cout <<
"mesh curvature : ";
360 cout <<
"NONE" << endl;
365 cout <<
"What would you like to do?\n"
367 "c) Change curvature\n"
372 "P) View partitioning\n"
373 "m) View materials\n"
375 "B) View boundary partitioning\n"
377 "h) View element sizes, h\n"
378 "k) View element ratios, kappa\n"
379 "J) View scaled Jacobian\n"
380 "l) Plot a function\n"
381 "x) Print sub-element stats\n"
382 "f) Find physical point in reference space\n"
383 "p) Generate a partitioning\n"
384 "o) Reorder elements\n"
385 "S) Save in MFEM format\n"
386 "V) Save in VTK format (only linear and quadratic meshes)\n"
389 "Z) Save in MFEM format with compression\n"
404 "Choose type of refinement:\n"
405 "s) standard refinement with Mesh::UniformRefinement()\n"
406 "b) Mesh::UniformRefinement() (bisection for tet meshes)\n"
407 "u) uniform refinement with a factor\n"
408 "g) non-uniform refinement (Gauss-Lobatto) with a factor\n"
409 "l) refine locally using the region() function\n"
426 cout <<
"enter refinement factor --> " << flush;
429 if (ref_factor <= 1 || ref_factor > 32) {
break; }
439 for (
int i = 0; i < mesh->
GetNE(); i++)
449 marked_elements.
Append(i);
464 cout <<
"enter new order for mesh curvature --> " << flush;
473 cout <<
"scaling factor ---> " << flush;
479 for (
int i = 0; i < mesh->
GetNV(); i++)
501 cout <<
"Choose a transformation:\n"
502 "u) User-defined transform through mesh-explorer::transformation()\n"
503 "k) Kershaw transform\n"<<
"---> " << flush;
509 else if (type ==
'k')
511 cout <<
"Note: For Kershaw transformation, the input must be "
512 "Cartesian aligned with nx multiple of 6 and "
513 "both ny and nz multiples of 2."
514 "Kershaw transform works for 2D meshes also.\n" << flush;
516 double epsy, epsz = 0.0;
517 cout <<
"Kershaw transform factor, epsy in (0, 1]) ---> " << flush;
521 cout <<
"Kershaw transform factor, epsz in (0, 1]) ---> " << flush;
529 MFEM_ABORT(
"Transformation type not supported.");
537 cout <<
"jitter factor ---> " << flush;
544 cerr <<
"The mesh should have nodes, introduce curvature first!\n";
560 for (
int i = 0; i < fespace->
GetNE(); i++)
563 for (
int j = 0; j < dofs.
Size(); j++)
571 for (
int i = 0; i < fespace->
GetNDofs(); i++)
573 for (
int d = 0; d <
dim; d++)
580 cout <<
"move boundary nodes? [y/n] ---> " << flush;
587 for (
int i = 0; i < fespace->
GetNBE(); i++)
590 for (
int j = 0; j < vdofs.
Size(); j++)
607 double min_det_J, max_det_J, min_det_J_z, max_det_J_z;
608 double min_kappa, max_kappa, max_ratio_det_J_z;
610 max_det_J = max_kappa = max_ratio_det_J_z = -
infinity();
611 cout <<
"subdivision factor ---> " << flush;
614 bad_elems_by_geom = 0;
616 const int max_to_print = 10;
617 for (
int i = 0; i < mesh->
GetNE(); i++)
632 double det_J = J.
Det();
636 min_det_J_z = fmin(min_det_J_z, det_J);
637 max_det_J_z = fmax(max_det_J_z, det_J);
639 min_kappa = fmin(min_kappa, kappa);
640 max_kappa = fmax(max_kappa, kappa);
643 fmax(max_ratio_det_J_z, max_det_J_z/min_det_J_z);
644 min_det_J = fmin(min_det_J, min_det_J_z);
645 max_det_J = fmax(max_det_J, max_det_J_z);
646 if (min_det_J_z <= 0.0)
648 if (nz < max_to_print)
652 cout <<
"det(J) < 0 = " << min_det_J_z <<
" in element "
653 << i <<
", centered at: ";
657 bad_elems_by_geom[geom]++;
660 if (nz >= max_to_print)
662 cout <<
"det(J) < 0 for " << nz - max_to_print <<
" more elements "
665 cout <<
"\nbad elements = " << nz;
671 cout <<
"\nmin det(J) = " << min_det_J
672 <<
"\nmax det(J) = " << max_det_J
673 <<
"\nglobal ratio = " << max_det_J/min_det_J
674 <<
"\nmax el ratio = " << max_ratio_det_J_z
675 <<
"\nmin kappa = " << min_kappa
676 <<
"\nmax kappa = " << max_kappa << endl;
682 cout <<
"\npoint in physical space ---> " << flush;
683 for (
int i = 0; i < sdim; i++)
685 cin >> point_mat(i,0);
693 cout <<
"point in reference space:";
694 if (elem_ids[0] == -1)
696 cout <<
" NOT FOUND!\n";
700 cout <<
" element " << elem_ids[0] <<
", ip =";
701 cout <<
" " << ips[0].x;
704 cout <<
" " << ips[0].y;
707 cout <<
" " << ips[0].z;
716 cout <<
"What type of reordering?\n"
717 "g) Gecko edge-product minimization\n"
718 "h) Hilbert spatial sort\n"
731 int outer, inner, window, period;
732 cout <<
"Enter number of outer iterations (default 5): " << flush;
734 cout <<
"Enter number of inner iterations (default 4): " << flush;
736 cout <<
"Enter window size (default 4, beware of exponential cost): "
739 cout <<
"Enter period for window size increment (default 2): "
744 for (
int i = 0; i < outer; i++)
748 tentative, inner, window, period, seed,
true);
750 if (cost < best_cost)
752 ordering = tentative;
756 cout <<
"Final cost: " << best_cost << endl;
763 if (mk ==
'm' || mk ==
'b' || mk ==
'e' || mk ==
'v' || mk ==
'h' ||
764 mk ==
'k' || mk ==
'J' || mk ==
'p' || mk ==
'B' || mk ==
'P')
774 for (
int i = 0; i < mesh->
GetNE(); i++)
782 for (
int i = 0; i < mesh->
GetNE(); i++)
784 attr(i) = partitioning[i] + 1;
788 if (mk ==
'b' || mk ==
'B')
796 bdr_attr.
SetSpace(bdr_attr_fespace);
799 for (
int i = 0; i < bdr_mesh->
GetNE(); i++)
806 for (
int i = 0; i < bdr_mesh->
GetNE(); i++)
808 bdr_attr(i) = bdr_partitioning[i] + 1;
813 MFEM_WARNING(
"Unimplemented case.");
818 MFEM_WARNING(
"Unsupported mesh dimension.");
832 double a = double(rand()) / (double(RAND_MAX) + 1.);
833 int el0 = (int)floor(a * mesh->
GetNE());
834 cout <<
"Generating coloring starting with element " << el0+1
835 <<
" / " << mesh->
GetNE() << endl;
837 for (
int i = 0; i < coloring.
Size(); i++)
839 attr(i) = coloring[i];
841 cout <<
"Number of colors: " << attr.
Max() + 1 << endl;
842 for (
int i = 0; i < mesh->
GetNE(); i++)
854 for (
int i = 0; i < mesh->
GetNE(); i++)
864 attr(i) = -pow(-attr(i), 1.0/
double(dim));
868 attr(i) = pow(attr(i), 1.0/
double(dim));
870 h_min = min(h_min, attr(i));
871 h_max = max(h_max, attr(i));
873 cout <<
"h_min = " << h_min <<
", h_max = " << h_max << endl;
879 for (
int i = 0; i < mesh->
GetNE(); i++)
897 cout <<
"subdivision factor ---> " << flush;
899 for (
int i = 0; i < mesh->
GetNE(); i++)
918 for (
int k = 0; k < J.
Width(); k++)
926 attr(i) = fmin(sJ, attr(i));
933 cout <<
"What type of partitioning?\n"
935 "s) Simple 1D split of the element sequence\n"
936 "0) METIS_PartGraphRecursive (sorted neighbor lists)\n"
937 "1) METIS_PartGraphKway (sorted neighbor lists)"
939 "2) METIS_PartGraphVKway (sorted neighbor lists)\n"
940 "3) METIS_PartGraphRecursive\n"
941 "4) METIS_PartGraphKway\n"
942 "5) METIS_PartGraphVKway\n"
949 cout <<
"Enter nx: " << flush;
950 cin >> nxyz[0]; np = nxyz[0];
953 cout <<
"Enter ny: " << flush;
954 cin >> nxyz[1]; np *= nxyz[1];
957 cout <<
"Enter nz: " << flush;
958 cin >> nxyz[2]; np *= nxyz[2];
966 cout <<
"Enter number of processors: " << flush;
970 for (
int i = 0; i < mesh->
GetNE(); i++)
972 partitioning[i] = i * np / mesh->
GetNE();
978 int part_method = pk -
'0';
979 if (part_method < 0 || part_method > 5)
983 cout <<
"Enter number of processors: " << flush;
991 const char part_file[] =
"partitioning.txt";
992 ofstream opart(part_file);
993 opart <<
"number_of_elements " << mesh->
GetNE() <<
'\n'
994 <<
"number_of_processors " << np <<
'\n';
995 for (
int i = 0; i < mesh->
GetNE(); i++)
997 opart << partitioning[i] <<
'\n';
999 cout <<
"Partitioning file: " << part_file << endl;
1003 for (
int i = 0; i < mesh->
GetNE(); i++)
1005 proc_el[partitioning[i]]++;
1007 int min_el = proc_el[0], max_el = proc_el[0];
1008 for (
int i = 1; i < np; i++)
1010 if (min_el > proc_el[i])
1012 min_el = proc_el[i];
1014 if (max_el < proc_el[i])
1016 max_el = proc_el[i];
1019 cout <<
"Partitioning stats:\n"
1021 << setw(12) <<
"minimum"
1022 << setw(12) <<
"average"
1023 << setw(12) <<
"maximum"
1024 << setw(12) <<
"total" <<
'\n';
1025 cout <<
" elements "
1026 << setw(12) << min_el
1027 << setw(12) << double(mesh->
GetNE())/np
1028 << setw(12) << max_el
1029 << setw(12) << mesh->
GetNE() << endl;
1036 for (
int i = 0; i < mesh->
GetNE(); i++)
1038 attr(i) = partitioning[i] + 1;
1047 sol_sock.precision(14);
1050 sol_sock <<
"fem2d_gf_data_keys\n";
1053 mesh->
Print(sol_sock);
1060 mesh->
Print(sol_sock);
1061 for (
int i = 0; i < mesh->
GetNE(); i++)
1063 attr(i) = partitioning[i];
1071 attr.
Save(sol_sock);
1072 sol_sock <<
"RjlmAb***********";
1084 sol_sock <<
"fem3d_gf_data_keys\n";
1085 if (mk ==
'v' || mk ==
'h' || mk ==
'k' || mk ==
'J')
1087 mesh->
Print(sol_sock);
1089 else if (mk ==
'b' || mk ==
'B')
1091 bdr_mesh->
Print(sol_sock);
1092 bdr_attr.
Save(sol_sock);
1093 sol_sock <<
"mcaaA";
1095 sol_sock <<
"pppppp" <<
"pppppp" <<
"pppppp";
1102 mesh->
Print(sol_sock);
1103 for (
int i = 0; i < mesh->
GetNE(); i++)
1105 attr(i) = partitioning[i];
1113 if (mk !=
'b' && mk !=
'B')
1115 attr.
Save(sol_sock);
1131 cout <<
"Unable to connect to "
1132 << vishost <<
':' << visport << endl;
1134 delete attr_fespace;
1135 delete bdr_attr_fespace;
1143 cout <<
"Enter projection space order: " << flush;
1164 sol_sock.precision(14);
1165 sol_sock <<
"solution\n" << *mesh << level << flush;
1169 cout <<
"Unable to connect to "
1170 << vishost <<
':' << visport << endl;
1177 const char omesh_file[] =
"mesh-explorer.mesh";
1178 ofstream omesh(omesh_file);
1179 omesh.precision(14);
1181 cout <<
"New mesh file: " << omesh_file << endl;
1186 const char omesh_file[] =
"mesh-explorer.vtk";
1187 ofstream omesh(omesh_file);
1188 omesh.precision(14);
1190 cout <<
"New VTK mesh file: " << omesh_file << endl;
1193 #ifdef MFEM_USE_ZLIB
1196 const char omesh_file[] =
"mesh-explorer.mesh.gz";
1198 omesh.precision(14);
1200 cout <<
"New mesh file: " << omesh_file << endl;
1206 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.
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 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 PrintCharacteristics(Vector *Vh=NULL, Vector *Vk=NULL, std::ostream &os=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.
void MakeOwner(FiniteElementCollection *fec_)
Make the GridFunction the owner of fec and fes.
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)
Geometry::Type GetElementBaseGeometry(int i) const
void DeleteAll()
Delete the whole array.
Mesh * skin_mesh(Mesh *mesh)
DofTransformation * GetBdrElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom for i'th boundary element.
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)
void PrintWithPartitioning(int *partitioning, std::ostream &os, int elem_attr=0) const
Prints the mesh with boundary elements given by the boundary of the subdomains, so that the boundary ...
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 ...
void PrintVTK(std::ostream &os)
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()
virtual DofTransformation * GetElementDofs(int elem, Array< int > &dofs) const
Returns indices of degrees of freedom of element 'elem'.
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.
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 Print(std::ostream &os=mfem::out) 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...
Nodes: x_i = i/(n-1), i=0,...,n-1.
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 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)
bool Good() const
Return true if the command line options were parsed successfully.