dune-fem  2.6-git
function/adaptivefunction/adaptivefunction.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_ADAPTIVEFUNCTION_HH
2 #define DUNE_FEM_ADAPTIVEFUNCTION_HH
3 
4 #include <memory>
5 #include <string>
6 #include <utility>
7 
15 
16 namespace Dune
17 {
18  namespace Fem
19  {
20 
21  template <class DiscreteFunctionSpace>
22  class AdaptiveDiscreteFunction;
23 
24 
25 
26  template< typename DiscreteFunctionSpace >
28  : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace,
29  SimpleBlockVector< StaticArray< typename DiscreteFunctionSpace::RangeFieldType > , DiscreteFunctionSpace::localBlockSize > >
30  {
33  };
34 
35 
36 
42  template <class DiscreteFunctionSpace>
44  : public DiscreteFunctionDefault< AdaptiveDiscreteFunction< DiscreteFunctionSpace > >
45  {
48 
49  public:
52  typedef typename BaseType :: DofType DofType;
53 
54  using BaseType::assign;
55 
56  typedef MutableBlockVector< DynamicArray< DofType >, DiscreteFunctionSpaceType::localBlockSize > MutableDofVectorType;
57 
63  AdaptiveDiscreteFunction( const std::string& name,
65  : BaseType( name, space ),
66  memObject_(),
68  {}
69 
76  AdaptiveDiscreteFunction( const std::string& name,
78  const DofType* data )
79  : BaseType( name, space ),
80  memObject_(),
82  {}
83 
90  AdaptiveDiscreteFunction( const std::string& name,
93  : BaseType( name, space ),
94  memObject_(),
96  {}
97 
100  : BaseType( "copy of " + other.name(), other.space() ),
101  memObject_(),
102  dofVector_( allocateDofStorage( other.space() ) )
103  {
104  assign( other );
105  }
106 
109  : BaseType( static_cast< BaseType && >( other ) ),
110  memObject_( std::move( other.memObject_ ) ),
111  dofVector_( other.dofVector_ )
112  {}
113 
115  ThisType& operator= ( const ThisType& ) = delete;
116  ThisType& operator= ( ThisType&& ) = delete;
117 
118  DofType* leakPointer() { return dofVector().data(); }
119  const DofType* leakPointer() const { return dofVector().data(); }
120 
123 
125  const DofVectorType& dofVector() const { return dofVector_; }
126 
129  {
130  if( memObject_ )
131  memObject_->enableDofCompression();
132  }
133 
134  protected:
135 
138  {
139  StaticArray< DofType > array_;
140  DofVectorType dofVector_;
141  typedef typename DofVectorType :: SizeType SizeType;
142 
143  std::string name_;
144 
145  public:
146  DofStorageWrapper ( const SizeType size,
147  const DofType *v )
148  : array_( size, const_cast< DofType* >(v) ),
149  dofVector_( array_ ),
150  name_("deprecated")
151  {}
152 
153  const std::string& name () const { return name_; }
154 
156  DofVectorType &getArray () { return dofVector_; }
157 
160 
162  int size () const { return dofVector_.size(); }
163  };
164 
165  protected:
166  // allocate unmanaged dof storage
169  const DofType *v )
170  {
171  DofStorageWrapper *dsw = new DofStorageWrapper( size, v );
172  assert( dsw );
173 
174  // save pointer to object
175  memObject_.reset( dsw );
176  // return array
177  return dsw->getArray();
178  }
179 
180 
181  // allocate managed dof storage
183  {
184  std::string name("deprecated");
185  // create memory object
186  std::pair< DofStorageInterface*, DofVectorType* > memPair
187  = allocateManagedDofStorage( space.gridPart().grid(), space.blockMapper(),
188  name, (MutableDofVectorType *) 0 );
189 
190  // save pointer
191  memObject_.reset( memPair.first );
192  return *(memPair.second);
193  }
194 
195  std::unique_ptr< DofStorageInterface > memObject_;
197  };
198 
199  } // end namespace Fem
200 } // end namespace Dune
201 
202 #endif // #ifndef DUNE_FEM_ADAPTIVEFUNCTION_HH
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:626
Definition: bindguard.hh:11
Definition: function/adaptivefunction/adaptivefunction.hh:45
DofType * leakPointer()
Definition: function/adaptivefunction/adaptivefunction.hh:118
AdaptiveDiscreteFunction(ThisType &&other)
Move constructor.
Definition: function/adaptivefunction/adaptivefunction.hh:108
std::unique_ptr< DofStorageInterface > memObject_
Definition: function/adaptivefunction/adaptivefunction.hh:195
DofVectorType & dofVector_
Definition: function/adaptivefunction/adaptivefunction.hh:196
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grid changes a dof compression is done...
Definition: function/adaptivefunction/adaptivefunction.hh:128
const DofVectorType & dofVector() const
Definition: function/adaptivefunction/adaptivefunction.hh:125
ThisType & operator=(const ThisType &)=delete
DofVectorType & dofVector()
Definition: function/adaptivefunction/adaptivefunction.hh:122
AdaptiveDiscreteFunction(const ThisType &other)
Copy constructor.
Definition: function/adaptivefunction/adaptivefunction.hh:99
MutableBlockVector< DynamicArray< DofType >, DiscreteFunctionSpaceType::localBlockSize > MutableDofVectorType
Definition: function/adaptivefunction/adaptivefunction.hh:56
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: function/adaptivefunction/adaptivefunction.hh:63
BaseType ::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: function/adaptivefunction/adaptivefunction.hh:50
BaseType ::DofType DofType
Definition: function/adaptivefunction/adaptivefunction.hh:52
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, const DofType *data)
Constructor to use if the vector storing the dofs already exists.
Definition: function/adaptivefunction/adaptivefunction.hh:76
BaseType ::DofVectorType DofVectorType
Definition: function/adaptivefunction/adaptivefunction.hh:51
DofVectorType & allocateDofStorageWrapper(const size_t size, const DofType *v)
Definition: function/adaptivefunction/adaptivefunction.hh:168
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, DofVectorType &dofVector)
Constructor to use if the vector storing the dofs already exists.
Definition: function/adaptivefunction/adaptivefunction.hh:90
DofVectorType & allocateDofStorage(const DiscreteFunctionSpaceType &space)
Definition: function/adaptivefunction/adaptivefunction.hh:182
void assign(const DiscreteFunctionType &g)
Definition: common/discretefunction.hh:764
const DofType * leakPointer() const
Definition: function/adaptivefunction/adaptivefunction.hh:119
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: function/adaptivefunction/adaptivefunction.hh:32
AdaptiveDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType
Definition: function/adaptivefunction/adaptivefunction.hh:31
wrapper class to create fake DofStorage from DofType*
Definition: function/adaptivefunction/adaptivefunction.hh:138
DofStorageWrapper(const SizeType size, const DofType *v)
Definition: function/adaptivefunction/adaptivefunction.hh:146
DofVectorType & getArray()
return array
Definition: function/adaptivefunction/adaptivefunction.hh:156
void enableDofCompression()
do nothing here since we are using StaticArray
Definition: function/adaptivefunction/adaptivefunction.hh:159
const std::string & name() const
returns name of dof storage
Definition: function/adaptivefunction/adaptivefunction.hh:153
int size() const
return array's size
Definition: function/adaptivefunction/adaptivefunction.hh:162
Definition: defaultblockvectors.hh:284
Traits class for a DiscreteFunction.
Definition: common/discretefunction.hh:60
Definition: common/discretefunction.hh:539
SizeType size() const
Return the number of blocks in the block vector.
Definition: common/discretefunction.hh:704
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:644
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: common/discretefunction.hh:561
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:128
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: common/discretefunction.hh:662
BaseType ::DofType DofType
Definition: common/discretefunction.hh:604
Traits ::DofVectorType DofVectorType
type of DofVector
Definition: common/discretefunction.hh:586
static constexpr std::size_t blockSize
size of the dof blocks
Definition: common/discretefunction.hh:146
Definition: common/discretefunction.hh:1013
Definition: mutable.hh:31
Interface class for a dof storage object to be stored in discrete functions.
Definition: dofmanager.hh:271
discrete function space