Commit 1187b1be authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Adding operator function.

Removing parameter mesh from method getValue in operators.
parent 99f2203b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line

        * tnlBoundaryConditionsSetter was implemented 
           - it allows to set boundary conditions to given function
           - in explicit solvers, it must be called explicitly now after calling tnlExplicitUpdater

2015-12-25 Tomas Oberhuber  <tomas.oberhuber@fjfi.cvut.cz>
        * significant changes in grids
            - the central structure is now grid entity rather than grid itself
+67 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlOperatorFunction.h  -  description
                             -------------------
    begin                : Dec 31, 2015
    copyright            : (C) 2015 by 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 TNLOPERATORFUNCTION_H
#define	TNLOPERATORFUNCTION_H

#include <type_traits>
#include <core/tnlCuda.h>

template< typename Operator,
          typename MeshFunction,
          typename BoundaryConditions >
class tnlOperatorFunction
{
   static_assert( std::is_same< typename Operator::MeshType, typename MeshFunction::MeshType >::value,
                  "Operator and MeshFunction have different mesh type." );
   static_assert( std::is_same< typename Operator::MeshType, typename BoundaryConditions::MeshType >::value,
                  "Operator and BoundaryConditions have different mesh type." );
   
   public:
      
      typedef Operator OperatorType;
      typedef MeshFunction MeshFunctionType;
      typedef BoundaryConditions BoundaryConditionsType;
      typedef typename OperatorType::MeshType MeshType;
      typedef typename OperatorType::RealType RealType;
      typedef typename OperatorType::DeviceType DeviceType;
      typedef typename OperatorType::IndexType IndexType;
      
      tnlOperatorFunction(
         const OperatorType& operator_,
         const MeshFunctionType& function,
         const BoundaryConditionsType& boundaryConditions );
      
      template< typename MeshEntity >
      __cuda_callable__
      RealType operator()(
         const MeshEntity& meshEntity,
         const RealType& time );
      
   protected:
      
      const Operator& operator_;
      
      const MeshFunction& function;
      
      const BoundaryConditions& boundaryConditions;
         
};


#endif	/* TNLOPERATORFUNCTION_H */
+52 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlOperatorFunction_impl.h  -  description
                             -------------------
    begin                : Dec 31, 2015
    copyright            : (C) 2015 by 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 TNLOPERATORFUNCTION_IMPL_H
#define	TNLOPERATORFUNCTION_IMPL_H


template< typename Operator,
          typename Function >
tnlOperatorFunction< Operator, Function >::
tnlOperatorFunction(
   const OperatorType& operator_,
   const MeshFunctionType& function,
   const BoundaryConditionsType& boundaryConditions )
:  operator_( operator_ ),
   function( function ),
   boundaryConditions( boundaryConditions )
{   
}

template< typename Operator,
          typename Function >
   template< typename MeshEntity >
__cuda_callable__
typename tnlOperatorFunction< Operator, Function >::RealType 
tnlOperatorFunction< Operator, Function >::operator()(
   const MeshEntity& meshEntity,
   const RealType& time )
{
   static_assert( MeshEntity::entityDimensions == Function::getMeshEntityDimensions(), "Wrong mesh entity dimensions." );
   if( meshEntity.isBoundaryEntity() )
      return boundaryConditions.getValue( meshEntity, function.getData(), time );
   return operator_.getValue( meshEntity, function.getData(), time );
}


#endif	/* TNLOPERATORFUNCTION_IMPL_H */
+4 −1
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, EntityDimension
   public:
      
      typedef tnlGrid< Dimensions, Real, Device, Index > GridType;
      typedef GridType MeshType;
      typedef typename GridType::IndexType IndexType;
      typedef typename GridType::CoordinatesType CoordinatesType;
      typedef Config ConfigType;
@@ -168,6 +169,7 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, Dimensions, Con
   public:
      
      typedef tnlGrid< Dimensions, Real, Device, Index > GridType;
      typedef GridType MeshType;
      typedef typename GridType::IndexType IndexType;
      typedef typename GridType::CoordinatesType CoordinatesType;
      typedef typename GridType::VertexType VertexType;
@@ -279,6 +281,7 @@ class tnlGridEntity< tnlGrid< Dimensions, Real, Device, Index >, 0, Config >
   public:
      
      typedef tnlGrid< Dimensions, Real, Device, Index > GridType;
      typedef GridType MeshType;
      typedef typename GridType::IndexType IndexType;
      typedef typename GridType::CoordinatesType CoordinatesType;
      typedef typename GridType::VertexType VertexType;
+18 −18
Original line number Diff line number Diff line
@@ -31,8 +31,7 @@ processBoundaryEntities( const GridType& grid,
   /****
    * Boundary cells
    */
   const int CellDimensions = GridType::meshDimensions;
   //typename GridType::template GridEntity< CellDimensions > entity( grid );
   static_assert( GridEntity::entityDimensions == 1, "The entity has wrong dimensions." );
   GridEntity entity( grid );

   CoordinatesType& coordinates = entity.getCoordinates();
@@ -58,8 +57,7 @@ processInteriorEntities( const GridType& grid,
   /****
    * Interior cells
    */
   const int CellDimensions = GridType::meshDimensions;
   //typename GridType::template GridEntity< CellDimensions > cell( grid );
   static_assert( GridEntity::entityDimensions == 1, "The entity has wrong dimensions." );
   GridEntity cell( grid );

   const IndexType& xSize = grid.getDimensions().x();
@@ -85,8 +83,7 @@ processBoundaryEntities( const GridType& grid,
   /****
    * Boundary vertices
    */
   const int VerticesDimensions = 0;
   //typename GridType::template GridEntity< VerticesDimensions > entity( grid );
   static_assert( GridEntity::entityDimensions == 0, "The entity has wrong dimensions." );
   GridEntity entity( grid );
   
   CoordinatesType& coordinates = entity.getCoordinates();
@@ -112,10 +109,9 @@ processInteriorEntities( const GridType& grid,
   /****
    * Interior vertices
    */
   const int VerticesDimensions = 0;
   //typename GridType::template GridEntity< VerticesDimensions > entity( grid );
   GridEntity entity( grid );
   static_assert( GridEntity::entityDimensions == 0, "The entity has wrong dimensions." );
   
   GridEntity entity( grid );   
   CoordinatesType& coordinates = entity.getCoordinates();
   const IndexType& xSize = grid.getDimensions().x();
   for( coordinates.x() = 1; coordinates.x() < xSize; coordinates.x() ++ )
@@ -134,6 +130,7 @@ processInteriorEntities( const GridType& grid,
#ifdef HAVE_CUDA
template< typename Real,
          typename Index,
          typename GridEntity,
          typename UserData,
          typename EntitiesProcessor,
          bool processAllEntities,
@@ -143,10 +140,9 @@ __global__ void tnlTraverserGrid1DCells( const tnlGrid< 1, Real, tnlCuda, Index
                                         Index gridXIdx )
{
   typedef tnlGrid< 1, Real, tnlCuda, Index > GridType;   
   const int CellDimensions = GridType::meshDimensions;
   //typename GridType::template GridEntity< CellDimensions > entity( *grid );
   GridEntity entity( *grid );
   typedef typename GridType::CoordinatesType CoordinatesType;
   
   GridEntity entity( *grid );
   CoordinatesType& coordinates = entity.getCoordinates();

   const Index index = ( gridXIdx * tnlCuda::getMaxGridSize() + blockIdx.x ) * blockDim.x + threadIdx.x;
@@ -178,6 +174,7 @@ processBoundaryEntities( const GridType& grid,
   /****
    * Boundary conditions
    */
   static_assert( GridEntity::entityDimensions == 1, "The entity has wrong dimensions." );
   GridType* kernelGrid = tnlCuda::passToDevice( grid );
   UserData* kernelUserData = tnlCuda::passToDevice( userData );

@@ -187,7 +184,7 @@ processBoundaryEntities( const GridType& grid,
   const IndexType cudaXGrids = tnlCuda::getNumberOfGrids( cudaBlocks.x );

   for( IndexType gridXIdx = 0; gridXIdx < cudaXGrids; gridXIdx ++ )
      tnlTraverserGrid1DCells< Real, Index, UserData, EntitiesProcessor, false, true >
      tnlTraverserGrid1DCells< Real, Index, GridEntity, UserData, EntitiesProcessor, false, true >
                             <<< cudaBlocks, cudaBlockSize >>>
                             ( kernelGrid,
                               kernelUserData,
@@ -213,6 +210,7 @@ processInteriorEntities( const GridType& grid,
   /****
    * Interior cells
    */
   static_assert( GridEntity::entityDimensions == 1, "The entity has wrong dimensions." );
   checkCudaDevice;
   GridType* kernelGrid = tnlCuda::passToDevice( grid );
   UserData* kernelUserData = tnlCuda::passToDevice( userData );
@@ -227,7 +225,7 @@ processInteriorEntities( const GridType& grid,
   {
      if( gridXIdx == cudaXGrids - 1 )
         cudaGridSize.x = cudaBlocks.x % tnlCuda::getMaxGridSize();
      tnlTraverserGrid1DCells< Real, Index, UserData, EntitiesProcessor, false, false >
      tnlTraverserGrid1DCells< Real, Index, GridEntity, UserData, EntitiesProcessor, false, false >
         <<< cudaGridSize, cudaBlockSize >>>
         ( kernelGrid,
           kernelUserData,
@@ -243,6 +241,7 @@ processInteriorEntities( const GridType& grid,
#ifdef HAVE_CUDA
template< typename Real,
          typename Index,
          typename GridEntity,
          typename UserData,
          typename EntitiesProcessor,
          bool processAllEntities,
@@ -252,7 +251,6 @@ __global__ void tnlTraverserGrid1DVertices( const tnlGrid< 1, Real, tnlCuda, Ind
                                            Index gridXIdx )
{
   typedef tnlGrid< 1, Real, tnlCuda, Index > GridType;
   //typename GridType::template GridEntity< GridType::Vertices > vertex;
   GridEntity vertex( *grid );

   const Index& xSize = grid->getDimensions().x();
@@ -290,6 +288,7 @@ processBoundaryEntities( const GridType& grid,
   /****
    * Boundary vertices
    */
   static_assert( GridEntity::entityDimensions == 0, "The entity has wrong dimensions." );
   GridType* kernelGrid = tnlCuda::passToDevice( grid );
   UserData* kernelUserData = tnlCuda::passToDevice( userData );

@@ -299,7 +298,7 @@ processBoundaryEntities( const GridType& grid,
   const IndexType cudaXGrids = tnlCuda::getNumberOfGrids( cudaBlocks.x );

   for( IndexType gridXIdx = 0; gridXIdx < cudaXGrids; gridXIdx ++ )
      tnlTraverserGrid1DVertices< Real, Index, UserData, EntitiesProcessor, false, true >
      tnlTraverserGrid1DVertices< Real, Index, GridEntity, UserData, EntitiesProcessor, false, true >
         <<< cudaBlocks, cudaBlockSize >>>
         ( kernelGrid,
           kernelUserData,
@@ -327,6 +326,7 @@ processInteriorEntities( const GridType& grid,
   /****
    * Interior vertices
    */
   static_assert( GridEntity::entityDimensions == 0, "The entity has wrong dimensions." );
   checkCudaDevice;
   GridType* kernelGrid = tnlCuda::passToDevice( grid );
   UserData* kernelUserData = tnlCuda::passToDevice( userData );
@@ -341,7 +341,7 @@ processInteriorEntities( const GridType& grid,
   {
      if( gridXIdx == cudaXGrids - 1 )
         cudaGridSize.x = cudaBlocks.x % tnlCuda::getMaxGridSize();
      tnlTraverserGrid1DVertices< Real, Index, UserData, EntitiesProcessor, false, false >
      tnlTraverserGrid1DVertices< Real, Index, GridEntity, UserData, EntitiesProcessor, false, false >
         <<< cudaGridSize, cudaBlockSize >>>
         ( kernelGrid,
           kernelUserData,
Loading