LCOV - code coverage report
Current view: top level - include/interfaces - BoundaryRestrictable.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 99787a Lines: 11 11 100.0 %
Date: 2025-10-14 20:01:24 Functions: 6 7 85.7 %
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             : #ifdef MOOSE_KOKKOS_ENABLED
      13             : #include "KokkosTypes.h"
      14             : #endif
      15             : 
      16             : // MOOSE includes
      17             : #include "InputParameters.h"
      18             : #include "MaterialData.h"
      19             : 
      20             : class MooseMesh;
      21             : 
      22             : /**
      23             :  * /class BoundaryRestrictable
      24             :  * /brief Provides functionality for limiting the object to certain boundary ids
      25             :  * The is class the inheriting class with methods useful for limiting an object
      26             :  * to certain boundaries. The parameters "_boundary_id" and "boundary", which are
      27             :  * created with BoundaryRestrictable::validParams() are used the framework.
      28             :  */
      29             : class BoundaryRestrictable
      30             : {
      31             : public:
      32             :   /// A flag changing the behavior of hasBoundary
      33             :   enum TEST_TYPE
      34             :   {
      35             :     ALL,
      36             :     ANY
      37             :   };
      38             : 
      39             :   /**
      40             :    * Class constructor
      41             :    * Populates the _bnd_ids for the given boundary names supplied
      42             :    * with the 'boundary' input parameter
      43             :    * @param parameters The input parameters
      44             :    * @param nodal True indicates that the object is operating on nodesets, false for sidesets
      45             :    */
      46             :   BoundaryRestrictable(const MooseObject * moose_object, bool nodal);
      47             : 
      48             :   static InputParameters validParams();
      49             : 
      50             :   /**
      51             :    * Class constructor
      52             :    * Populates the 'block' input parameters when an object is also block restricted,
      53             :    * see the general class documentation for details.
      54             :    * @param parameters The input parameters (see the detailed help for additional information)
      55             :    * @param block_ids The block ids that the object is restricted to
      56             :    * @param nodal True indicates that the object is operating on nodesets, false for sidesets
      57             :    */
      58             :   BoundaryRestrictable(const MooseObject * moose_object,
      59             :                        const std::set<SubdomainID> & block_ids,
      60             :                        bool nodal);
      61             : 
      62             : #ifdef MOOSE_KOKKOS_ENABLED
      63             :   /**
      64             :    * Special constructor used for Kokkos functor copy during parallel dispatch
      65             :    */
      66             :   BoundaryRestrictable(const BoundaryRestrictable & object, const Moose::Kokkos::FunctorCopy & key);
      67             : #endif
      68             : 
      69             :   /**
      70             :    * Helper for determining if the object is boundary restricted. This is needed for the
      71             :    * MaterialPropertyInterface.
      72             :    */
      73             :   static bool restricted(const std::set<BoundaryID> & ids);
      74             : 
      75             :   /**
      76             :    * Empty class destructor
      77             :    */
      78             :   virtual ~BoundaryRestrictable();
      79             : 
      80             :   /**
      81             :    * Return the boundary IDs for this object
      82             :    * @return A set of all boundary ids for which the object is restricted
      83             :    */
      84             :   const virtual std::set<BoundaryID> & boundaryIDs() const;
      85             : 
      86             :   /**
      87             :    * Return the boundary names for this object
      88             :    * @return A set of all boundary names for which the object is restricted
      89             :    */
      90             :   const std::vector<BoundaryName> & boundaryNames() const;
      91             : 
      92             :   /**
      93             :    * Return the number of boundaries for this object
      94             :    * @return The number of boundary ids
      95             :    */
      96             :   unsigned int numBoundaryIDs() const;
      97             : 
      98             :   /**
      99             :    * Test if the supplied boundary name is valid for this object
     100             :    * @param name A BoundaryName to check
     101             :    * @return True if the given id is valid for this object
     102             :    */
     103             :   bool hasBoundary(const BoundaryName & name) const;
     104             : 
     105             :   /**
     106             :    * Test if the supplied vector of boundary names are valid for this object
     107             :    * @param names A vector of BoundaryNames to check
     108             :    * @return True if the given ids are valid for this object
     109             :    */
     110             :   bool hasBoundary(const std::vector<BoundaryName> & names) const;
     111             : 
     112             :   /**
     113             :    * Test if the supplied boundary ids are valid for this object
     114             :    * @param id A BoundaryID to check
     115             :    * @return True if the given id is valid for this object
     116             :    */
     117             :   bool hasBoundary(const BoundaryID & id) const;
     118             : 
     119             :   /**
     120             :    * Test if the supplied vector boundary ids are valid for this object
     121             :    * @param ids A vector of BoundaryIDs ids to check
     122             :    * @param type A flag for the type of matching to perform: ALL requires that all supplied
     123             :    * ids must match those of the object; ANY requires that any one of the supplied ids must
     124             :    * match those of the object
     125             :    * @return True if the all of the given ids are found within the ids for this object
     126             :    */
     127             :   bool hasBoundary(const std::vector<BoundaryID> & ids, TEST_TYPE type = ALL) const;
     128             : 
     129             :   /**
     130             :    * Test if the supplied set of boundary ids are valid for this object
     131             :    * @param ids A std::set of BoundaryIDs to check
     132             :    * @param type A flag for the type of matching to perform: ALL requires that all supplied
     133             :    * ids must match those of the object; ANY requires that any one of the supplied ids must
     134             :    * match those of the object
     135             :    *
     136             :    * @return True if the all of the given ids are found within the ids for this object
     137             :    * \see isSubset
     138             :    */
     139             :   bool hasBoundary(const std::set<BoundaryID> & ids, TEST_TYPE type = ALL) const;
     140             : 
     141             :   /**
     142             :    * Test if the class boundary ids are a subset of the supplied objects
     143             :    * @param ids A std::set of boundaries to check
     144             :    * @return True if all of the boundary ids for this class are found within the given ids (opposite
     145             :    * of hasBoundary)
     146             :    * \see hasBoundary
     147             :    */
     148             :   bool isBoundarySubset(const std::set<BoundaryID> & ids) const;
     149             : 
     150             :   /*
     151             :    * Test if the class boundary ids are a subset of the supplied objects
     152             :    * @param ids A std::set of Boundary IDs to check
     153             :    * @return True if all of the boundary ids for this class are found within the given ids (opposite
     154             :    * of hasBoundary)
     155             :    * \see hasBoundary
     156             :    */
     157             :   bool isBoundarySubset(const std::vector<BoundaryID> & ids) const;
     158             : 
     159             :   /**
     160             :    * Check if a material property is valid for all boundaries of this object
     161             :    *
     162             :    * This method returns true if the supplied property name has been declared
     163             :    * in a Material object on the boundary ids for this object.
     164             :    *
     165             :    * @tparam T The type of material property
     166             :    * @param prop_name the name of the property to query
     167             :    * @return true if the property exists for all boundary ids of the object, otherwise false
     168             :    */
     169             :   template <typename T, bool is_ad = false>
     170             :   bool hasBoundaryMaterialProperty(const std::string & prop_name) const;
     171             : 
     172             :   /**
     173             :    * Returns true if this object has been restricted to a boundary
     174             :    * @see MooseObject
     175             :    */
     176             :   virtual bool boundaryRestricted() const;
     177             : 
     178             :   /**
     179             :    * Returns the set of all boundary ids for the entire mesh
     180             :    * @return A const reference the the boundary ids for the entire mesh
     181             :    */
     182             :   const std::set<BoundaryID> & meshBoundaryIDs() const;
     183             : 
     184             :   /**
     185             :    * Whether integrity/coverage checking should be conducted for moose variables used in this
     186             :    * object. This should return true if variables are only evaluated locally, e.g. on the current
     187             :    * node or element. This should return false if evaluation of this object entails non-local
     188             :    * variable evaluations
     189             :    */
     190     1327167 :   virtual bool checkVariableBoundaryIntegrity() const { return true; }
     191             : 
     192             : private:
     193             :   /// Pointer to FEProblemBase
     194             :   FEProblemBase * _bnd_feproblem;
     195             : 
     196             :   /// Point to mesh
     197             :   MooseMesh * _bnd_mesh;
     198             : 
     199             :   /// Set of the boundary ids
     200             :   std::set<BoundaryID> _bnd_ids;
     201             : 
     202             :   /// Vector of the boundary ids
     203             :   std::vector<BoundaryID> _vec_ids;
     204             : 
     205             :   /// Vector the the boundary names
     206             :   std::vector<BoundaryName> _boundary_names;
     207             : 
     208             :   /// Flag for allowing dual restriction with BlockRestrictable
     209             :   const bool _bnd_dual_restrictable;
     210             : 
     211             :   /// An empty set for referencing when block_ids is not included
     212             :   const std::set<SubdomainID> _empty_block_ids;
     213             : 
     214             :   /// Reference to the block_ids, defaults to an empty set if not provided
     215             :   const std::set<SubdomainID> & _block_ids;
     216             : 
     217             :   /// Thread id for this object
     218             :   THREAD_ID _bnd_tid;
     219             : 
     220             :   /// Pointer to MaterialData for boundary (@see hasBoundaryMaterialProperty)
     221             :   const MaterialData & _bnd_material_data;
     222             : 
     223             :   /// Whether or not this object is restricted to nodesets
     224             :   bool _bnd_nodal;
     225             : 
     226             :   /// The moose object that this is an interface for
     227             :   const MooseObject & _moose_object;
     228             : 
     229             :   /**
     230             :    * An initialization routine needed for dual constructors
     231             :    */
     232             :   void initializeBoundaryRestrictable();
     233             : 
     234             : #ifdef MOOSE_KOKKOS_ENABLED
     235             :   void initializeKokkosBoundaryRestrictable(MooseMesh * mesh);
     236             : #endif
     237             : 
     238             : protected:
     239             :   /**
     240             :    * A helper method to avoid circular #include problems.
     241             :    * @see hasBoundaryMaterialProperty
     242             :    */
     243             :   bool hasBoundaryMaterialPropertyHelper(const std::string & prop_name) const;
     244             : 
     245             : #ifdef MOOSE_KOKKOS_SCOPE
     246             :   /**
     247             :    * Get the number of nodes this Kokkos object is operating on
     248             :    * @returns The number of nodes local to this process
     249             :    */
     250       70932 :   KOKKOS_FUNCTION dof_id_type numKokkosBoundaryNodes() const { return _kokkos_node_ids.size(); }
     251             :   /**
     252             :    * Get the number of sides this Kokkos object is operating on
     253             :    * @returns The number of sides local to this process
     254             :    */
     255        8632 :   KOKKOS_FUNCTION dof_id_type numKokkosBoundarySides() const
     256             :   {
     257        8632 :     return _kokkos_element_side_ids.size();
     258             :   }
     259             :   /**
     260             :    * Get the contiguous node ID this Kokkos thread is operating on
     261             :    * @param tid The thread ID
     262             :    * @returns The contiguous node ID
     263             :    */
     264      337545 :   KOKKOS_FUNCTION ContiguousNodeID kokkosBoundaryNodeID(ThreadID tid) const
     265             :   {
     266      337545 :     return _kokkos_node_ids[tid];
     267             :   }
     268             :   /**
     269             :    * Get the contiguous element ID - side index pair this Kokkos thread is operating on
     270             :    * @param tid The thread ID
     271             :    * @returns The contiguous element ID - side index pair
     272             :    */
     273       44590 :   KOKKOS_FUNCTION auto kokkosBoundaryElementSideID(ThreadID tid) const
     274             :   {
     275       44590 :     return _kokkos_element_side_ids[tid];
     276             :   }
     277             : #endif
     278             : 
     279             : #ifdef MOOSE_KOKKOS_ENABLED
     280             : private:
     281             :   /**
     282             :    * List of contiguous node IDs this Kokkos object is operating on
     283             :    */
     284             :   Moose::Kokkos::Array<ContiguousNodeID> _kokkos_node_ids;
     285             :   /**
     286             :    * List of contiguous element ID - side index pairs this Kokkos object is operating on
     287             :    */
     288             :   Moose::Kokkos::Array<Moose::Kokkos::Pair<ContiguousElementID, unsigned int>>
     289             :       _kokkos_element_side_ids;
     290             : #endif
     291             : };
     292             : 
     293             : template <typename T, bool is_ad>
     294             : bool
     295          26 : BoundaryRestrictable::hasBoundaryMaterialProperty(const std::string & prop_name) const
     296             : {
     297             :   // If you get here the supplied property is defined on all boundaries, but is still subject
     298             :   // existence in the MateialData class
     299          44 :   return hasBoundaryMaterialPropertyHelper(prop_name) &&
     300          44 :          _bnd_material_data.haveGenericProperty<T, is_ad>(prop_name);
     301             : }

Generated by: LCOV version 1.14