LCOV - code coverage report
Current view: top level - include/raytracing - ElemExtrema.h (source / functions) Hit Total Coverage
Test: idaholab/moose ray_tracing: #31405 (292dce) with base fef103 Lines: 19 19 100.0 %
Date: 2025-09-04 07:56:07 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "RayTracingCommon.h"
      13             : 
      14             : // MOOSE includes
      15             : #include "MooseTypes.h"
      16             : 
      17             : namespace libMesh
      18             : {
      19             : class Elem;
      20             : }
      21             : 
      22             : /**
      23             :  * Helper for defining if at an element's edge, vertex, or neither
      24             :  */
      25             : struct ElemExtrema : std::pair<unsigned short, unsigned short>
      26             : {
      27             :   /**
      28             :    * Default constructor: sets entires to invalid (not at vertex or edge)
      29             :    */
      30             :   ElemExtrema()
      31             :     : std::pair<unsigned short, unsigned short>(RayTracingCommon::invalid_vertex,
      32             :                                                 RayTracingCommon::invalid_vertex)
      33             :   {
      34             :   }
      35             : 
      36             :   ElemExtrema(const unsigned short v1, const unsigned short v2)
      37             :     : std::pair<unsigned short, unsigned short>(v1, v2)
      38             :   {
      39             :   }
      40             : 
      41             :   /**
      42             :    * @returns true if at the extrema (edge or vertex)
      43             :    */
      44    81788869 :   bool atExtrema() const { return first != RayTracingCommon::invalid_vertex; }
      45             :   /**
      46             :    * @returns true if the data is invalid
      47             :    */
      48             :   bool isInvalid() const
      49             :   {
      50        3411 :     return first == RayTracingCommon::invalid_vertex && second == RayTracingCommon::invalid_vertex;
      51             :   }
      52             : 
      53             :   /**
      54             :    * @returns true if at a vertex
      55             :    */
      56             :   bool atVertex() const
      57             :   {
      58    14399419 :     return first != RayTracingCommon::invalid_vertex && second == RayTracingCommon::invalid_vertex;
      59             :   }
      60             :   /**
      61             :    * @returns true if at vertex \p v
      62             :    */
      63             :   bool atVertex(const unsigned short v) const
      64             :   {
      65           3 :     return first == v && second == RayTracingCommon::invalid_vertex;
      66             :   }
      67             : 
      68             :   /**
      69             :    * @returns true if at an edge
      70             :    */
      71             :   bool atEdge() const
      72             :   {
      73     1117197 :     return first != RayTracingCommon::invalid_vertex && second != RayTracingCommon::invalid_vertex;
      74             :   }
      75             :   /**
      76             :    * @returns true if at the edge defined by vertices \p v1 and \p v2
      77             :    */
      78             :   bool atEdge(const unsigned short v1, const unsigned short v2) const
      79             :   {
      80    15000392 :     return second != RayTracingCommon::invalid_vertex &&
      81     4128422 :            ((first == v1 && second == v2) || (first == v2 && second == v1));
      82             :   }
      83             : 
      84             :   /**
      85             :    * Invalidates the current state
      86             :    */
      87             :   void invalidate()
      88             :   {
      89   239917004 :     first = RayTracingCommon::invalid_vertex;
      90   239228836 :     second = RayTracingCommon::invalid_vertex;
      91      688168 :   }
      92             : 
      93             :   /**
      94             :    * @returns The vertex ID when at a vertex
      95             :    */
      96             :   unsigned short vertex() const
      97             :   {
      98             :     mooseAssert(atVertex(), "Not at a vertex");
      99          11 :     return first;
     100             :   }
     101             :   /**
     102             :    * @returns The vertices that contain the edge when at an edge
     103             :    */
     104             :   const std::pair<unsigned short, unsigned short> & edgeVertices() const
     105             :   {
     106             :     mooseAssert(atEdge(), "Not at an edge");
     107     4325854 :     return *this;
     108             :   }
     109             : 
     110             :   /**
     111             :    * Prints the current state (at edge, at vertex, not at either)
     112             :    */
     113             :   std::string print() const;
     114             : 
     115             :   /**
     116             :    * Sets the "at vertex" state
     117             :    */
     118             :   void setVertex(const unsigned short vertex)
     119             :   {
     120             :     mooseAssert(vertex != RayTracingCommon::invalid_vertex, "Setting invalid vertex");
     121     3663258 :     first = vertex;
     122        9744 :     second = RayTracingCommon::invalid_vertex;
     123     3657642 :   }
     124             :   /**
     125             :    * Sets the "at edge" state
     126             :    */
     127             :   void setEdge(const unsigned short v1, const unsigned short v2)
     128             :   {
     129             :     mooseAssert(v1 != RayTracingCommon::invalid_vertex, "Setting invalid vertex");
     130             :     mooseAssert(v2 != RayTracingCommon::invalid_vertex, "Setting invalid vertex");
     131     8502408 :     first = v1;
     132      983400 :     second = v2;
     133     7519008 :   }
     134             :   /**
     135             :    * Sets the "at edge" state
     136             :    */
     137             :   void setEdge(const std::pair<unsigned short, unsigned short> & vertices)
     138             :   {
     139           1 :     setEdge(vertices.first, vertices.second);
     140             :   }
     141             : 
     142             :   /**
     143             :    * @returns The vertex point when at a vertex
     144             :    */
     145             :   const Point & vertexPoint(const libMesh::Elem * elem) const;
     146             :   /**
     147             :    * @returns The edge when at an edge
     148             :    */
     149             :   std::unique_ptr<const libMesh::Elem> buildEdge(const Elem * elem) const;
     150             :   /**
     151             :    * @returns Whether or not the current state (at vertex/edge) is valid
     152             :    * for the given \p elem and \p point.
     153             :    *
     154             :    * This ONLY checks for validity when atExtrema().
     155             :    */
     156             :   bool isValid(const Elem * const elem, const Point & point) const;
     157             : };
     158             : 
     159             : std::ostream & operator<<(std::ostream & os, const ElemExtrema & elem_extrema);

Generated by: LCOV version 1.14