LCOV - code coverage report
Current view: top level - include/kokkos/mesh - KokkosMesh.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33416 (b10b36) with base 9fbd27 Lines: 71 71 100.0 %
Date: 2026-07-23 16:15:30 Functions: 36 36 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://www.mooseframework.org
       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 "KokkosTypes.h"
      13             : 
      14             : #ifdef MOOSE_KOKKOS_SCOPE
      15             : #include "KokkosUtils.h"
      16             : #endif
      17             : 
      18             : using ContiguousSubdomainID = SubdomainID;
      19             : using ContiguousBoundaryID = BoundaryID;
      20             : using ContiguousElementID = dof_id_type;
      21             : using ContiguousNodeID = dof_id_type;
      22             : 
      23             : class MooseMesh;
      24             : 
      25             : namespace Moose::Kokkos
      26             : {
      27             : 
      28             : /**
      29             :  * The Kokkos object that contains the information of an element
      30             :  * The IDs used in Kokkos are different from the MOOSE or libMesh IDs
      31             :  * The Kokkos IDs start from zero in each process and are contiguous
      32             :  */
      33             : struct ElementInfo
      34             : {
      35             :   /**
      36             :    * Element type ID
      37             :    */
      38             :   unsigned int type = libMesh::invalid_uint;
      39             :   /**
      40             :    * Contiguous element ID
      41             :    */
      42             :   ContiguousElementID id = libMesh::DofObject::invalid_id;
      43             :   /**
      44             :    * Contiguous subdomain ID
      45             :    */
      46             :   ContiguousSubdomainID subdomain = std::numeric_limits<ContiguousSubdomainID>::max();
      47             : };
      48             : 
      49             : /**
      50             :  * The Kokkos mesh object
      51             :  */
      52             : class Mesh
      53             : {
      54             : public:
      55             :   /**
      56             :    * Constructor
      57             :    * @param mesh The MOOSE mesh
      58             :    */
      59       52464 :   Mesh(MooseMesh & mesh) : _mesh(mesh) {}
      60             :   /**
      61             :    * Get the underyling MOOSE mesh
      62             :    * @returns The MOOSE mesh
      63             :    */
      64             :   const MooseMesh & getMesh() { return _mesh; }
      65             :   /**
      66             :    * Get whether the mesh was initialized
      67             :    */
      68     5247051 :   [[nodiscard]] bool initialized() const { return _initialized; }
      69             :   /**
      70             :    * Update the mesh
      71             :    */
      72             :   void update();
      73             : 
      74             :   /**
      75             :    * Mark that element geometry data is needed; initElementGeometry() will be called on the next
      76             :    * update()
      77             :    */
      78         739 :   void setNeedsElementGeometry() { _needs_element_geometry = true; }
      79             : 
      80             :   /**
      81             :    * Mark that element-side geometry data is needed; initElementSideGeometry() will be called on the
      82             :    * next update()
      83             :    */
      84         739 :   void setNeedsElementSideGeometry()
      85             :   {
      86         739 :     _needs_element_side_geometry = true;
      87         739 :     setNeedsElementGeometry();
      88         739 :   }
      89             : 
      90             :   /**
      91             :    * Get the number of subdomains
      92             :    * @returns The number of subdomains
      93             :    */
      94       32131 :   auto getNumSubdomains() const { return _maps->subdomain_id_mapping.size(); }
      95             :   /**
      96             :    * Get the number of local elements types
      97             :    * @returns The number of local element types
      98             :    */
      99        7380 :   auto getNumLocalElementTypes() const { return _maps->elem_type_id_mapping.size(); }
     100             :   /**
     101             :    * Get the element type ID map
     102             :    * @returns The element type ID map
     103             :    */
     104       12510 :   const auto & getElementTypeMap() const { return _maps->elem_type_id_mapping; }
     105             :   /**
     106             :    * Get the number of local elements
     107             :    * @returns The number of local elements
     108             :    */
     109      142612 :   dof_id_type getNumLocalElements() const { return _num_local_elems; }
     110             :   /**
     111             :    * Get the total number of elements, i.e. the local elements plus the ghost elements
     112             :    * @returns The total number of elements
     113             :    */
     114             :   dof_id_type getNumLocalAndPossiblyOneNeighborLayerGhostElements() const;
     115             :   /**
     116             :    * Get the number of local elements in a MOOSE subdomain
     117             :    * @param subdomain The MOOSE subdomain ID
     118             :    * @returns The local number of elements in the subdomain
     119             :    */
     120         321 :   auto getNumSubdomainLocalElements(const SubdomainID subdomain) const
     121             :   {
     122         321 :     auto range = libmesh_map_find(_maps->subdomain_elem_id_ranges, subdomain);
     123         321 :     return range.second - range.first;
     124             :   }
     125             :   /**
     126             :    * Get the number of local nodes including semi-local nodes
     127             :    * @returns The number of local nodes including semi-local nodes
     128             :    */
     129        5497 :   auto getNumLocalNodes() const { return _num_local_nodes; }
     130             :   /**
     131             :    * Get the list of local nodes including semi-local nodes
     132             :    * @returns The list of local nodes including semi-local nodes
     133             :    */
     134        6592 :   const auto & getLocalNodes() const { return _maps->local_nodes; }
     135             :   /**
     136             :    * Get the contiguous subdomain ID of a MOOSE subdomain
     137             :    * @param subdomain The MOOSE subdomain ID
     138             :    * @returns The contiguous subdomain ID
     139             :    */
     140             :   ContiguousSubdomainID getContiguousSubdomainID(const SubdomainID subdomain) const;
     141             :   /**
     142             :    * Get the contiguous boundary ID of a boundary
     143             :    * @param boundary The MOOSE boundary ID
     144             :    * @returns The contiguous boundary ID
     145             :    */
     146             :   ContiguousBoundaryID getContiguousBoundaryID(const BoundaryID boundary) const;
     147             :   /**
     148             :    * Get the element type ID of an element
     149             :    * @param elem The libMesh element
     150             :    * @returns The element type ID
     151             :    */
     152             :   unsigned int getElementTypeID(const Elem * elem) const;
     153             :   /**
     154             :    * Get the contiguous element ID of an element
     155             :    * @param elem The libMesh element
     156             :    * @returns The contiguous element ID
     157             :    */
     158             :   ContiguousElementID getContiguousElementID(const Elem * elem) const;
     159             :   /**
     160             :    * Get the ghost element ID map (host-side only)
     161             :    * @returns Map from ghost Elem* to contiguous element ID
     162             :    */
     163        4242 :   const auto & getGhostElemIdMapping() const { return _maps->ghost_elem_id_mapping; }
     164             :   /**
     165             :    * Get the range of contiguous element IDs for a subdomain
     166             :    * @param subdomain The MOOSE subdomain ID
     167             :    * @returns The range of contiguous element IDs in the subdomain
     168             :    */
     169       19085 :   auto getSubdomainContiguousElementIDRange(const SubdomainID subdomain) const
     170             :   {
     171       19085 :     const auto & range = libmesh_map_find(_maps->subdomain_elem_id_ranges, subdomain);
     172       19085 :     return libMesh::make_range(range.first, range.second);
     173             :   }
     174             :   /**
     175             :    * Get the contiguous node ID of a node
     176             :    * @param node The libMesh node
     177             :    * @returns The contiguous node ID that starts from zero in each process
     178             :    */
     179             :   ContiguousNodeID getContiguousNodeID(const Node * node) const;
     180             :   /**
     181             :    * Get the list of local contiguous node IDs for a subdomain
     182             :    * NOTE: This list excludes semi-local nodes
     183             :    * @param subdomain The MOOSE subdomain ID
     184             :    * @returns The list of local contiguous node IDs in the subdomain
     185             :    */
     186       12884 :   const auto & getSubdomainContiguousNodeIDs(const SubdomainID subdomain) const
     187             :   {
     188       12884 :     return libmesh_map_find(_maps->subdomain_node_ids, subdomain);
     189             :   }
     190             :   /**
     191             :    * Get the list of local contiguous node IDs for a boundary
     192             :    * NOTE: This list excludes semi-local nodes
     193             :    * @param boundary The MOOSE boundary ID
     194             :    * @returns The list of local contiguous node IDs on the boundary
     195             :    */
     196       13728 :   const auto & getBoundaryContiguousNodeIDs(const BoundaryID boundary) const
     197             :   {
     198       13728 :     return libmesh_map_find(_maps->boundary_node_ids, boundary);
     199             :   }
     200             : #ifdef MOOSE_KOKKOS_SCOPE
     201             :   /**
     202             :    * Get the element information object
     203             :    * @param elem The contiguous element ID
     204             :    * @returns The element information object
     205             :    */
     206    75530226 :   KOKKOS_FUNCTION const auto & getElementInfo(ContiguousElementID elem) const
     207             :   {
     208             :     KOKKOS_ASSERT(elem < _elem_info.size());
     209             : 
     210    75530226 :     return _elem_info[elem];
     211             :   }
     212             :   /**
     213             :    * Get the neighbor contiguous element ID
     214             :    * @param elem The contiguous element ID
     215             :    * @param side The side index
     216             :    * @returns The neighbor contiguous element ID
     217             :    */
     218      263440 :   KOKKOS_FUNCTION ContiguousElementID getNeighbor(ContiguousElementID elem, unsigned int side) const
     219             :   {
     220      263440 :     return _elem_neighbor(side, elem);
     221             :   }
     222             :   /**
     223             :    * Get the coordinate-weighted area of an element side
     224             :    * @param elem The local contiguous element ID
     225             :    * @param side The side index
     226             :    * @returns The side area including the coordinate transformation factor
     227             :    */
     228       81924 :   KOKKOS_FUNCTION Real getSideArea(ContiguousElementID elem, unsigned int side) const
     229             :   {
     230             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     231       81924 :     return _side_area(side, elem);
     232             :   }
     233             :   /**
     234             :    * Get the centroid of an element side
     235             :    * @param elem The contiguous element ID
     236             :    * @param side The side index
     237             :    * @returns The side centroid
     238             :    */
     239       82478 :   KOKKOS_FUNCTION Real3 getSideCentroid(ContiguousElementID elem, unsigned int side) const
     240             :   {
     241             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     242       82478 :     return _side_centroid(side, elem);
     243             :   }
     244             :   /**
     245             :    * Get the outward unit normal of an element side
     246             :    * @param elem The contiguous element ID
     247             :    * @param side The side index
     248             :    * @returns The side normal
     249             :    */
     250        2032 :   KOKKOS_FUNCTION Real3 getSideNormal(ContiguousElementID elem, unsigned int side) const
     251             :   {
     252             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     253        2032 :     return _side_normal(side, elem);
     254             :   }
     255             :   /**
     256             :    * Get the element-centroid to side-centroid vector for an element side
     257             :    * @param elem The contiguous element ID
     258             :    * @param side The side index
     259             :    * @returns The element-centroid to side-centroid vector
     260             :    */
     261             :   KOKKOS_FUNCTION Real3 getElementCentroidToSideCentroidVector(ContiguousElementID elem,
     262             :                                                                unsigned int side) const
     263             :   {
     264             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     265             :     return _elem_centroid_to_side_centroid(side, elem);
     266             :   }
     267             :   /**
     268             :    * Get the element-centroid to side-centroid distance for an element side
     269             :    * @param elem The contiguous element ID
     270             :    * @param side The side index
     271             :    * @returns The element-centroid to side-centroid distance
     272             :    */
     273        1074 :   KOKKOS_FUNCTION Real getElementCentroidToSideCentroidDistance(ContiguousElementID elem,
     274             :                                                                 unsigned int side) const
     275             :   {
     276             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     277        1074 :     return _elem_centroid_to_side_centroid_distance(side, elem);
     278             :   }
     279             :   /**
     280             :    * Get the element-centroid to neighbor-centroid vector for an element side with a neighbor
     281             :    * @param elem The contiguous element ID
     282             :    * @param side The side index
     283             :    * @returns The element-centroid to neighbor-centroid vector, or a zero vector when the side has
     284             :    *          no contiguous neighbor ID
     285             :    */
     286             :   KOKKOS_FUNCTION Real3 getElementCentroidToNeighborCentroidVector(ContiguousElementID elem,
     287             :                                                                    unsigned int side) const
     288             :   {
     289             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     290             :     return _elem_centroid_to_neighbor_centroid(side, elem);
     291             :   }
     292             :   /**
     293             :    * Get the element-centroid to neighbor-centroid distance for an element side with a neighbor
     294             :    * @param elem The contiguous element ID
     295             :    * @param side The side index
     296             :    * @returns The element-centroid to neighbor-centroid distance, or zero when the side has no
     297             :    *          contiguous neighbor ID
     298             :    */
     299       77740 :   KOKKOS_FUNCTION Real getElementCentroidToNeighborCentroidDistance(ContiguousElementID elem,
     300             :                                                                     unsigned int side) const
     301             :   {
     302             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     303       77740 :     return _elem_centroid_to_neighbor_centroid_distance(side, elem);
     304             :   }
     305             :   /**
     306             :    * @returns The boundary ID associated with an element side. If there is none, the returned value
     307             :    * will be \p Moose::INVALID_BOUNDARY_ID
     308             :    */
     309             :   KOKKOS_FUNCTION BoundaryID getSideBoundaryID(ContiguousElementID elem, unsigned int side) const
     310             :   {
     311             :     KOKKOS_ASSERT(_element_side_geometry_initialized);
     312             :     return _side_boundary_id(side, elem);
     313             :   }
     314             :   /**
     315             :    * Get the coordinate-weighted volume of a local element
     316             :    * @param elem The local contiguous element ID
     317             :    * @returns The element volume including the coordinate transformation factor
     318             :    */
     319       10610 :   KOKKOS_FUNCTION Real getElementVolume(ContiguousElementID elem) const
     320             :   {
     321             :     KOKKOS_ASSERT(_element_geometry_initialized);
     322             :     KOKKOS_ASSERT(elem < _elem_volume.size());
     323       10610 :     return _elem_volume[elem];
     324             :   }
     325             :   /**
     326             :    * Get the centroid of a local element
     327             :    * @param elem The local contiguous element ID
     328             :    * @returns The element centroid
     329             :    */
     330       10610 :   KOKKOS_FUNCTION Real3 getElementCentroid(ContiguousElementID elem) const
     331             :   {
     332             :     KOKKOS_ASSERT(_element_geometry_initialized);
     333             :     KOKKOS_ASSERT(elem < _elem_centroid.size());
     334       10610 :     return _elem_centroid[elem];
     335             :   }
     336             : 
     337             :   /**
     338             :    * Allocate and populate local element centroids and coordinate-weighted volumes
     339             :    */
     340             :   void initElementGeometry();
     341             : 
     342             :   /**
     343             :    * Allocate and populate cached side geometry: side areas, centroids, normals, element-centroid
     344             :    * to side-centroid and element-centroid to neighbor-centroid vectors and their magnitudes, and
     345             :    * boundary IDs
     346             :    */
     347             :   void initElementSideGeometry();
     348             : 
     349             :   /**
     350             :    * Get the number of sides of an element type
     351             :    * @param elem_type The element type ID
     352             :    * @returns The number of sides of the element type
     353             :    */
     354             :   KOKKOS_FUNCTION unsigned int getNumSides(unsigned int elem_type) const
     355             :   {
     356             :     return _num_sides[elem_type];
     357             :   }
     358             :   /**
     359             :    * Get the number of nodes of an element type
     360             :    * @param elem_type The element type ID
     361             :    * @returns The number of nodes of the element type
     362             :    */
     363      948852 :   KOKKOS_FUNCTION unsigned int getNumNodes(unsigned int elem_type) const
     364             :   {
     365      948852 :     return _num_nodes[elem_type];
     366             :   }
     367             :   /**
     368             :    * Get the number of nodes on a side of an element type
     369             :    * @param elem_type The element type ID
     370             :    * @param side The side index
     371             :    * @returns The number of nodes on the side of the element type
     372             :    */
     373      318580 :   KOKKOS_FUNCTION unsigned int getNumNodes(unsigned int elem_type, unsigned int side) const
     374             :   {
     375      318580 :     return _num_side_nodes[elem_type][side];
     376             :   }
     377             :   /**
     378             :    * Get the extra element ID of an element
     379             :    * @param elem The contiguous element ID
     380             :    * @param index The extra element ID index
     381             :    * @returns The extra element ID
     382             :    */
     383         500 :   KOKKOS_FUNCTION dof_id_type getExtraElementID(ContiguousElementID elem, unsigned int index) const
     384             :   {
     385             :     KOKKOS_ASSERT(elem < _extra_elem_ids.n(0));
     386             :     KOKKOS_ASSERT(index < _extra_elem_ids.n(1));
     387             : 
     388         500 :     return _extra_elem_ids(elem, index);
     389             :   }
     390             :   /**
     391             :    * Get the starting contiguous element ID of a subdomain
     392             :    * @param subdomain The contiguous subdomain ID
     393             :    * @returns The starting contiguous element ID
     394             :    */
     395     6954329 :   KOKKOS_FUNCTION dof_id_type getStartingContiguousElementID(ContiguousSubdomainID subdomain) const
     396             :   {
     397     6954329 :     return _starting_elem_id[subdomain];
     398             :   }
     399             :   /**
     400             :    * Get the contiguous node ID for an element
     401             :    * @param elem The contiguous element ID
     402             :    * @param node The node index
     403             :    * @returns The contiguous node ID
     404             :    */
     405     4001916 :   KOKKOS_FUNCTION ContiguousNodeID getContiguousNodeID(ContiguousElementID elem,
     406             :                                                        unsigned int node) const
     407             :   {
     408     4001916 :     return _nodes(node, elem);
     409             :   }
     410             :   /**
     411             :    * Get the contiguous node ID for a side
     412             :    * @param elem The contiguous element ID
     413             :    * @param side The side index
     414             :    * @param node The node index
     415             :    * @returns The contiguous node ID
     416             :    */
     417      639592 :   KOKKOS_FUNCTION ContiguousNodeID getContiguousNodeID(ElementInfo info,
     418             :                                                        unsigned int side,
     419             :                                                        unsigned int node) const
     420             :   {
     421      639592 :     return _nodes(_local_side_node[info.type](node, side), info.id);
     422             :   }
     423             :   /**
     424             :    * Get the coordinate of a node
     425             :    * @param node The contiguous node ID
     426             :    * @returns The node coordinate
     427             :    */
     428     5081874 :   KOKKOS_FUNCTION Real3 getNodePoint(ContiguousNodeID node) const { return _points[node]; }
     429             :   /**
     430             :    * Get whether a node is on a boundary
     431             :    * @param node The contiguous node ID
     432             :    * @param boundary The contiguous boundary ID
     433             :    * @returns Whether the node is on the boundary
     434             :    */
     435             :   KOKKOS_FUNCTION bool isBoundaryNode(ContiguousNodeID node, ContiguousBoundaryID boundary) const;
     436             : #endif
     437             : 
     438             : private:
     439             :   /**
     440             :    * Initialize host maps
     441             :    */
     442             :   void initMap();
     443             :   /**
     444             :    * Initialize device element data
     445             :    */
     446             :   void initElement();
     447             : 
     448             :   /**
     449             :    * Reference of the MOOSE mesh
     450             :    */
     451             :   MooseMesh & _mesh;
     452             :   /**
     453             :    * Flag whether the mesh was initialized
     454             :    */
     455             :   bool _initialized = false;
     456             : 
     457             :   /**
     458             :    * The wrapper of host maps
     459             :    */
     460             :   struct MeshMap
     461             :   {
     462             :     /**
     463             :      * Map from the MOOSE subdomain ID to the contiguous subdomain ID
     464             :      */
     465             :     std::unordered_map<SubdomainID, ContiguousSubdomainID> subdomain_id_mapping;
     466             :     /**
     467             :      * Map from the MOOSE boundary ID to the contiguous boundary ID
     468             :      */
     469             :     std::unordered_map<BoundaryID, ContiguousBoundaryID> boundary_id_mapping;
     470             :     /**
     471             :      * Map from the MOOSE element type to the element type ID
     472             :      */
     473             :     std::unordered_map<ElemType, unsigned int> elem_type_id_mapping;
     474             :     /**
     475             :      * List of local nodes including semi-local nodes
     476             :      */
     477             :     std::vector<Node *> local_nodes;
     478             :     /**
     479             :      * Map from off-process ghost node to the contiguous node ID
     480             :      */
     481             :     std::unordered_map<const Node *, ContiguousNodeID> ghost_node_id_mapping;
     482             :     /**
     483             :      * Map from off-process ghost Elem* to its contiguous element ID on this process
     484             :      */
     485             :     std::unordered_map<const Elem *, ContiguousElementID> ghost_elem_id_mapping;
     486             :     /**
     487             :      * Range of the contiguous element IDs in each subdomain
     488             :      */
     489             :     std::unordered_map<SubdomainID, std::pair<ContiguousElementID, ContiguousElementID>>
     490             :         subdomain_elem_id_ranges;
     491             :     /**
     492             :      * List of the contiguous node IDs in each subdomain
     493             :      * NOTE: This list excludes semi-local nodes
     494             :      */
     495             :     std::unordered_map<SubdomainID, std::vector<ContiguousNodeID>> subdomain_node_ids;
     496             :     /**
     497             :      * List of the contiguous node IDs on each boundary
     498             :      * NOTE: This list excludes semi-local nodes
     499             :      */
     500             :     std::unordered_map<BoundaryID, std::set<ContiguousNodeID>> boundary_node_ids;
     501             :   };
     502             :   /**
     503             :    * A shared pointer holding all the host maps to avoid deep copy
     504             :    */
     505             :   std::shared_ptr<MeshMap> _maps;
     506             : 
     507             :   /**
     508             :    * Element integer for Kokkos contiguous element ID
     509             :    */
     510             :   unsigned int _elem_id_integer = libMesh::invalid_uint;
     511             :   /**
     512             :    * Node integer for Kokkos contiguous node ID
     513             :    */
     514             :   unsigned int _node_id_integer = libMesh::invalid_uint;
     515             :   /**
     516             :    * Number of local elements
     517             :    */
     518             :   dof_id_type _num_local_elems = 0;
     519             :   /**
     520             :    * Number of ghost (off-process neighbor) elements
     521             :    */
     522             :   dof_id_type _num_ghost_elems = 0;
     523             :   /**
     524             :    * Number of local nodes including semi-local nodes
     525             :    */
     526             :   dof_id_type _num_local_nodes = 0;
     527             :   /**
     528             :    * Element information
     529             :    */
     530             :   Array<ElementInfo> _elem_info;
     531             :   /**
     532             :    * Neighbor contiguous element IDs of each element
     533             :    */
     534             :   Array2D<ContiguousElementID> _elem_neighbor;
     535             :   /**
     536             :    * Starting contiguous element ID of each subdomain
     537             :    */
     538             :   Array<ContiguousElementID> _starting_elem_id;
     539             :   /**
     540             :    * Extra element IDs
     541             :    */
     542             :   Array2D<dof_id_type> _extra_elem_ids;
     543             :   /**
     544             :    * Number of sides of each element type
     545             :    */
     546             :   Array<unsigned int> _num_sides;
     547             :   /**
     548             :    * Number of nodes of each element type
     549             :    */
     550             :   Array<unsigned int> _num_nodes;
     551             :   /**
     552             :    * Number of nodes per side of each element side
     553             :    */
     554             :   Array<Array<unsigned int>> _num_side_nodes;
     555             :   /**
     556             :    * Map from local side node index to local element node index
     557             :    */
     558             :   Array<Array2D<unsigned int>> _local_side_node;
     559             :   /**
     560             :    * Node coordinates
     561             :    */
     562             :   Array<Real3> _points;
     563             :   /**
     564             :    * Contiguous node IDs of each element
     565             :    */
     566             :   Array2D<ContiguousNodeID> _nodes;
     567             :   /**
     568             :    * Contiguous node IDs on each boundary
     569             :    */
     570             :   Array<Array<ContiguousNodeID>> _boundary_nodes;
     571             : 
     572             :   /// Whether initElementGeometry() has been called and the element geometry cache is populated
     573             :   bool _element_geometry_initialized = false;
     574             :   /// Whether initElementGeometry() should be called on the next update()
     575             :   bool _needs_element_geometry = false;
     576             :   /// Whether initElementSideGeometry() has been called and the side geometry cache is populated
     577             :   bool _element_side_geometry_initialized = false;
     578             :   /// Whether initElementSideGeometry() should be called on the next update()
     579             :   bool _needs_element_side_geometry = false;
     580             :   /// Cached coordinate-weighted local element volumes indexed by contiguous element ID
     581             :   Array<Real> _elem_volume;
     582             :   /// Cached local element centroids indexed by contiguous element ID
     583             :   Array<Real3> _elem_centroid;
     584             :   /// Cached coordinate-weighted side areas indexed by (side, local contiguous element ID)
     585             :   Array2D<Real> _side_area;
     586             :   /// Cached side centroids indexed by (side, contiguous element ID)
     587             :   Array2D<Real3> _side_centroid;
     588             :   /// Cached side normals indexed by (side, contiguous element ID)
     589             :   Array2D<Real3> _side_normal;
     590             :   /// Element-centroid to side-centroid vectors indexed by (side, contiguous element ID)
     591             :   Array2D<Real3> _elem_centroid_to_side_centroid;
     592             :   /// Element-centroid to side-centroid distances indexed by (side, contiguous element ID)
     593             :   Array2D<Real> _elem_centroid_to_side_centroid_distance;
     594             :   /// Element-centroid to neighbor-centroid vectors indexed by (side, contiguous element ID)
     595             :   Array2D<Real3> _elem_centroid_to_neighbor_centroid;
     596             :   /// Element-centroid to neighbor-centroid distances indexed by (side, contiguous element ID)
     597             :   Array2D<Real> _elem_centroid_to_neighbor_centroid_distance;
     598             :   /// Boundary IDs for each side indexed by (side, contiguous element ID)
     599             :   Array2D<BoundaryID> _side_boundary_id;
     600             : };
     601             : 
     602             : #ifdef MOOSE_KOKKOS_SCOPE
     603             : KOKKOS_FUNCTION inline bool
     604      664470 : Mesh::isBoundaryNode(ContiguousNodeID node, ContiguousBoundaryID boundary) const
     605             : {
     606      664470 :   if (!_boundary_nodes[boundary].size())
     607      106880 :     return false;
     608             : 
     609      557590 :   auto begin = &_boundary_nodes[boundary].begin();
     610      557590 :   auto end = &_boundary_nodes[boundary].end();
     611      557590 :   auto target = Utils::find(node, begin, end);
     612             : 
     613      557590 :   return target != end;
     614             : }
     615             : #endif
     616             : 
     617             : inline dof_id_type
     618        5654 : Mesh::getNumLocalAndPossiblyOneNeighborLayerGhostElements() const
     619             : {
     620        5654 :   return _num_local_elems + _num_ghost_elems;
     621             : }
     622             : 
     623             : /**
     624             :  * The Kokkos interface that holds the host reference of the Kokkos mesh and copies it to device
     625             :  * during parallel dispatch
     626             :  * Maintains synchronization between host and device Kokkos mesh and provides access to the
     627             :  * appropriate Kokkos mesh depending on the architecture
     628             :  */
     629             : class MeshHolder
     630             : {
     631             : public:
     632             :   /**
     633             :    * Constructor
     634             :    * @param mesh The Kokkos mesh
     635             :    */
     636       63738 :   MeshHolder(const Mesh & mesh) : _mesh_host(mesh), _mesh_device(mesh) {}
     637             :   /**
     638             :    * Copy constructor
     639             :    */
     640     1318280 :   MeshHolder(const MeshHolder & holder)
     641      762191 :     : _mesh_host(holder._mesh_host), _mesh_device(holder._mesh_host)
     642             :   {
     643     1318280 :   }
     644             : 
     645             : #ifdef MOOSE_KOKKOS_SCOPE
     646             :   /**
     647             :    * Get the const reference of the Kokkos mesh
     648             :    * @returns The const reference of the Kokkos mesh depending on the architecture this function
     649             :    * is being called on
     650             :    */
     651    95834881 :   KOKKOS_FUNCTION const Mesh & kokkosMesh() const
     652             :   {
     653    95834881 :     KOKKOS_IF_ON_HOST(
     654             :         if (!_mesh_host.initialized()) mooseError(
     655             :             "kokkosMesh() was called too early. Kokkos mesh is available after problem "
     656             :             "initialization. Override initialSetup() if you need to setup your object data "
     657             :             "using the Kokkos mesh.");
     658             : 
     659             :         return _mesh_host;)
     660             : 
     661    90587830 :     return _mesh_device;
     662             :   }
     663             : #endif
     664             : 
     665             : private:
     666             :   /**
     667             :    * Host reference of the Kokkos mesh
     668             :    */
     669             :   const Mesh & _mesh_host;
     670             :   /**
     671             :    * Device copy of the Kokkos mesh
     672             :    */
     673             :   const Mesh _mesh_device;
     674             : };
     675             : 
     676             : } // namespace Moose::Kokkos

Generated by: LCOV version 1.14