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

Refactoring gradient norm operators.

parent f0675c08
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -19,12 +19,7 @@
#ifndef TNLFUNCTION_H
#define	TNLFUNCTION_H

#include <core/vectors/tnlStaticVector.h>

enum tnlDomainType { NonspaceDomain, SpaceDomain, MeshDomain, MeshInteriorDomain, MeshBoundaryDomain };
   /*MeshFunction,
                       SpaceDomain,
                       SpaceDomain };*/

template< int Dimensions,
          tnlDomainType DomainType = SpaceDomain >
+1 −2
Original line number Diff line number Diff line
@@ -6,8 +6,7 @@ SET( headers tnlLinearDiffusion.h
             tnlExactLinearDiffusion_impl.h
	     tnlNonlinearDiffusion.h
             tnlNonlinearDiffusion_impl.h
             tnlExactNonlinearDiffusion.h             
             tnlExactNonlinearDiffusion_impl.h )
             tnlExactNonlinearDiffusion.h )

SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/operators/diffusion )

+47 −18
Original line number Diff line number Diff line
@@ -42,14 +42,16 @@ class tnlExactNonlinearDiffusion< Nonlinearity, 1 >
   
      template< typename Function >
      __cuda_callable__
      Real operator()( const Function& function,
                       const Vertex& v,
                       const Real& time = 0.0 ) const
      typename Function::RealType
      operator()( const Function& function,
                  const typename Function::VertexType& v,
                  const typename Function::RealType& time = 0.0 ) const
      {
         const Real u_x = function.template getPartialDerivative< 1, 0, 0 >( v, time );
         const Real u_xx = function.template getPartialDerivative< 2, 0, 0 >( v, time );
         const Real g = nonlinearity( function, v, time ) 
         const Real g_x = nonlinearity::template getPartialDerivative< Function, 1, 0, 0 >( function, v, time );
         typedef typename Function::RealType RealType;         
         const RealType u_x = function.template getPartialDerivative< 1, 0, 0 >( v, time );
         const RealType u_xx = function.template getPartialDerivative< 2, 0, 0 >( v, time );
         const RealType g = nonlinearity( function, v, time ); 
         const RealType g_x = nonlinearity.template getPartialDerivative< Function, 1, 0, 0 >( function, v, time );
         return u_xx - u_x * g_x / g;          
      }
   
@@ -76,9 +78,22 @@ class tnlExactNonlinearDiffusion< Nonlinearity, 2 >

      template< typename Function >
      __cuda_callable__
      Real operator()( const Function& function,
                       const VertexType& v,
                       const Real& time = 0.0 ) const;
      typename Function::RealType
      operator()( const Function& function,
                  const typename Function::VertexType& v,
                  const typename Function::RealType& time = 0.0 ) const
      {
         typedef typename Function::RealType RealType;         
         const RealType u_x = function.template getPartialDerivative< 1, 0, 0 >( v, time );
         const RealType u_y = function.template getPartialDerivative< 0, 1, 0 >( v, time );
         const RealType u_xx = function.template getPartialDerivative< 2, 0, 0 >( v, time );
         const RealType u_yy = function.template getPartialDerivative< 0, 2, 0 >( v, time );
         const RealType g = nonlinearity( function, v, time ); 
         const RealType g_x = nonlinearity.template getPartialDerivative< Function, 1, 0, 0 >( function, v, time );
         const RealType g_y = nonlinearity.template getPartialDerivative< Function, 0, 1, 0 >( function, v, time );

         return  u_xx + u_yy - ( g_x * u_x + g_y * u_y ) / g; 
      }

      protected:
         
@@ -104,15 +119,29 @@ class tnlExactNonlinearDiffusion< Nonlinearity, 3 >
      
      template< typename Function >
      __cuda_callable__
      Real operator()( const Function& function,
                       const VertexType& v,
                       const Real& time = 0.0 ) const;
      typename Function::RealType 
      operator()( const Function& function,
                  const typename Function::VertexType& v,
                  const typename Function::RealType& time = 0.0 ) const
      {
         typedef typename Function::RealType RealType;         
         const RealType u_x  = function.template getPartialDerivative< 1, 0, 0 >( v, time );
         const RealType u_y  = function.template getPartialDerivative< 0, 1, 0 >( v, time );
         const RealType u_z  = function.template getPartialDerivative< 0, 0, 1 >( v, time );
         const RealType u_xx = function.template getPartialDerivative< 2, 0, 0 >( v, time );
         const RealType u_yy = function.template getPartialDerivative< 0, 2, 0 >( v, time );
         const RealType u_zz = function.template getPartialDerivative< 0, 0, 2 >( v, time );
         const RealType g = nonlinearity( function, v, time ) ;
         const RealType g_x = nonlinearity.template getPartialDerivative< Function, 1, 0, 0 >( function, v, time );
         const RealType g_y = nonlinearity.template getPartialDerivative< Function, 0, 1, 0 >( function, v, time );
         const RealType g_z = nonlinearity.template getPartialDerivative< Function, 0, 0, 1 >( function, v, time );

         return  u_xx + u_yy + u_zz - ( g_x * u_x + g_y * u_y + g_z * u_z ) / g; 
      }
      
      protected:
         
         Nonlinearity nonlinearity;
};

#include "tnlExactNonlinearDiffusion_impl.h"

#endif /* TNLEXACTNONLINEARDIFFUSION_H_ */
+0 −90
Original line number Diff line number Diff line
/***************************************************************************
                          tnlExactLinearDiffusion_impl.h  -  description
                             -------------------
    begin                : Aug 8, 2014
    copyright            : (C) 2014 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 TNLEXACTNONLINEARDIFFUSION_IMPL_H_
#define TNLEXACTNONLINEARDIFFUSION_IMPL_H_

template< typename Nonlinearity >
tnlString
tnlExactNonlinearDiffusion< Nonlinearity, 1 >::
getType()
{
   return "tnlExactNonlinearDiffusion< " + Nonlinearity::getType() + ", 1 >";
}

template< typename Nonlinearity >
template< typename Function, typename Vertex, typename Real >
__cuda_callable__
Real
tnlExactNonlinearDiffusion< Nonlinearity, 1 >::
operator()( const Function& function,
          const Vertex& v,
          const Real& time ) const
{
   return function.template getPartialDerivative< 2, 0, 0 >( v, time ) - function.template getPartialDerivative< 1, 0, 0 >( v, time ) 
          * Nonlinearity::template getPartialDerivative< Function, 1, 0, 0>(function, v, time ) / Nonlinearity( function, v, time );
}

template< typename Nonlinearity >
tnlString
tnlExactNonlinearDiffusion< Nonlinearity, 2 >::
getType()
{
   return "tnlExactNonlinearDiffusion< " + Nonlinearity::getType() + ", 2 >";
}

template< typename Nonlinearity >
template< typename Function, typename Vertex, typename Real >
__cuda_callable__
Real
tnlExactNonlinearDiffusion< Nonlinearity, 2 >::
operator()( const Function& function,
          const Vertex& v,
          const Real& time ) const
{
   return  function.template getPartialDerivative< 2, 0, 0 >( v, time ) +  function.template getPartialDerivative< 0, 2, 0 >( v, time )
           -( Nonlinearity::template getPartialDerivative<1, 0, 0> (function, v, time) * function.template getPartialDerivative< 1, 0, 0 >( v, time ) 
           + Nonlinearity::template getPartialDerivative<0, 1, 0> (function, v, time) * function.template getPartialDerivative< 0, 1, 0 >( v, time ) ) 
           / Nonlinearity::template getPartialDerivative<0, 0, 0> (function, v, time);
}

template< typename Nonlinearity >
tnlString
tnlExactNonlinearDiffusion< Nonlinearity, 3 >::
getType()
{
   return "tnlExactNonlinearDiffusion< " + Nonlinearity::getType() + ", 3 >";
}

template< typename Nonlinearity >
template< typename Function, typename Vertex, typename Real >
__cuda_callable__
Real
tnlExactNonlinearDiffusion< Nonlinearity, 3 >::
operator()( const Function& function,
          const Vertex& v,
          const Real& time ) const
{
   return  function.template getPartialDerivative< 2, 0, 0 >( v, time ) +  function.template getPartialDerivative< 0, 2, 0 >( v, time )
           +  function.template getPartialDerivative< 0, 0, 2 >( v, time )
           -( Nonlinearity::template getPartialDerivative<1, 0, 0> (function, v, time) * function.template getPartialDerivative< 1, 0, 0 >( v, time ) 
           + Nonlinearity::template getPartialDerivative<0, 1, 0> (function, v, time) * function.template getPartialDerivative< 0, 1, 0 >( v, time )
           + Nonlinearity::template getPartialDerivative<0, 0, 1> (function, v, time) * function.template getPartialDerivative< 0, 0, 1 >( v, time ) )
           / Nonlinearity::template getPartialDerivative<0, 0, 0> (function, v, time);
}

#endif /* TNLEXACTNONLINEARDIFFUSION_IMPL_H_ */
+6 −6
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ class tnlExactGradientNorm< 1, Real >
      __cuda_callable__
      typename Function::RealType
         getPartialDerivative( const Function& function,
                               const typename Function::Vertex& v,
                               const typename Function::VertexType& v,
                               const typename Function::RealType& time = 0.0 ) const
      {
         static_assert( XDerivative >= 0 && YDerivative >= 0 && ZDerivative >= 0,
@@ -138,8 +138,8 @@ class tnlExactGradientNorm< 2, Real >
      __cuda_callable__
      typename Function::RealType
         getPartialDerivative( const Function& function,
                               const typename Function::Vertex& v,
                               const Real& time = 0.0 ) const
                               const typename Function::VertexType& v,
                               const typename Function::RealType& time = 0.0 ) const
      {
         static_assert( XDerivative >= 0 && YDerivative >= 0 && ZDerivative >= 0,
            "Partial derivative must be non-negative integer." );
@@ -213,15 +213,15 @@ class tnlExactGradientNorm< 3, Real >
      __cuda_callable__
      typename Function::RealType
         getPartialDerivative( const Function& function,
                               const typename Function::Vertex& v,
                               const Real& time = 0.0 ) const
                               const typename Function::VertexType& v,
                               const typename Function::RealType& time = 0.0 ) const
      {
         static_assert( XDerivative >= 0 && YDerivative >= 0 && ZDerivative >= 0,
            "Partial derivative must be non-negative integer." );
         static_assert( XDerivative < 2 && YDerivative < 2 && ZDerivative < 2,
            "Partial derivative of higher order then 1 are not implemented yet." );
         typedef typename Function::RealType RealType;

         typedef typename Function::RealType RealType;
         if( XDerivative == 1 && YDerivative == 0 && ZDerivative == 0 )
         {
            const RealType f_x  = function.template getPartialDerivative< 1, 0, 0 >( v, time );            
Loading