dune-fem  2.4.1-rc
adaptivefunction/adaptivefunction.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_ADAPTIVEFUNCTION_HH
2 #define DUNE_FEM_ADAPTIVEFUNCTION_HH
3 
4 //- System includes
5 #include <string>
6 #include <vector>
7 
8 //- Dune includes
9 #include <dune/common/typetraits.hh>
12 
16 
17 //- Local includes
21 
22 namespace Dune
23 {
24 
25  namespace Fem
26  {
27 
33  template <class DiscreteFunctionSpace>
35 
36  template< typename DiscreteFunctionSpace >
38  : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace,
39  SimpleBlockVector< StaticArray< typename DiscreteFunctionSpace::RangeFieldType > , DiscreteFunctionSpace::localBlockSize > >
40  {
43  };
44 
45  template <class DiscreteFunctionSpace>
47  : public DiscreteFunctionDefault< AdaptiveDiscreteFunction< DiscreteFunctionSpace > >
48  {
50  typedef DiscreteFunctionDefault< ThisType > BaseType;
51 
52  public:
55  typedef typename BaseType :: DofType DofType;
56 
57  using BaseType::assign;
58 
59  typedef MutableBlockVector< MutableArray< DofType >, DiscreteFunctionSpaceType::localBlockSize > MutableDofVectorType;
60 
61  AdaptiveDiscreteFunction( const std::string &name,
62  const DiscreteFunctionSpaceType &space )
63  : BaseType( name, space ),
64  memObject_(),
65  dofVector_( allocateDofStorage( space ) )
66  {
67  }
68 
69  AdaptiveDiscreteFunction( const std::string &name,
70  const DiscreteFunctionSpaceType &space,
71  const DofType* data )
72  : BaseType( name, space ),
73  memObject_(),
74  dofVector_( allocateDofStorageWrapper( space.blockMapper().size() * DofVectorType::blockSize, data ) )
75  {
76  }
77 
78  AdaptiveDiscreteFunction( const std::string &name,
79  const DiscreteFunctionSpaceType &space,
80  DofVectorType& dofVector )
81  : BaseType( name, space ),
82  memObject_(),
83  dofVector_( dofVector )
84  {
85  }
86 
88  : BaseType( "copy of " + other.name(), other.space() ),
89  memObject_(),
90  dofVector_( allocateDofStorage( other.space() ) )
91  {
92  assign( other );
93  }
94 
95  DofType* leakPointer() { return dofVector().data(); }
96  const DofType* leakPointer() const { return dofVector().data(); }
97 
98  DofVectorType& dofVector() { return dofVector_; }
99  const DofVectorType& dofVector() const { return dofVector_; }
100 
104  {
105  if( memObject_ )
106  memObject_->enableDofCompression();
107  }
108 
109  protected:
110 
113  {
114  StaticArray< DofType > array_;
115  DofVectorType dofVector_;
116  typedef typename DofVectorType :: SizeType SizeType;
117 
118  std::string name_;
119 
120  public:
121  DofStorageWrapper ( const SizeType size,
122  const DofType *v )
123  : array_( size, const_cast< DofType* >(v) ),
124  dofVector_( array_ ),
125  name_("deprecated")
126  {}
127 
128  const std::string& name () const { return name_; }
129 
131  DofVectorType &getArray () { return dofVector_; }
132 
135 
137  int size () const { return dofVector_.size(); }
138  };
139 
140  protected:
141  // allocate unmanaged dof storage
142  DofVectorType&
143  allocateDofStorageWrapper ( const size_t size,
144  const DofType *v )
145  {
146  DofStorageWrapper *dsw = new DofStorageWrapper( size, v );
147  assert( dsw );
148 
149  // save pointer to object
150  memObject_.reset( dsw );
151  // return array
152  return dsw->getArray();
153  }
154 
155 
156  // allocate managed dof storage
157  DofVectorType& allocateDofStorage ( const DiscreteFunctionSpaceType &space )
158  {
159  std::string name("deprecated");
160  // create memory object
161  std::pair< DofStorageInterface*, DofVectorType* > memPair
162  = allocateManagedDofStorage( space.gridPart().grid(), space.blockMapper(),
163  name, (MutableDofVectorType *) 0 );
164 
165  // save pointer
166  memObject_.reset( memPair.first );
167  return *(memPair.second);
168  }
169 
170  // pointer to allocated DofVector
171  std::unique_ptr< DofStorageInterface > memObject_;
172 
173  DofVectorType& dofVector_;
174  };
175 
176  } // end namespace Fem
177 
178 } // end namespace Dune
179 #endif // #ifndef DUNE_FEM_ADAPTIVEFUNCTION_HH
DofVectorType & dofVector_
Definition: adaptivefunction/adaptivefunction.hh:173
void enableDofCompression()
do nothing here since we are using StaticArray
Definition: adaptivefunction/adaptivefunction.hh:134
std::unique_ptr< DofStorageInterface > memObject_
Definition: adaptivefunction/adaptivefunction.hh:171
AdaptiveDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType
Definition: adaptivefunction/adaptivefunction.hh:41
Traits class for a DiscreteFunction.
Definition: discretefunction.hh:60
const std::string & name() const
returns name of dof storage
Definition: adaptivefunction/adaptivefunction.hh:128
Definition: adaptivefunction/adaptivefunction.hh:34
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
DofVectorType & allocateDofStorage(const DiscreteFunctionSpaceType &space)
Definition: adaptivefunction/adaptivefunction.hh:157
DofVectorType & dofVector()
Definition: adaptivefunction/adaptivefunction.hh:98
Definition: discretefunction.hh:63
wrapper class to create fake DofStorage from DofType*
Definition: adaptivefunction/adaptivefunction.hh:112
This file implements a dense vector with a dynamic size.
Definition: defaultblockvectors.hh:455
const DofType * leakPointer() const
Definition: adaptivefunction/adaptivefunction.hh:96
DofStorageWrapper(const SizeType size, const DofType *v)
Definition: adaptivefunction/adaptivefunction.hh:121
DofVectorType & getArray()
return array
Definition: adaptivefunction/adaptivefunction.hh:131
BaseType::DofVectorType DofVectorType
Definition: adaptivefunction/adaptivefunction.hh:54
AdaptiveDiscreteFunction(const AdaptiveDiscreteFunction &other)
Definition: adaptivefunction/adaptivefunction.hh:87
Definition: coordinate.hh:4
Interface class for a dof storage object to be stored in discrete functions.
Definition: dofmanager.hh:282
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, const DofType *data)
Definition: adaptivefunction/adaptivefunction.hh:69
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: discretefunction.hh:571
int size() const
return array&#39;s size
Definition: adaptivefunction/adaptivefunction.hh:137
Definition: discretefunction.hh:1034
DofType * leakPointer()
Definition: adaptivefunction/adaptivefunction.hh:95
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grdi changes a dof compression is done...
Definition: adaptivefunction/adaptivefunction.hh:103
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Definition: adaptivefunction/adaptivefunction.hh:61
Traits::DofVectorType DofVectorType
type of DofVector
Definition: discretefunction.hh:596
BaseType::DofType DofType
Definition: discretefunction.hh:613
discrete function space
MutableBlockVector< MutableArray< DofType >, DiscreteFunctionSpaceType::localBlockSize > MutableDofVectorType
Definition: adaptivefunction/adaptivefunction.hh:59
DofVectorType & allocateDofStorageWrapper(const size_t size, const DofType *v)
Definition: adaptivefunction/adaptivefunction.hh:143
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: adaptivefunction/adaptivefunction.hh:42
const DofVectorType & dofVector() const
Definition: adaptivefunction/adaptivefunction.hh:99
Definition: const.hh:24
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, DofVectorType &dofVector)
Definition: adaptivefunction/adaptivefunction.hh:78
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: adaptivefunction/adaptivefunction.hh:53
BaseType::DofType DofType
Definition: adaptivefunction/adaptivefunction.hh:55