Commit 4f23eb70 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing neighbour entity getter -- cross stencil storage.

parent a6ff63e8
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -128,6 +128,7 @@ class tnlNeighbourGridEntityGetter<
      typedef Index IndexType;
      typedef typename GridType::CoordinatesType CoordinatesType;
      typedef tnlGridEntityGetter< GridType, NeighbourEntityDimensions > GridEntityGetter;
      typedef tnlNeighbourGridEntityGetter< GridEntityType, 1, StencilStorage > ThisType;
      
      static const int stencilSize = Config::getStencilSize();
      
@@ -167,8 +168,8 @@ class tnlNeighbourGridEntityGetter<
              cerr << "entity.getCoordinates() = " << entity.getCoordinates()
                   << " entity.getGrid().getDimensions() = " << entity.getGrid().getDimensions()
                   << " EntityDimensions = " << EntityDimensions );
         //if( step < -stencilSize || step > stencilSize )
         //   return this->entity.getIndex() + step;
         if( step < -stencilSize || step > stencilSize )
            return this->entity.getIndex() + step;
         return stencil[ stencilSize + step ];
      }
     
@@ -178,16 +179,16 @@ class tnlNeighbourGridEntityGetter<
         public:
            
            __cuda_callable__
            void exec( const IndexType& entityIndex )
            static void exec( ThisType& neighbourEntityGetter, const IndexType& entityIndex )
            {
               //stencil[ index + stencilSize ] = entityIndex + index;
               neighbourEntityGetter.stencil[ index + stencilSize ] = entityIndex + index;
            }
      };
      
      __cuda_callable__
      void refresh( const GridType& grid, const IndexType& entityIndex )
      {
         tnlStaticFor< IndexType, -stencilSize, stencilSize, StencilRefresher >::exec( entityIndex );
         tnlStaticFor< IndexType, -stencilSize, stencilSize, StencilRefresher >::exec( *this, entityIndex );
      };      
      
   protected:
+48 −5
Original line number Diff line number Diff line
@@ -130,6 +130,8 @@ class tnlNeighbourGridEntityGetter<
      typedef typename GridType::CoordinatesType CoordinatesType;
      typedef tnlGridEntityGetter< GridType, NeighbourEntityDimensions > GridEntityGetter;
      
      static const int stencilSize = Config::getStencilSize();

      __cuda_callable__ inline
      tnlNeighbourGridEntityGetter( const GridEntityType& entity )
      : entity( entity )
@@ -168,16 +170,57 @@ class tnlNeighbourGridEntityGetter<
              cerr << "entity.getCoordinates()  + CoordinatesType( stepX, stepY ) = " << entity.getCoordinates()  + CoordinatesType( stepX, stepY )
                   << " entity.getGrid().getDimensions() = " << entity.getGrid().getDimensions()
                   << " EntityDimensions = " << EntityDimensions );
         if( ( stepX != 0 && stepY != 0 ) ||
             ( stepX < -stencilSize || stepX > stencilSize ||
               stepY < -stencilSize || stepY > stencilSize ) )         
            return this->entity.getIndex() + stepY * entity.getGrid().getDimensions().x() + stepX;
         if( stepY == 0 )
            return stencilX[ stepX + stencilSize ];
         return stencilY[ stepY + stencilSize ];
         
      }
      
      template< IndexType index > 
      class StencilXRefresher
      {
         public:
            
            __cuda_callable__
      void refresh( const GridType& grid, const IndexType& entityIndex ){};
            static void exec( ThisType& neighbourEntityGetter, const IndexType& entityIndex )
            {
               neighbourEntityGetter.stencil[ index + stencilSize ] = entityIndex + index;
            }
      };

      template< IndexType index > 
      class StencilYRefresher
      {
         public:
            
            __cuda_callable__
            static void exec( ThisType& neighbourEntityGetter, const IndexType& entityIndex )
            {
               neighbourEntityGetter.stencil[ index + stencilSize ] = 
                  entityIndex + index * neighbourEntityGetter.entity.getGrid().getDimensions().x();
            }
      };

      
      __cuda_callable__
      void refresh( const GridType& grid, const IndexType& entityIndex )
      {
         tnlStaticFor< IndexType, -stencilSize, -1, StencilYRefresher >::exec( *this, entityIndex );
         tnlStaticFor< IndexType, 1, stencilSize, StencilYRefresher >::exec( *this, entityIndex );
         tnlStaticFor< IndexType, -stencilSize, stencilSize, StencilXRefresher >::exec( *this, entityIndex );
      };
      
   protected:

      const GridEntityType& entity;
      
      IndexType stencilX[ 2 * stencilSize + 1 ];
      IndexType stencilY[ 2 * stencilSize + 1 ];
      
      //tnlNeighbourGridEntityGetter(){};      
};

+49 −2
Original line number Diff line number Diff line
@@ -171,16 +171,63 @@ class tnlNeighbourGridEntityGetter<
                   << entity.getCoordinates()  + CoordinatesType( stepX, stepY, stepZ )
                   << " entity.getGrid().getDimensions() = " << entity.getGrid().getDimensions()
                   << " EntityDimensions = " << EntityDimensions );
         if( ( stepX != 0 && stepY != 0 && stepZ != 0 ) ||
             ( stepX < -stencilSize || stepX > stencilSize ||
               stepY < -stencilSize || stepY > stencilSize ||
               stepZ < -stencilSize || stepZ > stencilSize ) )                  
            return this->entity.getIndex() + ( stepZ * entity.getGrid().getDimensions().y() + stepY ) * entity.getGrid().getDimensions().x() + stepX;
         if( stepY == 0 && stepZ == 0 )
            return stencilX[ stepX + stencilSize ];
         if( stepZ == 0 )
            return stencilY[ stepY + stencilSize ];
         return stencilZ[ stepZ + stencilSize ];

      }
      
      template< IndexType index > 
      class StencilXRefresher
      {
         public:
            
            __cuda_callable__
      void refresh( const GridType& grid, const IndexType& entityIndex ){};
            static void exec( ThisType& neighbourEntityGetter, const IndexType& entityIndex )
            {
               neighbourEntityGetter.stencil[ index + stencilSize ] = entityIndex + index;
            }
      };

      template< IndexType index > 
      class StencilYRefresher
      {
         public:
            
            __cuda_callable__
            static void exec( ThisType& neighbourEntityGetter, const IndexType& entityIndex )
            {
               neighbourEntityGetter.stencil[ index + stencilSize ] = 
                  entityIndex + index * neighbourEntityGetter.entity.getGrid().getDimensions().x();
            }
      };

      
      __cuda_callable__
      void refresh( const GridType& grid, const IndexType& entityIndex )
      {
         tnlStaticFor< IndexType, -stencilSize, -1, StencilZRefresher >::exec( *this, entityIndex );
         tnlStaticFor< IndexType, 1, stencilSize, StencilZRefresher >::exec( *this, entityIndex );
         tnlStaticFor< IndexType, -stencilSize, -1, StencilYRefresher >::exec( *this, entityIndex );
         tnlStaticFor< IndexType, 1, stencilSize, StencilYRefresher >::exec( *this, entityIndex );         
         tnlStaticFor< IndexType, -stencilSize, stencilSize, StencilXRefresher >::exec( *this, entityIndex );
      };
      
   protected:

      const GridEntityType& entity;
      
      IndexType stencilX[ 2 * stencilSize + 1 ];
      IndexType stencilY[ 2 * stencilSize + 1 ];
      IndexType stencilZ[ 2 * stencilSize + 1 ];
      
      //tnlNeighbourGridEntityGetter(){};            
};