1 // The libMesh Finite Element Library. 2 // Copyright (C) 2002-2020 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 4 // This library is free software; you can redistribute it and/or 5 // modify it under the terms of the GNU Lesser General Public 6 // License as published by the Free Software Foundation; either 7 // version 2.1 of the License, or (at your option) any later version. 8 9 // This library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // Lesser General Public License for more details. 13 14 // You should have received a copy of the GNU Lesser General Public 15 // License along with this library; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 18 19 20 #ifndef LIBMESH_MESH_MODIFICATION_H 21 #define LIBMESH_MESH_MODIFICATION_H 22 23 // Local Includes 24 #include "libmesh/libmesh_common.h" 25 #include "libmesh/id_types.h" // for boundary_id_type, subdomain_id_type 26 27 namespace libMesh 28 { 29 30 // forward declarations 31 template <typename Output> class FunctionBase; 32 class MeshBase; 33 34 35 // ------------------------------------------------------------ 36 // MeshTools::Modification namespace 37 namespace MeshTools 38 { 39 /** 40 * Tools for \p Mesh modification. 41 * 42 * \author Benjamin S. Kirk 43 * \date 2004 44 */ 45 namespace Modification 46 { 47 /** 48 * Randomly perturb the nodal locations. This function will 49 * move each node \p factor fraction of its minimum neighboring 50 * node separation distance. Nodes on the boundary are not moved 51 * by default, however they may be by setting the flag 52 * \p perturb_boundary true. 53 */ 54 void distort (MeshBase & mesh, 55 const Real factor, const bool perturb_boundary=false); 56 57 /** 58 * Deterministically perturb the nodal locations. This function will 59 * move each node from it's current x/y/z coordinates to a new x/y/z 60 * coordinate given by the first LIBMESH_DIM components of the 61 * specified function \p mapfunc 62 * 63 * Nodes on the boundary are also moved. 64 * 65 * Currently, non-vertex nodes are moved in the same way as vertex 66 * nodes, according to (newx,newy,newz) = mapfunc(x,y,z). This 67 * behavior is often suboptimal for higher order geometries and may be 68 * subject to change in future libMesh versions. 69 */ 70 void redistribute (MeshBase & mesh, 71 const FunctionBase<Real> & mapfunc); 72 73 74 /** 75 * Translates the mesh. The grid points are translated in the 76 * \p x direction by \p xt, in the \p y direction by \p yt, 77 * etc... 78 */ 79 void translate (MeshBase & mesh, 80 const Real xt=0., const Real yt=0., const Real zt=0.); 81 82 // /** 83 // * Rotates the mesh in the xy plane. The rotation is 84 // * counter-clock-wise (mathematical definition). 85 // * The angle is in degrees (360 make a full circle) 86 // */ 87 // void rotate2D (MeshBase & mesh, 88 // const Real alpha=0.); 89 90 /** 91 * Rotates the mesh in 3D space. 92 * Here the standard Euler angles are adopted 93 * (http://mathworld.wolfram.com/EulerAngles.html) 94 * The angles are in degrees (360 make a full circle) 95 */ 96 void rotate (MeshBase & mesh, 97 const Real phi, const Real theta=0., const Real psi=0.); 98 99 /** 100 * Scales the mesh. The grid points are scaled in the 101 * \p x direction by \p xs, in the \p y direction by \p ys, 102 * etc... If only \p xs is specified then the scaling is 103 * assumed uniform in all directions. 104 */ 105 void scale (MeshBase & mesh, 106 const Real xs, const Real ys=0., const Real zs=0.); 107 108 /** 109 * Converts the 2D quadrilateral elements of a Mesh into 110 * triangular elements. 111 * 112 * \note Only works for 2D elements! 3D elements are ignored. 113 * \note Probably won't do the right thing for meshes which 114 * have been refined previously. 115 */ 116 void all_tri (MeshBase & mesh); 117 118 /** 119 * Smooth the mesh with a simple Laplace smoothing algorithm. The mesh is 120 * smoothed \p n_iterations times. If the parameter \p power is 0, each 121 * node is moved to the average position of the neighboring connected 122 * nodes. If \p power > 0, the node positions are weighted by their 123 * distance. The positions of higher order nodes, and nodes living in 124 * refined elements, are calculated from the vertex positions of their 125 * parent nodes. Only works in 2D. 126 * 127 * \author Martin Luthi (luthi@gi.alaska.edu) 128 * \date 2005 129 */ 130 void smooth(MeshBase &, unsigned int, Real); 131 132 #ifdef LIBMESH_ENABLE_AMR 133 /** 134 * Removes all the refinement tree structure of Mesh, leaving 135 * only the highest-level (most-refined) elements. This is useful 136 * when you want to write out a uniformly-refined grid to be treated later 137 * as an initial mesh. 138 * 139 * \note Many functions in LibMesh assume a conforming (with no 140 * hanging nodes) grid exists at some level, so you probably only want 141 * to do this on meshes which have been uniformly refined. 142 */ 143 void flatten(MeshBase & mesh); 144 #endif // #ifdef LIBMESH_ENABLE_AMR 145 146 /** 147 * Finds any boundary ids that are currently old_id, 148 * changes them to new_id 149 */ 150 void change_boundary_id (MeshBase & mesh, 151 const boundary_id_type old_id, 152 const boundary_id_type new_id); 153 154 /** 155 * Finds any subdomain ids that are currently old_id, 156 * changes them to new_id 157 */ 158 void change_subdomain_id (MeshBase & mesh, 159 const subdomain_id_type old_id, 160 const subdomain_id_type new_id); 161 162 } // end namespace Meshtools::Modification 163 } // end namespace MeshTools 164 165 } // namespace libMesh 166 167 168 #endif // LIBMESH_MESH_MODIFICATION_H 169