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

Refactoring operators - setMatrixElements method.

parent e8382143
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ ADD_SUBDIRECTORY( operator-Q )
ADD_SUBDIRECTORY( operator-curvature )

SET( headers tnlDirichletBoundaryConditions.h
             tnlDirichletBoundaryConditions_impl.h
             tnlExactFunctionInverseOperator.h
             tnlExactIdentityOperator.h
             tnlExactOperatorComposition.h
+3 −3
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ class tnlFiniteVolumeNonlinearOperator< tnlGrid< 1,MeshReal, Device, MeshIndex >
             typename Vector,
             typename Matrix >
   __cuda_callable__
      void updateLinearSystem( const RealType& time,
      void setMatrixElements( const RealType& time,
                               const RealType& tau,
                               const MeshType& mesh,
                               const IndexType& index,
@@ -106,7 +106,7 @@ class tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex
             typename Vector,
             typename Matrix >
   __cuda_callable__
      void updateLinearSystem( const RealType& time,
      void setMatrixElements( const RealType& time,
                               const RealType& tau,
                               const MeshType& mesh,
                               const IndexType& index,
@@ -158,7 +158,7 @@ class tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex
             typename Vector,
             typename Matrix >
   __cuda_callable__
      void updateLinearSystem( const RealType& time,
      void setMatrixElements( const RealType& time,
                               const RealType& tau,
                               const MeshType& mesh,
                               const IndexType& index,
+3 −3
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ template< typename MeshEntity,
__cuda_callable__
void
tnlFiniteVolumeNonlinearOperator< tnlGrid< 1, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >::
updateLinearSystem( const RealType& time,
setMatrixElements( const RealType& time,
                    const RealType& tau,
                    const MeshType& mesh,
                    const IndexType& index,
@@ -155,7 +155,7 @@ template< typename MeshEntity,
__cuda_callable__
void
tnlFiniteVolumeNonlinearOperator< tnlGrid< 2, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >::
updateLinearSystem( const RealType& time,
setMatrixElements( const RealType& time,
                    const RealType& tau,
                    const MeshType& mesh,
                    const IndexType& index,
@@ -268,7 +268,7 @@ __cuda_callable__
#endif
void
tnlFiniteVolumeNonlinearOperator< tnlGrid< 3, MeshReal, Device, MeshIndex >, OperatorQ, Real, Index >::
updateLinearSystem( const RealType& time,
setMatrixElements( const RealType& time,
                    const RealType& tau,
                    const MeshType& mesh,
                    const IndexType& index,
+33 −48
Original line number Diff line number Diff line
@@ -55,12 +55,10 @@ class tnlLinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index
      
      static constexpr int getMeshDimensions() { return Dimensions; }
      
      template< int EntityDimensions = Dimensions >
      using MeshFunction = tnlMeshFunction< MeshType, EntityDimensions >;

      static tnlString getType();

      template< typename PreimageFunction, typename MeshEntity >
      template< typename PreimageFunction,
                typename MeshEntity >
      __cuda_callable__
      inline Real operator()( const PreimageFunction& u,
                              const MeshEntity& entity,
@@ -72,19 +70,17 @@ class tnlLinearDiffusion< tnlGrid< 1,MeshReal, Device, MeshIndex >, Real, Index
                                             const IndexType& index,
                                             const MeshEntity& entity ) const;

      template< typename MeshEntity,
                typename Vector,
                typename MatrixRow >
      template< typename PreimageFunction,
                typename MeshEntity,
                typename Matrix,
                typename Vector >
      __cuda_callable__
      inline void updateLinearSystem( const RealType& time,
                                      const RealType& tau,
                                      const MeshType& mesh,
                                      const IndexType& index,
      inline void setMatrixElements( const PreimageFunction& u,
                                     const MeshEntity& entity,
                                      const MeshFunction< 1 >& u,
                                      Vector& b,
                                      MatrixRow& matrixRow ) const;

                                     const RealType& time,
                                     const RealType& tau,
                                     Matrix& matrix,
                                     Vector& b ) const;
};


@@ -110,10 +106,6 @@ class tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index
      
      static constexpr int getMeshDimensions() { return Dimensions; }

      
      template< int EntityDimensions = Dimensions >
      using MeshFunction = tnlMeshFunction< MeshType, EntityDimensions >;      

      static tnlString getType();

      template< typename PreimageFunction, typename EntityType >
@@ -128,18 +120,17 @@ class tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index
                                             const IndexType& index,
                                             const EntityType& entity ) const;
      
      template< typename Vector,
                typename MatrixRow,
                typename EntityType >
      template< typename PreimageFunction,
                typename MeshEntity,
                typename Matrix,
                typename Vector >
      __cuda_callable__
      inline void updateLinearSystem( const RealType& time,
      inline void setMatrixElements( const PreimageFunction& u,
                                     const MeshEntity& entity,
                                     const RealType& time,
                                     const RealType& tau,
                                      const MeshType& mesh,
                                      const IndexType& index,
                                      const EntityType& entity,
                                      const MeshFunction< 2 >& u,
                                      Vector& b,
                                      MatrixRow& matrixRow ) const;
                                     Matrix& matrix,
                                     Vector& b ) const;
};


@@ -165,10 +156,6 @@ class tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index
      
      static constexpr int getMeshDimensions() { return Dimensions; }      

      template< int EntityDimensions = Dimensions >
      using MeshFunction = tnlMeshFunction< MeshType, EntityDimensions >;

      
      static tnlString getType();

      template< typename PreimageFunction, 
@@ -184,19 +171,17 @@ class tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index
                                             const IndexType& index,
                                             const EntityType& entity ) const;

      template< typename Vector,
                typename MatrixRow,
                typename EntityType >
      template< typename PreimageFunction,
                typename MeshEntity,
                typename Matrix,
                typename Vector >
      __cuda_callable__
      inline void updateLinearSystem( const RealType& time,
      inline void setMatrixElements( const PreimageFunction& u,
                                     const MeshEntity& entity,
                                     const RealType& time,
                                     const RealType& tau,
                                      const MeshType& mesh,
                                      const IndexType& index,
                                      const EntityType& entity,
                                      const MeshFunction< 3 >& u,
                                      Vector& b,
                                      MatrixRow& matrixRow ) const;

                                     Matrix& matrix,
                                     Vector& b ) const;
};


+45 −39
Original line number Diff line number Diff line
@@ -82,25 +82,27 @@ template< typename MeshReal,
          typename MeshIndex,
          typename Real,
          typename Index >
   template< typename MeshEntity,
             typename Vector, 
             typename Matrix >
   template< typename PreimageFunction,
             typename MeshEntity,
             typename Matrix,
             typename Vector >
__cuda_callable__
inline
void
tnlLinearDiffusion< tnlGrid< 1, MeshReal, Device, MeshIndex >, Real, Index >::
updateLinearSystem( const RealType& time,
                    const RealType& tau,
                    const MeshType& mesh,
                    const IndexType& index,
setMatrixElements( const PreimageFunction& u,
                   const MeshEntity& entity,
                    const MeshFunction< 1 >& u,
                    Vector& b,
                    Matrix& matrix ) const
                   const RealType& time,
                   const RealType& tau,
                   Matrix& matrix,
                   Vector& b ) const
{
   static_assert( MeshEntity::entityDimensions == 1, "Wrong mesh entity dimensions." );
   static_assert( PreimageFunction::getEntitiesDimensions() == 1, "Wrong preimage function" );
   const typename MeshEntity::template NeighbourEntities< 1 >& neighbourEntities = entity.getNeighbourEntities();
   const IndexType& index = entity.getIndex();
   typename Matrix::MatrixRow matrixRow = matrix.getRow( index );
   const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2 >();
   const RealType lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2 >();
   matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< -1 >(),      - lambdaX );
   matrixRow.setElement( 1, index,                                              2.0 * lambdaX );
   matrixRow.setElement( 2, neighbourEntities.template getEntityIndex< 1 >(),       - lambdaX );   
@@ -171,26 +173,28 @@ template< typename MeshReal,
          typename MeshIndex,
          typename Real,
          typename Index >
   template< typename Vector,
   template< typename PreimageFunction,
             typename MeshEntity,
             typename Matrix,
             typename EntityType >
             typename Vector >
__cuda_callable__
inline
void
tnlLinearDiffusion< tnlGrid< 2, MeshReal, Device, MeshIndex >, Real, Index >::
updateLinearSystem( const RealType& time,
setMatrixElements( const PreimageFunction& u,
                   const MeshEntity& entity,
                   const RealType& time,
                   const RealType& tau,
                    const MeshType& mesh,
                    const IndexType& index,
                    const EntityType& entity,
                    const MeshFunction< 2 >& u,
                    Vector& b,
                    Matrix& matrix ) const
                   Matrix& matrix,
                   Vector& b ) const
{
   static_assert( MeshEntity::entityDimensions == 2, "Wrong mesh entity dimensions." );
   static_assert( PreimageFunction::getEntitiesDimensions() == 2, "Wrong preimage function" );
   const IndexType& index = entity.getIndex();
   typename Matrix::MatrixRow matrixRow = matrix.getRow( index );
   const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2, 0 >();
   const RealType lambdaY = tau * mesh.template getSpaceStepsProducts< 0, -2 >();
   const typename EntityType::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities();
   const RealType lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0 >();
   const RealType lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2 >();
   const typename MeshEntity::template NeighbourEntities< 2 >& neighbourEntities = entity.getNeighbourEntities();
   matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, -1 >(), -lambdaY );
   matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< -1, 0 >(), -lambdaX );
   matrixRow.setElement( 2, index,                                                        2.0 * ( lambdaX + lambdaY ) );
@@ -266,27 +270,29 @@ template< typename MeshReal,
          typename MeshIndex,
          typename Real,
          typename Index >
   template< typename Vector,
   template< typename PreimageFunction,
             typename MeshEntity,
             typename Matrix,
             typename EntityType >
             typename Vector >
__cuda_callable__
inline
void
tnlLinearDiffusion< tnlGrid< 3, MeshReal, Device, MeshIndex >, Real, Index >::
updateLinearSystem( const RealType& time,
setMatrixElements( const PreimageFunction& u,
                   const MeshEntity& entity,
                   const RealType& time,
                   const RealType& tau,
                    const MeshType& mesh,
                    const IndexType& index,
                    const EntityType& entity,
                    const MeshFunction< 3 >& u,
                    Vector& b,
                    Matrix& matrix ) const
                   Matrix& matrix,
                   Vector& b ) const
{
   const typename EntityType::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities();
   static_assert( MeshEntity::entityDimensions == 3, "Wrong mesh entity dimensions." );
   static_assert( PreimageFunction::getEntitiesDimensions() == 3, "Wrong preimage function" );   
   const typename MeshEntity::template NeighbourEntities< 3 >& neighbourEntities = entity.getNeighbourEntities();
   const IndexType& index = entity.getIndex();
   typename Matrix::MatrixRow matrixRow = matrix.getRow( index );
   const RealType lambdaX = tau * mesh.template getSpaceStepsProducts< -2, 0, 0 >();
   const RealType lambdaY = tau * mesh.template getSpaceStepsProducts< 0, -2, 0 >();
   const RealType  lambdaZ = tau * mesh.template getSpaceStepsProducts< 0, 0, -2 >();
   const RealType lambdaX = tau * entity.getMesh().template getSpaceStepsProducts< -2, 0, 0 >();
   const RealType lambdaY = tau * entity.getMesh().template getSpaceStepsProducts< 0, -2, 0 >();
   const RealType lambdaZ = tau * entity.getMesh().template getSpaceStepsProducts< 0, 0, -2 >();
   matrixRow.setElement( 0, neighbourEntities.template getEntityIndex< 0, 0, -1 >(), -lambdaZ );
   matrixRow.setElement( 1, neighbourEntities.template getEntityIndex< 0, -1, 0 >(), -lambdaY );
   matrixRow.setElement( 2, neighbourEntities.template getEntityIndex< -1, 0, 0 >(), -lambdaX );
Loading