Commit 84d33d3d authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Refactoring entity tags layer: added getEntityTagsView, removed...

Refactoring entity tags layer: added getEntityTagsView, removed resetEntityTags, optimized Mesh::reorderEntities
parent ff94f4a9
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -333,8 +333,11 @@ reorderEntities( const GlobalIndexArray& perm,
#endif

   IndexPermutationApplier< Mesh, Dimension >::exec( *this, perm, iperm );
   // update boundary tags
   static_cast< EntityTagsLayerFamily* >( this )->initLayer();
   // permute entity tags
   auto tags = this->template getEntityTagsView< Dimension >();
   IndexPermutationApplier< Mesh, Dimension >::permuteArray( tags, perm );
   // update the entity tags layer
   this->template updateEntityTagsLayer< Dimension >();
}


+12 −11
Original line number Diff line number Diff line
@@ -134,29 +134,30 @@ private:
   static void permuteDualGraph( Mesh_& mesh, const GlobalIndexArray& perm, const GlobalIndexArray& iperm ) {}

public:
   template< typename Array >
   static void permuteArray( Array& array, const GlobalIndexArray& perm )
   template< typename ArrayOrView >
   static void permuteArray( ArrayOrView& array, const GlobalIndexArray& perm )
   {
      using IndexType = typename Array::IndexType;
      using DeviceType = typename Array::DeviceType;
      using ValueType = typename ArrayOrView::ValueType;
      using IndexType = typename ArrayOrView::IndexType;
      using DeviceType = typename ArrayOrView::DeviceType;

      Array buffer( array.getSize() );
      Containers::Array< ValueType, DeviceType, IndexType > buffer( array.getSize() );

      // kernel to copy entities to new array, applying the permutation
      // kernel to copy values to new array, applying the permutation
      auto kernel1 = [] __cuda_callable__
         ( IndexType i,
           const typename Array::ValueType* array,
           typename Array::ValueType* buffer,
           const ValueType* array,
           ValueType* buffer,
           const IndexType* perm )
      {
         buffer[ i ] = array[ perm[ i ] ];
      };

      // kernel to copy permuted entities back to the mesh
      // kernel to copy permuted values back to the mesh
      auto kernel2 = [] __cuda_callable__
         ( IndexType i,
           typename Array::ValueType* array,
           const typename Array::ValueType* buffer )
           ValueType* array,
           const ValueType* buffer )
      {
         array[ i ] = buffer[ i ];
      };
+23 −2
Original line number Diff line number Diff line
@@ -57,11 +57,32 @@ protected:
   };

   template< int Dimension >
   struct ResetEntityTags
   class ResetEntityTags
   {
      using WeakTrait = WeakStorageTrait< MeshConfig, Device, DimensionTag< Dimension > >;
      static constexpr bool enabled = WeakTrait::entityTagsEnabled;

      // _T is necessary to force *partial* specialization, since explicit specializations
      // at class scope are forbidden
      template< bool enabled = true, typename _T = void >
      struct Worker
      {
         static void exec( Mesh& mesh )
         {
            mesh.template getEntityTagsView< Dimension >().setValue( 0 );
         }
      };

      template< typename _T >
      struct Worker< false, _T >
      {
         static void exec( Mesh& mesh ) {}
      };

   public:
      static void exec( Mesh& mesh )
      {
         mesh.template resetEntityTags< Dimension >();
         Worker< enabled >::exec( mesh );
      }
   };

+12 −3
Original line number Diff line number Diff line
@@ -81,9 +81,18 @@ public:
      ghostsOffset = entitiesCount;
   }

   void resetEntityTags( DimensionTag )
   __cuda_callable__
   typename EntityTagsArrayType::ViewType
   getEntityTagsView( DimensionTag )
   {
      return tags.getView();
   }

   __cuda_callable__
   typename EntityTagsArrayType::ConstViewType
   getEntityTagsView( DimensionTag ) const
   {
      tags.setValue( 0 );
      return tags.getConstView();
   }

   __cuda_callable__
@@ -268,7 +277,7 @@ protected:
   Layer& operator=( const Layer< MeshConfig, Device_, DimensionTag >& other ) { return *this; }

   void setEntitiesCount( DimensionTag, const GlobalIndexType& entitiesCount ) {}
   void resetEntityTags( DimensionTag ) {}
   void getEntityTagsView( DimensionTag ) {}
   void getEntityTag( DimensionTag, const GlobalIndexType& ) const {}
   void addEntityTag( DimensionTag, const GlobalIndexType&, TagType ) const {}
   void removeEntityTag( DimensionTag, const GlobalIndexType&, TagType ) const {}
+22 −9
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ class LayerInheritor
   using BaseType = LayerInheritor< MeshConfig, Device, typename Dimension::Increment >;
protected:
   using LayerType::setEntitiesCount;
   using LayerType::resetEntityTags;
   using LayerType::getEntityTagsView;
   using LayerType::getEntityTag;
   using LayerType::addEntityTag;
   using LayerType::removeEntityTag;
@@ -41,7 +41,7 @@ protected:
   using LayerType::getGhostEntitiesOffset;

   using BaseType::setEntitiesCount;
   using BaseType::resetEntityTags;
   using BaseType::getEntityTagsView;
   using BaseType::getEntityTag;
   using BaseType::addEntityTag;
   using BaseType::removeEntityTag;
@@ -113,7 +113,7 @@ class LayerInheritor< MeshConfig, Device, DimensionTag< MeshConfig::meshDimensio
{
protected:
   void setEntitiesCount();
   void resetEntityTags();
   void getEntityTagsView();
   void getEntityTag() const;
   void addEntityTag();
   void removeEntityTag();
@@ -154,6 +154,7 @@ class LayerFamily
{
   using MeshTraitsType = MeshTraits< MeshConfig, Device >;
   using GlobalIndexType = typename MeshTraitsType::GlobalIndexType;
   using EntityTagsArrayType = typename MeshTraitsType::EntityTagsArrayType;
   using TagType = typename MeshTraitsType::EntityTagType;
   using BaseType = LayerInheritor< MeshConfig, Device, DimensionTag< 0 > >;
   template< int Dimension >
@@ -168,6 +169,24 @@ public:
   using BaseType::BaseType;
   using BaseType::operator=;

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

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

   template< int Dimension >
   __cuda_callable__
   TagType getEntityTag( const GlobalIndexType& entityIndex ) const
@@ -252,12 +271,6 @@ protected:
   {
      BaseType::setEntitiesCount( DimensionTag< Dimension >(), entitiesCount );
   }

   template< int Dimension >
   void resetEntityTags()
   {
      BaseType::resetEntityTags( DimensionTag< Dimension >() );
   }
};

} // namespace EntityTags