LCOV - code coverage report
Current view: top level - src/mesquite/QualityMetric - EdgeQM.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 39 51 76.5 %
Date: 2020-07-18 00:09:26 Functions: 7 9 77.8 %
Branches: 48 100 48.0 %

           Branch data     Line data    Source code
       1                 :            : /* *****************************************************************
       2                 :            :     MESQUITE -- The Mesh Quality Improvement Toolkit
       3                 :            : 
       4                 :            :     Copyright 2009 Sandia National Laboratories.  Developed at the
       5                 :            :     University of Wisconsin--Madison under SNL contract number
       6                 :            :     624796.  The U.S. Government and the University of Wisconsin
       7                 :            :     retain certain rights to 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                 :            :     (2009) [email protected]
      24                 :            : 
      25                 :            :   ***************************************************************** */
      26                 :            : 
      27                 :            : /** \file EdgeQM.cpp
      28                 :            :  *  \brief
      29                 :            :  *  \author Jason Kraftcheck
      30                 :            :  */
      31                 :            : 
      32                 :            : #include "Mesquite.hpp"
      33                 :            : #include "EdgeQM.hpp"
      34                 :            : #include "ElemSampleQM.hpp"
      35                 :            : #include "PatchData.hpp"
      36                 :            : #include "TopologyInfo.hpp"
      37                 :            : 
      38                 :            : namespace MBMesquite
      39                 :            : {
      40                 :            : 
      41         [ -  + ]:         12 : EdgeQM::~EdgeQM() {}
      42                 :            : 
      43                 :          0 : void EdgeQM::get_evaluations( PatchData& pd, std::vector< size_t >& handles, bool free_vertices_only, MsqError& err )
      44                 :            : {
      45                 :          0 :     get_edge_evaluations( pd, handles, free_vertices_only, false, err );
      46                 :          0 : }
      47                 :            : 
      48                 :      36630 : void EdgeQM::get_single_pass( PatchData& pd, std::vector< size_t >& handles, bool free_vertices_only, MsqError& err )
      49                 :            : {
      50                 :      36630 :     get_edge_evaluations( pd, handles, free_vertices_only, true, err );
      51                 :      36630 : }
      52                 :            : 
      53                 :            : struct EdgeData
      54                 :            : {
      55                 :            :     size_t endVtx;
      56                 :            :     size_t adjElem;
      57                 :            :     unsigned elemEdge;
      58                 :            : };
      59                 :            : 
      60                 :     762692 : inline bool operator<( const EdgeData& e1, const EdgeData& e2 )
      61                 :            : {
      62                 :     762692 :     return e1.endVtx < e2.endVtx;
      63                 :            : }
      64                 :     256314 : inline bool operator==( const EdgeData& e1, const EdgeData& e2 )
      65                 :            : {
      66                 :     256314 :     return e1.endVtx == e2.endVtx;
      67                 :            : }
      68                 :            : 
      69                 :      36630 : void EdgeQM::get_edge_evaluations( PatchData& pd, std::vector< size_t >& handles, bool free_vertices_only,
      70                 :            :                                    bool single_pass_evaluate, MsqError& err )
      71                 :            : {
      72         [ +  - ]:      36630 :     std::vector< EdgeData > vtx_edges;
      73 [ +  - ][ +  - ]:      36630 :     size_t n_verts  = free_vertices_only ? pd.num_free_vertices() : pd.num_nodes();
                 [ #  # ]
      74 [ +  - ][ +  - ]:      36630 :     size_t n_cutoff = single_pass_evaluate ? pd.num_nodes() : n_verts;
      75                 :      36630 :     handles.clear();
      76                 :            : 
      77 [ +  + ][ +  - ]:      73260 :     for( size_t i = 0; i < n_verts; ++i )
      78                 :            :     {
      79 [ +  - ][ +  - ]:      36630 :         if( pd.vertex_by_index( i ).is_flag_set( MsqVertex::MSQ_PATCH_FIXED ) ) continue;
                 [ -  + ]
      80                 :            : 
      81                 :      36630 :         vtx_edges.clear();
      82                 :            : 
      83                 :            :         size_t n_elems;
      84                 :            :         const size_t* elems;
      85 [ +  - ][ +  - ]:      36630 :         elems = pd.get_vertex_element_adjacencies( i, n_elems, err );MSQ_ERRRTN( err );
         [ -  + ][ #  # ]
         [ #  # ][ -  + ]
      86                 :            : 
      87         [ +  + ]:     183102 :         for( size_t j = 0; j < n_elems; ++j )
      88                 :            :         {
      89         [ +  - ]:     146472 :             MsqMeshEntity& elem = pd.element_by_index( elems[j] );
      90 [ +  - ][ +  - ]:     146472 :             unsigned n_edges    = TopologyInfo::edges( elem.get_element_type() );
      91         [ +  + ]:     732360 :             for( unsigned k = 0; k < n_edges; ++k )
      92                 :            :             {
      93 [ +  - ][ +  - ]:     585888 :                 const unsigned* edge = TopologyInfo::edge_vertices( elem.get_element_type(), k, err );MSQ_ERRRTN( err );
         [ +  - ][ -  + ]
         [ #  # ][ #  # ]
                 [ -  + ]
      94                 :            : 
      95         [ +  - ]:     585888 :                 size_t vtx1 = elem.get_vertex_index_array()[edge[0]];
      96         [ +  - ]:     585888 :                 size_t vtx2 = elem.get_vertex_index_array()[edge[1]];
      97                 :            :                 size_t other;
      98         [ +  + ]:     585888 :                 if( vtx1 == i )
      99                 :     146472 :                     other = vtx2;
     100         [ +  + ]:     439416 :                 else if( vtx2 == i )
     101                 :     146472 :                     other = vtx1;
     102                 :            :                 else
     103                 :     292944 :                     continue;
     104                 :            : 
     105                 :            :                 // If !free_vertices_only, we'll visit every edge twice.
     106                 :            :                 // The first check below ensures that we only add each edge
     107                 :            :                 // once.  The second check is never true unless free_vertices_only
     108                 :            :                 // is true and single_pass_evaluate is false.  In that case, it
     109                 :            :                 // serves as an exception to the first rule for those cases in which
     110                 :            :                 // we visit an edge only once.  For single_pass_evaluate (e.g.
     111                 :            :                 // BCD initialization or QualityAssessor) we want to avoid visiting
     112                 :            :                 // and edge more than once for every patch rather than just within
     113                 :            :                 // this patch.
     114 [ -  + ][ #  # ]:     292944 :                 if( other > i || other > n_cutoff )
     115                 :            :                 {
     116                 :     292944 :                     EdgeData d = { other, elems[j], k };
     117         [ +  - ]:     292944 :                     vtx_edges.push_back( d );
     118                 :            :                 }
     119                 :            :             }  // end for each edge in element
     120                 :            :         }      // end for each element adjacent to vertex
     121                 :            : 
     122         [ +  - ]:      36630 :         std::sort( vtx_edges.begin(), vtx_edges.end() );
     123                 :      36630 :         std::vector< EdgeData >::iterator it, end;
     124         [ +  - ]:      36630 :         end = std::unique( vtx_edges.begin(), vtx_edges.end() );
     125 [ +  - ][ +  - ]:     183102 :         for( it = vtx_edges.begin(); it != end; ++it )
                 [ +  + ]
     126 [ +  - ][ +  - ]:     146472 :             handles.push_back( handle( it->elemEdge, it->adjElem ) );
         [ +  - ][ +  - ]
     127                 :      36630 :     }  // end for each (free) vertex
     128                 :            : }
     129                 :            : 
     130                 :          0 : bool EdgeQM::evaluate_with_indices( PatchData& pd, size_t p_handle, double& value, std::vector< size_t >& indices,
     131                 :            :                                     MsqError& err )
     132                 :            : {
     133                 :          0 :     const MsqMeshEntity& element = pd.element_by_index( elem( p_handle ) );
     134                 :          0 :     EntityTopology type          = element.get_element_type();
     135                 :          0 :     const unsigned* verts        = TopologyInfo::edge_vertices( type, edge( p_handle ) );
     136                 :          0 :     const size_t* conn           = element.get_vertex_index_array();
     137                 :          0 :     indices.clear();
     138         [ #  # ]:          0 :     if( conn[verts[0]] < pd.num_free_vertices() ) indices.push_back( conn[verts[0]] );
     139         [ #  # ]:          0 :     if( conn[verts[1]] < pd.num_free_vertices() ) indices.push_back( conn[verts[1]] );
     140                 :          0 :     return evaluate( pd, p_handle, value, err );
     141                 :            : }
     142                 :            : 
     143 [ +  - ][ +  - ]:          8 : }  // namespace MBMesquite

Generated by: LCOV version 1.11