dune-fem  2.4.1-rc
blockvectordiscretefunction/blockvectordiscretefunction.hh
Go to the documentation of this file.
1 // vim: set expandtab ts=2 sw=2 sts=2:
2 #ifndef DUNE_FEM_BLOCKVECTORDISCRETEFUNCTION_HH
3 #define DUNE_FEM_BLOCKVECTORDISCRETEFUNCTION_HH
4 
5 #include <string>
6 
7 #include <dune/common/exceptions.hh>
8 #include <dune/common/fvector.hh>
9 
10 #include <dune/geometry/referenceelements.hh>
11 
17 
20 
22 
23 namespace Dune
24 {
25 
26  namespace Fem
27  {
28 
29  // forward declaration
30  template< typename DiscreteFunctionSpace, typename BlockVector >
32 
44 
45 
52  template< typename DiscreteFunctionSpace, typename BlockVector >
54  : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace, BlockVector >
55  {
58  };
59 
66  template< typename DiscreteFunctionSpace, typename BlockVector >
68  : public DiscreteFunctionDefault< BlockVectorDiscreteFunction< DiscreteFunctionSpace, BlockVector > >,
70  {
71 
72  /*
73  I didn't implement these methods of DiscreteFunctionDefault (deliberately):
74  void print ( std :: ostream &out ) const;
75  */
77  typedef DiscreteFunctionDefault< ThisType > BaseType;
78 
79  typedef ParallelScalarProduct< ThisType > ScalarProductType;
80 
81  public:
82  // ==================== Types
83 
87  typedef BlockVector BlockVectorType;
89  typedef BlockVectorType DofVectorType;
90 
91  // methods from DiscreteFunctionDefault
92  using BaseType::assign;
93 
100  BlockVectorDiscreteFunction ( const std::string &name,
101  const DiscreteFunctionSpaceType &dfSpace,
102  DofVectorType &dofVector )
103  : BaseType( name, dfSpace ),
104  memObject_(),
105  dofVector_( dofVector )
106  {}
107 
113  BlockVectorDiscreteFunction ( const std::string &name,
114  const DiscreteFunctionSpaceType &dfSpace )
115  : BaseType( name, dfSpace ),
116  memObject_(),
117  dofVector_( allocateDofStorage( dfSpace ) )
118  {}
119 
120 
123  BlockVectorDiscreteFunction ( const ThisType &other )
124  : BaseType( "copy of "+other.name(), other.space() ),
125  memObject_(),
126  dofVector_( allocateDofStorage( other.space() ) )
127  {
128  // copy dof vector content
129  assign( other );
130  }
131 
132  private:
133  // an empty constructor would not make sense for a discrete function
135 
136  // TODO: un-disallow this??
137  ThisType &operator= ( const ThisType &other );
138 
139  public:
144  const DofVectorType &dofVector () const
145  {
146  return dofVector_;
147  }
148 
153  DofVectorType &dofVector ()
154  {
155  return dofVector_;
156  }
157 
161  {
162  if( memObject_ )
163  memObject_->enableDofCompression();
164  }
165 
166  protected:
167  DofVectorType& allocateDofStorage( const DiscreteFunctionSpaceType& space )
168  {
169  std::string name("deprecated");
170  std::pair< DofStorageInterface*, DofVectorType* > memPair(
171  allocateManagedDofStorage< DofVectorType >( space.gridPart().grid(), space.blockMapper(), name ) );
172 
173  memObject_.reset( memPair.first );
174  return *memPair.second;
175  }
176 
177  /*
178  * ============================== data fields ====================
179  */
180  std::unique_ptr< DofStorageInterface > memObject_;
181  DofVectorType& dofVector_;
182  };
183 
184  } // namespace Fem
185 
186 } // namespace Dune
187 
188 #endif // #ifndef DUNE_FEM_BLOCKVECTORDISCRETEFUNCTION_HH
const DofVectorType & dofVector() const
Obtain constant reference to the dof vector.
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:144
Traits class for a DiscreteFunction.
Definition: discretefunction.hh:60
BlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &dfSpace, DofVectorType &dofVector)
Constructor to use if the vector storing the dofs (which is a block vector) already exists...
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:100
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:57
BlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &dfSpace)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:113
DofVectorType & dofVector()
Obtain reference to the dof vector.
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:153
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grdi changes a dof compression is done...
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:160
DofVectorType & allocateDofStorage(const DiscreteFunctionSpaceType &space)
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:167
BlockVectorDiscreteFunction(const ThisType &other)
Copy constructor.
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:123
Definition: discretefunction.hh:63
BlockVectorDiscreteFunction< DiscreteFunctionSpace, BlockVector > DiscreteFunctionType
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:56
This file implements a dense vector with a dynamic size.
Definition: scalarproducts.hh:483
Definition: coordinate.hh:4
DofVectorType & dofVector_
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:181
Definition: discretefunction.hh:1034
discrete function space
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:31
BlockVectorType DofVectorType
type for the class which implements the block vector (which is the dof vector)
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:89
Definition: const.hh:24
DiscreteFunctionSpace DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:85
BlockVector BlockVectorType
type for the class which implements the block vector
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:87
Tag for discrete functions using block vectors.
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:43
std::unique_ptr< DofStorageInterface > memObject_
Definition: blockvectordiscretefunction/blockvectordiscretefunction.hh:180