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

Implementing finite differences.

parent ddb066d8
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -57,9 +57,9 @@ class tnlLinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index

      static tnlString getType();

      template< typename MeshEntity >
      template< typename MeshFunction, typename MeshEntity >
      __cuda_callable__
      inline Real getValue( const MeshFunction< 1 >& u,
      inline Real operator()( const MeshFunction< 1 >& u,
                              const MeshEntity& entity,
                              const RealType& time = 0.0 ) const;

@@ -113,7 +113,7 @@ class tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index

      template< typename EntityType >
      __cuda_callable__
      inline Real getValue( const MeshFunction< 2 >& u,
      inline Real operator()( const MeshFunction< 2 >& u,
                              const EntityType& entity,
                              const Real& time = 0.0 ) const;

@@ -166,7 +166,7 @@ class tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index

      template< typename EntityType >
      __cuda_callable__
      inline Real getValue( const MeshFunction< 3 >& u,
      inline Real operator()( const MeshFunction< 3 >& u,
                              const EntityType& entity,
                              const Real& time = 0.0 ) const;

+9 −9
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ __cuda_callable__
inline
Real
tnlLinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index >::
getValue( const MeshFunction< 1 >& u,
operator()( const MeshFunction< 1 >& u,
            const MeshEntity& entity,
            const Real& time ) const
{
@@ -147,7 +147,7 @@ __cuda_callable__
inline
Real
tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index >::
getValue( const MeshFunction< 2 >& u,
operator()( const MeshFunction< 2 >& u,
            const EntityType& entity,
            const Real& time ) const
{
@@ -219,7 +219,7 @@ __cuda_callable__
inline
Real
tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index >::
getValue( const MeshFunction< 3 >& u,
operator()( const MeshFunction< 3 >& u,
            const EntityType& entity,
            const Real& time ) const
{
+53 −6
Original line number Diff line number Diff line
/* 
 * File:   tnlBackwardFiniteDifference.h
 * Author: oberhuber
 *
 * Created on January 9, 2016, 11:17 AM
 */
/***************************************************************************
                          tnlBackwardFiniteDifference.h  -  description
                             -------------------
    begin                : Jan 9, 2016
    copyright            : (C) 2016 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 TNLBACKWARDFINITEDIFFERENCE_H
#define	TNLBACKWARDFINITEDIFFERENCE_H

#include <operators/fdm/tnlFiniteDifferences.h>

template< typename Mesh,
          int Xdifference = 0,
          int YDifference = 0,
@@ -18,5 +30,40 @@ class tnlBackwardFiniteDifference
{    
};

template< int Dimensions,
          typename MeshReal,
          typename MeshDevice,
          typename MeshIndex,
          int XDifference,
          int YDifference,
          int ZDifference,
          typename Real,
          typename Index >
class tnlBackwardFiniteDifference< tnlGrid< Dimensions, MeshReal, MeshDevice, MeshIndex >, Real, Index >
: tnlDomain< Dimensions, MeshInteriorDomain >
{
   public:
      
      typedef tnlGrid< Dimensions, MeshReal, MeshDevice, MeshIndex > MeshType;
      typedef Real RealType;
      typedef MeshDevice DeviceType;
      typedef Index IndexType;      
      
      static const int Dimensions = MeshType::meshDimensions;
      
      static constexpr int getMeshDimensions() { return Dimensions; }
      
      template< typename MeshFunction, typename MeshEntity >
      __cuda_callable__
      inline Real operator()( const MeshFunction& u,
                              const MeshEntity& entity,
                              const RealType& time = 0.0 ) const
      {
         static_assert( MeshFunction::getMeshEntityDimensions() == Dimensions,
            "Finite differences can be evaluate only on mesh cells, i.e. the dimensions count of the mesh entities of mesh function must be the same as mesh dimensions count." );
         return tnlFiniteDifferences< MeshType, Real, Index, XDifference, YDifference, ZDifference, -1, -1, -1 >::getValue( u, entity );
      };
};

#endif	/* TNLBACKWARDFINITEDIFFERENCE_H */
+62 −6
Original line number Diff line number Diff line
/* 
 * File:   tnlCentralFiniteDifference.h
 * Author: oberhuber
 *
 * Created on January 9, 2016, 11:17 AM
 */
/***************************************************************************
                          tnlCentralFiniteDifference.h  -  description
                             -------------------
    begin                : Jan 9, 2016
    copyright            : (C) 2016 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 TNLCENTRALFINITEDIFFERENCE_H
#define	TNLCENTRALFINITEDIFFERENCE_H

#include <operators/fdm/tnlFiniteDifferences.h>

template< typename Mesh,
          int Xdifference = 0,
          int YDifference = 0,
          int ZDifference = 0,
          typename RealType = typename Mesh::RealType,
          typename IndexType = typename Mesh::IndexType >
class tnlCentralFiniteDifference
{    
};

template< int Dimensions,
          typename MeshReal,
          typename MeshDevice,
          typename MeshIndex,
          int XDifference,
          int YDifference,
          int ZDifference,
          typename Real,
          typename Index >
class tnlCentralFiniteDifference< tnlGrid< Dimensions, MeshReal, MeshDevice, MeshIndex >, Real, Index >
: tnlDomain< Dimensions, MeshInteriorDomain >
{
   public:
      
      typedef tnlGrid< Dimensions, MeshReal, MeshDevice, MeshIndex > MeshType;
      typedef Real RealType;
      typedef MeshDevice DeviceType;
      typedef Index IndexType;      
      
      static const int Dimensions = MeshType::meshDimensions;
      
      static constexpr int getMeshDimensions() { return Dimensions; }
      
      template< typename MeshFunction, typename MeshEntity >
      __cuda_callable__
      inline Real operator()( const MeshFunction& u,
                              const MeshEntity& entity,
                              const RealType& time = 0.0 ) const
      {
         static_assert( MeshFunction::getMeshEntityDimensions() == Dimensions,
            "Finite differences can be evaluate only on mesh cells, i.e. the dimensions count of the mesh entities of mesh function must be the same as mesh dimensions count." );
         return tnlFiniteDifferences< MeshType, Real, Index, XDifference, YDifference, ZDifference, 0, 0, 0 >::getValue( u, entity );
      };
};


#endif	/* TNLCENTRALFINITEDIFFERENCE_H */
+51 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlExactDifference.h  -  description
                             -------------------
    begin                : Jan 10, 2016
    copyright            : (C) 2016 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 TNLEXACTDIFFERENCE_H
#define	TNLEXACTDIFFERENCE_H

template< typename Function,
          int XDerivative,
          int YDerivative,
          int ZDerivative >
class tnlExactDifference
   : public tnlDomain< Function::getDimensions(), SpaceDomain >
{
   public:
      
      typedef Function FunctionType;
      typedef typename Function::RealType RealType;
      typedef typename Function::VertexType VertexType;
      
      
      RealType operator()( 
         const FunctionType& function,
         const VertexType& vertex,
         const RealType& time = 0 )
      {
         return function.template getPartialDerivative<
            XDerivative,
            YDerivative,
            ZDerivative >(
            vertex, 
            time );
      };
};


#endif	/* TNLEXACTDIFFERENCE_H */
Loading