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

Adding Linear Grid Geometry.

parent 8b4280d3
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#define NAVIERSTOKESSETTER_IMPL_H_

#include <mesh/tnlGrid.h>
#include <mesh/tnlLinearGridGeometry.h>
#include <schemes/euler/fvm/tnlLaxFridrichs.h>
#include <schemes/gradient/tnlCentralFDMGradient.h>

@@ -38,7 +39,8 @@ bool navierStokesSetter< SolverStarter > :: run( const tnlParameterContainer& pa
   const tnlString& schemeName = parameters. GetParameter< tnlString >( "scheme" );
   if( dimensions == 2 )
   {
      typedef tnlGrid< 2, RealType, DeviceType, IndexType > MeshType;
      typedef tnlGrid< 2, RealType, DeviceType, IndexType, tnlLinearGridGeometry > MeshType;
      //typedef tnlGrid< 2, RealType, DeviceType, IndexType > MeshType;
      if( schemeName == "lax-fridrichs" )
         return solverStarter. run< navierStokesSolver< MeshType,
                                                        tnlLaxFridrichs< MeshType,
+2 −1
Original line number Diff line number Diff line
SET( headers tnlGrid1D_impl.h
             tnlGrid2D_impl.h
             tnlGrid3D_impl.h
             tnlIdenticalGridGeometry_impl.h )
             tnlIdenticalGridGeometry_impl.h
             tnlLinearGridGeometry_impl.h )

SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/implementation/mesh )    
SET( tnl_implementation_mesh_SOURCES
+301 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlLinearGridGeometry_impl.h  -  description
                             -------------------
    begin                : May 10, 2013
    copyright            : (C) 2013 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef TNLLINEARGRIDGEOMETRY_IMPL_H_
#define TNLLINEARGRIDGEOMETRY_IMPL_H_

#include <core/tnlFile.h>
#include <core/tnlAssert.h>

/****
 * Linear geometry for 1D
 */

template< typename Real,
          typename Device,
          typename Index >
void tnlLinearGridGeometry< 1, Real, Device, Index > :: setParametricStep( const VertexType& parametricStep )
{
   this -> parametricStep = parametricStep;
   this -> elementMeasure = this -> parametricStep. x();
}

template< typename Real,
          typename Device,
          typename Index >
const typename tnlLinearGridGeometry< 1, Real, Device, Index > :: VertexType&
   tnlLinearGridGeometry< 1, Real, Device, Index > :: getParametricStep() const
{
   return this -> parametricStep;
}

template< typename Real,
          typename Device,
          typename Index >
void tnlLinearGridGeometry< 1, Real, Device, Index > :: getElementCenter( const VertexType& origin,
                                                                             const CoordinatesType& coordinates,
                                                                             VertexType& center ) const
{
   center. x() = ( coordinates. x() + 0.5 ) * parametricStep. x();
}

template< typename Real,
          typename Device,
          typename Index >
Real tnlLinearGridGeometry< 1, Real, Device, Index > :: getElementMeasure( const CoordinatesType& i ) const
{
   return elementMeasure;
}

template< typename Real,
          typename Device,
          typename Index >
   template< Index dx >
Real tnlLinearGridGeometry< 1, Real, Device, Index > :: getElementsDistance( const Index i ) const
{
   return dx * parametricStep. x();
}

template< typename Real,
          typename Device,
          typename Index >
template< Index dx >
void tnlLinearGridGeometry< 1, Real, Device, Index > :: getEdgeCoordinates( const Index i,
                                                                               const VertexType& origin,
                                                                               VertexType& coordinates ) const
{
   coordinates. x() = origin. x() + ( i + 0.5 * ( 1.0 + dx ) ) * parametricStep. x();
}

template< typename Real,
          typename Device,
          typename Index >
template< Index dx >
Real tnlLinearGridGeometry< 1, Real, Device, Index > :: getEdgeLength( const Index i ) const
{
   return 0.0;
}

template< typename Real,
          typename Device,
          typename Index >
template< Index dx >
void tnlLinearGridGeometry< 1, Real, Device, Index > :: getEdgeNormal( const Index i,
                                                                          VertexType& normal ) const
{
   tnlAssert( dx == 1 || dx == -1, cerr << " dx = " << dx << " dy = " << dy << endl );
   normal. x() = dx;
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlLinearGridGeometry< 1, Real, Device, Index > :: save( tnlFile& file ) const
{
   if( ! this -> parametricStep. save( file ) )
      return false;
   return true;
};

template< typename Real,
          typename Device,
          typename Index >
bool tnlLinearGridGeometry< 1, Real, Device, Index > :: load( tnlFile& file )
{
   if( ! this -> parametricStep. load( file ) )
      return false;
   this -> elementMeasure = this -> parametricStep. x();
   return true;
};

/****
 * Linear geometry for 2D
 */

template< typename Real,
          typename Device,
          typename Index >
void tnlLinearGridGeometry< 2, Real, Device, Index > :: setParametricStep( const VertexType& parametricStep )
{
   this -> parametricStep = parametricStep;
   this -> elementMeasure = this -> parametricStep. x() * this -> parametricStep. y();
}

template< typename Real,
          typename Device,
          typename Index >
const typename tnlLinearGridGeometry< 2, Real, Device, Index > :: VertexType&
   tnlLinearGridGeometry< 2, Real, Device, Index > :: getParametricStep() const
{
   return this -> parametricStep;
}

template< typename Real,
          typename Device,
          typename Index >
void tnlLinearGridGeometry< 2, Real, Device, Index > :: getElementCenter( const VertexType& origin,
                                                                             const CoordinatesType& coordinates,
                                                                             VertexType& center ) const
{
   center. x() = ( coordinates. x() + 0.5 ) * parametricStep. x();
   center. y() = ( coordinates. y() + 0.5 ) * parametricStep. y();
}

template< typename Real,
          typename Device,
          typename Index >
Real tnlLinearGridGeometry< 2, Real, Device, Index > :: getElementMeasure( const CoordinatesType& coordinates ) const
{
   return elementMeasure;
}

template< typename Real,
          typename Device,
          typename Index >
   template< int dx, int dy >
Real tnlLinearGridGeometry< 2, Real, Device, Index > :: getElementCoVolumeMeasure( const CoordinatesType& coordinates ) const
{
   return 0.5 * elementMeasure;
}


template< typename Real,
          typename Device,
          typename Index >
Real tnlLinearGridGeometry< 2, Real, Device, Index > :: getElementsDistance( const CoordinatesType& c1,
                                                                                const CoordinatesType& c2 ) const
{
   CoordinatesType c( c2 );
   c -= c1;
   if( c. y() == 0 )
      return parametricStep. x() * fabs( c. x() );
   if( c. x() == 0 )
      return parametricStep. y() * fabs( c. y() );
   return sqrt( c. x() * c. x() + c. y() * c. y() );
}

/*
template< typename Real,
          typename Device,
          typename Index >
template< Index dx, Index dy >
void tnlLinearGridGeometry< 2, Real, Device, Index > :: getEdgeCoordinates( const Index i,
                                                                               const Index j,
                                                                               const VertexType& origin,
                                                                               VertexType& coordinates ) const
{
   coordinates. x() = origin. x() + ( i + 0.5 * ( 1.0 + dx ) ) * parametricStep. x();
   coordinates. y() = origin. y() + ( j + 0.5 * ( 1.0 + dy ) ) * parametricStep. y();
}

template< typename Real,
          typename Device,
          typename Index >
template< Index dx, Index dy >
Real tnlLinearGridGeometry< 2, Real, Device, Index > :: getEdgeLength( const Index i,
                                                                          const Index j ) const
{
   if( dy == 0 && dx == 1 )
      return parametricStep. y();
   if( dy == 1 && dx == 0 )
      return parametricStep. x();
   tnlAssert( false, cerr << "Bad values of dx and dy - dx = " << dx << " dy = " << dy );
}*/

template< typename Real,
          typename Device,
          typename Index >
template< Index dx, Index dy >
void tnlLinearGridGeometry< 2, Real, Device, Index > :: getEdgeNormal( const CoordinatesType& coordinates,
                                                                       VertexType& normal ) const
{
   tnlAssert( ( dx == 0 || dx == 1 || dx == -1 ||
                dy == 0 || dy == 1 || dy == -1 ) &&
               dx * dy == 0 && dx + dy != 0 , cerr << " dx = " << dx << " dy = " << dy << endl );
   /*VertexType v1, v2, origin( 0 );
   if( dy == 0 )
   {
      if( dx == 1 )
      {
         this -> getVertex< 1, 1 >( coordinates, origin, v1 );
         this -> getVertex< 1, -1 >( coordinates, origin, v2 );
      }
      else // dx == -1
      {
         this -> getVertex< -1, -1 >( coordinates, origin, v1 );
         this -> getVertex< -1, 1 >( coordinates, origin, v2 );
      }
   }
   else // dx == 0
   {
      if( dy == 1 )
      {
         this -> getVertex< -1, 1 >( coordinates, origin, v1 );
         this -> getVertex< 1, 1 >( coordinates, origin, v2 );
      }
      else
      {
         this -> getVertex< 1, -1 >( coordinates, origin, v1 );
         this -> getVertex< -1, -1 >( coordinates, origin, v2 );
      }
   }
   normal. x() = v1. y() - v2. y();
   normal. y() = v2. x() - v1. x();*/

   normal. x() = dx * parametricStep. y();
   normal. y() = dy * parametricStep. x();

}

template< typename Real,
          typename Device,
          typename Index >
   template< Index dx, Index dy >
void tnlLinearGridGeometry< 2, Real, Device, Index > :: getVertex( const CoordinatesType& coordinates,
                                                                   const VertexType& origin,
                                                                   VertexType& vertex ) const
{
   tnlAssert( ( dx == 0 || dx == 1 || dx == -1 ||
                dy == 0 || dy == 1 || dy == -1 ), cerr << " dx = " << dx << " dy = " << dy << endl );
   vertex. x() = origin. x() + ( coordinates. x() + 0.5 * ( 1 + dx ) ) * parametricStep. x();
   vertex. y() = origin. y() + ( coordinates. y() + 0.5 * ( 1 + dy ) ) * parametricStep. y();
}

template< typename Real,
          typename Device,
          typename Index >
bool tnlLinearGridGeometry< 2, Real, Device, Index > :: save( tnlFile& file ) const
{
   if( ! this -> parametricStep. save( file ) )
      return false;
   return true;
};

template< typename Real,
          typename Device,
          typename Index >
bool tnlLinearGridGeometry< 2, Real, Device, Index > :: load( tnlFile& file )
{
   if( ! this -> parametricStep. load( file ) )
      return false;
   this -> elementMeasure = this -> parametricStep. x() * this -> parametricStep. y();
   return true;
};




#endif /* TNLLINEARGRIDGEOMETRY_IMPL_H_ */
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ ADD_SUBDIRECTORY( topology )

SET( headers tnlGrid.h
             tnlIdenticalGridGeometry.h
             tnlLinearGridGeometry.h
             tnlDummyMesh.h
             config.h 
             information.h 
+147 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlLinearGridGeometry.h  -  description
                             -------------------
    begin                : May 10, 2013
    copyright            : (C) 2013 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TNLLINEARGRIDGEOMETRY_H_
#define TNLLINEARGRIDGEOMETRY_H_


#include <core/tnlHost.h>

template< int Dimensions,
          typename Real = double,
          typename Device = tnlHost,
          typename Index = int >
class tnlLinearGridGeometry
{
};

template< typename Real,
          typename Device,
          typename Index >
class tnlLinearGridGeometry< 1, Real, Device, Index >
{
   public:

   typedef Real RealType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef tnlTuple< 1, Index > CoordinatesType;
   typedef tnlTuple< 1, Real > VertexType;

   void setParametricStep( const VertexType& parametricStep );

   const VertexType& getParametricStep() const;

   void getElementCenter( const VertexType& origin,
                          const CoordinatesType& coordinates,
                          VertexType& center ) const;

   Real getElementMeasure( const CoordinatesType& i ) const;

   template< Index dx >
   Real getElementsDistance( const Index i ) const;

   template< Index dx >
   void getEdgeCoordinates( const Index i,
                            const VertexType& origin,
                            VertexType& coordinates ) const;

   template< Index dx >
   Real getEdgeLength( const Index i ) const;

   template< Index dx >
   void getEdgeNormal( const Index i,
                       VertexType& normal ) const;

   void getVertexCoordinates( const Index i,
                              const VertexType& origin,
                              VertexType& coordinates ) const;

   bool save( tnlFile& file ) const;

   bool load( tnlFile& file );

   protected:

   VertexType parametricStep;

   Real elementMeasure;
};

template< typename Real,
          typename Device,
          typename Index >
class tnlLinearGridGeometry< 2, Real, Device, Index >
{
   public:

   typedef Real RealType;
   typedef Device DeviceType;
   typedef Index IndexType;
   typedef tnlTuple< 2, Index > CoordinatesType;
   typedef tnlTuple< 2, Real > VertexType;

   void setParametricStep( const VertexType& parametricStep );

   const VertexType& getParametricStep() const;

   void getElementCenter( const VertexType& origin,
                          const tnlTuple< 2, Index >& coordinates,
                          VertexType& center ) const;

   Real getElementMeasure( const tnlTuple< 2, Index >& coordinates ) const;

   template< int dx, int dy >
   Real getElementCoVolumeMeasure( const CoordinatesType& coordinates ) const;

   Real getElementsDistance( const CoordinatesType& c1,
                             const CoordinatesType& c2 ) const;

   /*template< Index dx, Index dy >
   void getEdgeCoordinates( const Index i,
                            const Index j,
                            const VertexType& origin,
                            VertexType& coordinates ) const;

   template< Index dx, Index dy >
   Real getEdgeLength( const Index i,
                       const Index j ) const;*/

   template< Index dx, Index dy >
   void getEdgeNormal( const CoordinatesType& coordinates,
                       VertexType& normal ) const;

   template< Index dx, Index dy >
   void getVertex( const CoordinatesType& coordinates,
                   const VertexType& origin,
                   VertexType& vertex ) const;

   bool save( tnlFile& file ) const;

   bool load( tnlFile& file );

   protected:

   VertexType parametricStep;

   Real elementMeasure;
};

#include <implementation/mesh/tnlLinearGridGeometry_impl.h>


#endif /* TNLLINEARGRIDGEOMETRY_H_ */