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

Implementing mesh function evaluator.

parent 5e2816f9
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
TODO:
 - implementovat tuple pro snazsi a snad efektoivnejsi prenos dat na GPU
 - nebylo by nutne definovat pomocne datove structury pro traverser
 - data by se na hostu preskupila do souvisleho bloku dat a ten se prenesl najednou


TODO:
 - zavest namespaces

@@ -21,9 +27,6 @@ TODO: Mesh
 * prejmenovat Tagy v topologies na Topology zrejme
 * zrusit tnlStorageTraits

TODO: v tnlMeshResolver se provadi preklad pro vsechny mozne sablonove parametry => prorezat

TODO: napsat FunctionDiscretizer pro jednotne rozhrani RightHandSide

TODO: implementace maticovych resicu
      * Gaussova eliminace
+45 −9
Original line number Diff line number Diff line
@@ -21,10 +21,46 @@
#include <mesh/tnlGrid.h>
#include <functions/tnlMeshFunction.h>

template< typename MeshFunction1,
          typename MeshFunction2 >
template< typename OutMeshFunction,
          typename InFunction >
class tnlMeshFunctionEvaluator
{
   public:
      typedef typename OutMeshFunction::MeshType MeshType;
      typedef typename MeshType::RealType MeshRealType;
      typedef typename MeshType::DeviceType MeshDeviceType;
      typedef typename MeshType::IndexType MeshIndexType;
      typedef typename OutMeshFunction::Real RealType;
      
      const static int meshEntityDimensions = OutMeshFunction::entityDimensions;
      
      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,
                          const InFunction& function,                          
                          const RealType& time = 0.0,
                          const RealType& outFunctionMultiplicator = 0.0,
                          const RealType& inFunctionMultiplicator = 1.0 );
      
      class TraverserUserData
      {
         public:
            TraverserUserData( const InFunction* function,
                               const RealType* time,
                               OutMeshFunction* meshFunction,
                               const RealType* outFunctionMultiplicator,
                               const RealType* inFunctionMultiplicator )
            : meshFunction( meshFunction ), function( function ), time( time ), 
              outFunctionMultiplicator( outFunctionMultiplicator ),
              inFunctionMultiplicator( inFunctionMultiplicator ){}

         protected:
            OutMeshFunction* meshFunction;            
            const InFunction* function;
            const RealType *time, *outFunctionMultiplicator, *inFunctionMultiplicator;
            
      };
}; 

template< int Dimensions,
@@ -43,14 +79,14 @@ class tnlMeshFunctionEvaluator< tnlMeshFunction< tnlGrid< Dimensions, MeshReal1,
      
      typedef tnlGrid< Dimensions, MeshReal1, MeshDevice1, MeshIndex1 > Mesh1;
      typedef tnlGrid< Dimensions, MeshReal2, MeshDevice2, MeshIndex2 > Mesh2;
      typedef tnlMeshFunction< Mesh1, MeshEntityDimensions, Real > MeshFunction1;
      typedef tnlMeshFunction< Mesh2, MeshEntityDimensions, Real > MeshFunction2;
      typedef tnlMeshFunction< Mesh1, MeshEntityDimensions, Real > OutMeshFunction;
      typedef tnlMeshFunction< Mesh2, MeshEntityDimensions, Real > InFunction;
      
      static void assign( const MeshFunction1& f1,
                          MeshFunction2& f2 )
      static void assign( OutMeshFunction& f1,
                          const InFunction& f2 )
      {
         if( f1.getMesh().getDimensions() == f2.getMesh().getDimensions() )
            f2.getData() = f1.getData();
            f1.getData() = f2.getData();
         else
         {
            //TODO: Interpolace
+90 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlMeshFunctionEvaluator.h  -  description
                             -------------------
    begin                : Jan 5, 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 TNLMESHFUNCTIONEVALUATOR_IMPL_H
#define	TNLMESHFUNCTIONEVALUATOR_IMPL_H

template< typename OutMeshFunction,
          typename InFunction >
void
tnlMeshFunctionEvaluator< OutMeshFunction, InFunction >::
assign( OutMeshFunction& meshFunction,
        const InFunction& function,
        const RealType& time,
        const RealType& outFunctionMultiplicator,
        const RealType& inFunctionMultiplicator )
{
   typedef typename MeshType::template MeshEntities< meshEntityDimensions > MeshEntityType;
   
   class AssignEntitiesProcessor
   {
      template< typename EntityType >
      __cuda_callable__
      static inline void processEntity( const MeshType& mesh,
                                        TraverserUserData& userData,
                                        const EntityType& entity )
      {
         typedef tnlFunctionAdapter< MeshType, InFunction > FunctionAdapter;
         ( * userData.meshFunction )( entity ) = 
               FunctionAdapter::getValue(
                  *userData.function,
                  entity,
                  *userData.time );
      }
   };

   if( std::is_same< MeshDeviceType, tnlHost >::value )
   {
      TraverserUserData userData( &meshFunction, &function, &time, &outFunctionMultiplicator, &inFunctionMultiplicator );
      tnlTraverser< MeshType, MeshEntityType > meshTraverser;
      meshTraverser.template processAllEntities< TraverserUserData,
                                                 AssignEntitiesProcessor >
                                                ( meshFunction.getMesh(),
                                                  userData );
   }
   if( std::is_same< MeshDeviceType, tnlCuda >::value )
   {      
      OutMeshFunction* kernelMeshFunction = tnlCuda::passToDevice( meshFunction );
      InFunction* kernelFunction = tnlCuda::passToDevice( function );
      RealType* kernelTime = tnlCuda::passToDevice( time );
      RealType* kernelOutFunctionMultiplicator = tnlCuda::passToDevice( outFunctionMultiplicator );
      RealType* kernelInFunctionMultiplicator = tnlCuda::passToDevice( inFunctionMultiplicator );
      
      TraverserUserData userData( kernelFunction, kernelTime, kernelMeshFunction, kernelOutFunctionMultiplicator, kernelInFunctionMultiplicator );
      checkCudaDevice;
      tnlTraverser< MeshType, MeshEntityType > meshTraverser;
      meshTraverser.template processAllEntities< TraverserUserData,
                                                 AssignEntitiesProcessor >
                                                ( meshFunction.getMesh(),
                                                  userData );
      

      checkCudaDevice;      
      tnlCuda::freeFromDevice( kernelMeshFunction );
      tnlCuda::freeFromDevice( kernelFunction );
      tnlCuda::freeFromDevice( kernelTime );
      tnlCuda::freeFromDevice( kernelOutFunctionMultiplicator );
      tnlCuda::freeFromDevice( kernelInFunctionMultiplicator );
            
      checkCudaDevice;
   }
}



#endif	/* TNLMESHFUNCTIONEVALUATOR_IMPL_H */