dune-fem  2.8-git
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 #if HAVE_PETSC
25  template <class DiscreteFunctionSpace>
26  class PetscDiscreteFunction;
27 #endif
28 
29  template< typename DiscreteFunctionSpace >
31  : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace,
32  SimpleBlockVector< StaticArray< typename DiscreteFunctionSpace::RangeFieldType > , DiscreteFunctionSpace::localBlockSize > >
33  {
36  };
37 
38 
39 
45  template <class DiscreteFunctionSpace>
47  : public DiscreteFunctionDefault< AdaptiveDiscreteFunction< DiscreteFunctionSpace > >
48  {
51 
52  public:
55  typedef typename BaseType :: DofType DofType;
56 
57  // generic assign method
58  using BaseType::assign;
59  using BaseType::name;
60 
61  typedef MutableBlockVector< DynamicArray< DofType >, DiscreteFunctionSpaceType::localBlockSize > MutableDofVectorType;
62 
68  AdaptiveDiscreteFunction( const std::string& name,
70  : BaseType( name, space ),
71  memObject_(),
73  {}
74 
81  AdaptiveDiscreteFunction( const std::string& name,
83  const DofType* data )
84  : BaseType( name, space ),
85  memObject_(),
87  {}
88 
95  AdaptiveDiscreteFunction( const std::string& name,
98  : BaseType( name, space ),
99  memObject_(),
101  {}
102 
105  : BaseType( "copy of " + other.name(), other.space() ),
106  memObject_(),
107  dofVector_( allocateDofStorage( other.space() ) )
108  {
109  assign( other );
110  }
111 
114  : BaseType( static_cast< BaseType && >( other ) ),
115  memObject_( std::move( other.memObject_ ) ),
116  dofVector_( other.dofVector_ )
117  {}
118 
120  ThisType& operator= ( const ThisType& ) = delete;
121  ThisType& operator= ( ThisType&& ) = delete;
122 
123 #if HAVE_PETSC
125  {
126  g.dofVector().copyTo( dofVector() );
127  }
128 #endif
129 
130  DofType* leakPointer() { return dofVector().data(); }
131  const DofType* leakPointer() const { return dofVector().data(); }
132 
135 
137  const DofVectorType& dofVector() const { return dofVector_; }
138 
141  {
142  if( memObject_ )
143  memObject_->enableDofCompression();
144  }
145 
146  protected:
147 
150  {
151  StaticArray< DofType > array_;
152  DofVectorType dofVector_;
153  typedef typename DofVectorType :: SizeType SizeType;
154 
155  public:
156  DofStorageWrapper ( const SizeType size,
157  const DofType *v )
158  : array_( size, const_cast< DofType* >(v) ),
159  dofVector_( array_ )
160  {}
161 
163  DofVectorType &getArray () { return dofVector_; }
164 
167 
169  int size () const { return dofVector_.size(); }
170  };
171 
172  protected:
173  // allocate unmanaged dof storage
176  const DofType *v )
177  {
178  DofStorageWrapper *dsw = new DofStorageWrapper( size, v );
179  assert( dsw );
180 
181  // save pointer to object
182  memObject_.reset( dsw );
183  // return array
184  return dsw->getArray();
185  }
186 
187 
188  // allocate managed dof storage
190  {
191  // create memory object
192  std::pair< DofStorageInterface*, DofVectorType* > memPair
193  = allocateManagedDofStorage( space.gridPart().grid(), space.blockMapper(),
194  (MutableDofVectorType *) 0 );
195 
196  // save pointer
197  memObject_.reset( memPair.first );
198  return *(memPair.second);
199  }
200 
201  std::unique_ptr< DofStorageInterface > memObject_;
203  };
204 
205  } // end namespace Fem
206 } // end namespace Dune
207 
208 #endif // #ifndef DUNE_FEM_ADAPTIVEFUNCTION_HH
static std::pair< DofStorageInterface *, DofStorageType * > allocateManagedDofStorage(const GridType &grid, const MapperType &mapper, const DofStorageType *=0)
default implementation for creating a managed dof storage
Definition: dofmanager.hh:561
Definition: bindguard.hh:11
Definition: adaptivefunction/adaptivefunction.hh:48
DofType * leakPointer()
Definition: adaptivefunction/adaptivefunction.hh:130
AdaptiveDiscreteFunction(ThisType &&other)
Move constructor.
Definition: adaptivefunction/adaptivefunction.hh:113
std::unique_ptr< DofStorageInterface > memObject_
Definition: adaptivefunction/adaptivefunction.hh:201
DofVectorType & dofVector_
Definition: adaptivefunction/adaptivefunction.hh:202
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grid changes a dof compression is done...
Definition: adaptivefunction/adaptivefunction.hh:140
const DofVectorType & dofVector() const
Definition: adaptivefunction/adaptivefunction.hh:137
ThisType & operator=(const ThisType &)=delete
DofVectorType & dofVector()
Definition: adaptivefunction/adaptivefunction.hh:134
AdaptiveDiscreteFunction(const ThisType &other)
Copy constructor.
Definition: adaptivefunction/adaptivefunction.hh:104
MutableBlockVector< DynamicArray< DofType >, DiscreteFunctionSpaceType::localBlockSize > MutableDofVectorType
Definition: adaptivefunction/adaptivefunction.hh:61
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: adaptivefunction/adaptivefunction.hh:68
BaseType ::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: adaptivefunction/adaptivefunction.hh:53
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:685
BaseType ::DofType DofType
Definition: adaptivefunction/adaptivefunction.hh:55
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, const DofType *data)
Constructor to use if the vector storing the dofs already exists.
Definition: adaptivefunction/adaptivefunction.hh:81
BaseType ::DofVectorType DofVectorType
Definition: adaptivefunction/adaptivefunction.hh:54
DofVectorType & allocateDofStorageWrapper(const size_t size, const DofType *v)
Definition: adaptivefunction/adaptivefunction.hh:175
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, DofVectorType &dofVector)
Constructor to use if the vector storing the dofs already exists.
Definition: adaptivefunction/adaptivefunction.hh:95
DofVectorType & allocateDofStorage(const DiscreteFunctionSpaceType &space)
Definition: adaptivefunction/adaptivefunction.hh:189
void assign(const DiscreteFunctionType &g)
Definition: common/discretefunction.hh:809
const DofType * leakPointer() const
Definition: adaptivefunction/adaptivefunction.hh:131
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: adaptivefunction/adaptivefunction.hh:35
AdaptiveDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType
Definition: adaptivefunction/adaptivefunction.hh:34
wrapper class to create fake DofStorage from DofType*
Definition: adaptivefunction/adaptivefunction.hh:150
DofStorageWrapper(const SizeType size, const DofType *v)
Definition: adaptivefunction/adaptivefunction.hh:156
DofVectorType & getArray()
return array
Definition: adaptivefunction/adaptivefunction.hh:163
void enableDofCompression()
do nothing here since we are using StaticArray
Definition: adaptivefunction/adaptivefunction.hh:166
int size() const
return array's size
Definition: adaptivefunction/adaptivefunction.hh:169
Definition: defaultblockvectors.hh:346
Traits class for a DiscreteFunction.
Definition: common/discretefunction.hh:61
Definition: common/discretefunction.hh:578
SizeType size() const
Return the number of blocks in the block vector.
Definition: common/discretefunction.hh:749
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:685
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: common/discretefunction.hh:600
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:133
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: common/discretefunction.hh:703
BaseType ::DofType DofType
Definition: common/discretefunction.hh:643
Traits ::DofVectorType DofVectorType
type of DofVector
Definition: common/discretefunction.hh:625
static constexpr std::size_t blockSize
size of the dof blocks
Definition: common/discretefunction.hh:148
Definition: common/discretefunction.hh:1064
Definition: cachedcommmanager.hh:47
Interface class for a dof storage object to be stored in discrete functions.
Definition: dofmanager.hh:213
discrete function space