From cb1c1a319211d6b6624fd78afa88e54dc7f333e7 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Mon, 29 Apr 2013 17:10:43 +0200 Subject: [PATCH] Adding tnlLinearDiffusion. --- examples/navier-stokes/Makefile | 4 +- .../navier-stokes/navierStokesSetter_impl.h | 5 +- examples/navier-stokes/navierStokesSolver.h | 2 + .../navier-stokes/navierStokesSolver_impl.h | 24 +++++--- src/implementation/schemes/CMakeLists.txt | 13 ++-- .../schemes/diffusion/CMakeLists.txt | 15 +++++ .../diffusion/tnlLinearDiffusion_impl.h | 59 +++++++++++++++++++ .../schemes/euler/fvm/tnlLaxFridrichs_impl.h | 48 +++++++-------- .../gradient/tnlCentralFDMGradient_impl.h | 17 +++--- src/schemes/CMakeLists.txt | 3 +- src/schemes/diffusion/CMakeLists.txt | 4 ++ src/schemes/diffusion/tnlLinearDiffusion.h | 57 ++++++++++++++++++ src/schemes/euler/fvm/tnlLaxFridrichs.h | 4 +- 13 files changed, 201 insertions(+), 54 deletions(-) create mode 100755 src/implementation/schemes/diffusion/CMakeLists.txt create mode 100644 src/implementation/schemes/diffusion/tnlLinearDiffusion_impl.h create mode 100755 src/schemes/diffusion/CMakeLists.txt create mode 100644 src/schemes/diffusion/tnlLinearDiffusion.h diff --git a/examples/navier-stokes/Makefile b/examples/navier-stokes/Makefile index 7fa14627ff..d689e5125b 100644 --- a/examples/navier-stokes/Makefile +++ b/examples/navier-stokes/Makefile @@ -10,8 +10,8 @@ CXX = g++ CUDA_CXX = nvcc OMP_FLAGS = -DHAVE_OPENMP -fopenmp #CXX_FLAGS = -std=gnu++0x -I$(TNL_INCLUDE_DIR) -O0 -g -DDEBUG $(OMP_FLAGS) -#CXX_FLAGS = -std=gnu++0x -I$(TNL_INCLUDE_DIR) -O3 $(OMP_FLAGS) -CXX_FLAGS = -DHAVE_NOT_CXX11 -I$(TNL_INCLUDE_DIR) -O3 $(OMP_FLAGS) +CXX_FLAGS = -std=gnu++0x -I$(TNL_INCLUDE_DIR) -O3 $(OMP_FLAGS) +#CXX_FLAGS = -DHAVE_NOT_CXX11 -I$(TNL_INCLUDE_DIR) -O3 $(OMP_FLAGS) LD_FLAGS = -L$(TNL_INSTALL_DIR) -ltnl-0.1 -lgomp SOURCES = main.cpp diff --git a/examples/navier-stokes/navierStokesSetter_impl.h b/examples/navier-stokes/navierStokesSetter_impl.h index b55d099496..6fa754ef4f 100644 --- a/examples/navier-stokes/navierStokesSetter_impl.h +++ b/examples/navier-stokes/navierStokesSetter_impl.h @@ -42,10 +42,7 @@ bool navierStokesSetter< SolverStarter > :: run( const tnlParameterContainer& pa if( schemeName == "lax-fridrichs" ) return solverStarter. run< navierStokesSolver< MeshType, tnlLaxFridrichs< MeshType, - tnlCentralFDMGradient< MeshType :: Dimensions, - typename MeshType :: RealType, - typename MeshType :: DeviceType, - typename MeshType :: IndexType > > > > + tnlCentralFDMGradient< MeshType > > > > ( parameters ); } } diff --git a/examples/navier-stokes/navierStokesSolver.h b/examples/navier-stokes/navierStokesSolver.h index 82903ae363..e112a5bc1b 100644 --- a/examples/navier-stokes/navierStokesSolver.h +++ b/examples/navier-stokes/navierStokesSolver.h @@ -97,6 +97,8 @@ class navierStokesSolver EulerScheme eulerScheme; + tnlCentralFDMGradient< MeshType > pressureGradient; + navierStokesSolverMonitor< RealType, IndexType > solverMonitor; }; diff --git a/examples/navier-stokes/navierStokesSolver_impl.h b/examples/navier-stokes/navierStokesSolver_impl.h index 420e28a6ab..4f564f1cad 100644 --- a/examples/navier-stokes/navierStokesSolver_impl.h +++ b/examples/navier-stokes/navierStokesSolver_impl.h @@ -144,7 +144,10 @@ bool navierStokesSolver< Mesh, EulerScheme > :: init( const tnlParameterContaine /**** * Set-up numerical scheme */ + pressureGradient. setFunction( p ); + pressureGradient. bindMesh( this -> mesh ); this -> eulerScheme. bindMesh( this -> mesh ); + this -> eulerScheme. setPressureGradient( this -> pressureGradient ); return true; } @@ -309,9 +312,9 @@ void navierStokesSolver< Mesh, EulerScheme > :: updatePhysicalQuantities( const template< typename Mesh, typename EulerScheme > void navierStokesSolver< Mesh, EulerScheme > :: GetExplicitRHS( const RealType& time, - const RealType& tau, - DofVectorType& u, - DofVectorType& fu ) + const RealType& tau, + DofVectorType& u, + DofVectorType& fu ) { tnlSharedVector< RealType, DeviceType, IndexType > rho, rho_u1, rho_u2, rho_t, rho_u1_t, rho_u2_t; @@ -429,18 +432,18 @@ void navierStokesSolver< Mesh, EulerScheme > :: GetExplicitRHS( const RealType& IndexType n = mesh. getElementIndex( j + 1, i ); IndexType s = mesh. getElementIndex( j - 1, i ); - const RealType& u = this -> u1[ c ]; - const RealType& v = this -> u2[ c ]; - const RealType u_sqr = u * u; - const RealType v_sqr = v * v; + //const RealType& u = this -> u1[ c ]; + //const RealType& v = this -> u2[ c ]; + //const RealType u_sqr = u * u; + //const RealType v_sqr = v * v; eulerScheme. getExplicitRhs( c, rho_t[ c ], rho_u1_t[ c ], rho_u2_t[ c ] ); //rho_u1_t[ c ] += -( p[ e ] - p[ w ] ) / ( 2.0 * hx ); - rho_u2_t[ c ] += //-( p[ n ] - p[ s ] ) / ( 2.0 * hy ); - - startUpCoefficient * this -> gravity * this -> rho[ c ]; + //rho_u2_t[ c ] += -( p[ n ] - p[ s ] ) / ( 2.0 * hy ); + //- startUpCoefficient * this -> gravity * this -> rho[ c ]; /*** * Add the viscosity term @@ -491,6 +494,9 @@ void navierStokesSolver< Mesh, EulerScheme > :: GetExplicitRHS( const RealType& } rhsDofVector = fu; + //makeSnapshot( 0.0, 1 ); + //getchar(); + } #ifdef HAVE_CUDA diff --git a/src/implementation/schemes/CMakeLists.txt b/src/implementation/schemes/CMakeLists.txt index 528e0aabe0..93f0713d26 100755 --- a/src/implementation/schemes/CMakeLists.txt +++ b/src/implementation/schemes/CMakeLists.txt @@ -1,19 +1,22 @@ -ADD_SUBDIRECTORY( euler ) ADD_SUBDIRECTORY( gradient ) +ADD_SUBDIRECTORY( diffusion ) +ADD_SUBDIRECTORY( euler ) SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/implementation/schemes ) if( BUILD_CUDA) - set( tnl_implementation_schemes_CUDA__SOURCES - ${tnl_implementation_schemes_euler_CUDA__SOURCES} + set( tnl_implementation_schemes_CUDA__SOURCES + ${tnl_implementation_schemes_diffusion_CUDA__SOURCES} ${tnl_implementation_schemes_gradient_CUDA__SOURCES} + ${tnl_implementation_schemes_euler_CUDA__SOURCES} ${common_SOURCES} PARENT_SCOPE ) endif() -set( tnl_implementation_schemes_SOURCES - ${tnl_implementation_schemes_euler_SOURCES} +set( tnl_implementation_schemes_SOURCES + ${tnl_implementation_schemes_diffusion_SOURCES} ${tnl_implementation_schemes_gradient_SOURCES} + ${tnl_implementation_schemes_euler_SOURCES} ${common_SOURCES} PARENT_SCOPE ) diff --git a/src/implementation/schemes/diffusion/CMakeLists.txt b/src/implementation/schemes/diffusion/CMakeLists.txt new file mode 100755 index 0000000000..1d52b529df --- /dev/null +++ b/src/implementation/schemes/diffusion/CMakeLists.txt @@ -0,0 +1,15 @@ +set( headers tnlLinearDiffusion_impl.h ) + +SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/implementation/schemes/diffusion ) + +if( BUILD_CUDA) + set( tnl_implementation_schemes_diffusion_CUDA__SOURCES + ${common_SOURCES} + PARENT_SCOPE ) +endif() + +set( tnl_implementation_schemes_diffusion_SOURCES + ${common_SOURCES} + PARENT_SCOPE ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/implementation/schemes/diffusion ) diff --git a/src/implementation/schemes/diffusion/tnlLinearDiffusion_impl.h b/src/implementation/schemes/diffusion/tnlLinearDiffusion_impl.h new file mode 100644 index 0000000000..c708676805 --- /dev/null +++ b/src/implementation/schemes/diffusion/tnlLinearDiffusion_impl.h @@ -0,0 +1,59 @@ +/*************************************************************************** + tnlLinearDiffusion_impl.h - description + ------------------- + begin : Apr 26, 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 TNLLINEARDIFFUSION_IMPL_H_ +#define TNLLINEARDIFFUSION_IMPL_H_ + +template< typename Real, typename Device, typename Index > +tnlLinearDiffusion< tnlGrid< 2, Real, Device, Index > > :: tnlLinearDiffusion() +: mesh( 0 ) +{ +} + +template< typename Real, typename Device, typename Index > +void tnlLinearDiffusion< tnlGrid< 2, Real, Device, Index > > :: bindMesh( const tnlGrid< 2, RealType, DeviceType, IndexType >& mesh ) +{ + this -> mesh = &mesh; +} + +template< typename Real, typename Device, typename Index > + template< typename Vector > +void tnlLinearDiffusion< tnlGrid< 2, Real, Device, Index > > :: setFunction( Vector& f ) +{ + this -> f. bind( f ); + this -> f. setName( tnlString( "bind Of " ) + f. getName() ); +} + +template< typename Real, typename Device, typename Index > +void tnlLinearDiffusion< tnlGrid< 2, Real, Device, Index > > :: getGradient( const Index& i, + RealType& diffusion ) const +{ + tnlAssert( this -> mesh, cerr << "No mesh was set in tnlLinearDiffusion. Use the bindMesh method." ); + + const Real hx = mesh -> getSpaceStep(). x() ); + const Real hy = mesh -> getSpaceStep(). y() ); + + const Index e = mesh -> getElementNeighbour( i, 0, 1 ); + const Index w = mesh -> getElementNeighbour( i, 0, -1 ); + const Index n = mesh -> getElementNeighbour( i, 1, 0 ); + const Index s = mesh -> getElementNeighbour( i, -1, 0 ); + + diffusion = ( f[ e ] - 2.0 * f[ c ] + f[ w ] ) / ( hx * hx ) + + ( f[ n ] - 2.0 * f[ c ] + f[ s ] ) / ( hy * hy ); +} + +#endif diff --git a/src/implementation/schemes/euler/fvm/tnlLaxFridrichs_impl.h b/src/implementation/schemes/euler/fvm/tnlLaxFridrichs_impl.h index 472db7edea..344dd17044 100644 --- a/src/implementation/schemes/euler/fvm/tnlLaxFridrichs_impl.h +++ b/src/implementation/schemes/euler/fvm/tnlLaxFridrichs_impl.h @@ -21,8 +21,8 @@ template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: tnlLaxFridrichs() : regularizeEps( 0.0 ), @@ -34,18 +34,17 @@ tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: bindMesh( const MeshType& mesh ) { this -> mesh = &mesh; } - template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: setRegularization( const RealType& epsilon ) { this -> regularizeEps = epsilon; @@ -53,8 +52,8 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: setViscosityCoefficient( const RealType& v ) { this -> viscosityCoefficient = v; @@ -62,38 +61,41 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: setRho( Vector& rho ) { this -> rho. bind( rho ); + this -> rho. setName( tnlString( "bind Of " ) + rho. getName() ); } template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: setRhoU1( Vector& rho_u1 ) { this -> rho_u1. bind( rho_u1 ); + this -> rho_u1. setName( tnlString( "bind Of " ) + rho_u1. getName() ); } template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: setRhoU2( Vector& rho_u2 ) { this -> rho_u2. bind( rho_u2 ); + this -> rho_u2. setName( tnlString( "bind Of " ) + rho_u2. getName() ); } template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > template< typename Vector > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: setPressureGradient( Vector& grad_p ) { @@ -102,8 +104,8 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: getExplicitRhs( const IndexType centralVolume, RealType& rho_t, RealType& rho_u1_t, @@ -137,7 +139,7 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: /**** * Compute the pressure gradient */ - RealType p_x, p_y; + RealType p_x( 0.0 ), p_y( 0.0 ); pressureGradient -> getGradient( c, p_x, p_y ); /**** @@ -158,9 +160,9 @@ void tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > -typename MeshType :: RealType tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: regularize( const RealType& r ) const + typename Index, + typename PressureGradient > +Real tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > :: regularize( const Real& r ) const { return r + ( ( r >= 0 ) - ( r < 0 ) ) * this -> regularizeEps; } diff --git a/src/implementation/schemes/gradient/tnlCentralFDMGradient_impl.h b/src/implementation/schemes/gradient/tnlCentralFDMGradient_impl.h index 1f964ae44a..068ef4dbac 100644 --- a/src/implementation/schemes/gradient/tnlCentralFDMGradient_impl.h +++ b/src/implementation/schemes/gradient/tnlCentralFDMGradient_impl.h @@ -27,7 +27,7 @@ tnlCentralFDMGradient< tnlGrid< 2, Real, Device, Index > > :: tnlCentralFDMGradi template< typename Real, typename Device, typename Index > void tnlCentralFDMGradient< tnlGrid< 2, Real, Device, Index > > :: bindMesh( const tnlGrid< 2, RealType, DeviceType, IndexType >& mesh ) { - this -> mesh = mesh; + this -> mesh = &mesh; } template< typename Real, typename Device, typename Index > @@ -35,19 +35,20 @@ template< typename Real, typename Device, typename Index > void tnlCentralFDMGradient< tnlGrid< 2, Real, Device, Index > > :: setFunction( Vector& f ) { this -> f. bind( f ); + this -> f. setName( tnlString( "bind Of " ) + f. getName() ); } template< typename Real, typename Device, typename Index > void tnlCentralFDMGradient< tnlGrid< 2, Real, Device, Index > > :: getGradient( const Index& i, - RealType& f_x, - RealType& f_y ) const + RealType& f_x, + RealType& f_y ) const { - tnlAssert( this -> mesh, cerr << "No mesh was set in tnlCentralFDMGradient" ); + tnlAssert( this -> mesh, cerr << "No mesh was set in tnlCentralFDMGradient. Use the bindMesh method." ); - const Index e = mesh -> getElementNeighbour( i, 1, 0 ); - const Index w = mesh -> getElementNeighbour( i, -1, 0 ); - const Index n = mesh -> getElementNeighbour( i, 0, 1 ); - const Index s = mesh -> getElementNeighbour( i, 0, -1 ); + const Index e = mesh -> getElementNeighbour( i, 0, 1 ); + const Index w = mesh -> getElementNeighbour( i, 0, -1 ); + const Index n = mesh -> getElementNeighbour( i, 1, 0 ); + const Index s = mesh -> getElementNeighbour( i, -1, 0 ); f_x = ( f[ e ] - f[ w ] ) / ( 2.0 * mesh -> getSpaceStep(). x() ); f_y = ( f[ n ] - f[ s ] ) / ( 2.0 * mesh -> getSpaceStep(). y() ); diff --git a/src/schemes/CMakeLists.txt b/src/schemes/CMakeLists.txt index 60a6021346..2f020a4de8 100755 --- a/src/schemes/CMakeLists.txt +++ b/src/schemes/CMakeLists.txt @@ -1,2 +1,3 @@ -ADD_SUBDIRECTORY( euler ) ADD_SUBDIRECTORY( gradient ) +ADD_SUBDIRECTORY( diffusion ) +ADD_SUBDIRECTORY( euler ) \ No newline at end of file diff --git a/src/schemes/diffusion/CMakeLists.txt b/src/schemes/diffusion/CMakeLists.txt new file mode 100755 index 0000000000..e6eaf3c385 --- /dev/null +++ b/src/schemes/diffusion/CMakeLists.txt @@ -0,0 +1,4 @@ +SET( headers tnlLinearDiffusion.h + ) + +INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/schemes/diffusion ) diff --git a/src/schemes/diffusion/tnlLinearDiffusion.h b/src/schemes/diffusion/tnlLinearDiffusion.h new file mode 100644 index 0000000000..92174fa08c --- /dev/null +++ b/src/schemes/diffusion/tnlLinearDiffusion.h @@ -0,0 +1,57 @@ +/*************************************************************************** + tnlLinearDiffusion.h - description + ------------------- + begin : Apr 29, 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 TNLLINEARDIFFUSION_H_ +#define TNLLINEARDIFFUSION_H_ + +#include <mesh/tnlGrid.h> +#include <core/tnlHost.h> + +template< typename Mesh > +class tnlLinearDiffusion +{ +}; + +template< typename Real, typename Device, typename Index > +class tnlLinearDiffusion< tnlGrid< 2, Real, Device, Index > > +{ + public: + + typedef Real RealType; + typedef Device DeviceType; + typedef Index IndexType; + + tnlLinearDiffusion(); + + void bindMesh( const tnlGrid< 2, RealType, DeviceType, IndexType >& mesh ); + + template< typename Vector > + void setFunction( Vector& f ); // TODO: add const + + void getGradient( const Index& i, + RealType& diffusion ) const; + protected: + + // TODO: change to ConstSharedVector + tnlSharedVector< RealType, DeviceType, IndexType > f; + + const tnlGrid< 2, RealType, DeviceType, IndexType >* mesh; +}; + +#include <implementation/schemes/gradient/tnlLinearDiffusion_impl.h> + +#endif diff --git a/src/schemes/euler/fvm/tnlLaxFridrichs.h b/src/schemes/euler/fvm/tnlLaxFridrichs.h index fc1c7f011c..0a881c1e92 100644 --- a/src/schemes/euler/fvm/tnlLaxFridrichs.h +++ b/src/schemes/euler/fvm/tnlLaxFridrichs.h @@ -30,8 +30,8 @@ class tnlLaxFridrichs template< typename Real, typename Device, - typename Index > -template< typename PressureGradient > + typename Index, + typename PressureGradient > class tnlLaxFridrichs< tnlGrid< 2, Real, Device, Index >, PressureGradient > { public: -- GitLab