dune-fem  2.4.1-rc
blockvectorfunction/blockvectorfunction.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_BLOCKVECTORFUNCTION_HH
2 #define DUNE_FEM_BLOCKVECTORFUNCTION_HH
3 
4 //- system includes
5 #include <fstream>
6 #include <iostream>
7 
8 //- Dune inlcudes
9 #include <dune/common/exceptions.hh>
12 
14 
19 
21 
22 namespace Dune
23 {
24 
25  namespace Fem
26  {
33  template< class DiscreteFunctionSpace,
34  class Block >
36  : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace, ISTLBlockVector< Block > >
37  {
40  };
41 
42 
43  template < class DiscreteFunctionSpace, class Block >
45  : public DiscreteFunctionDefault< ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpace, Block > >
46  {
49 
50  public:
53  typedef typename BaseType :: DofType DofType;
54  typedef typename DofVectorType :: DofContainerType DofContainerType;
55  typedef DofContainerType DofStorageType;
56 
57  using BaseType::assign;
58 
59  ISTLBlockVectorDiscreteFunction( const std::string &name,
60  const DiscreteFunctionSpaceType &space )
61  : BaseType( name, space ),
62  memObject_(),
63  dofVector_( allocateDofStorage( space ) )
64  {
65  }
66 
67  ISTLBlockVectorDiscreteFunction( const std::string &name,
68  const DiscreteFunctionSpaceType &space,
69  const DofContainerType& dofContainer )
70  : BaseType( name, space ),
71  memObject_(),
72  dofVector_( const_cast< DofContainerType& > (dofContainer) )
73  {
74  }
75 
77  : BaseType( "copy of " + other.name(), other.space() ),
78  memObject_(),
79  dofVector_( allocateDofStorage( other.space() ) )
80  {
81  assign( other );
82  }
83 
85  {
86  if( memObject_ )
87  memObject_->enableDofCompression();
88  }
89 
91  DofContainerType& blockVector() { return dofVector().array(); }
93  const DofContainerType& blockVector() const { return dofVector().array(); }
94 
95  DofVectorType& dofVector() { return dofVector_; }
96  const DofVectorType& dofVector() const { return dofVector_; }
97 
98  protected:
99  // allocate managed dof storage
100  DofContainerType& allocateDofStorage ( const DiscreteFunctionSpaceType &space )
101  {
102  std::string name("deprecated");
103  // create memory object
104  std::pair< DofStorageInterface*, DofContainerType* > memPair
105  = allocateManagedDofStorage( space.gridPart().grid(), space.blockMapper(),
106  name, (DofContainerType *) 0 );
107 
108  // save pointer
109  memObject_.reset( memPair.first );
110  return *(memPair.second);
111  }
112 
113  // pointer to allocated DofVector
114  std::unique_ptr< DofStorageInterface > memObject_;
115 
116  // DofVector object holds pointer to dof container
117  DofVectorType dofVector_;
118  };
119 
120  } // namespace Fem
121 
122 } // namespace Dune
123 
124 #endif // #ifndef DUNE_FEM_BLOCKVECTORFUNCTION_HH
Traits class for a DiscreteFunction.
Definition: discretefunction.hh:60
const DofVectorType & dofVector() const
Definition: blockvectorfunction/blockvectorfunction.hh:96
static std::pair< DofStorageInterface *, DofStorageType * > allocateManagedDofStorage(const GridType &grid, const MapperType &mapper, const std::string &name, const DofStorageType *=0)
default implementation for creating a managed dof storage
Definition: dofmanager.hh:610
Definition: discretefunction.hh:63
std::unique_ptr< DofStorageInterface > memObject_
Definition: blockvectorfunction/blockvectorfunction.hh:114
This file implements a dense vector with a dynamic size.
DofContainerType & blockVector()
convenience method for usage with ISTL solvers
Definition: blockvectorfunction/blockvectorfunction.hh:91
DofVectorType::DofContainerType DofContainerType
Definition: blockvectorfunction/blockvectorfunction.hh:54
DofVectorType & dofVector()
Definition: blockvectorfunction/blockvectorfunction.hh:95
ISTLBlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Definition: blockvectorfunction/blockvectorfunction.hh:59
Definition: coordinate.hh:4
DofContainerType & allocateDofStorage(const DiscreteFunctionSpaceType &space)
Definition: blockvectorfunction/blockvectorfunction.hh:100
ISTLBlockVectorDiscreteFunction(const ISTLBlockVectorDiscreteFunction &other)
Definition: blockvectorfunction/blockvectorfunction.hh:76
ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpace, Block > DiscreteFunctionType
Definition: blockvectorfunction/blockvectorfunction.hh:38
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: discretefunction.hh:571
DofContainerType DofStorageType
Definition: blockvectorfunction/blockvectorfunction.hh:55
Definition: discretefunction.hh:1034
void enableDofCompression()
Definition: blockvectorfunction/blockvectorfunction.hh:84
Traits::DofVectorType DofVectorType
type of DofVector
Definition: discretefunction.hh:596
BaseType::DofType DofType
Definition: discretefunction.hh:613
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: blockvectorfunction/blockvectorfunction.hh:39
discrete function space
Definition: blockvectorfunction/blockvectorfunction.hh:44
ISTLBlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, const DofContainerType &dofContainer)
Definition: blockvectorfunction/blockvectorfunction.hh:67
const DofContainerType & blockVector() const
convenience method for usage with ISTL solvers
Definition: blockvectorfunction/blockvectorfunction.hh:93
DofVectorType dofVector_
Definition: blockvectorfunction/blockvectorfunction.hh:117
Definition: const.hh:24
BaseType::DofVectorType DofVectorType
Definition: blockvectorfunction/blockvectorfunction.hh:52
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: blockvectorfunction/blockvectorfunction.hh:51
BaseType::DofType DofType
Definition: blockvectorfunction/blockvectorfunction.hh:53