1#ifndef DUNE_FEM_TEMPORARYLOCALMATRIX_HH 
    2#define DUNE_FEM_TEMPORARYLOCALMATRIX_HH 
   10#include <dune/fem/operator/common/localmatrix.hh> 
   11#include <dune/fem/storage/rowreferencevector.hh> 
   22    template< 
class DomainSpaceImp, 
class RangeSpaceImp >
 
   23    class TemporaryLocalMatrix;
 
   30    template< 
class DomainSpaceImp, 
class RangeSpaceImp >
 
   31    struct TemporaryLocalMatrixTraits
 
   33      typedef DomainSpaceImp DomainSpaceType;
 
   34      typedef RangeSpaceImp RangeSpaceType;
 
   36      typedef TemporaryLocalMatrix< DomainSpaceType, RangeSpaceType >
 
   39      typedef typename DomainSpaceType :: RangeFieldType DomainFieldType;
 
   40      typedef typename RangeSpaceType :: RangeFieldType RangeFieldType;
 
   41      typedef RangeFieldType LittleBlockType;
 
   51  template< 
class DomainSpaceImp, 
class RangeSpaceImp >
 
   52  struct DenseMatVecTraits< Fem::TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > >
 
   54    typedef Fem::TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > derived_type;
 
   56    typedef typename Fem::TemporaryLocalMatrixTraits< DomainSpaceImp, RangeSpaceImp >::RangeFieldType value_type;
 
   57    typedef int size_type;
 
   59    typedef DynamicVector< value_type > row_type;
 
   61    typedef Fem::RowReferenceVector< value_type > row_reference;
 
   62    typedef Fem::RowReferenceVector< const value_type > const_row_reference;
 
   70  template< 
class DomainSpaceImp, 
class RangeSpaceImp >
 
   71  struct FieldTraits< Fem::TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > >
 
   72    : 
public FieldTraits< typename Fem::TemporaryLocalMatrixTraits< DomainSpaceImp, RangeSpaceImp >::RangeFieldType >
 
   96    template< 
class DomainSpaceImp, 
class RangeSpaceImp >
 
   98      : 
public DenseMatrix< TemporaryLocalMatrix< DomainSpaceImp, RangeSpaceImp > >,
 
   99        public LocalMatrixDefault< TemporaryLocalMatrixTraits< DomainSpaceImp, RangeSpaceImp > >
 
  102      typedef DomainSpaceImp DomainSpaceType;
 
  103      typedef RangeSpaceImp RangeSpaceType;
 
  105      typedef TemporaryLocalMatrixTraits< DomainSpaceType, RangeSpaceType >
 
  114      typedef typename Traits :: DomainFieldType DomainFieldType;
 
  115      typedef typename Traits :: RangeFieldType RangeFieldType;
 
  117      typedef int size_type;
 
  118      typedef RangeFieldType value_type;
 
  120      typedef RowReferenceVector< value_type > row_reference;
 
  121      typedef RowReferenceVector< const value_type > const_row_reference;
 
  123      typedef std::vector< RangeFieldType > MatrixEntriesType;
 
  125      MatrixEntriesType fields_;
 
  137      template< 
class DomainEntityType, 
class RangeEntityType >
 
  140                                    const DomainEntityType &domainEntity,
 
  141                                    const RangeEntityType &rangeEntity )
 
  143        fields_( rows() * columns() )
 
  147      template< 
class DomainEntityType, 
class RangeEntityType >
 
  148      inline void init ( 
const DomainEntityType &domainEntity,
 
  149                         const RangeEntityType &rangeEntity )
 
  151        bind( domainEntity, rangeEntity );
 
  155      template< 
class DomainEntityType, 
class RangeEntityType >
 
  156      inline void bind ( 
const DomainEntityType &domainEntity,
 
  157                         const RangeEntityType &rangeEntity )
 
  160        fields_.resize( rows() * columns() );
 
  170      inline void add ( 
const int localRow,
 
  172                        const RangeFieldType &value )
 
  174        assert( (localRow >= 0) && (localRow < rows()) );
 
  175        assert( (localCol >= 0) && (localCol < columns()) );
 
  176        fields_[ localRow * columns() + localCol ] += value;
 
  180      inline void set ( 
const int localRow,
 
  182                        const RangeFieldType &value )
 
  184        assert( (localRow >= 0) && (localRow < rows()) );
 
  185        assert( (localCol >= 0) && (localCol < columns()) );
 
  186        fields_[ localRow * columns() + localCol ] = value;
 
  190      inline const RangeFieldType 
get ( 
const int localRow,
 
  191                                        const int localCol )
 const 
  193        assert( (localRow >= 0) && (localRow < rows()) );
 
  194        assert( (localCol >= 0) && (localCol < columns()) );
 
  195        return fields_[ localRow * columns() + localCol ];
 
  199      inline void scale( 
const RangeFieldType &value )
 
  201        const std::size_t 
size = fields_.size();
 
  202        for( std::size_t i=0; i<
size; ++i )
 
  204          fields_[ i ] *= value;
 
  211        std::fill( fields_.begin() , fields_.end() , 0 );
 
  217        const int col = columns();
 
  218        auto start = fields_.begin() + localRow * col;
 
  219        auto end   = start + col;
 
  220        std::fill( start, end, 0 );
 
  223      size_type rows ()
 const { 
return mat_rows(); }
 
  224      size_type cols ()
 const { 
return mat_cols(); }
 
  225      size_type columns ()
 const { 
return mat_cols(); }
 
  231      row_reference mat_access ( size_type i )
 
  233        const size_type cols = mat_cols();
 
  234        return row_reference( fields_.data() + i*cols, cols );
 
  237      const_row_reference mat_access ( size_type i )
 const 
  239        const size_type cols = mat_cols();
 
  240        return const_row_reference( fields_.data() + i*cols, cols );
 
  244      const RangeFieldType* data()
 const { 
return fields_.data(); }
 
  246      void print( std::ostream& out )
 const 
  248        out << 
"TLM ("<<rows ()<<
","<<cols()<<
"):"<<std::endl;
 
  249        for( size_type r = 0; r<rows(); ++r )
 
  251          for( size_type c = 0; c<cols(); ++c )
 
  253            out << 
get( r , c ) << 
" ";
 
  257        out << std::endl << std::endl;
 
DenseMatrix based on std::vector< std::vector< T > >
Definition: blockmatrix.hh:24
 
Default implementation for local matrix classes.
Definition: localmatrix.hh:287
 
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: localmatrix.hh:352
 
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:394
 
const RangeSpaceType & rangeSpace() const
access to the range space
Definition: localmatrix.hh:385
 
void unbind()
clear local matrix from entities
Definition: localmatrix.hh:361
 
const DomainSpaceType & domainSpace() const
access to the domain space
Definition: localmatrix.hh:382
 
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:388
 
A local matrix with a small array as storage.
Definition: temporarylocalmatrix.hh:100
 
void init(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: temporarylocalmatrix.hh:148
 
void scale(const RangeFieldType &value)
scale matrix with scalar value
Definition: temporarylocalmatrix.hh:199
 
const RangeBasisFunctionSetType & rangeBasisFunctionSet() const
access to the base function set within the range space
Definition: localmatrix.hh:394
 
void add(const int localRow, const int localCol, const RangeFieldType &value)
add value to matrix entry (row,col) where row and col are local row and local column
Definition: temporarylocalmatrix.hh:170
 
void bind(const DomainEntityType &domainEntity, const RangeEntityType &rangeEntity)
initialize the local matrix to entities
Definition: temporarylocalmatrix.hh:156
 
void set(const int localRow, const int localCol, const RangeFieldType &value)
set value of matrix entry (row,col) where row and col are local row and local column
Definition: temporarylocalmatrix.hh:180
 
void unbind()
clear local matrix from entities
Definition: temporarylocalmatrix.hh:164
 
void clear()
set all entries of local matrix to zero
Definition: temporarylocalmatrix.hh:209
 
const RangeFieldType get(const int localRow, const int localCol) const
get value of matrix entry (row,col) where row and col are local row and local column
Definition: temporarylocalmatrix.hh:190
 
const DomainBasisFunctionSetType & domainBasisFunctionSet() const
access to the base function set within the domain space
Definition: localmatrix.hh:388
 
void clearRow(const int localRow)
set row to zero values
Definition: temporarylocalmatrix.hh:215
 
Implements a matrix constructed from a given type representing a field and a compile-time given numbe...
 
This file implements a dense vector with a dynamic size.
 
Dune namespace.
Definition: alignedallocator.hh:13
 
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75