Quinoa all test code coverage report
Current view: top level - Mesh - DerivedData.hpp (source / functions) Hit Total Coverage
Commit: -128-NOTFOUND Lines: 21 21 100.0 %
Date: 2024-04-29 14:42:33 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // *****************************************************************************
       2                 :            : /*!
       3                 :            :   \file      src/Mesh/DerivedData.hpp
       4                 :            :   \copyright 2012-2015 J. Bakosi,
       5                 :            :              2016-2018 Los Alamos National Security, LLC.,
       6                 :            :              2019-2021 Triad National Security, LLC.
       7                 :            :              All rights reserved. See the LICENSE file for details.
       8                 :            :   \brief     Generate data structures derived from unstructured mesh
       9                 :            :   \details   Generate data structures derived from the connectivity information
      10                 :            :      of an unstructured mesh.
      11                 :            : */
      12                 :            : // *****************************************************************************
      13                 :            : #ifndef DerivedData_h
      14                 :            : #define DerivedData_h
      15                 :            : 
      16                 :            : #include <vector>
      17                 :            : #include <map>
      18                 :            : #include <utility>
      19                 :            : #include <cstddef>
      20                 :            : #include "Types.hpp"
      21                 :            : #include "Fields.hpp"
      22                 :            : #include "UnsMesh.hpp"
      23                 :            : 
      24                 :            : namespace tk {
      25                 :            : 
      26                 :            : //! Const array defining the node ordering convention for tetrahedron faces
      27                 :            : //! \details This two-dimensional array stores the naming/ordering convention of
      28                 :            : //!   the node indices of a tetrahedron (tet) element. The dimensions are 4x3 as
      29                 :            : //!   a tetrahedron has a total of 4 nodes and each (triangle) face has 3 nodes.
      30                 :            : //!   Thus the array below associates tet node 0 with nodes {1,2,3}, tet node 1
      31                 :            : //!   with {2,0,3}, tet node 2 with {3,0,1}, and tet node 3 with {0,2,1}. Note
      32                 :            : //!   that not only these mappings are important, but also the order of the
      33                 :            : //!   nodes within the triplets as this specific order also defines the outwards
      34                 :            : //!   normal of each face.
      35                 :            : const std::array< UnsMesh::Face, 4 >
      36                 :            :   lpofa{{ {{1,2,3}}, {{2,0,3}}, {{3,0,1}}, {{0,2,1}} }};
      37                 :            : 
      38                 :            : //! Const array defining the node ordering convention for tetrahedron edges
      39                 :            : const std::array< UnsMesh::Edge, 6 >
      40                 :            :   lpoed{{ {{0,1}}, {{1,2}}, {{0,2}}, {{0,3}}, {{1,3}}, {{2,3}} }};
      41                 :            : 
      42                 :            : //! Const array defining the node ordering convention for triangle edges
      43                 :            : const std::array< UnsMesh::Edge, 3 > lpoet{{ {{0,1}}, {{1,2}}, {{2,0}} }};
      44                 :            : 
      45                 :            : //! Determine edge orientation
      46                 :            : int
      47                 :            : orient( const UnsMesh::Edge& t, const UnsMesh::Edge& e );
      48                 :            : 
      49                 :            : //! Compute number of points (nodes) in mesh from connectivity
      50                 :            : std::size_t
      51                 :            : npoin_in_graph( const std::vector< std::size_t >& inpoel );
      52                 :            : 
      53                 :            : //! Compute the unit normal vector of a triangle
      54                 :            : //! \param[in] x1 x coordinate of the 1st vertex of the triangle
      55                 :            : //! \param[in] x2 x coordinate of the 2nd vertex of the triangle
      56                 :            : //! \param[in] x3 x coordinate of the 3rd vertex of the triangle
      57                 :            : //! \param[in] y1 y coordinate of the 1st vertex of the triangle
      58                 :            : //! \param[in] y2 y coordinate of the 2nd vertex of the triangle
      59                 :            : //! \param[in] y3 y coordinate of the 3rd vertex of the triangle
      60                 :            : //! \param[in] z1 z coordinate of the 1st vertex of the triangle
      61                 :            : //! \param[in] z2 z coordinate of the 2nd vertex of the triangle
      62                 :            : //! \param[in] z3 z coordinate of the 3rd vertex of the triangle
      63                 :            : //! \param[out] nx x coordinate of the unit normal
      64                 :            : //! \param[out] ny y coordinate of the unit normal
      65                 :            : //! \param[out] nz z coordinate of the unit normal
      66                 :            : #pragma omp declare simd
      67                 :            : inline void
      68                 :    6034245 : normal( real x1, real x2, real x3,
      69                 :            :         real y1, real y2, real y3,
      70                 :            :         real z1, real z2, real z3,
      71                 :            :         real& nx, real& ny, real& nz )
      72                 :            : {
      73                 :    6034245 :   real ax = x2 - x1;
      74                 :    6034245 :   real ay = y2 - y1;
      75                 :    6034245 :   real az = z2 - z1;
      76                 :            : 
      77                 :    6034245 :   real bx = x3 - x1;
      78                 :    6034245 :   real by = y3 - y1;
      79                 :    6034245 :   real bz = z3 - z1;
      80                 :            : 
      81                 :    6034245 :   real n1 =   ay*bz - az*by;
      82                 :    6034245 :   real n2 = -(ax*bz - az*bx);
      83                 :    6034245 :   real n3 =   ax*by - ay*bx;
      84                 :            : 
      85                 :    6034245 :   auto farea = std::sqrt( n1*n1 + n2*n2 + n3*n3 );
      86                 :            : 
      87                 :    6034245 :   nx = n1/farea;
      88                 :    6034245 :   ny = n2/farea;
      89                 :    6034245 :   nz = n3/farea;
      90                 :    6034245 : }
      91                 :            : 
      92                 :            : //! Compute the unit normal vector of a triangle
      93                 :            : std::array< real, 3 >
      94                 :            : normal( const std::array< real, 3 >& x,
      95                 :            :         const std::array< real, 3 >& y,
      96                 :            :         const std::array< real, 3 >& z );
      97                 :            : 
      98                 :            : //! Compute the are of a triangle
      99                 :            : //! \param[in] x1 x coordinate of the 1st vertex of the triangle
     100                 :            : //! \param[in] x2 x coordinate of the 2nd vertex of the triangle
     101                 :            : //! \param[in] x3 x coordinate of the 3rd vertex of the triangle
     102                 :            : //! \param[in] y1 y coordinate of the 1st vertex of the triangle
     103                 :            : //! \param[in] y2 y coordinate of the 2nd vertex of the triangle
     104                 :            : //! \param[in] y3 y coordinate of the 3rd vertex of the triangle
     105                 :            : //! \param[in] z1 z coordinate of the 1st vertex of the triangle
     106                 :            : //! \param[in] z2 z coordinate of the 2nd vertex of the triangle
     107                 :            : //! \param[in] z3 z coordinate of the 3rd vertex of the triangle
     108                 :            : //! \return Area of the triangle
     109                 :            : #pragma omp declare simd
     110                 :            : inline real
     111                 :    6034245 : area( real x1, real x2, real x3,
     112                 :            :       real y1, real y2, real y3,
     113                 :            :       real z1, real z2, real z3 )
     114                 :            : {
     115                 :    6034245 :   auto sidea = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) );
     116                 :    6034245 :   auto sideb = sqrt( (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2) + (z3-z2)*(z3-z2) );
     117                 :    6034245 :   auto sidec = sqrt( (x1-x3)*(x1-x3) + (y1-y3)*(y1-y3) + (z1-z3)*(z1-z3) );
     118                 :            : 
     119                 :    6034245 :   auto semip = 0.5 * (sidea + sideb + sidec);
     120                 :            : 
     121                 :    6034245 :   return sqrt( semip * (semip-sidea) * (semip-sideb) * (semip-sidec) );
     122                 :            : }
     123                 :            : 
     124                 :            : //! Compute the area of a triangle
     125                 :            : real
     126                 :            : area( const std::array< real, 3 >& x,
     127                 :            :       const std::array< real, 3 >& y,
     128                 :            :       const std::array< real, 3 >& z );
     129                 :            : 
     130                 :            : //! Generate derived data structure, elements surrounding points
     131                 :            : std::pair< std::vector< std::size_t >, std::vector< std::size_t > >
     132                 :            : genEsup( const std::vector< std::size_t >& inpoel, std::size_t nnpe );
     133                 :            : 
     134                 :            : //! Generate derived data structure, points surrounding points
     135                 :            : std::pair< std::vector< std::size_t >, std::vector< std::size_t > >
     136                 :            : genPsup( const std::vector< std::size_t >& inpoel,
     137                 :            :          std::size_t nnpe,
     138                 :            :          const std::pair< std::vector< std::size_t >,
     139                 :            :                           std::vector< std::size_t > >& esup );
     140                 :            : 
     141                 :            : //! Generate derived data structure, edges surrounding points
     142                 :            : std::pair< std::vector< std::size_t >, std::vector< std::size_t > >
     143                 :            : genEdsup( const std::vector< std::size_t >& inpoel,
     144                 :            :           std::size_t nnpe,
     145                 :            :           const std::pair< std::vector< std::size_t >,
     146                 :            :                            std::vector< std::size_t > >& esup );
     147                 :            : 
     148                 :            : //! Generate derived data structure, edge connectivity
     149                 :            : std::vector< std::size_t >
     150                 :            : genInpoed( const std::vector< std::size_t >& inpoel,
     151                 :            :            std::size_t nnpe,
     152                 :            :            const std::pair< std::vector< std::size_t >,
     153                 :            :                             std::vector< std::size_t > >& esup );
     154                 :            : 
     155                 :            : //! Generate derived data structure, elements surrounding points of elements
     156                 :            : std::pair< std::vector< std::size_t >, std::vector< std::size_t > >
     157                 :            : genEsupel( const std::vector< std::size_t >& inpoel,
     158                 :            :            std::size_t nnpe,
     159                 :            :            const std::pair< std::vector< std::size_t >,
     160                 :            :                             std::vector< std::size_t > >& esup );
     161                 :            : 
     162                 :            : //! Generate derived data structure, elements surrounding elements
     163                 :            : std::pair< std::vector< std::size_t >, std::vector< std::size_t > >
     164                 :            : genEsuel( const std::vector< std::size_t >& inpoel,
     165                 :            :           std::size_t nnpe,
     166                 :            :           const std::pair< std::vector< std::size_t >,
     167                 :            :                            std::vector< std::size_t > >& esup );
     168                 :            : 
     169                 :            : //! \brief Generate derived data structure, elements surrounding elements
     170                 :            : //!   as a fixed length data structure as a full vector, including boundary
     171                 :            : //!   elements as -1.
     172                 :            : std::vector< int >
     173                 :            : genEsuelTet( const std::vector< std::size_t >& inpoel,
     174                 :            :              const std::pair< std::vector< std::size_t >,
     175                 :            :                               std::vector< std::size_t > >& esup );
     176                 :            : 
     177                 :            : //! Generate derived data structure, edges of elements
     178                 :            : std::vector< std::size_t >
     179                 :            : genInedel( const std::vector< std::size_t >& inpoel,
     180                 :            :            std::size_t nnpe,
     181                 :            :            const std::vector< std::size_t >& inpoed );
     182                 :            : 
     183                 :            : //! Generate derived data structure, elements surrounding edges
     184                 :            : std::unordered_map< UnsMesh::Edge, std::vector< std::size_t >,
     185                 :            :                     UnsMesh::Hash<2>, UnsMesh::Eq<2> >
     186                 :            : genEsued( const std::vector< std::size_t >& inpoel,
     187                 :            :           std::size_t nnpe,
     188                 :            :           const std::pair< std::vector< std::size_t >,
     189                 :            :                            std::vector< std::size_t > >& esup );
     190                 :            : 
     191                 :            : //! Generate total number of boundary faces in this chunk
     192                 :            : std::size_t
     193                 :            : genNbfacTet( std::size_t tnbfac,
     194                 :            :              const std::vector< std::size_t >& inpoel,
     195                 :            :              const std::vector< std::size_t >& triinpoel_complete,
     196                 :            :              const std::map< int, std::vector< std::size_t > >& bface_complete,
     197                 :            :              const std::unordered_map< std::size_t, std::size_t >& lid,
     198                 :            :              std::vector< std::size_t >& triinpoel,
     199                 :            :              std::map< int, std::vector< std::size_t > >& bface );
     200                 :            : 
     201                 :            : //! Generate number of internal and physical-boundary faces
     202                 :            : std::size_t
     203                 :            : genNipfac( std::size_t nfpe,
     204                 :            :            std::size_t nbfac,
     205                 :            :            const std::vector< int >& esuelTet );
     206                 :            : 
     207                 :            : //! Generate derived data structure, elements surrounding faces
     208                 :            : std::vector< int >
     209                 :            : genEsuf( std::size_t nfpe,
     210                 :            :          std::size_t nipfac,
     211                 :            :          std::size_t nbfac,
     212                 :            :          const std::vector< std::size_t >& belem,
     213                 :            :          const std::vector< int >& esuelTet );
     214                 :            : 
     215                 :            : //! Generate derived data structure, node-face connectivity
     216                 :            : std::vector< std::size_t >
     217                 :            : genInpofaTet( std::size_t nipfac,
     218                 :            :               std::size_t nbfac,
     219                 :            :               const std::vector< std::size_t >& inpoel,
     220                 :            :               const std::vector< std::size_t >& triinpoel,
     221                 :            :               const std::vector< int >& esuelTet );
     222                 :            : 
     223                 :            : //! Generate derived data structure, host/boundary element
     224                 :            : std::vector< std::size_t >
     225                 :            : genBelemTet( std::size_t nbfac,
     226                 :            :               const std::vector< std::size_t >& inpofa,
     227                 :            :               const std::pair< std::vector< std::size_t >,
     228                 :            :                                std::vector< std::size_t > >& esup );
     229                 :            : 
     230                 :            : //! Generate derived data structure, face geometry
     231                 :            : Fields
     232                 :            : genGeoFaceTri( std::size_t nipfac,
     233                 :            :                const std::vector< std::size_t >& inpofa,
     234                 :            :                const UnsMesh::Coords& coord );
     235                 :            : 
     236                 :            : //! Compute geometry of the face given by three vertices
     237                 :            : Fields
     238                 :            : geoFaceTri( const std::array< real, 3 >& x,
     239                 :            :             const std::array< real, 3 >& y,
     240                 :            :             const std::array< real, 3 >& z );
     241                 :            : 
     242                 :            : //! Generate derived data structure, element geometry
     243                 :            : Fields
     244                 :            : genGeoElemTet( const std::vector< std::size_t >& inpoel,
     245                 :            :                const UnsMesh::Coords& coord );
     246                 :            : 
     247                 :            : //! Perform leak-test on mesh (partition)
     248                 :            : bool
     249                 :            : leakyPartition( const std::vector< int >& esueltet,
     250                 :            :                 const std::vector< std::size_t >& inpoel,
     251                 :            :                 const UnsMesh::Coords& coord );
     252                 :            : 
     253                 :            : //! Check if mesh (partition) is conforming
     254                 :            : bool
     255                 :            : conforming( const std::vector< std::size_t >& inpoel,
     256                 :            :             const UnsMesh::Coords& coord,
     257                 :            :             bool cerr = true,
     258                 :            :             const std::vector< std::size_t >& rid={} );
     259                 :            : 
     260                 :            : //! Determine if a point is in a tetrahedron
     261                 :            : bool
     262                 :            : intet( const std::array< std::vector< real >, 3 >& coord,
     263                 :            :        const std::vector< std::size_t >& inpoel,
     264                 :            :        const std::vector< real >& p,
     265                 :            :        std::size_t e,
     266                 :            :        std::array< real, 4 >& N );
     267                 :            : 
     268                 :            : //! Compute curl of a vector field at nodes of unstructured tetrahedra mesh
     269                 :            : tk::UnsMesh::Coords
     270                 :            : curl( const std::array< std::vector< tk::real >, 3 >& coord,
     271                 :            :       const std::vector< std::size_t >& inpoel,
     272                 :            :       const tk::UnsMesh::Coords& v );
     273                 :            : 
     274                 :            : //! Compute divergence of vector field at nodes of unstructured tetrahedra mesh
     275                 :            : std::vector< tk::real >
     276                 :            : div( const std::array< std::vector< tk::real >, 3 >& coord,
     277                 :            :      const std::vector< std::size_t >& inpoel,
     278                 :            :      const tk::UnsMesh::Coords& v );
     279                 :            : 
     280                 :            : //! Compute gradient of a scalar field at nodes of unstructured tetrahedra mesh
     281                 :            : tk::UnsMesh::Coords
     282                 :            : grad( const std::array< std::vector< tk::real >, 3 >& coord,
     283                 :            :       const std::vector< std::size_t >& inpoel,
     284                 :            :       const std::vector< tk::real >& phi );
     285                 :            : 
     286                 :            : } // tk::
     287                 :            : 
     288                 :            : #endif // DerivedData_h

Generated by: LCOV version 1.14