dune-fem 2.8.0
Loading...
Searching...
No Matches
blockvectorfunction/blockvectorfunction.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_BLOCKVECTORFUNCTION_HH
2#define DUNE_FEM_BLOCKVECTORFUNCTION_HH
3
4#include <memory>
5#include <string>
6#include <utility>
7
14
15namespace Dune
16{
17 namespace Fem
18 {
25 template< class DiscreteFunctionSpace,
26 class Block >
28 : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace, ISTLBlockVector< Block > >
29 {
32 };
33
34
35
36 template < class DiscreteFunctionSpace, class Block >
38 : public DiscreteFunctionDefault< ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpace, Block > >
39 {
42
43 public:
44 typedef typename BaseType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
45 typedef typename BaseType :: GridType GridType;
46 typedef typename BaseType :: DofVectorType DofVectorType;
47 typedef typename BaseType :: DofType DofType;
48 typedef typename DofVectorType :: DofContainerType DofContainerType;
50
51 typedef typename BaseType :: ScalarProductType ScalarProductType;
52
53 using BaseType::assign;
54 using BaseType::name;
55
63 : BaseType( name, space ),
64 memObject_(),
66 {}
67
77 : BaseType( name, space ),
78 memObject_(),
80 {}
81
84 : BaseType( "copy of " + other.name(), other.space() ),
85 memObject_(),
87 {
88 assign( other );
89 }
90
93 : BaseType( static_cast< BaseType && >( other ) ),
94 memObject_( std::move( other.memObject_ ) ),
95 dofVector_( memObject_->getArray() )
96 {}
97
99 ThisType& operator= ( const ThisType& ) = delete;
101
104 {
105 if( memObject_ )
106 memObject_->enableDofCompression();
107 }
108
109#if HAVE_PETSC
111 {
112 g.dofVector().copyTo( dofVector() );
113 }
114#endif
115
117 DofContainerType& blockVector() { return dofVector().array(); }
118
120 const DofContainerType& blockVector() const { return dofVector().array(); }
121
124
126 const DofVectorType& dofVector() const { return dofVector_; }
127
130
131 protected:
132 using BaseType :: scalarProduct_;
133
134 typedef typename DiscreteFunctionSpaceType :: BlockMapperType BlockMapperType;
135
138 public ManagedDofStorageImplementation< GridType,
139 BlockMapperType,
140 DofVectorType >
141 {
143 protected:
144 // pointer to data if created here
145 std::unique_ptr< DofContainerType > myDofContainer_;
146 // array wrapper class
148
150 {
151 if( otherData )
152 {
153 // user data provided from outside
154 return otherData ;
155 }
156 else
157 {
158 // create new data vector
159 myDofContainer_.reset( new DofContainerType( size ) );
160 return myDofContainer_.operator->();
161 }
162 }
163 public:
166 const BlockMapperType& mapper,
167 DofContainerType* otherData = nullptr )
168 : BaseType( grid, mapper, myArray_ ),
169 myArray_( createData( mapper.size(), otherData ) )
170 {
171 }
172 };
173
174
175 // allocate managed dof storage
177 {
178 memObject_.reset( new ISTLDofStorage( space.gridPart().grid(), space.blockMapper(), otherData ) );
179 return memObject_->getArray();
180 }
181
182 // pointer to allocated DofVector
183 std::unique_ptr< ISTLDofStorage > memObject_;
184
185 // DofVector object holds pointer to dof container
187 };
188
189 } // namespace Fem
190} // namespace Dune
191
192#endif // #ifndef DUNE_FEM_BLOCKVECTORFUNCTION_HH
int size() const
return size of underlying array
Definition: dofmanager.hh:333
STL namespace.
Definition: bindguard.hh:11
MutableLocalFunction< DiscreteFunctionType > LocalFunctionType
Definition: blockvectorfunction/blockvectorfunction.hh:31
ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpace, Block > DiscreteFunctionType
Definition: blockvectorfunction/blockvectorfunction.hh:30
Definition: blockvectorfunction/blockvectorfunction.hh:39
DofVectorType & dofVector()
Definition: blockvectorfunction/blockvectorfunction.hh:123
DofContainerType & blockVector()
convenience method for usage with ISTL solvers
Definition: blockvectorfunction/blockvectorfunction.hh:117
ISTLBlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: blockvectorfunction/blockvectorfunction.hh:61
BaseType::GridType GridType
Definition: blockvectorfunction/blockvectorfunction.hh:45
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grid changes a dof compression is done...
Definition: blockvectorfunction/blockvectorfunction.hh:103
BaseType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: blockvectorfunction/blockvectorfunction.hh:44
ScalarProductType & scalarProduct()
returns ScalarProduct to be used with ISTLInverseOp
Definition: blockvectorfunction/blockvectorfunction.hh:129
DofVectorType & dofVector_
Definition: blockvectorfunction/blockvectorfunction.hh:186
DofVectorType & allocateDofStorage(const DiscreteFunctionSpaceType &space, DofContainerType *otherData=nullptr)
Definition: blockvectorfunction/blockvectorfunction.hh:176
ISTLBlockVectorDiscreteFunction(const ThisType &other)
Copy constructor.
Definition: blockvectorfunction/blockvectorfunction.hh:83
const DofContainerType & blockVector() const
convenience method for usage with ISTL solvers
Definition: blockvectorfunction/blockvectorfunction.hh:120
std::unique_ptr< ISTLDofStorage > memObject_
Definition: blockvectorfunction/blockvectorfunction.hh:183
ISTLBlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, const DofContainerType &dofVector)
Constructor to use if the vector storing the dofs already exists.
Definition: blockvectorfunction/blockvectorfunction.hh:74
ThisType & operator=(const ThisType &)=delete
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:691
DofContainerType DofStorageType
Definition: blockvectorfunction/blockvectorfunction.hh:49
BaseType::ScalarProductType ScalarProductType
Definition: blockvectorfunction/blockvectorfunction.hh:51
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:132
BaseType::DofVectorType DofVectorType
Definition: blockvectorfunction/blockvectorfunction.hh:46
DofVectorType::DofContainerType DofContainerType
Definition: blockvectorfunction/blockvectorfunction.hh:48
BaseType::DofType DofType
Definition: blockvectorfunction/blockvectorfunction.hh:47
ISTLBlockVectorDiscreteFunction(ThisType &&other)
Move constructor.
Definition: blockvectorfunction/blockvectorfunction.hh:92
const DofVectorType & dofVector() const
Definition: blockvectorfunction/blockvectorfunction.hh:126
DiscreteFunctionSpaceType::BlockMapperType BlockMapperType
Definition: blockvectorfunction/blockvectorfunction.hh:134
Definition: blockvectorfunction/blockvectorfunction.hh:141
DofVectorType myArray_
Definition: blockvectorfunction/blockvectorfunction.hh:147
std::unique_ptr< DofContainerType > myDofContainer_
Definition: blockvectorfunction/blockvectorfunction.hh:145
DofContainerType * createData(const size_t size, DofContainerType *otherData)
Definition: blockvectorfunction/blockvectorfunction.hh:149
ISTLDofStorage(const GridType &grid, const BlockMapperType &mapper, DofContainerType *otherData=nullptr)
Constructor of ManagedDofStorage.
Definition: blockvectorfunction/blockvectorfunction.hh:165
Traits class for a DiscreteFunction.
Definition: common/discretefunction.hh:61
Definition: common/discretefunction.hh:584
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: common/discretefunction.hh:709
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:691
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:132
Definition: common/discretefunction.hh:1081
Definition: cachedcommmanager.hh:47
Definition: dofmanager.hh:270
discrete function space