DUNE-FEM (unstable)

adaptivefunction.hh
1#ifndef DUNE_FEM_ADAPTIVEFUNCTION_HH
2#define DUNE_FEM_ADAPTIVEFUNCTION_HH
3
4#include <memory>
5#include <string>
6#include <utility>
7
8#include <dune/fem/common/stackallocator.hh>
9#include <dune/fem/function/common/discretefunction.hh>
10#include <dune/fem/function/blockvectors/defaultblockvectors.hh>
11#include <dune/fem/function/localfunction/mutable.hh>
12#include <dune/fem/space/common/dofmanager.hh>
13#include <dune/fem/space/mapper/nonblockmapper.hh>
14#include <dune/fem/storage/dynamicarray.hh>
15
16namespace 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 >
30 struct DiscreteFunctionTraits< AdaptiveDiscreteFunction< DiscreteFunctionSpace > >
31 : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace,
32 SimpleBlockVector< StaticArray< typename DiscreteFunctionSpace::RangeFieldType > , DiscreteFunctionSpace::localBlockSize > >
33 {
34 typedef AdaptiveDiscreteFunction< DiscreteFunctionSpace > DiscreteFunctionType;
35 typedef MutableLocalFunction< DiscreteFunctionType > LocalFunctionType;
36 };
37
38
39
45 template <class DiscreteFunctionSpace>
47 : public DiscreteFunctionDefault< AdaptiveDiscreteFunction< DiscreteFunctionSpace > >
48 {
51
52 public:
53 typedef typename BaseType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
54 typedef typename BaseType :: DofVectorType DofVectorType;
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,
69 const DiscreteFunctionSpaceType& space )
70 : BaseType( name, space ),
71 memObject_(),
72 dofVector_( allocateDofStorage( space ) )
73 {}
74
81 AdaptiveDiscreteFunction( const std::string& name,
82 const DiscreteFunctionSpaceType& space,
83 const DofType* data )
84 : BaseType( name, space ),
85 memObject_(),
86 dofVector_( allocateDofStorageWrapper( space.blockMapper().size() * DofVectorType::blockSize, data ) )
87 {}
88
95 AdaptiveDiscreteFunction( const std::string& name,
96 const DiscreteFunctionSpaceType& space,
97 DofVectorType& dofVector )
98 : BaseType( name, space ),
99 memObject_(),
100 dofVector_( dofVector )
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
119 AdaptiveDiscreteFunction () = delete;
120 ThisType& operator= ( const ThisType& ) = delete;
121 ThisType& operator= ( ThisType&& ) = delete;
122
123#if HAVE_PETSC
124 void assign( const PetscDiscreteFunction< DiscreteFunctionSpaceType >& g )
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
134 DofVectorType& dofVector() { return dofVector_; }
135
137 const DofVectorType& dofVector() const { return dofVector_; }
138
141 {
142 if( memObject_ )
143 memObject_->enableDofCompression();
144 }
145
146 protected:
147
150 {
152 DofVectorType dofVector_;
153 typedef typename DofStorageInterface::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 SizeType size () const { return dofVector_.size(); }
170 };
171
172 protected:
173 // allocate unmanaged dof storage
174 DofVectorType&
175 allocateDofStorageWrapper ( const size_t size,
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
189 DofVectorType& allocateDofStorage ( const DiscreteFunctionSpaceType &space )
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_;
202 DofVectorType& dofVector_;
203 };
204
205 } // end namespace Fem
206} // end namespace Dune
207
208#endif // #ifndef DUNE_FEM_ADAPTIVEFUNCTION_HH
discrete function space
wrapper class to create fake DofStorage from DofType*
Definition: adaptivefunction.hh:150
DofVectorType & getArray()
return array
Definition: adaptivefunction.hh:163
SizeType size() const
return array's size
Definition: adaptivefunction.hh:169
void enableDofCompression()
do nothing here since we are using StaticArray
Definition: adaptivefunction.hh:166
Definition: adaptivefunction.hh:48
AdaptiveDiscreteFunction(ThisType &&other)
Move constructor.
Definition: adaptivefunction.hh:113
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grid changes a dof compression is done...
Definition: adaptivefunction.hh:140
AdaptiveDiscreteFunction(const ThisType &other)
Copy constructor.
Definition: adaptivefunction.hh:104
const std::string & name() const
obtain the name of the discrete function
Definition: discretefunction.hh:691
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: adaptivefunction.hh:68
DofVectorType & dofVector()
Definition: adaptivefunction.hh:134
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, const DofType *data)
Constructor to use if the vector storing the dofs already exists.
Definition: adaptivefunction.hh:81
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:132
AdaptiveDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, DofVectorType &dofVector)
Constructor to use if the vector storing the dofs already exists.
Definition: adaptivefunction.hh:95
const DofVectorType & dofVector() const
Definition: adaptivefunction.hh:137
Definition: discretefunction.hh:584
Traits::DofVectorType DofVectorType
type of DofVector
Definition: discretefunction.hh:631
SizeType size() const
Return the number of blocks in the block vector.
Definition: discretefunction.hh:755
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: discretefunction.hh:709
const std::string & name() const
obtain the name of the discrete function
Definition: discretefunction.hh:691
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: discretefunction.hh:606
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:132
static constexpr std::size_t blockSize
size of the dof blocks
Definition: discretefunction.hh:148
Interface class for a dof storage object to be stored in discrete functions.
Definition: dofmanager.hh:212
forward declaration
Definition: discretefunction.hh:51
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:578
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)