Commit 3cde9e64 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Adding entity index to the grid entities.

parent eba9670f
Loading
Loading
Loading
Loading
+0 −37
Original line number Diff line number Diff line
@@ -107,43 +107,6 @@ class tnlGrid< 2, Real, Device, Index > : public tnlObject
   
   
   
   
   



   __cuda_callable__
   inline Index getCellIndex( const CoordinatesType& cellCoordinates ) const;

   __cuda_callable__
   inline CoordinatesType getCellCoordinates( const IndexType cellIndex ) const;

   template< int nx, int ny >
   __cuda_callable__
   inline Index getFaceIndex( const CoordinatesType& faceCoordinates ) const;

   __cuda_callable__
   inline CoordinatesType getFaceCoordinates( const Index faceIndex, int& nx, int& ny ) const;


   __cuda_callable__
   inline Index getVertexIndex( const CoordinatesType& vertexCoordinates ) const;

   __cuda_callable__
   inline CoordinatesType getVertexCoordinates( const Index vertexIndex ) const;

   template< int dx, int dy >
   __cuda_callable__
   inline IndexType getCellNextToCell( const IndexType& cellIndex ) const;

   template< int nx, int ny >
   __cuda_callable__
   inline IndexType getFaceNextToCell( const IndexType& cellIndex ) const;

   template< int nx, int ny >
   __cuda_callable__
   inline IndexType getCellNextToFace( const IndexType& cellIndex ) const;

   __cuda_callable__
   inline const RealType& getHx() const;

+21 −221
Original line number Diff line number Diff line
@@ -252,186 +252,6 @@ Vertex tnlGrid< 2, Real, Device, Index > :: getEntityCenter( const GridEntity< E



template< typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
Index tnlGrid< 2, Real, Device, Index > :: getCellIndex( const CoordinatesType& cellCoordinates ) const
{
   tnlAssert( cellCoordinates.x() >= 0 && cellCoordinates.x() < this->getDimensions().x(),
              cerr << "cellCoordinates.x() = " << cellCoordinates.x()
                   << " this->getDimensions().x() = " << this->getDimensions().x() );
   tnlAssert( cellCoordinates.y() >= 0 && cellCoordinates.y() < this->getDimensions().y(),
              cerr << "cellCoordinates.y() = " << cellCoordinates.y()
                   << " this->getDimensions().y() = " << this->getDimensions().y() )

   return cellCoordinates.y() * this->dimensions.x() + cellCoordinates.x();
}

template< typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
typename tnlGrid< 2, Real, Device, Index >::CoordinatesType
tnlGrid< 2, Real, Device, Index >::getCellCoordinates( const Index cellIndex ) const
{
   tnlAssert( cellIndex >= 0 && cellIndex < this->template getEntitiesCount< Cells >(),
              cerr << " cellIndex = " << cellIndex
                   << " this->template getEntitiesCount< Cells >() = " << this->template getEntitiesCount< Cells >() );
   return CoordinatesType( cellIndex % this->getDimensions().x(), cellIndex / this->getDimensions().x() );
}

template< typename Real,
          typename Device,
          typename Index >
template< int nx, int ny >
__cuda_callable__ inline
Index tnlGrid< 2, Real, Device, Index >::getFaceIndex( const CoordinatesType& faceCoordinates ) const
{
   tnlStaticAssert( nx >= 0 && ny >= 0 && nx + ny == 1, "Wrong template parameters nx or ny." );
   if( nx )
   {
      tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions().x() + 1,
                 cerr << "faceCoordinates.x() = " << faceCoordinates.x()
                      << " this->getDimensions().x() + 1 = " << this->getDimensions().x() + 1 );
      tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions().y(),
                 cerr << "faceCoordinates.y() = " << faceCoordinates.y()
                      << " this->getDimensions().y() = " << this->getDimensions().y() );
      return faceCoordinates.y() * ( this->getDimensions().x() + 1 ) + faceCoordinates.x();
   }
   tnlAssert( faceCoordinates.x() >= 0 && faceCoordinates.x() < this->getDimensions().x(),
              cerr << "faceCoordinates.x() = " << faceCoordinates.x()
                   << " this->getDimensions().x() = " << this->getDimensions().x() );
   tnlAssert( faceCoordinates.y() >= 0 && faceCoordinates.y() < this->getDimensions().y() + 1,
              cerr << "faceCoordinates.y() = " << faceCoordinates.y()
                   << " this->getDimensions().y() + 1 = " << this->getDimensions().y() + 1 );
   return this->numberOfNxFaces + faceCoordinates.y() * this->getDimensions().x() + faceCoordinates.x();
}

template< typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
typename tnlGrid< 2, Real, Device, Index >::CoordinatesType
tnlGrid< 2, Real, Device, Index >::getFaceCoordinates( const Index faceIndex, int& nx, int& ny ) const
{
   tnlAssert( faceIndex >= 0 && faceIndex < ( this->template getEntitiesCount< Faces >() ),
              cerr << " faceIndex = " << faceIndex
                   << " this->template getEntitiesCount< Faces >() = " << ( this->template getEntitiesCount< Faces >() ) );
   if( faceIndex < this->numberOfNxFaces )
   {
      nx = 1;
      ny = 0;
      const IndexType aux = this->getDimensions().x() + 1;
      return CoordinatesType( faceIndex % aux, faceIndex / aux );
   }
   nx = 0;
   ny = 1;
   const IndexType i = faceIndex - this->numberOfNxFaces;
   const IndexType& aux = this->getDimensions().x();
   return CoordinatesType( i % aux, i / aux );
}

template< typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
Index tnlGrid< 2, Real, Device, Index > :: getVertexIndex( const CoordinatesType& vertexCoordinates ) const
{
   tnlAssert( vertexCoordinates.x() >= 0 && vertexCoordinates.x() < this->getDimensions().x() + 1,
              cerr << "vertexCoordinates.x() = " << vertexCoordinates.x()
                   << " this->getDimensions().x() + 1 = " << this->getDimensions().x() + 1 );
   tnlAssert( vertexCoordinates.y() >= 0 && vertexCoordinates.y() < this->getDimensions().y() + 1,
              cerr << "vertexCoordinates.y() = " << vertexCoordinates.y()
                   << " this->getDimensions().y() + 1 = " << this->getDimensions().y() + 1 );
   return vertexCoordinates.y() * ( this->dimensions.x() +1 ) + vertexCoordinates.x();
}

template< typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
typename tnlGrid< 2, Real, Device, Index > :: CoordinatesType
tnlGrid< 2, Real, Device, Index > :: getVertexCoordinates( const Index vertexIndex ) const
{
   tnlAssert( vertexIndex >= 0 && vertexIndex < this->getNumberOfVertices(),
              cerr << " vertexIndex = " << vertexIndex
                   << " this->getNumberOfVertices() = " << this->getNumberOfVertices() );
   const IndexType aux = this->dimensions.x() + 1;
   return CoordinatesType( vertexIndex % aux, vertexIndex / aux );
}

template< typename Real,
          typename Device,
          typename Index >
   template< int dx, int dy >
__cuda_callable__ inline
Index tnlGrid< 2, Real, Device, Index >::getCellNextToCell( const IndexType& cellIndex ) const
{
   const IndexType result = cellIndex + dx + dy * this->getDimensions().x();
   tnlAssert( result >= 0 &&
              result < this->template getEntitiesCount< 2 >(),
              cerr << " cellIndex = " << cellIndex
                   << " dx = " << dx
                   << " dy = " << dy
                   << " this->template getEntitiesCount< 2 >() = " << this->template getEntitiesCount< 2 >() );
   return result;
}

template< typename Real,
          typename Device,
          typename Index >
   template< int nx, int ny >
__cuda_callable__ inline
Index tnlGrid< 2, Real, Device, Index >::getFaceNextToCell( const IndexType& cellIndex ) const
{
   tnlAssert( nx * ny == 0 && nx + ny != 0,
              cerr << "nx = " << nx
                   << "ny = " << ny );
   IndexType result;
   if( nx )
      result = cellIndex + cellIndex / this->getDimensions().x() + ( nx + ( nx < 0 ) );
   if( ny )
      result = this->numberOfNxFaces + cellIndex + ( ny + ( ny < 0 ) ) * this->getDimensions().x();
   tnlAssert( result >= 0 &&
              result < ( this->template getEntitiesCount< Faces >() ),
              cerr << " cellIndex = " << cellIndex
                   << " nx = " << nx
                   << " ny = " << ny
                   << " this->template getEntitiesCout< Faces >() = " << ( this->template getEntitiesCount< Faces >() ) );
   return result;
}

template< typename Real,
          typename Device,
          typename Index >
   template< int nx, int ny >
__cuda_callable__ inline
Index tnlGrid< 2, Real, Device, Index >::getCellNextToFace( const IndexType& faceIndex ) const
{
   tnlAssert( abs( nx ) + abs( ny ) == 1,
              cerr << "nx = " << nx << " ny = " << ny );
#ifndef NDEBUG
   int _nx, _ny;
#endif   
   tnlAssert( ( nx + this->getFaceCoordinates( faceIndex, _nx, _ny ).x() >= 0 &&
                nx + this->getFaceCoordinates( faceIndex, _nx, _ny ).x() <= this->getDimensions().x() ),
              cerr << " nx = " << nx
                   << " this->getFaceCoordinates( faceIndex, _nx, _ny ).x() = " << this->getFaceCoordinates( faceIndex, _nx, _ny ).x()
                   << " this->getDimensions().x()  = " << this->getDimensions().x() );
   tnlAssert( ( ny + this->getFaceCoordinates( faceIndex, _nx, _ny ).y() >= 0 &&
                      ny + this->getFaceCoordinates( faceIndex, _nx, _ny ).y() <= this->getDimensions().y() ),
              cerr << " ny = " << ny
                   << " this->getFaceCoordinates( faceIndex, _nx, _ny ).y() = " << this->getFaceCoordinates( faceIndex, _nx, _ny ).y()
                   << " this->getDimensions().y()  = " << this->getDimensions().y() );

   IndexType result;
   if( nx )
      result = faceIndex + ( nx - ( nx > 0 ) ) - faceIndex / ( this->getDimensions().x() + 1 );
   if( ny )
      result = faceIndex - this->numberOfNxFaces + ( ny - ( ny > 0 ) ) * this->getDimensions().x();
}

template< typename Real,
          typename Device,
          typename Index >
@@ -531,36 +351,6 @@ Real tnlGrid< 2, Real, Device, Index > :: getSmallestSpaceStep() const
   return Min( this->hx, this->hy );
}

/*template< typename Real,
          typename Device,
          typename Index >
__cuda_callable__
Index tnlGrid< 2, Real, Device, Index > :: template getEntitiesCount< Cells >() const
{
   return this->numberOfCells;
};

template< typename Real,
          typename Device,
          typename Index >
   template< int nx,
             int ny >
__cuda_callable__
Index tnlGrid< 2, Real, Device, Index > :: getNumberOfFaces() const
{
   return nx * this->numberOfNxFaces + ny * this->numberOfNyFaces;
}

template< typename Real,
          typename Device,
          typename Index >
__cuda_callable__
Index tnlGrid< 2, Real, Device, Index > :: getNumberOfVertices() const
{
   return this->numberOfVertices;
}
*/


template< typename Real,
          typename Device,
@@ -667,13 +457,18 @@ template< typename Real,
                                                                 const typename GridFunction::RealType& p ) const
{
   typename GridFunction::RealType lpNorm( 0.0 );
   for( IndexType j = 0; j < getDimensions(). y(); j++ )
      for( IndexType i = 0; i < getDimensions(). x(); i++ )
   GridEntity< Cells > cell( *this );
   for( cell.getCoordinates().y() = 0;
        cell.getCoordinates().y() < getDimensions().y();
        cell.getCoordinates().y()++ )
      for( cell.getCoordinates().x() = 0;
           cell.getCoordinates().x() < getDimensions().x();
           cell.getCoordinates().x()++ )
      {
         IndexType c = this->getElementIndex( i, j );
         lpNorm += pow( tnlAbs( f1[ c ] ), p ) *
            this->getElementMeasure( CoordinatesType( i, j ) );
         IndexType c = this->getEntityIndex( cell );
         lpNorm += pow( tnlAbs( f1[ c ] ), p );
      }
   lpNorm *= this->cellProportions.x() * this->cellProportions.y();
   return pow( lpNorm, 1.0/p );
}

@@ -698,10 +493,15 @@ template< typename Real,
                                                                 const typename GridFunction::RealType& p ) const
{
   typename GridFunction::RealType lpNorm( 0.0 );
   for( IndexType j = 0; j < getDimensions(). y(); j++ )
      for( IndexType i = 0; i < getDimensions(). x(); i++ )
      {
         IndexType c = this->getCellIndex( CoordinatesType( i, j ) );
   GridEntity< Cells > cell( *this );
   for( cell.getCoordinates().y() = 0;
        cell.getCoordinates().y() < getDimensions().y();
        cell.getCoordinates().y()++ )
      for( cell.getCoordinates().x() = 0;
           cell.getCoordinates().x() < getDimensions().x();
           cell.getCoordinates().x()++ )
      {
         IndexType c = this->getEntityIndex( cell );
         lpNorm += pow( tnlAbs( f1[ c ] - f2[ c ] ), p );
      }
   lpNorm *= this->cellProportions.x() * this->cellProportions.y();
+25 −1
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, EntityDimension
      __cuda_callable__ inline
      void setCoordinates( const CoordinatesType& coordinates );

      __cuda_callable__ inline
      void setIndex( IndexType entityIndex );

      __cuda_callable__ inline
      Index getIndex() const;
      
      __cuda_callable__ inline
      const EntityOrientationType& getOrientation() const;
      
@@ -94,6 +100,8 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, EntityDimension
      
      const GridType& grid;
      
      IndexType entityIndex;
      
      CoordinatesType coordinates;
      
      EntityOrientationType orientation;
@@ -144,6 +152,12 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, Dimensions >
      __cuda_callable__ inline
      void setCoordinates( const CoordinatesType& coordinates );

      __cuda_callable__ inline
      void setIndex( IndexType entityIndex );

      __cuda_callable__ inline
      Index getIndex() const;
            
      __cuda_callable__ inline
      const EntityOrientationType getOrientation() const;     
      
@@ -162,6 +176,8 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, Dimensions >
      
      const GridType& grid;
      
      IndexType entityIndex;      
      
      CoordinatesType coordinates;
      
      EntityOrientationType orientation;
@@ -213,6 +229,12 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, 0 >
      __cuda_callable__ inline
      void setCoordinates( const CoordinatesType& coordinates );
      
      __cuda_callable__ inline
      void setIndex( IndexType entityIndex ) const;

      __cuda_callable__ inline
      Index getIndex() const;
            
      __cuda_callable__ inline
      const EntityOrientationType getOrientation() const;     
      
@@ -227,6 +249,8 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, 0 >
      
      const GridType& grid;
      
      IndexType entityIndex;      
      
      CoordinatesType coordinates;
      
      EntityOrientationType orientation;
+117 −5
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ __cuda_callable__ inline
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, EntityDimensions >::
tnlGridEntity( const tnlGrid< Dimensions, Real, Device, Index >& grid )
: grid( grid ),
  entityIndex( -1 ),
  coordinates( 0 ),
  orientation( 0 ),
  basis( 0 ) 
@@ -60,6 +61,7 @@ tnlGridEntity( const tnlGrid< Dimensions, Real, Device, Index >& grid,
               const EntityOrientationType& orientation,
               const EntityBasisType& basis )
: grid( grid ),
  entityIndex( -1 ),
  coordinates( coordinates ),
  orientation( orientation ),
  basis( basis )
@@ -105,6 +107,43 @@ setCoordinates( const CoordinatesType& coordinates )
   this->coordinates = coordinates;
}

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index,
          int EntityDimensions >
__cuda_callable__ inline
void
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, EntityDimensions >::
setIndex( IndexType entityIndex )
{
   tnlAssert( entityIndex >= 0 &&
              entityIndex < grid.template getEntitiesCount< EntityDimensions >(),
              cerr << "entityIndex = " << entityIndex
                   << " grid.template getEntitiesCount< EntityDimensions >() = " << grid.template getEntitiesCount< EntityDimensions >() );
   this->entityIndex = entityIndex;                   
}

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index,
          int EntityDimensions >
__cuda_callable__ inline
Index
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, EntityDimensions >::
getIndex() const
{
   tnlAssert( this->entityIndex >= 0 &&
              this-> entityIndex < grid.template getEntitiesCount< EntityDimensions >(),
              cerr << "this->entityIndex = " << this->entityIndex
                   << " grid.template getEntitiesCount< EntityDimensions >() = " << grid.template getEntitiesCount< EntityDimensions >() );
   tnlAssert( this->entityIndex == grid.getEntityIndex( *this ),
              cerr << "this->entityIndex = " << this->entityIndex
                   << " grid.getEntityIndex( *this ) = " << grid.getEntityIndex( *this ) );
   return this->entityIndex;
}

template< int Dimensions,
          typename Real,
          typename Device,
@@ -172,14 +211,13 @@ tnlNeighbourGridEntityGetter<
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, EntityDimensions >::
getNeighbourEntities() const
{
   return tnlNeighbourGridEntityGetter< ThisType, EntityDimensions >( this->grid, *this );
   return tnlNeighbourGridEntityGetter< ThisType, NeighbourEntityDimensions >( this->grid, *this );
}


/****
 * Specialization for cells
 */

template< int Dimensions,
          typename Real,
          typename Device,
@@ -197,7 +235,8 @@ template< int Dimensions,
__cuda_callable__ inline
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, Dimensions >::
tnlGridEntity( const GridType& grid )
: grid( grid )
: grid( grid ),
  entityIndex( -1 )
{
   this->coordinates = CoordinatesType( ( Index ) 0 );
   this->orientation = EntityOrientationType( ( Index ) 0 );
@@ -215,6 +254,7 @@ tnlGridEntity( const GridType& grid,
               const EntityOrientationType& orientation,
               const EntityBasisType& basis )
: grid( grid ),
  entityIndex( -1 ),
  coordinates( coordinates )
{
   this->orientation = EntityOrientationType( ( Index ) 0 );
@@ -257,6 +297,41 @@ setCoordinates( const CoordinatesType& coordinates )
   this->coordinates = coordinates;
}

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
void
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, Dimensions >::
setIndex( IndexType entityIndex )
{
   tnlAssert( entityIndex >= 0 &&
              entityIndex < grid.template getEntitiesCount< Dimensions >(),
              cerr << "entityIndex = " << entityIndex
                   << " grid.template getEntitiesCount< Dimensions >() = " << grid.template getEntitiesCount< Dimensions >() );
   this->entityIndex = entityIndex;                   
}

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
Index
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, Dimensions >::
getIndex() const
{
   tnlAssert( this->entityIndex >= 0 &&
              this-> entityIndex < grid.template getEntitiesCount< Dimensions >(),
              cerr << "this->entityIndex = " << this->entityIndex
                   << " grid.template getEntitiesCount< Dimensions >() = " << grid.template getEntitiesCount< Dimensions >() );
   tnlAssert( this->entityIndex == grid.getEntityIndex( *this ),
              cerr << "this->index = " << this->entityIndex
                   << " grid.getEntityIndex( *this ) = " << grid.getEntityIndex( *this ) );
   return this->entityIndex;
}

template< int Dimensions,
          typename Real,
          typename Device,
@@ -293,7 +368,7 @@ tnlNeighbourGridEntityGetter<
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, Dimensions >::
getNeighbourEntities() const
{
   return tnlNeighbourGridEntityGetter< ThisType, Dimensions >( this->grid, *this );
   return tnlNeighbourGridEntityGetter< ThisType, NeighbourEntityDimensions >( this->grid, *this );
}

/****
@@ -317,6 +392,7 @@ __cuda_callable__ inline
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, 0 >::
tnlGridEntity( const GridType& grid )
 : grid( grid ),
   entityIndex( -1 ),
   coordinates( 0 ),
   orientation( 1 ),
   basis( 0 )
@@ -334,6 +410,7 @@ tnlGridEntity( const GridType& grid,
               const EntityOrientationType& orientation,
               const EntityBasisType& basis )
: grid( grid ),
  entityIndex( -1 ),
  coordinates( coordinates )
{  
}
@@ -374,6 +451,41 @@ setCoordinates( const CoordinatesType& coordinates )
   this->coordinates = coordinates;
}

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
void
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, 0 >::
setIndex( IndexType entityIndex ) const
{
   tnlAssert( entityIndex >= 0 &&
              entityIndex < grid.template getEntitiesCount< 0 >(),
              cerr << "entityIndex = " << entityIndex
                   << " grid.template getEntitiesCount< 0 >() = " << grid.template getEntitiesCount< 0 >() );
   this->entityIndex = entityIndex;                   
}

template< int Dimensions,
          typename Real,
          typename Device,
          typename Index >
__cuda_callable__ inline
Index
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, 0 >::
getIndex() const
{
   tnlAssert( this->entityIndex >= 0 &&
              this-> entityIndex < grid.template getEntitiesCount< 0 >(),
              cerr << "this->entityIndex = " << this->entityIndex
                   << " grid.template getEntitiesCount< 0 >() = " << grid.template getEntitiesCount< 0 >() );
   tnlAssert( this->entityIndex == grid.getEntityIndex( *this ),
              cerr << "this->entityIndex = " << this->entityIndex
                   << " grid.getEntityIndex( *this ) = " << grid.getEntityIndex( *this ) );
   return this->entityIndex;
}

template< int Dimensions,
          typename Real,
          typename Device,
@@ -410,7 +522,7 @@ tnlNeighbourGridEntityGetter<
tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, 0 >::
getNeighbourEntities() const
{
   return tnlNeighbourGridEntityGetter< ThisType, Dimensions >( this->grid, *this );
   return tnlNeighbourGridEntityGetter< ThisType, NeighbourEntityDimensions >( this->grid, *this );
}

#endif	/* TNLGRIDENTITY_IMPL_H */
+8 −30

File changed.

Preview size limit exceeded, changes collapsed.

Loading