From 3a9ef536f98ee5c5c42aca3cffc964b398be4933 Mon Sep 17 00:00:00 2001
From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz>
Date: Fri, 10 May 2013 16:53:46 +0200
Subject: [PATCH] Adding Linear Grid Geometry.

---
 .../navier-stokes/navierStokesSetter_impl.h   |   4 +-
 src/implementation/mesh/CMakeLists.txt        |   3 +-
 .../mesh/tnlLinearGridGeometry_impl.h         | 301 ++++++++++++++++++
 src/mesh/CMakeLists.txt                       |   1 +
 src/mesh/tnlLinearGridGeometry.h              | 147 +++++++++
 5 files changed, 454 insertions(+), 2 deletions(-)
 create mode 100644 src/implementation/mesh/tnlLinearGridGeometry_impl.h
 create mode 100644 src/mesh/tnlLinearGridGeometry.h

diff --git a/examples/navier-stokes/navierStokesSetter_impl.h b/examples/navier-stokes/navierStokesSetter_impl.h
index 6fa754ef4f..b3d8d9c3f1 100644
--- a/examples/navier-stokes/navierStokesSetter_impl.h
+++ b/examples/navier-stokes/navierStokesSetter_impl.h
@@ -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,
diff --git a/src/implementation/mesh/CMakeLists.txt b/src/implementation/mesh/CMakeLists.txt
index d91af8415a..70b934dfde 100755
--- a/src/implementation/mesh/CMakeLists.txt
+++ b/src/implementation/mesh/CMakeLists.txt
@@ -1,7 +1,8 @@
 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
diff --git a/src/implementation/mesh/tnlLinearGridGeometry_impl.h b/src/implementation/mesh/tnlLinearGridGeometry_impl.h
new file mode 100644
index 0000000000..54624acda0
--- /dev/null
+++ b/src/implementation/mesh/tnlLinearGridGeometry_impl.h
@@ -0,0 +1,301 @@
+/***************************************************************************
+                          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_ */
diff --git a/src/mesh/CMakeLists.txt b/src/mesh/CMakeLists.txt
index 54e53cd107..a80df75497 100755
--- a/src/mesh/CMakeLists.txt
+++ b/src/mesh/CMakeLists.txt
@@ -9,6 +9,7 @@ ADD_SUBDIRECTORY( topology )
 
 SET( headers tnlGrid.h
              tnlIdenticalGridGeometry.h
+             tnlLinearGridGeometry.h
              tnlDummyMesh.h
              config.h 
              information.h 
diff --git a/src/mesh/tnlLinearGridGeometry.h b/src/mesh/tnlLinearGridGeometry.h
new file mode 100644
index 0000000000..7c8263b2dc
--- /dev/null
+++ b/src/mesh/tnlLinearGridGeometry.h
@@ -0,0 +1,147 @@
+/***************************************************************************
+                          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_ */
-- 
GitLab