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;
103 for (
int p = 0;
p < np;
p++)
106 fname << mesh_prefix <<
'.' << setfill(
'0') << setw(6) <<
p;
110 cerr <<
"Can not open mesh file: " << fname.str().c_str()
112 for (p--; p >= 0; p--)
114 delete mesh_array[
p];
118 mesh_array[
p] =
new Mesh(meshin, 1, 0);
122 for (
int i = 0; i < mesh_array[
p]->GetNE(); i++)
124 mesh_array[
p]->GetElement(i)->SetAttribute(p+1);
126 for (
int i = 0; i < mesh_array[
p]->GetNBE(); i++)
128 mesh_array[
p]->GetBdrElement(i)->SetAttribute(p+1);
132 mesh =
new Mesh(mesh_array, np);
134 for (
int p = 0;
p < np;
p++)
136 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;
252 int main (
int argc,
char *argv[])
255 const char *mesh_file =
"../../data/beam-hex.mesh";
259 args.
AddOption(&mesh_file,
"-m",
"--mesh",
260 "Mesh file to visualize.");
262 "Load mesh from multiple processors.");
263 args.
AddOption(&refine,
"-ref",
"--refinement",
"-no-ref",
"--no-refinement",
264 "Prepare the mesh for refinement or not.");
273 cout <<
"Visualize and manipulate a serial mesh:\n"
274 <<
" mesh-explorer -m <mesh_file>\n"
275 <<
"Visualize and manipulate a parallel mesh:\n"
276 <<
" mesh-explorer -np <#proc> -m <mesh_prefix>\n" << endl
284 Mesh *bdr_mesh = NULL;
287 mesh =
new Mesh(mesh_file, 1, refine);
319 cout <<
"boundary attribs :";
324 cout <<
'\n' <<
"material attribs :";
330 cout <<
"mesh curvature : ";
337 cout <<
"NONE" << endl;
342 cout <<
"What would you like to do?\n"
344 "c) Change curvature\n"
349 "m) View materials\n"
352 "h) View element sizes, h\n"
353 "k) View element ratios, kappa\n"
354 "l) Plot a function\n"
355 "x) Print sub-element stats\n"
356 "f) Find physical point in reference space\n"
357 "p) Generate a partitioning\n"
358 "o) Reorder elements\n"
359 "S) Save in MFEM format\n"
360 "V) Save in VTK format (only linear and quadratic meshes)\n"
363 "Z) Save in MFEM format with compression\n"
378 "Choose type of refinement:\n"
379 "s) standard refinement with Mesh::UniformRefinement()\n"
380 "b) Mesh::UniformRefinement() (bisection for tet meshes)\n"
381 "u) uniform refinement with a factor\n"
382 "g) non-uniform refinement (Gauss-Lobatto) with a factor\n"
383 "l) refine locally using the region() function\n"
400 cout <<
"enter refinement factor --> " << flush;
403 if (ref_factor <= 1 || ref_factor > 32) {
break; }
406 Mesh *rmesh =
new Mesh(mesh, ref_factor, ref_type);
415 for (
int i = 0; i < mesh->
GetNE(); i++)
425 marked_elements.
Append(i);
440 cout <<
"enter new order for mesh curvature --> " << flush;
449 cout <<
"scaling factor ---> " << flush;
455 for (
int i = 0; i < mesh->
GetNV(); i++)
483 cout <<
"jitter factor ---> " << flush;
490 cerr <<
"The mesh should have nodes, introduce curvature first!\n";
506 for (
int i = 0; i < fespace->
GetNE(); i++)
509 for (
int j = 0; j < dofs.
Size(); j++)
517 for (
int i = 0; i < fespace->
GetNDofs(); i++)
519 for (
int d = 0; d <
dim; d++)
526 cout <<
"move boundary nodes? [y/n] ---> " << flush;
533 for (
int i = 0; i < fespace->
GetNBE(); i++)
536 for (
int j = 0; j < vdofs.
Size(); j++)
553 double min_det_J, max_det_J, min_det_J_z, max_det_J_z;
554 double min_kappa, max_kappa, max_ratio_det_J_z;
556 max_det_J = max_kappa = max_ratio_det_J_z = -
infinity();
557 cout <<
"subdivision factor ---> " << flush;
560 bad_elems_by_geom = 0;
561 for (
int i = 0; i < mesh->
GetNE(); i++)
576 double det_J = J.
Det();
580 min_det_J_z = fmin(min_det_J_z, det_J);
581 max_det_J_z = fmax(max_det_J_z, det_J);
583 min_kappa = fmin(min_kappa, kappa);
584 max_kappa = fmax(max_kappa, kappa);
587 fmax(max_ratio_det_J_z, max_det_J_z/min_det_J_z);
588 min_det_J = fmin(min_det_J, min_det_J_z);
589 max_det_J = fmax(max_det_J, max_det_J_z);
590 if (min_det_J_z <= 0.0)
593 bad_elems_by_geom[
geom]++;
596 cout <<
"\nbad elements = " << nz;
602 cout <<
"\nmin det(J) = " << min_det_J
603 <<
"\nmax det(J) = " << max_det_J
604 <<
"\nglobal ratio = " << max_det_J/min_det_J
605 <<
"\nmax el ratio = " << max_ratio_det_J_z
606 <<
"\nmin kappa = " << min_kappa
607 <<
"\nmax kappa = " << max_kappa << endl;
613 cout <<
"\npoint in physical space ---> " << flush;
614 for (
int i = 0; i < sdim; i++)
616 cin >> point_mat(i,0);
624 cout <<
"point in reference space:";
625 if (elem_ids[0] == -1)
627 cout <<
" NOT FOUND!\n";
631 cout <<
" element " << elem_ids[0] <<
", ip =";
632 cout <<
" " << ips[0].x;
635 cout <<
" " << ips[0].y;
638 cout <<
" " << ips[0].z;
647 cout <<
"What type of reordering?\n"
648 "g) Gecko edge-product minimization\n"
649 "h) Hilbert spatial sort\n"
662 int outer, inner, window, period;
663 cout <<
"Enter number of outer iterations (default 5): " << flush;
665 cout <<
"Enter number of inner iterations (default 4): " << flush;
667 cout <<
"Enter window size (default 4, beware of exponential cost): "
670 cout <<
"Enter period for window size increment (default 2): "
675 for (
int i = 0; i < outer; i++)
679 tentative, inner, window, period, seed,
true);
681 if (cost < best_cost)
683 ordering = tentative;
687 cout <<
"Final cost: " << best_cost << endl;
694 if (mk ==
'm' || mk ==
'b' || mk ==
'e' || mk ==
'v' || mk ==
'h' ||
695 mk ==
'k' || mk ==
'p')
707 for (
int i = 0; i < mesh->
GetNE(); i++)
722 bdr_attr.
SetSpace(bdr_attr_fespace);
723 for (
int i = 0; i < bdr_mesh->
GetNE(); i++)
725 bdr_part[i] = (bdr_attr(i) = bdr_mesh->
GetAttribute(i)) - 1;
743 double a = double(rand()) / (double(RAND_MAX) + 1.);
744 int el0 = (int)floor(a * mesh->
GetNE());
745 cout <<
"Generating coloring starting with element " << el0+1
746 <<
" / " << mesh->
GetNE() << endl;
748 for (
int i = 0; i < coloring.
Size(); i++)
750 attr(i) = coloring[i];
752 cout <<
"Number of colors: " << attr.
Max() + 1 << endl;
753 for (
int i = 0; i < mesh->
GetNE(); i++)
756 attr(i) = part[i] = i;
766 for (
int i = 0; i < mesh->
GetNE(); i++)
776 attr(i) = -pow(-attr(i), 1.0/
double(dim));
780 attr(i) = pow(attr(i), 1.0/
double(dim));
782 h_min = min(h_min, attr(i));
783 h_max = max(h_max, attr(i));
785 cout <<
"h_min = " << h_min <<
", h_max = " << h_max << endl;
791 for (
int i = 0; i < mesh->
GetNE(); i++)
803 int *partitioning = NULL, np;
804 cout <<
"What type of partitioning?\n"
806 "s) Simple 1D split of the element sequence\n"
807 "0) METIS_PartGraphRecursive (sorted neighbor lists)\n"
808 "1) METIS_PartGraphKway (sorted neighbor lists)"
810 "2) METIS_PartGraphVKway (sorted neighbor lists)\n"
811 "3) METIS_PartGraphRecursive\n"
812 "4) METIS_PartGraphKway\n"
813 "5) METIS_PartGraphVKway\n"
820 cout <<
"Enter nx: " << flush;
821 cin >> nxyz[0]; np = nxyz[0];
824 cout <<
"Enter ny: " << flush;
825 cin >> nxyz[1]; np *= nxyz[1];
828 cout <<
"Enter nz: " << flush;
829 cin >> nxyz[2]; np *= nxyz[2];
836 cout <<
"Enter number of processors: " << flush;
839 partitioning =
new int[mesh->
GetNE()];
840 for (
int i = 0; i < mesh->
GetNE(); i++)
842 partitioning[i] = i * np / mesh->
GetNE();
847 int part_method = pk -
'0';
848 if (part_method < 0 || part_method > 5)
852 cout <<
"Enter number of processors: " << flush;
858 const char part_file[] =
"partitioning.txt";
859 ofstream opart(part_file);
860 opart <<
"number_of_elements " << mesh->
GetNE() <<
'\n'
861 <<
"number_of_processors " << np <<
'\n';
862 for (
int i = 0; i < mesh->
GetNE(); i++)
864 opart << partitioning[i] <<
'\n';
866 cout <<
"Partitioning file: " << part_file << endl;
870 for (
int i = 0; i < mesh->
GetNE(); i++)
872 proc_el[partitioning[i]]++;
874 int min_el = proc_el[0], max_el = proc_el[0];
875 for (
int i = 1; i < np; i++)
877 if (min_el > proc_el[i])
881 if (max_el < proc_el[i])
886 cout <<
"Partitioning stats:\n"
888 << setw(12) <<
"minimum"
889 << setw(12) <<
"average"
890 << setw(12) <<
"maximum"
891 << setw(12) <<
"total" <<
'\n';
893 << setw(12) << min_el
894 << setw(12) << double(mesh->
GetNE())/np
895 << setw(12) << max_el
896 << setw(12) << mesh->
GetNE() << endl;
903 for (
int i = 0; i < mesh->
GetNE(); i++)
905 attr(i) = part[i] = partitioning[i];
907 delete [] partitioning;
915 sol_sock.precision(14);
918 sol_sock <<
"fem2d_gf_data_keys\n";
921 mesh->
Print(sol_sock);
928 mesh->
Print(sol_sock);
929 for (
int i = 0; i < mesh->
GetNE(); i++)
940 sol_sock <<
"RjlmAb***********";
952 sol_sock <<
"fem3d_gf_data_keys\n";
953 if (mk ==
'v' || mk ==
'h' || mk ==
'k')
955 mesh->
Print(sol_sock);
959 bdr_mesh->
Print(sol_sock);
960 bdr_attr.
Save(sol_sock);
963 sol_sock <<
"pppppp" <<
"pppppp" <<
"pppppp";
970 mesh->
Print(sol_sock);
971 for (
int i = 0; i < mesh->
GetNE(); i++)
999 cout <<
"Unable to connect to "
1000 << vishost <<
':' << visport << endl;
1002 delete attr_fespace;
1003 delete bdr_attr_fespace;
1011 cout <<
"Enter projection space order: " << flush;
1032 sol_sock.precision(14);
1033 sol_sock <<
"solution\n" << *mesh << level << flush;
1037 cout <<
"Unable to connect to "
1038 << vishost <<
':' << visport << endl;
1045 const char mesh_file[] =
"mesh-explorer.mesh";
1046 ofstream omesh(mesh_file);
1047 omesh.precision(14);
1049 cout <<
"New mesh file: " << mesh_file << endl;
1054 const char mesh_file[] =
"mesh-explorer.vtk";
1055 ofstream omesh(mesh_file);
1056 omesh.precision(14);
1058 cout <<
"New VTK mesh file: " << mesh_file << endl;
1061 #ifdef MFEM_USE_ZLIB
1064 const char mesh_file[] =
"mesh-explorer.mesh.gz";
1066 omesh.precision(14);
1068 cout <<
"New mesh file: " << mesh_file << endl;
1074 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
Mesh * read_par_mesh(int np, const char *mesh_prefix)
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 MakeOwner(FiniteElementCollection *_fec)
Make the GridFunction the owner of fec and fes.
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().
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 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[])
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)
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)
virtual void GetElementDofs(int i, Array< int > &dofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
GeometryRefiner GlobGeometryRefiner
int GetAttribute() const
Return element's attribute.
void GetHilbertElementOrdering(Array< int > &ordering)
Piecewise-constant discontinuous finite elements in 3D. This class is kept only for backward compatib...
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.
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.
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)
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)
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 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.
double f(const Vector &p)
bool Good() const
Return true if the command line options were parsed successfully.