LCOV - code coverage report
Current view: top level - src/mesquite/Mesh - MeshImplData.hpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 16 25 64.0 %
Date: 2020-07-18 00:09:26 Functions: 11 17 64.7 %
Branches: 7 18 38.9 %

           Branch data     Line data    Source code
       1                 :            : /* *****************************************************************
       2                 :            :     MESQUITE -- The Mesh Quality Improvement Toolkit
       3                 :            : 
       4                 :            :     Copyright 2004 Lawrence Livermore National Laboratory.  Under
       5                 :            :     the terms of Contract B545069 with the University of Wisconsin --
       6                 :            :     Madison, Lawrence Livermore National Laboratory retains certain
       7                 :            :     rights in this software.
       8                 :            : 
       9                 :            :     This library is free software; you can redistribute it and/or
      10                 :            :     modify it under the terms of the GNU Lesser General Public
      11                 :            :     License as published by the Free Software Foundation; either
      12                 :            :     version 2.1 of the License, or (at your option) any later version.
      13                 :            : 
      14                 :            :     This library is distributed in the hope that it will be useful,
      15                 :            :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :            :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :            :     Lesser General Public License for more details.
      18                 :            : 
      19                 :            :     You should have received a copy of the GNU Lesser General Public License
      20                 :            :     (lgpl.txt) along with this library; if not, write to the Free Software
      21                 :            :     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      22                 :            : 
      23                 :            :     [email protected]
      24                 :            : 
      25                 :            :   ***************************************************************** */
      26                 :            : 
      27                 :            : #ifndef MESQUITE_MESH_IMPL_DATA_HPP
      28                 :            : #define MESQUITE_MESH_IMPL_DATA_HPP
      29                 :            : 
      30                 :            : #include "Mesquite.hpp"
      31                 :            : #include "Vector3D.hpp"
      32                 :            : #include "MeshInterface.hpp"
      33                 :            : 
      34                 :            : #include <vector>
      35                 :            : #include <sys/types.h>
      36                 :            : 
      37                 :            : namespace MBMesquite
      38                 :            : {
      39                 :            : 
      40                 :            : class MsqError;
      41                 :            : 
      42                 :            : /** Class to store mesh representation for MeshImpl */
      43                 :        286 : class MeshImplData
      44                 :            : {
      45                 :            : 
      46                 :            :   public:
      47 [ +  - ][ +  - ]:        143 :     MeshImplData() : haveSlavedFlags( false ) {}
                 [ +  - ]
      48                 :            : 
      49                 :            :     /** Clear all data */
      50                 :            :     void clear();
      51                 :            : 
      52                 :            :     /** Get number of vertices, does not include mid-nodes */
      53                 :            :     size_t num_vertices() const;
      54                 :            :     /** Get number of elements */
      55                 :            :     size_t num_elements() const;
      56                 :            :     /** Get number of vertex uses (sum of connectivity length for all elements)
      57                 :            :      * Does not count mid-nodes */
      58                 :            :     size_t num_vertex_uses() const;
      59                 :            : 
      60                 :     140982 :     size_t max_vertex_index() const
      61                 :            :     {
      62                 :     140982 :         return vertexList.size();
      63                 :            :     }
      64                 :     100920 :     size_t max_element_index() const
      65                 :            :     {
      66                 :     100920 :         return elementList.size();
      67                 :            :     }
      68                 :            : 
      69                 :            :     /** Copy internal representation into CSR rep
      70                 :            :      *  Does not include mid-nodes. */
      71                 :            :     void copy_mesh( size_t* vertex_handle_array, size_t* element_hanlde_array, size_t* element_conn_offsets,
      72                 :            :                     size_t* element_conn_indices );
      73                 :            : 
      74                 :            :     /** Get all vertices, including mid-nodes */
      75                 :            :     void all_vertices( std::vector< size_t >& list, MsqError& err ) const;
      76                 :            : 
      77                 :            :     /** Get all elements */
      78                 :            :     void all_elements( std::vector< size_t >& list, MsqError& err ) const;
      79                 :            : 
      80                 :            :     /** Check if passed vertex index is valid */
      81                 :   37722626 :     inline bool is_vertex_valid( size_t index ) const
      82                 :            :     {
      83 [ +  - ][ +  - ]:   37722626 :         return index < vertexList.size() && vertexList[index].valid;
      84                 :            :     }
      85                 :            : 
      86                 :            :     /** Check if passed element index is valid */
      87                 :    9176019 :     inline bool is_element_valid( size_t index ) const
      88                 :            :     {
      89 [ +  - ][ +  - ]:    9176019 :         return index < elementList.size() && !elementList[index].connectivity.empty();
      90                 :            :     }
      91                 :            : 
      92                 :            :     /** Check if the specified node is used as a mid-node on any element */
      93                 :            :     bool is_mid_node( size_t index ) const;
      94                 :            :     /** Check if the specified node is used as a corner vertex on any element */
      95                 :            :     bool is_corner_node( size_t index ) const;
      96                 :            : 
      97                 :            :     /** Get vertex coordinates */
      98                 :            :     const Vector3D& get_vertex_coords( size_t index, MsqError& err ) const;
      99                 :            : 
     100                 :            :     /** Set vertex coordinates */
     101                 :            :     void set_vertex_coords( size_t index, const Vector3D& coords, MsqError& err );
     102                 :            : 
     103                 :            :     /** Get vertex fixed flag */
     104                 :            :     bool vertex_is_fixed( size_t index, MsqError& err ) const;
     105                 :            : 
     106                 :            :     /** Get vertex slaved flag */
     107                 :            :     bool vertex_is_slaved( size_t index, MsqError& err ) const;
     108                 :            : 
     109                 :            :     /** Set vertex fixed flag */
     110                 :            :     void fix_vertex( size_t index, bool flag, MsqError& err );
     111                 :            : 
     112                 :            :     /** Set vertex slaved flag */
     113                 :            :     void slave_vertex( size_t index, bool flag, MsqError& err );
     114                 :            : 
     115                 :            :     /** Get vertex byte */
     116                 :            :     unsigned char get_vertex_byte( size_t index, MsqError& err ) const;
     117                 :            : 
     118                 :            :     /** Set vertex byte */
     119                 :            :     void set_vertex_byte( size_t index, unsigned char value, MsqError& err );
     120                 :            : 
     121                 :            :     /** Get element type */
     122                 :            :     EntityTopology element_topology( size_t index, MsqError& err ) const;
     123                 :            : 
     124                 :            :     /** Set element type */
     125                 :            :     void element_topology( size_t index, EntityTopology type, MsqError& err );
     126                 :            : 
     127                 :            :     /** Get element connectivity list, including mid-nodes */
     128                 :            :     const std::vector< size_t >& element_connectivity( size_t index, MsqError& err ) const;
     129                 :            : 
     130                 :            :     /** Get vertex adjacency list */
     131                 :            :     const std::vector< size_t >& vertex_adjacencies( size_t index, MsqError& err ) const;
     132                 :            : 
     133                 :            :     /** Allocate space for specified number of vertices */
     134                 :            :     void allocate_vertices( size_t count, MsqError& err );
     135                 :            : 
     136                 :            :     /** Allocate space for specified number of elements */
     137                 :            :     void allocate_elements( size_t count, MsqError& err );
     138                 :            : 
     139                 :            :     /** Set allocated but unset veretx to specified values */
     140                 :            :     void reset_vertex( size_t index, const Vector3D& coords, bool fixed, MsqError& err );
     141                 :            : 
     142                 :            :     /**
     143                 :            :      *  Clear element at specified index (if any) including
     144                 :            :      *  connectivity and adjacency data, and re-initialize with
     145                 :            :      *  passed data.
     146                 :            :      */
     147                 :            :     void reset_element( size_t index, const std::vector< long >& vertices, EntityTopology topology, MsqError& err );
     148                 :            :     void reset_element( size_t index, const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err );
     149                 :            : 
     150                 :            :     /** Add a new vertex */
     151                 :            :     size_t add_vertex( const Vector3D& coords, bool fixed, MsqError& err );
     152                 :            :     /** Add a new element */
     153                 :            :     size_t add_element( const std::vector< long >& vertices, EntityTopology topology, MsqError& err );
     154                 :            :     size_t add_element( const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err );
     155                 :            : 
     156                 :            :     /** Delete a vertex - may not be referenced by any element */
     157                 :            :     void delete_vertex( size_t index, MsqError& err );
     158                 :            :     /** Delete an element */
     159                 :            :     void delete_element( size_t index, MsqError& err );
     160                 :            : 
     161                 :            :     /** Get all mid-nodes and their adjacent corner vertices */
     162                 :            :     void copy_higher_order( std::vector< size_t >& mid_nodes, std::vector< size_t >& vertices,
     163                 :            :                             std::vector< size_t >& vertex_indices, std::vector< size_t >& index_offsets,
     164                 :            :                             MsqError& err );
     165                 :            : 
     166                 :            :     /** \brief Get elements adjacent to ALL of the passed nodes.
     167                 :            :      *
     168                 :            :      * Return the list of elements that is the intersection of the
     169                 :            :      * adjacency lists of the specified vertices.
     170                 :            :      */
     171                 :            :     void get_adjacent_elements( std::vector< size_t >::const_iterator nodes,
     172                 :            :                                 std::vector< size_t >::const_iterator nodes_end, std::vector< size_t >& elems_out,
     173                 :            :                                 MsqError& err );
     174                 :            : 
     175                 :            :     /**\brief Skin mesh
     176                 :            :      *
     177                 :            :      * Get the boundary of a mesh as element sides
     178                 :            :      *
     179                 :            :      *\param sides Element sides as pairs of values : { elem_index, side_number }
     180                 :            :      */
     181                 :            :     void skin( std::vector< size_t >& sides, MsqError& err );
     182                 :            : 
     183                 :       1186 :     bool have_slaved_flags() const
     184                 :            :     {
     185                 :       1186 :         return haveSlavedFlags;
     186                 :            :     }
     187                 :            : 
     188                 :            :   private:
     189                 :            :     /**\brief helper function for skinning
     190                 :            :      *
     191                 :            :      * Check if any elements adjacent to a side of an element
     192                 :            :      * are of the same dimension as the input element.
     193                 :            :      *\param elem  The element
     194                 :            :      *\param nodes The nodes composing the side of the element
     195                 :            :      */
     196                 :            :     bool has_adjacent_elements( size_t elem, const std::vector< size_t >& nodes, MsqError& err );
     197                 :            : 
     198                 :            :     /** Clear existing element data */
     199                 :            :     void clear_element( size_t index, MsqError& err );
     200                 :            : 
     201                 :            :     /** Set cleared element */
     202                 :            :     void set_element( size_t index, const std::vector< long >& vertices, EntityTopology topology, MsqError& err );
     203                 :            : 
     204                 :            :     /** Set cleared element */
     205                 :            :     void set_element( size_t index, const std::vector< size_t >& vertices, EntityTopology topology, MsqError& err );
     206                 :            : 
     207                 :            :     /** Struct holding a vertex */
     208                 :     131502 :     struct Vertex
     209                 :            :     {
     210                 :          0 :         Vertex( const Vector3D& pos, bool is_fixed )
     211                 :          0 :             : coords( pos ), midcount( 0 ), fixed( is_fixed ), valid( true ), byte( '\0' )
     212                 :            :         {
     213                 :          0 :         }
     214                 :            : 
     215                 :     131502 :         Vertex() : midcount( 0 ), valid( false ), byte( '\0' ) {}
     216                 :            : 
     217                 :            :         Vector3D coords;                   /**< location */
     218                 :            :         std::vector< size_t > adjacencies; /**< indices of adjacent elements */
     219                 :            :         unsigned midcount;                 /**< num elements referencing this as a mid-node */
     220                 :            :         bool fixed;                        /**< is fixed */
     221                 :            :         bool slaved;
     222                 :            :         bool valid;         /**< is a valid (initialized) array entry */
     223                 :            :         unsigned char byte; /**< mark */
     224                 :            :     };
     225                 :            : 
     226                 :            :     /** Struct holding an element */
     227                 :     232612 :     struct Element
     228                 :            :     {
     229                 :            :         std::vector< size_t > connectivity; /**< list of vertex indices */
     230                 :            :         EntityTopology topology;            /**< element type */
     231                 :     232612 :         Element() : topology( MIXED ) {}
     232                 :            :     };
     233                 :            : 
     234                 :            :     std::vector< Vertex > vertexList;   /**< Array of vertices */
     235                 :            :     std::vector< Element > elementList; /**< Array of elements */
     236                 :            : 
     237                 :            :     /** List of unused indices in vertex list */
     238                 :            :     std::vector< size_t > deletedVertexList;
     239                 :            :     /** List of unused indices in element list */
     240                 :            :     std::vector< size_t > deletedElementList;
     241                 :            : 
     242                 :            :     bool haveSlavedFlags;
     243                 :            : };
     244                 :            : 
     245                 :            : /**\brief VertexIterator for MeshImpl
     246                 :            :  *
     247                 :            :  * Iterate over valid vertex indices
     248                 :            :  */
     249                 :            : class MeshImplVertIter : public VertexIterator
     250                 :            : {
     251                 :            :   private:
     252                 :            :     MeshImplData* mesh;
     253                 :            :     size_t index;
     254                 :            : 
     255                 :            :   public:
     256                 :          0 :     MeshImplVertIter( MeshImplData* data ) : mesh( data )
     257                 :            :     {
     258         [ #  # ]:          0 :         restart();
     259                 :          0 :     }
     260                 :            : 
     261                 :            :     virtual ~MeshImplVertIter();
     262                 :            : 
     263                 :            :     virtual void restart();
     264                 :            : 
     265                 :            :     virtual void operator++();
     266                 :            : 
     267                 :            :     virtual Mesh::VertexHandle operator*() const;
     268                 :            : 
     269                 :            :     virtual bool is_at_end() const;
     270                 :            : };
     271                 :            : 
     272                 :            : /**\brief ElementIterator for MeshImpl
     273                 :            :  *
     274                 :            :  * Iterate over valid element indices
     275                 :            :  */
     276                 :            : class MeshImplElemIter : public ElementIterator
     277                 :            : {
     278                 :            :   private:
     279                 :            :     MeshImplData* mesh;
     280                 :            :     size_t index;
     281                 :            : 
     282                 :            :   public:
     283                 :          0 :     MeshImplElemIter( MeshImplData* data ) : mesh( data )
     284                 :            :     {
     285         [ #  # ]:          0 :         restart();
     286                 :          0 :     }
     287                 :            : 
     288                 :            :     virtual ~MeshImplElemIter();
     289                 :            : 
     290                 :            :     virtual void restart();
     291                 :            : 
     292                 :            :     virtual void operator++();
     293                 :            : 
     294                 :            :     virtual Mesh::ElementHandle operator*() const;
     295                 :            : 
     296                 :            :     virtual bool is_at_end() const;
     297                 :            : };
     298                 :            : 
     299                 :            : }  // namespace MBMesquite
     300                 :            : 
     301                 :            : #endif

Generated by: LCOV version 1.11