54int main(
int argc,
char *argv[])
57 const char *mesh_file =
"../../data/beam-tet.vtk";
60 bool visualization = 1;
63 args.
AddOption(&mesh_file,
"-m",
"--mesh",
66 "Set of attributes to remove from the mesh.");
67 args.
AddOption(&bdr_attr,
"-b",
"--bdr-attr",
68 "Set of attributes to assign to the new boundary elements.");
69 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
71 "Enable or disable GLVis visualization.");
80 Mesh mesh(mesh_file, 0, 0);
85 if (bdr_attr.
Size() == 0)
88 for (
int i=0; i<attr.
Size(); i++)
90 bdr_attr[i] = max_bdr_attr + attr[i];
93 MFEM_VERIFY(attr.
Size() == bdr_attr.
Size(),
94 "Size mismatch in attribute arguments.");
100 for (
int i=0; i<attr.
Size(); i++)
102 marker[attr[i]-1] = 1;
103 attr_inv[attr[i]-1] = i;
107 int num_elements = 0;
108 for (
int e=0; e<mesh.
GetNE(); e++)
111 if (!marker[elem_attr-1]) { num_elements++; }
115 int num_bdr_elements = 0;
118 int e1 = -1, e2 = -1;
125 if (a1 == 0 || a2 == 0)
127 if (a1 == 0 && !marker[a2-1]) { num_bdr_elements++; }
128 else if (a2 == 0 && !marker[a1-1]) { num_bdr_elements++; }
132 if (marker[a1-1] && !marker[a2-1]) { num_bdr_elements++; }
133 else if (!marker[a1-1] && marker[a2-1]) { num_bdr_elements++; }
137 cout <<
"Number of Elements: " << mesh.
GetNE() <<
" -> "
138 << num_elements << endl;
139 cout <<
"Number of Boundary Elements: " << mesh.
GetNBE() <<
" -> "
140 << num_bdr_elements << endl;
146 for (
int v=0; v<mesh.
GetNV(); v++)
152 for (
int e=0; e<mesh.
GetNE(); e++)
156 if (!marker[elem_attr-1])
166 for (
int be=0; be<mesh.
GetNBE(); be++)
172 if (!marker[elem_attr-1])
182 int e1 = -1, e2 = -1;
185 int i1 = -1, i2 = -1;
192 if (a1 != 0 && a2 != 0)
194 if (marker[a1-1] && !marker[a2-1])
202 else if (!marker[a1-1] && marker[a2-1])
231 trimmed_mesh.
SetCurvature(order, discont, sdim, ordering);
242 for (
int e = 0; e < mesh.
GetNE(); e++)
246 if (!marker[elem_attr-1])
259 ofstream mesh_ofs(
"trimmer.mesh");
260 mesh_ofs.precision(8);
261 trimmed_mesh.
Print(mesh_ofs);
269 sol_sock.precision(8);
270 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)