Commit 216517fa authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Avoiding unnecessary (de)allocations in LinearSystemAssembler

parent d7b7276b
Loading
Loading
Loading
Loading
+32 −34
Original line number Diff line number Diff line
@@ -27,26 +27,23 @@ template< typename Real,
class LinearSystemAssemblerTraverserUserData
{
   public:
      typedef Matrix MatrixType;
      typedef typename Matrix::DeviceType DeviceType;

      const Real time;
      Real time = 0.0;

      const Real tau;
      Real tau = 0.0;

      const DifferentialOperator* differentialOperator;
      const DifferentialOperator* differentialOperator = NULL;

      const BoundaryConditions* boundaryConditions;
      const BoundaryConditions* boundaryConditions = NULL;

      const RightHandSide* rightHandSide;
      const RightHandSide* rightHandSide = NULL;
      
      const MeshFunction* u;
      const MeshFunction* u = NULL;
      
      DofVector* b;
      DofVector* b = NULL;

      Matrix* matrix;
      Matrix* matrix = NULL;

      LinearSystemAssemblerTraverserUserData( const Real& time,
      void setUserData( const Real& time,
                        const Real& tau,
                        const DifferentialOperator* differentialOperator,
                        const BoundaryConditions* boundaryConditions,
@@ -54,18 +51,16 @@ class LinearSystemAssemblerTraverserUserData
                        const MeshFunction* u,
                        Matrix* matrix,
                        DofVector* b )
      : time( time ),
        tau( tau ),
        differentialOperator( differentialOperator ),
        boundaryConditions( boundaryConditions ),
        rightHandSide( rightHandSide ),
        u( u ),
        b( b ),
        matrix( matrix )
      {}

   protected:

      {
         this->time = time;
         this->tau = tau;
         this->differentialOperator = differentialOperator;
         this->boundaryConditions = boundaryConditions;
         this->rightHandSide = rightHandSide;
         this->u = u;
         this->b = b;
         this->matrix = matrix;
      }
};


@@ -111,7 +106,7 @@ class LinearSystemAssembler
                  const RightHandSidePointer& rightHandSidePointer,
                  const MeshFunctionPointer& uPointer,
                  MatrixPointer& matrixPointer,
                  DofVectorPointer& bPointer ) const;
                  DofVectorPointer& bPointer );

 
      class TraverserBoundaryEntitiesProcessor
@@ -168,6 +163,9 @@ class LinearSystemAssembler
                                                         rhs );
         }
   };

protected:
   SharedPointer< TraverserUserData, DeviceType > userDataPointer;
};

} // namespace PDE
+12 −12
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ assembly( const RealType& time,
          const RightHandSidePointer& rightHandSidePointer,
          const MeshFunctionPointer& uPointer,
          MatrixPointer& matrixPointer,
          DofVectorPointer& bPointer ) const
          DofVectorPointer& bPointer )
{
      static_assert( std::is_same< MeshFunction,
                                Containers::Vector< typename MeshFunction::RealType,
@@ -50,8 +50,8 @@ assembly( const RealType& time,
   Assert( maxRowLength > 0, );

   {
      SharedPointer< TraverserUserData, DeviceType >
         userData( time,
      this->userDataPointer->setUserData(
            time,
            tau,
            &differentialOperatorPointer.template getData< DeviceType >(),
            &boundaryConditionsPointer.template getData< DeviceType >(),
@@ -63,11 +63,11 @@ assembly( const RealType& time,
      meshTraverser.template processBoundaryEntities< TraverserUserData,
                                                      TraverserBoundaryEntitiesProcessor >
                                                    ( meshPointer,
                                                      userData );
                                                      userDataPointer );
      meshTraverser.template processInteriorEntities< TraverserUserData,
                                                      TraverserInteriorEntitiesProcessor >
                                                    ( meshPointer,
                                                      userData );
                                                      userDataPointer );
   }
}

+1 −0
Original line number Diff line number Diff line
@@ -551,6 +551,7 @@ assemblyLinearSystem( const RealType& time,
                      DofVectorPointer& b,
                      MeshDependentDataPointer& meshDependentData )
{
   // TODO: the instance should be "cached" like this->explicitUpdater, but there is a problem with MatrixPointer
   Solvers::PDE::LinearSystemAssembler< Mesh,
                             MeshFunctionType,
                             DifferentialOperator,