MOAB: Mesh Oriented datABase  (version 5.2.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) kraftche@cae.wisc.edu
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, Mesh* mesh, const char* tag_name,
00069                                                  MeshDomain** domain_array, const int* id_array, unsigned array_length,
00070                                                  MsqError& err );
00071 
00072     /**\brief Skin mesh and classify skin entities geometrically.
00073      *
00074      * Calculate the boundary of the mesh, and classify boundary
00075      * entities by calculating the distance from the mesh domain
00076      * to each vertex.
00077      *
00078      * NOTE:  Mesquite's limited MeshDomain callback interface
00079      * is not sufficient for robust geometric classification.  If
00080      * the mesh is not sufficiently refined, this method may produce
00081      * invalid results.
00082      *
00083      * NOTE:  This method should not be used for surface meshes.
00084      * Everything in a surface mesh should be classified to a domain.
00085      * not just the skin.  Use classify_geometrically instead.
00086      *
00087      *\param result   DomainClassifier to popupate
00088      *\param mesh     The MBMesquite::Mesh instance
00089      *\param tolerance Maximum distance a vertex may deviate from its domain.
00090      *\param domain_array Array of MeshDomain instances.
00091      *\param dimension_array Topological dimensiono of each MeshDomain
00092      *\param array_length Length of 'domain_array' and 'dimension_array'
00093      */
00094     MESQUITE_EXPORT static void classify_skin_geometrically( DomainClassifier& result, Mesh* mesh, double tolerance,
00095                                                              MeshDomain** domain_array, const int* dimension_array,
00096                                                              unsigned array_length, MsqError& err );
00097 
00098     /**\brief Classify all mesh entities geometrically.
00099      *
00100      * Classify entities by distance from vertex coordiantes to
00101      * mesh domain instances.
00102      *
00103      * NOTE:  Mesquite's limited MeshDomain callback interface
00104      * is not sufficient for robust geometric classification.  If
00105      * the mesh is not sufficiently refined, this method may produce
00106      * invalid results.
00107      *
00108      * NOTE:  This method is likely to fail for many domains for
00109      *        volume meshes.  Use classify_skin_geometrically for
00110      *        volume meshes.
00111      *
00112      *\param result   DomainClassifier to popupate
00113      *\param mesh     The MBMesquite::Mesh instance
00114      *\param tolerance Maximum distance a vertex may deviate from its domain.
00115      *\param domain_array Array of MeshDomain instances.
00116      *\param dimension_array Topological dimensiono of each MeshDomain
00117      *\param array_length Length of 'domain_array' and 'dimension_array'
00118      */
00119     MESQUITE_EXPORT static void classify_geometrically( DomainClassifier& result, Mesh* mesh, double tolerance,
00120                                                         MeshDomain** domain_array, const int* dimension_array,
00121                                                         unsigned array_length, MsqError& err );
00122 
00123     struct DomainSet
00124     {
00125         MESQUITE_EXPORT DomainSet( MeshDomain* dom ) : domain( dom ) {}
00126         MESQUITE_EXPORT DomainSet() : domain( 0 ) {}
00127         MeshDomain* domain;
00128         MESQUITE_EXPORT void set_vertices( const std::vector< Mesh::VertexHandle >& verts )
00129         {
00130             vertices = verts;
00131         }
00132         MESQUITE_EXPORT void set_elements( const std::vector< Mesh::ElementHandle >& elems )
00133         {
00134             elements = elems;
00135         }
00136         MESQUITE_EXPORT void get_vertices( std::vector< Mesh::VertexHandle >& verts ) const
00137         {
00138             verts = vertices;
00139         }
00140         MESQUITE_EXPORT void get_elements( std::vector< Mesh::ElementHandle >& elems ) const
00141         {
00142             elems = elements;
00143         }
00144         std::vector< Mesh::VertexHandle > vertices;
00145         std::vector< Mesh::ElementHandle > elements;
00146     };
00147 
00148     /**\brief Specify classification explicitly for each entity.
00149      *
00150      * For each mesh element and vertex that is classified to
00151      * a domain, specify that classification explicitly.
00152      *
00153      *\param result           DomainClassifier to popupate
00154      *\param mesh             The MBMesquite::Mesh instance
00155      *\param domain_set_array Array of DomainClassifier::DomainSet structs
00156      *                        specifying for each MeshDomain: the
00157      *                        domain instance and the elements and
00158      *                        vertices associated with the domain.
00159      *\param array_length     Length of 'domain_set_array'
00160      */
00161     MESQUITE_EXPORT static void classify_by_handle( DomainClassifier& result, Mesh* mesh, DomainSet* domain_set_array,
00162                                                     unsigned array_length, MsqError& err );
00163 
00164     MESQUITE_EXPORT DomainClassifier() : deleteSubDomains( false ) {}
00165 
00166     MESQUITE_EXPORT virtual ~DomainClassifier();
00167 
00168     MESQUITE_EXPORT
00169     virtual void snap_to( Mesh::VertexHandle entity_handle, Vector3D& coordinate ) const;
00170 
00171     MESQUITE_EXPORT
00172     virtual void vertex_normal_at( Mesh::VertexHandle entity_handle, Vector3D& coordinate ) const;
00173     MESQUITE_EXPORT
00174     virtual void element_normal_at( Mesh::ElementHandle entity_handle, Vector3D& coordinate ) const;
00175 
00176     MESQUITE_EXPORT
00177     virtual void vertex_normal_at( const Mesh::VertexHandle* handles, Vector3D coordinates[], unsigned count,
00178                                    MsqError& err ) const;
00179 
00180     MESQUITE_EXPORT
00181     virtual void closest_point( Mesh::VertexHandle handle, const Vector3D& position, Vector3D& closest,
00182                                 Vector3D& normal, MsqError& err ) const;
00183 
00184     MESQUITE_EXPORT
00185     virtual void domain_DoF( const Mesh::VertexHandle* handle_array, unsigned short* dof_array, size_t num_handles,
00186                              MsqError& err ) const;
00187 
00188     /**\brief Clear all data, including MeshDomain list */
00189     MESQUITE_EXPORT
00190     void clear()
00191     {
00192         vertexList.clear();
00193         elementList.clear();
00194     }
00195 
00196     struct DomainBlock
00197     {
00198         Mesh::EntityHandle firstHandle;
00199         Mesh::EntityHandle lastHandle;
00200         MeshDomain* domain;
00201     };
00202 
00203     MESQUITE_EXPORT
00204     MeshDomain* find_vertex_domain( Mesh::VertexHandle vertex ) const
00205     {
00206         return find_domain( vertex, vertexList );
00207     }
00208     MESQUITE_EXPORT
00209     MeshDomain* find_element_domain( Mesh::ElementHandle element ) const
00210     {
00211         return find_domain( element, elementList );
00212     }
00213 
00214     MESQUITE_EXPORT
00215     void delete_sub_domains( bool yesno )
00216     {
00217         deleteSubDomains = yesno;
00218     }
00219 
00220     MESQUITE_EXPORT
00221     void delete_all_sub_domains();
00222 
00223   private:
00224     bool deleteSubDomains;
00225 
00226     static MeshDomain* find_domain( Mesh::EntityHandle handle, const std::vector< DomainBlock >& list );
00227 
00228     std::vector< DomainBlock > vertexList;
00229     std::vector< DomainBlock > elementList;
00230 };
00231 
00232 }  // namespace MBMesquite
00233 
00234 #endif  // MSQ_DOMAIN_CLASSIFIER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines