54int main(
int argc,
char *argv[])
57 const char *mesh_file =
"../../data/beam-tet.vtk";
61 bool visualization = 1;
64 args.
AddOption(&mesh_file,
"-m",
"--mesh",
67 "Set of attributes to remove from the mesh.");
68 args.
AddOption(&bdr_attr,
"-b",
"--bdr-attr",
69 "Set of attributes to assign to the new boundary elements.");
70 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
72 "Enable or disable GLVis visualization.");
73 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
82 Mesh mesh(mesh_file, 0, 0);
87 if (bdr_attr.
Size() == 0)
90 for (
int i=0; i<attr.
Size(); i++)
92 bdr_attr[i] = max_bdr_attr + attr[i];
95 MFEM_VERIFY(attr.
Size() == bdr_attr.
Size(),
96 "Size mismatch in attribute arguments.");
102 for (
int i=0; i<attr.
Size(); i++)
104 marker[attr[i]-1] = 1;
105 attr_inv[attr[i]-1] = i;
109 int num_elements = 0;
110 for (
int e=0; e<mesh.
GetNE(); e++)
113 if (!marker[elem_attr-1]) { num_elements++; }
117 int num_bdr_elements = 0;
120 int e1 = -1, e2 = -1;
127 if (a1 == 0 || a2 == 0)
129 if (a1 == 0 && !marker[a2-1]) { num_bdr_elements++; }
130 else if (a2 == 0 && !marker[a1-1]) { num_bdr_elements++; }
134 if (marker[a1-1] && !marker[a2-1]) { num_bdr_elements++; }
135 else if (!marker[a1-1] && marker[a2-1]) { num_bdr_elements++; }
139 cout <<
"Number of Elements: " << mesh.
GetNE() <<
" -> "
140 << num_elements << endl;
141 cout <<
"Number of Boundary Elements: " << mesh.
GetNBE() <<
" -> "
142 << num_bdr_elements << endl;
148 for (
int v=0; v<mesh.
GetNV(); v++)
154 for (
int e=0; e<mesh.
GetNE(); e++)
158 if (!marker[elem_attr-1])
168 for (
int be=0; be<mesh.
GetNBE(); be++)
174 if (!marker[elem_attr-1])
184 int e1 = -1, e2 = -1;
187 int i1 = -1, i2 = -1;
194 if (a1 != 0 && a2 != 0)
196 if (marker[a1-1] && !marker[a2-1])
204 else if (!marker[a1-1] && marker[a2-1])
233 trimmed_mesh.
SetCurvature(order, discont, sdim, ordering);
244 for (
int e = 0; e < mesh.
GetNE(); e++)
248 if (!marker[elem_attr-1])
261 ofstream mesh_ofs(
"trimmer.mesh");
262 mesh_ofs.precision(8);
263 trimmed_mesh.
Print(mesh_ofs);
270 sol_sock.precision(8);
271 sol_sock <<
"mesh\n" << trimmed_mesh << flush;
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
Abstract data type element.
Geometry::Type GetGeometryType() const
virtual Element * Duplicate(Mesh *m) const =0
virtual void GetVertices(Array< int > &v) const =0
Get the indices defining the vertices.
void SetAttribute(const int attr)
Set element's attribute.
int GetAttribute() const
Return element's attribute.
virtual void SetVertices(const Array< int > &v)=0
Set the indices defining the vertices.
int GetOrder() const
Return the order (polynomial degree) of the FE collection, corresponding to the order/degree returned...
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 ...
Ordering::Type GetOrdering() const
Return the ordering method.
const FiniteElementCollection * FEColl() const
Class for grid function - Vector with associated FE space.
FiniteElementSpace * FESpace()
Arbitrary order "L2-conforming" discontinuous finite elements.
Element * NewElement(int geom)
int AddBdrElement(Element *elem)
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void GetFaceInfos(int Face, int *Inf1, int *Inf2) const
int GetNumFaces() const
Return the number of faces (3D), edges (2D) or vertices (1D).
const FiniteElementSpace * GetNodalFESpace() const
const Element * GetElement(int i) const
Return pointer to the i'th element object.
void FinalizeTopology(bool generate_bdr=true)
Finalize the construction of the secondary topology (connectivity) data of a Mesh.
virtual void Print(std::ostream &os=mfem::out, const std::string &comments="") const
int AddVertex(real_t x, real_t y=0.0, real_t z=0.0)
int GetNE() const
Returns number of elements.
const Element * GetFace(int i) const
Return pointer to the i'th face element object.
int Dimension() const
Dimension of the reference space used within the elements.
const Element * GetBdrElement(int i) const
Return pointer to the i'th boundary element object.
int AddElement(Element *elem)
void GetFaceElements(int Face, int *Elem1, int *Elem2) const
int SpaceDimension() const
Dimension of the physical space containing the mesh.
void GetNodes(Vector &node_coord) const
int GetNV() const
Returns number of vertices. Vertices are only at the corners of elements, where you would expect them...
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....
int GetNBE() const
Returns number of boundary elements.
virtual void Finalize(bool refine=false, bool fix_orientation=false)
Finalize the construction of a general Mesh.
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Set the curvature of the mesh nodes using the given polynomial degree.
Array< int > attributes
A list of all unique element attributes used by the Mesh.
const real_t * GetVertex(int i) const
Return pointer to vertex i's coordinates.
void RemoveUnusedVertices()
Remove unused vertices and rebuild mesh connectivity.
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.
void SetSubVector(const Array< int > &dofs, const real_t value)
Set the entries listed in dofs to the given value.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
std::function< real_t(const Vector &)> f(real_t mass_coeff)