Commit b633d0d1 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Added iteration methods to Mesh: forAll, forBoundary, forInterior, forLocal, forGhost

parent 53bd736d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -192,8 +192,8 @@ public:
                << "\tGhost levels:\t" << getGhostLevels() << "\n"
                << "\tGhost cells count:\t" << localMesh.template getGhostEntitiesCount< Mesh::getMeshDimension() >() << "\n"
                << "\tGhost vertices count:\t" << localMesh.template getGhostEntitiesCount< 0 >() << "\n"
                << "\tBoundary cells count:\t" << localMesh.template getBoundaryEntitiesCount< Mesh::getMeshDimension() >() << "\n"
                << "\tBoundary vertices count:\t" << localMesh.template getBoundaryEntitiesCount< 0 >() << "\n";
                << "\tBoundary cells count:\t" << localMesh.template getBoundaryIndices< Mesh::getMeshDimension() >().getSize() << "\n"
                << "\tBoundary vertices count:\t" << localMesh.template getBoundaryIndices< 0 >().getSize() << "\n";
            const GlobalIndexType globalPointIndices = getGlobalIndices< 0 >().getSize();
            const GlobalIndexType globalCellIndices = getGlobalIndices< Mesh::getMeshDimension() >().getSize();
            if( getGhostLevels() > 0 ) {
+56 −0
Original line number Diff line number Diff line
@@ -175,6 +175,62 @@ class Mesh
      GlobalIndexType getCellNeighborIndex( const GlobalIndexType cellIndex, const LocalIndexType neighborIndex ) const;


      /**
       * \brief Execute function \e f in parallel for all mesh entities with dimension \e EntityDimension.
       *
       * The function \e f is executed as `f(i)`, where `GlobalIndexType i` is the global index of the
       * mesh entity to be processed. The mesh itself is not passed to the function `f`, it is the user's
       * responsibility to ensure proper access to the mesh if needed, e.g. by the means of lambda capture
       * and/or using a \ref SharedPointer.
       */
      template< int EntityDimension, typename Device2 = DeviceType, typename Func >
      void forAll( Func f ) const;

      /**
       * \brief Execute function \e f in parallel for all boundary mesh entities with dimension \e EntityDimension.
       *
       * The function \e f is executed as `f(i)`, where `GlobalIndexType i` is the global index of the
       * mesh entity to be processed. The mesh itself is not passed to the function `f`, it is the user's
       * responsibility to ensure proper access to the mesh if needed, e.g. by the means of lambda capture
       * and/or using a \ref SharedPointer.
       */
      template< int EntityDimension, typename Device2 = DeviceType, typename Func >
      void forBoundary( Func f ) const;

      /**
       * \brief Execute function \e f in parallel for all interior mesh entities with dimension \e EntityDimension.
       *
       * The function \e f is executed as `f(i)`, where `GlobalIndexType i` is the global index of the
       * mesh entity to be processed. The mesh itself is not passed to the function `f`, it is the user's
       * responsibility to ensure proper access to the mesh if needed, e.g. by the means of lambda capture
       * and/or using a \ref SharedPointer.
       */
      template< int EntityDimension, typename Device2 = DeviceType, typename Func >
      void forInterior( Func f ) const;

      /**
       * \brief Execute function \e f in parallel for all local mesh entities with dimension \e EntityDimension.
       *
       * The function \e f is executed as `f(i)`, where `GlobalIndexType i` is the global index of the
       * mesh entity to be processed. The mesh itself is not passed to the function `f`, it is the user's
       * responsibility to ensure proper access to the mesh if needed, e.g. by the means of lambda capture
       * and/or using a \ref SharedPointer.
       */
      template< int EntityDimension, typename Device2 = DeviceType, typename Func >
      void forLocal( Func f ) const;

      /**
       * \brief Execute function \e f in parallel for all ghost mesh entities with dimension \e EntityDimension.
       *
       * The function \e f is executed as `f(i)`, where `GlobalIndexType i` is the global index of the
       * mesh entity to be processed. The mesh itself is not passed to the function `f`, it is the user's
       * responsibility to ensure proper access to the mesh if needed, e.g. by the means of lambda capture
       * and/or using a \ref SharedPointer.
       */
      template< int EntityDimension, typename Device2 = DeviceType, typename Func >
      void forGhost( Func f ) const;


      /*
       * The permutations follow the definition used in the Metis library: Let M
       * be the original mesh and M' the permuted mesh. Then entity with index i
+62 −0
Original line number Diff line number Diff line
@@ -239,6 +239,68 @@ getCellNeighborIndex( const GlobalIndexType cellIndex, const LocalIndexType neig
}


template< typename MeshConfig, typename Device >
   template< int EntityDimension, typename Device2, typename Func >
void
Mesh< MeshConfig, Device >::
forAll( Func f ) const
{
   const GlobalIndexType entitiesCount = getEntitiesCount< EntityDimension >();
   Algorithms::ParallelFor< Device2 >::exec( (GlobalIndexType) 0, entitiesCount, f );
}

template< typename MeshConfig, typename Device >
   template< int EntityDimension, typename Device2, typename Func >
void
Mesh< MeshConfig, Device >::
forBoundary( Func f ) const
{
   const auto boundaryIndices = this->template getBoundaryIndices< EntityDimension >();
   const GlobalIndexType entitiesCount = boundaryIndices.getSize();
   auto wrapper = [f, boundaryIndices] __cuda_callable__ ( const GlobalIndexType i ) mutable
   {
      f( boundaryIndices[ i ] );
   };
   Algorithms::ParallelFor< Device2 >::exec( (GlobalIndexType) 0, entitiesCount, wrapper );
}

template< typename MeshConfig, typename Device >
   template< int EntityDimension, typename Device2, typename Func >
void
Mesh< MeshConfig, Device >::
forInterior( Func f ) const
{
   const auto interiorIndices = this->template getInteriorIndices< EntityDimension >();
   const GlobalIndexType entitiesCount = interiorIndices.getSize();
   auto wrapper = [f, interiorIndices] __cuda_callable__ ( const GlobalIndexType i ) mutable
   {
      f( interiorIndices[ i ] );
   };
   Algorithms::ParallelFor< Device2 >::exec( (GlobalIndexType) 0, entitiesCount, wrapper );
}

template< typename MeshConfig, typename Device >
   template< int EntityDimension, typename Device2, typename Func >
void
Mesh< MeshConfig, Device >::
forLocal( Func f ) const
{
   const GlobalIndexType ghostsOffset = this->template getGhostEntitiesOffset< EntityDimension >();
   Algorithms::ParallelFor< DeviceType >::exec( (GlobalIndexType) 0, ghostsOffset, f );
}

template< typename MeshConfig, typename Device >
   template< int EntityDimension, typename Device2, typename Func >
void
Mesh< MeshConfig, Device >::
forGhost( Func f ) const
{
   const GlobalIndexType ghostsOffset = this->template getGhostEntitiesOffset< EntityDimension >();
   const GlobalIndexType entitiesCount = this->template getEntitiesCount< EntityDimension >();
   Algorithms::ParallelFor< Device2 >::exec( ghostsOffset, entitiesCount, f );
}


template< typename MeshConfig, typename Device >
   template< int Dimension >
void
+6 −20
Original line number Diff line number Diff line
@@ -178,27 +178,15 @@ public:
   }

   __cuda_callable__
   GlobalIndexType getBoundaryEntitiesCount( DimensionTag ) const
   auto getBoundaryIndices( DimensionTag ) const
   {
      return boundaryIndices.getSize();
      return boundaryIndices.getConstView();
   }

   __cuda_callable__
   GlobalIndexType getBoundaryEntityIndex( DimensionTag, const GlobalIndexType& i ) const
   auto getInteriorIndices( DimensionTag ) const
   {
      return boundaryIndices[ i ];
   }

   __cuda_callable__
   GlobalIndexType getInteriorEntitiesCount( DimensionTag ) const
   {
      return interiorIndices.getSize();
   }

   __cuda_callable__
   GlobalIndexType getInteriorEntityIndex( DimensionTag, const GlobalIndexType& i ) const
   {
      return interiorIndices[ i ];
      return interiorIndices.getConstView();
   }

   __cuda_callable__
@@ -287,10 +275,8 @@ protected:
   void isBoundaryEntity( DimensionTag, const GlobalIndexType& ) const {}
   void isGhostEntity( DimensionTag, const GlobalIndexType& ) const {}
   void updateEntityTagsLayer( DimensionTag ) {}
   void getBoundaryEntitiesCount( DimensionTag ) const {}
   void getBoundaryEntityIndex( DimensionTag, const GlobalIndexType& i ) const {}
   void getInteriorEntitiesCount( DimensionTag ) const {}
   void getInteriorEntityIndex( DimensionTag, const GlobalIndexType& i ) const {}
   void getBoundaryIndices( DimensionTag ) const {}
   void getInteriorIndices( DimensionTag ) const {}
   void getGhostEntitiesCount() const;
   void getGhostEntitiesOffset() const;

+10 −32
Original line number Diff line number Diff line
@@ -35,10 +35,8 @@ protected:
   using LayerType::isBoundaryEntity;
   using LayerType::isGhostEntity;
   using LayerType::updateEntityTagsLayer;
   using LayerType::getBoundaryEntitiesCount;
   using LayerType::getBoundaryEntityIndex;
   using LayerType::getInteriorEntitiesCount;
   using LayerType::getInteriorEntityIndex;
   using LayerType::getBoundaryIndices;
   using LayerType::getInteriorIndices;
   using LayerType::getGhostEntitiesCount;
   using LayerType::getGhostEntitiesOffset;

@@ -50,10 +48,8 @@ protected:
   using BaseType::isBoundaryEntity;
   using BaseType::isGhostEntity;
   using BaseType::updateEntityTagsLayer;
   using BaseType::getBoundaryEntitiesCount;
   using BaseType::getBoundaryEntityIndex;
   using BaseType::getInteriorEntitiesCount;
   using BaseType::getInteriorEntityIndex;
   using BaseType::getBoundaryIndices;
   using BaseType::getInteriorIndices;
   using BaseType::getGhostEntitiesCount;
   using BaseType::getGhostEntitiesOffset;

@@ -124,10 +120,8 @@ protected:
   void isBoundaryEntity() const;
   void isGhostEntity() const;
   void updateEntityTagsLayer();
   void getBoundaryEntitiesCount() const;
   void getBoundaryEntityIndex() const;
   void getInteriorEntitiesCount() const;
   void getInteriorEntityIndex() const;
   void getBoundaryIndices() const;
   void getInteriorIndices() const;
   void getGhostEntitiesCount() const;
   void getGhostEntitiesOffset() const;

@@ -216,34 +210,18 @@ public:

   template< int Dimension >
   __cuda_callable__
   GlobalIndexType getBoundaryEntitiesCount() const
   auto getBoundaryIndices() const
   {
      static_assert( WeakTrait< Dimension >::entityTagsEnabled, "You try to access entity tags which are not configured for storage." );
      return BaseType::getBoundaryEntitiesCount( DimensionTag< Dimension >() );
      return BaseType::getBoundaryIndices( DimensionTag< Dimension >() );
   }

   template< int Dimension >
   __cuda_callable__
   GlobalIndexType getBoundaryEntityIndex( const GlobalIndexType& i ) const
   auto getInteriorIndices() const
   {
      static_assert( WeakTrait< Dimension >::entityTagsEnabled, "You try to access entity tags which are not configured for storage." );
      return BaseType::getBoundaryEntityIndex( DimensionTag< Dimension >(), i );
   }

   template< int Dimension >
   __cuda_callable__
   GlobalIndexType getInteriorEntitiesCount() const
   {
      static_assert( WeakTrait< Dimension >::entityTagsEnabled, "You try to access entity tags which are not configured for storage." );
      return BaseType::getInteriorEntitiesCount( DimensionTag< Dimension >() );
   }

   template< int Dimension >
   __cuda_callable__
   GlobalIndexType getInteriorEntityIndex( const GlobalIndexType& i ) const
   {
      static_assert( WeakTrait< Dimension >::entityTagsEnabled, "You try to access entity tags which are not configured for storage." );
      return BaseType::getInteriorEntityIndex( DimensionTag< Dimension >(), i );
      return BaseType::getInteriorIndices( DimensionTag< Dimension >() );
   }

   template< int Dimension >
Loading