MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2007 Sandia National Laboratories. Developed at the 00005 University of Wisconsin--Madison under SNL contract number 00006 624796. The U.S. Government and the University of Wisconsin 00007 retain certain rights to this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 (2009) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file SlaveBoundaryVertices.cpp 00028 * \brief 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "SlaveBoundaryVertices.hpp" 00033 #include "Settings.hpp" 00034 #include "MsqError.hpp" 00035 #include "MeshInterface.hpp" 00036 #include "MsqVertex.hpp" 00037 00038 #include <vector> 00039 #include <algorithm> 00040 00041 namespace MBMesquite 00042 { 00043 00044 SlaveBoundaryVertices::SlaveBoundaryVertices( unsigned depth, unsigned dim ) : elemDepth( depth ), domainDoF( dim ) {} 00045 00046 std::string SlaveBoundaryVertices::get_name() const 00047 { 00048 return "SlaveBoundaryVertices"; 00049 } 00050 00051 double SlaveBoundaryVertices::loop_over_mesh( MeshDomainAssoc* mesh_and_domain, 00052 const Settings* settings, 00053 MsqError& err ) 00054 { 00055 Mesh* mesh = mesh_and_domain->get_mesh(); 00056 MeshDomain* domain = mesh_and_domain->get_domain(); 00057 00058 if( settings->get_slaved_ho_node_mode() != Settings::SLAVE_CALCULATED ) 00059 { 00060 MSQ_SETERR( err ) 00061 ( "Request to calculate higher-order node slaved status " 00062 "when Settings::get_get_slaved_ho_node_mode() " 00063 "!= SLAVE_CALCUALTED", 00064 MsqError::INVALID_STATE ); 00065 return 0.0; 00066 } 00067 00068 // If user said that we should treat fixed vertices as the 00069 // boundary, but specified that fixed vertices are defined 00070 // by the dimension of their geometric domain, then just 00071 // do distance from the geometric domain. 00072 int dim = this->domainDoF; 00073 if( dim >= 4 && settings->get_fixed_vertex_mode() != Settings::FIXED_FLAG ) dim = settings->get_fixed_vertex_mode(); 00074 00075 // Create a map to contain vertex depth. Intiliaze all to 00076 // elemDepth+1. 00077 std::vector< Mesh::VertexHandle > vertices; 00078 mesh->get_all_vertices( vertices, err ); 00079 MSQ_ERRZERO( err ); 00080 if( vertices.empty() ) return 0.0; 00081 std::sort( vertices.begin(), vertices.end() ); 00082 std::vector< unsigned short > depth( vertices.size(), elemDepth + 1 ); 00083 std::vector< bool > fixed; 00084 mesh->vertices_get_fixed_flag( arrptr( vertices ), fixed, vertices.size(), err ); 00085 MSQ_ERRZERO( err ); 00086 00087 // Initialize map with boundary vertices. 00088 if( dim >= 4 ) 00089 { 00090 for( size_t i = 0; i < vertices.size(); ++i ) 00091 if( fixed[i] ) depth[i] = 0; 00092 } 00093 else 00094 { 00095 if( !domain ) 00096 { 00097 MSQ_SETERR( err ) 00098 ( "Request to calculate higher-order node slaved status " 00099 "by distance from bounding domain without a domain.", 00100 MsqError::INVALID_STATE ); 00101 return 0.0; 00102 } 00103 00104 std::vector< unsigned short > dof( vertices.size() ); 00105 domain->domain_DoF( arrptr( vertices ), arrptr( dof ), vertices.size(), err ); 00106 MSQ_ERRZERO( err ); 00107 for( size_t i = 0; i < vertices.size(); ++i ) 00108 if( dof[i] <= dim ) depth[i] = 0; 00109 } 00110 00111 // Now iterate over elements repeatedly until we've found all of the 00112 // elements near the boundary. This could be done much more efficiently 00113 // using vertex-to-element adjacencies, but it is to common for 00114 // applications not to implement that unless doing relaxation smoothing. 00115 // This is O(elemDepth * elements.size() * ln(vertices.size())); 00116 std::vector< Mesh::ElementHandle > elements; 00117 std::vector< Mesh::ElementHandle >::const_iterator j, k; 00118 std::vector< Mesh::VertexHandle > conn; 00119 std::vector< size_t > junk( 2 ); 00120 mesh->get_all_elements( elements, err ); 00121 MSQ_ERRZERO( err ); 00122 if( elements.empty() ) return 0.0; 00123 bool some_changed; 00124 do 00125 { 00126 some_changed = false; 00127 for( j = elements.begin(); j != elements.end(); ++j ) 00128 { 00129 conn.clear(); 00130 junk.clear(); 00131 mesh->elements_get_attached_vertices( &*j, 1, conn, junk, err ); 00132 MSQ_ERRZERO( err ); 00133 unsigned short elem_depth = elemDepth + 1; 00134 for( k = conn.begin(); k != conn.end(); ++k ) 00135 { 00136 size_t i = std::lower_bound( vertices.begin(), vertices.end(), *k ) - vertices.begin(); 00137 if( i == vertices.size() ) 00138 { 00139 MSQ_SETERR( err ) 00140 ( "Invalid vertex handle in element connectivity list.", MsqError::INVALID_MESH ); 00141 return 0.0; 00142 } 00143 if( depth[i] < elem_depth ) elem_depth = depth[i]; 00144 } 00145 if( elem_depth == elemDepth + 1 ) continue; 00146 00147 ++elem_depth; 00148 for( k = conn.begin(); k != conn.end(); ++k ) 00149 { 00150 size_t i = std::lower_bound( vertices.begin(), vertices.end(), *k ) - vertices.begin(); 00151 if( depth[i] > elem_depth ) 00152 { 00153 depth[i] = elem_depth; 00154 some_changed = true; 00155 } 00156 } 00157 } // for(elements) 00158 } while( some_changed ); 00159 00160 // Now remove any corner vertices from the slaved set 00161 std::vector< Mesh::VertexHandle >::iterator p; 00162 std::vector< EntityTopology > types( elements.size() ); 00163 mesh->elements_get_topologies( arrptr( elements ), arrptr( types ), elements.size(), err ); 00164 MSQ_ERRZERO( err ); 00165 for( j = elements.begin(); j != elements.end(); ++j ) 00166 { 00167 const unsigned corners = TopologyInfo::corners( types[j - elements.begin()] ); 00168 conn.clear(); 00169 junk.clear(); 00170 mesh->elements_get_attached_vertices( &*j, 1, conn, junk, err ); 00171 MSQ_ERRZERO( err ); 00172 for( unsigned i = 0; i < corners; ++i ) 00173 { 00174 p = std::lower_bound( vertices.begin(), vertices.end(), conn[i] ); 00175 depth[p - vertices.begin()] = 0; 00176 } 00177 } 00178 00179 // Now mark all vertices *not* within specified depth as slave vertices. 00180 std::vector< unsigned char > bytes( vertices.size() ); 00181 mesh->vertices_get_byte( arrptr( vertices ), arrptr( bytes ), vertices.size(), err ); 00182 MSQ_ERRZERO( err ); 00183 for( size_t i = 0; i < vertices.size(); ++i ) 00184 { 00185 if( depth[i] <= elemDepth || fixed[i] ) 00186 bytes[i] &= ~MsqVertex::MSQ_DEPENDENT; 00187 else 00188 bytes[i] |= MsqVertex::MSQ_DEPENDENT; 00189 } 00190 00191 mesh->vertices_set_byte( arrptr( vertices ), arrptr( bytes ), vertices.size(), err ); 00192 MSQ_ERRZERO( err ); 00193 return 0.0; 00194 } 00195 00196 void SlaveBoundaryVertices::initialize_queue( MeshDomainAssoc*, const Settings*, MsqError& ) {} 00197 00198 } // namespace MBMesquite