MOAB: Mesh Oriented datABase  (version 5.4.1)
DomainClassifier.hpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2008 Lawrence Livermore National Laboratory.  Under
00005     the terms of Contract B545069 with the University of Wisconsin --
00006     Madison, Lawrence Livermore National Laboratory retains certain
00007     rights in 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     (2008) [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 #ifndef MSQ_DOMAIN_CLASSIFIER_HPP
00028 #define MSQ_DOMAIN_CLASSIFIER_HPP
00029 
00030 /** \file DomainClassifier.hpp
00031  *  \brief
00032  *  \author Jason Kraftcheck
00033  */
00034 
00035 #include "Mesquite.hpp"
00036 #include "MeshInterface.hpp"
00037 
00038 namespace MBMesquite
00039 {
00040 
00041 /**\brief Assign subsets of a mesh do different domains.
00042  *
00043  * Provide classification of mesh entities to domain(s).  For
00044  * example, given a domain defined by multiple surfaces and
00045  * curves of intersection, associate the appropriate elements
00046  * and vertices to the appropriate geometric entities.
00047  */
00048 class DomainClassifier : public MeshDomain
00049 {
00050   public:
00051     /**\brief Check that classification maps to B-Rep topology */
00052     MESQUITE_EXPORT void test_valid_classification( Mesh* mesh, MsqError& err );
00053 
00054     /**\brief Classify mesh entities using tag values
00055      *
00056      * Given a list of MeshDomain instances, a unique
00057      * integer ID for each MeshDomain, and a tag name:
00058      * classify mesh entities by matching the tag value
00059      * on each mesh entity to the list of MeshDomain IDs.
00060      *
00061      *\param result   DomainClassifier to popupate
00062      *\param mesh     The MBMesquite::Mesh instance
00063      *\param tag_name Tag containing integer domain ID for each mesh entity.
00064      *\param domain_array Array of MeshDomain instances.
00065      *\param id_array Array of integer MeshDomain IDs.
00066      *\param array_length Length of 'domain_array' and 'id_array'
00067      */
00068     static MESQUITE_EXPORT void classify_by_tag( DomainClassifier& result,
00069                                                  Mesh* mesh,
00070                                                  const char* tag_name,
00071                                                  MeshDomain** domain_array,
00072                                                  const int* id_array,
00073                                                  unsigned array_length,
00074                                                  MsqError& err );
00075 
00076     /**\brief Skin mesh and classify skin entities geometrically.
00077      *
00078      * Calculate the boundary of the mesh, and classify boundary
00079      * entities by calculating the distance from the mesh domain
00080      * to each vertex.
00081      *
00082      * NOTE:  Mesquite's limited MeshDomain callback interface
00083      * is not sufficient for robust geometric classification.  If
00084      * the mesh is not sufficiently refined, this method may produce
00085      * invalid results.
00086      *
00087      * NOTE:  This method should not be used for surface meshes.
00088      * Everything in a surface mesh should be classified to a domain.
00089      * not just the skin.  Use classify_geometrically instead.
00090      *
00091      *\param result   DomainClassifier to popupate
00092      *\param mesh     The MBMesquite::Mesh instance
00093      *\param tolerance Maximum distance a vertex may deviate from its domain.
00094      *\param domain_array Array of MeshDomain instances.
00095      *\param dimension_array Topological dimensiono of each MeshDomain
00096      *\param array_length Length of 'domain_array' and 'dimension_array'
00097      */
00098     MESQUITE_EXPORT static void classify_skin_geometrically( DomainClassifier& result,
00099                                                              Mesh* mesh,
00100                                                              double tolerance,
00101                                                              MeshDomain** domain_array,
00102                                                              const int* dimension_array,
00103                                                              unsigned array_length,
00104                                                              MsqError& err );
00105 
00106     /**\brief Classify all mesh entities geometrically.
00107      *
00108      * Classify entities by distance from vertex coordiantes to
00109      * mesh domain instances.
00110      *
00111      * NOTE:  Mesquite's limited MeshDomain callback interface
00112      * is not sufficient for robust geometric classification.  If
00113      * the mesh is not sufficiently refined, this method may produce
00114      * invalid results.
00115      *
00116      * NOTE:  This method is likely to fail for many domains for
00117      *        volume meshes.  Use classify_skin_geometrically for
00118      *        volume meshes.
00119      *
00120      *\param result   DomainClassifier to popupate
00121      *\param mesh     The MBMesquite::Mesh instance
00122      *\param tolerance Maximum distance a vertex may deviate from its domain.
00123      *\param domain_array Array of MeshDomain instances.
00124      *\param dimension_array Topological dimensiono of each MeshDomain
00125      *\param array_length Length of 'domain_array' and 'dimension_array'
00126      */
00127     MESQUITE_EXPORT static void classify_geometrically( DomainClassifier& result,
00128                                                         Mesh* mesh,
00129                                                         double tolerance,
00130                                                         MeshDomain** domain_array,
00131                                                         const int* dimension_array,
00132                                                         unsigned array_length,
00133                                                         MsqError& err );
00134 
00135     struct DomainSet
00136     {
00137         MESQUITE_EXPORT DomainSet( MeshDomain* dom ) : domain( dom ) {}
00138         MESQUITE_EXPORT DomainSet() : domain( 0 ) {}
00139         MeshDomain* domain;
00140         MESQUITE_EXPORT void set_vertices( const std::vector< Mesh::VertexHandle >& verts )
00141         {
00142             vertices = verts;
00143         }
00144         MESQUITE_EXPORT void set_elements( const std::vector< Mesh::ElementHandle >& elems )
00145         {
00146             elements = elems;
00147         }
00148         MESQUITE_EXPORT void get_vertices( std::vector< Mesh::VertexHandle >& verts ) const
00149         {
00150             verts = vertices;
00151         }
00152         MESQUITE_EXPORT void get_elements( std::vector< Mesh::ElementHandle >& elems ) const
00153         {
00154             elems = elements;
00155         }
00156         std::vector< Mesh::VertexHandle > vertices;
00157         std::vector< Mesh::ElementHandle > elements;
00158     };
00159 
00160     /**\brief Specify classification explicitly for each entity.
00161      *
00162      * For each mesh element and vertex that is classified to
00163      * a domain, specify that classification explicitly.
00164      *
00165      *\param result           DomainClassifier to popupate
00166      *\param mesh             The MBMesquite::Mesh instance
00167      *\param domain_set_array Array of DomainClassifier::DomainSet structs
00168      *                        specifying for each MeshDomain: the
00169      *                        domain instance and the elements and
00170      *                        vertices associated with the domain.
00171      *\param array_length     Length of 'domain_set_array'
00172      */
00173     MESQUITE_EXPORT static void classify_by_handle( DomainClassifier& result,
00174                                                     Mesh* mesh,
00175                                                     DomainSet* domain_set_array,
00176                                                     unsigned array_length,
00177                                                     MsqError& err );
00178 
00179     MESQUITE_EXPORT DomainClassifier() : deleteSubDomains( false ) {}
00180 
00181     MESQUITE_EXPORT virtual ~DomainClassifier();
00182 
00183     MESQUITE_EXPORT
00184     virtual void snap_to( Mesh::VertexHandle entity_handle, Vector3D& coordinate ) const;
00185 
00186     MESQUITE_EXPORT
00187     virtual void vertex_normal_at( Mesh::VertexHandle entity_handle, Vector3D& coordinate ) const;
00188     MESQUITE_EXPORT
00189     virtual void element_normal_at( Mesh::ElementHandle entity_handle, Vector3D& coordinate ) const;
00190 
00191     MESQUITE_EXPORT
00192     virtual void vertex_normal_at( const Mesh::VertexHandle* handles,
00193                                    Vector3D coordinates[],
00194                                    unsigned count,
00195                                    MsqError& err ) const;
00196 
00197     MESQUITE_EXPORT
00198     virtual void closest_point( Mesh::VertexHandle handle,
00199                                 const Vector3D& position,
00200                                 Vector3D& closest,
00201                                 Vector3D& normal,
00202                                 MsqError& err ) const;
00203 
00204     MESQUITE_EXPORT
00205     virtual void domain_DoF( const Mesh::VertexHandle* handle_array,
00206                              unsigned short* dof_array,
00207                              size_t num_handles,
00208                              MsqError& err ) const;
00209 
00210     /**\brief Clear all data, including MeshDomain list */
00211     MESQUITE_EXPORT
00212     void clear()
00213     {
00214         vertexList.clear();
00215         elementList.clear();
00216     }
00217 
00218     struct DomainBlock
00219     {
00220         Mesh::EntityHandle firstHandle;
00221         Mesh::EntityHandle lastHandle;
00222         MeshDomain* domain;
00223     };
00224 
00225     MESQUITE_EXPORT
00226     MeshDomain* find_vertex_domain( Mesh::VertexHandle vertex ) const
00227     {
00228         return find_domain( vertex, vertexList );
00229     }
00230     MESQUITE_EXPORT
00231     MeshDomain* find_element_domain( Mesh::ElementHandle element ) const
00232     {
00233         return find_domain( element, elementList );
00234     }
00235 
00236     MESQUITE_EXPORT
00237     void delete_sub_domains( bool yesno )
00238     {
00239         deleteSubDomains = yesno;
00240     }
00241 
00242     MESQUITE_EXPORT
00243     void delete_all_sub_domains();
00244 
00245   private:
00246     bool deleteSubDomains;
00247 
00248     static MeshDomain* find_domain( Mesh::EntityHandle handle, const std::vector< DomainBlock >& list );
00249 
00250     std::vector< DomainBlock > vertexList;
00251     std::vector< DomainBlock > elementList;
00252 };
00253 
00254 }  // namespace MBMesquite
00255 
00256 #endif  // MSQ_DOMAIN_CLASSIFIER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines