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

Implementing operators.

parent 49421c4f
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlExactOperatorFunction.h  -  description
                             -------------------
    begin                : Jan 5, 2016
    copyright            : (C) 2016 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 TNLEXACTOPERATORFUNCTION_H
#define	TNLEXACTOPERATORFUNCTION_H

template< typename Operator,
          typename Function >
class tnlExactOperatorFunction
{   
   public:
      
      typedef Operator OperatorType;
      typedef Function FunctionType;
      
      tnlExactOperatorFunction(
         const OperatorType& operator_,
         const FunctionType& function )
      : operator_( operator_ ), function( function ) {};
      
      template< typename VertexType,
                typename RealType = typename VertexType::RealType >
      __cuda_callable__
      RealType operator()(
         const VertexType& vertex,
         const RealType& time ) const
      {
         return this->operator_.getValue( function, vertex, time );
      }
      
   protected:
      
      const OperatorType& operator_;
      
      const FunctionType& function;               
};



#endif	/* TNLEXACTOPERATORFUNCTION_H */
+3 −1
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@
enum tnlFunctionType { GeneralFunction, 
                       MeshFunction,
                       AnalyticFunction,
                       AnalyticConstantFunction };
                       AnalyticConstantFunction,
                       AnalyticOperator,
                       MeshOperator };

template< int Dimensions,
          tnlFunctionType FunctionType = GeneralFunction >
+9 −1
Original line number Diff line number Diff line
@@ -93,7 +93,15 @@ class tnlMeshFunction :
      template< typename Function >
      ThisType& operator = ( const Function& f );
      
      RealType getLpNorm( const RealType& p );
      template< typename Function >
      ThisType& operator -= ( const Function& f );

      template< typename Function >
      ThisType& operator += ( const Function& f );
      
      RealType getLpNorm( const RealType& p ) const;
      
      RealType getMaxMorm() const;
      
      bool save( tnlFile& file ) const;

+31 −7
Original line number Diff line number Diff line
@@ -37,12 +37,36 @@ class tnlMeshFunctionEvaluator
      static_assert( MeshType::meshDimensions == InFunction::Dimensions, 
         "Input function and the mesh of the mesh function have both different number of dimensions." );
      
      static void assign( OutMeshFunction& meshFunction,
      static void evaluateAllEntities( OutMeshFunction& meshFunction,
                                       const InFunction& function,                          
                                       const RealType& time = 0.0,
                                       const RealType& outFunctionMultiplicator = 0.0,
                                       const RealType& inFunctionMultiplicator = 1.0 );
      
      static void evaluateInteriorEntities( OutMeshFunction& meshFunction,
                                            const InFunction& function,                          
                                            const RealType& time = 0.0,
                                            const RealType& outFunctionMultiplicator = 0.0,
                                            const RealType& inFunctionMultiplicator = 1.0 );

      static void evaluateBoundaryEntities( OutMeshFunction& meshFunction,
                                            const InFunction& function,                          
                                            const RealType& time = 0.0,
                                            const RealType& outFunctionMultiplicator = 0.0,
                                            const RealType& inFunctionMultiplicator = 1.0 );

   protected:

      enum EntitiesType { all, boundary, interior };
      
      static void evaluateEntities( OutMeshFunction& meshFunction,
                                    const InFunction& function,                          
                                    const RealType& time,
                                    const RealType& outFunctionMultiplicator,
                                    const RealType& inFunctionMultiplicator,
                                    EntitiesType entitiesType );

      
      class TraverserUserData
      {
         public:
@@ -63,7 +87,7 @@ class tnlMeshFunctionEvaluator
      };
}; 

template< int Dimensions,
/*template< int Dimensions,
          typename MeshReal1,
          typename MeshReal2,
          typename MeshDevice1,
@@ -92,7 +116,7 @@ class tnlMeshFunctionEvaluator< tnlMeshFunction< tnlGrid< Dimensions, MeshReal1,
            //TODO: Interpolace
         }
      };
};
};*/

#endif	/* TNLMESHFUNCTIONEVALUATOR_H */
+85 −10
Original line number Diff line number Diff line
@@ -18,6 +18,47 @@
#ifndef TNLMESHFUNCTIONEVALUATOR_IMPL_H
#define	TNLMESHFUNCTIONEVALUATOR_IMPL_H

template< typename OutMeshFunction,
          typename InFunction >
void
tnlMeshFunctionEvaluator< OutMeshFunction, InFunction >::
evaluateAllEntities( OutMeshFunction& meshFunction,
                     const InFunction& function,                          
                     const RealType& time = 0.0,
                     const RealType& outFunctionMultiplicator = 0.0,
                     const RealType& inFunctionMultiplicator = 1.0 )
{
   return evaluateEntities( meshFunction, function, time, outFunctionMultiplicator, inFunctionMultiplicator, all );
}

template< typename OutMeshFunction,
          typename InFunction >
void
tnlMeshFunctionEvaluator< OutMeshFunction, InFunction >::
evaluateInteriorEntities( OutMeshFunction& meshFunction,
                          const InFunction& function,                          
                          const RealType& time = 0.0,
                          const RealType& outFunctionMultiplicator = 0.0,
                          const RealType& inFunctionMultiplicator = 1.0 )
{
   return evaluateEntities( meshFunction, function, time, outFunctionMultiplicator, inFunctionMultiplicator, interior );
}

template< typename OutMeshFunction,
          typename InFunction >
void 
tnlMeshFunctionEvaluator< OutMeshFunction, InFunction >::
evaluateBoundaryEntities( OutMeshFunction& meshFunction,
                          const InFunction& function,                          
                          const RealType& time = 0.0,
                          const RealType& outFunctionMultiplicator = 0.0,
                          const RealType& inFunctionMultiplicator = 1.0 )
{
   return evaluateEntities( meshFunction, function, time, outFunctionMultiplicator, inFunctionMultiplicator, boundary );
}



template< typename OutMeshFunction,
          typename InFunction >
void
@@ -26,7 +67,8 @@ assign( OutMeshFunction& meshFunction,
        const InFunction& function,
        const RealType& time,
        const RealType& outFunctionMultiplicator,
        const RealType& inFunctionMultiplicator )
        const RealType& inFunctionMultiplicator,
        EntitisType entitiesType )
{
   typedef typename MeshType::template MeshEntities< meshEntityDimensions > MeshEntityType;
   
@@ -51,10 +93,27 @@ assign( OutMeshFunction& meshFunction,
   {
      TraverserUserData userData( &meshFunction, &function, &time, &outFunctionMultiplicator, &inFunctionMultiplicator );
      tnlTraverser< MeshType, MeshEntityType > meshTraverser;
      switch( entitiesType )
      {
         case all:            
            meshTraverser.template processAllEntities< TraverserUserData,
                                                       AssignEntitiesProcessor >
                                                     ( meshFunction.getMesh(),
                                                       userData );
            break;
         case interior:
            meshTraverser.template processInteriroEntities< TraverserUserData,
                                                            AssignEntitiesProcessor >
                                                          ( meshFunction.getMesh(),
                                                            userData );
            break;
         case boundary:
            meshTraverser.template processBoundaryEntities< TraverserUserData,
                                                            AssignEntitiesProcessor >
                                                          ( meshFunction.getMesh(),
                                                            userData );
            break;
      }
   }
   if( std::is_same< MeshDeviceType, tnlCuda >::value )
   {      
@@ -67,11 +126,27 @@ assign( OutMeshFunction& meshFunction,
      TraverserUserData userData( kernelFunction, kernelTime, kernelMeshFunction, kernelOutFunctionMultiplicator, kernelInFunctionMultiplicator );
      checkCudaDevice;
      tnlTraverser< MeshType, MeshEntityType > meshTraverser;
      switch( entitiesType )
      {
         case all:            
            meshTraverser.template processAllEntities< TraverserUserData,
                                                       AssignEntitiesProcessor >
                                                     ( meshFunction.getMesh(),
                                                       userData );
      
            break;
         case interior:
            meshTraverser.template processInteriorEntities< TraverserUserData,
                                                            AssignEntitiesProcessor >
                                                          ( meshFunction.getMesh(),
                                                            userData );
            break;
         case boundary:
            meshTraverser.template processBoundaryEntities< TraverserUserData,
                                                            AssignEntitiesProcessor >
                                                          ( meshFunction.getMesh(),
                                                            userData );
            break;
      }      

      checkCudaDevice;      
      tnlCuda::freeFromDevice( kernelMeshFunction );
Loading