dune-fem  2.8-git
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 
15 namespace 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:
45  typedef typename BaseType :: GridType GridType;
47  typedef typename BaseType :: DofType DofType;
48  typedef typename DofVectorType :: DofContainerType DofContainerType;
50 
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_(),
86  dofVector_( allocateDofStorage( other.space() ) )
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;
100  ThisType& operator= ( 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:
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 
149  DofContainerType* createData( const size_t size, DofContainerType* otherData )
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:
165  ISTLDofStorage( const GridType& grid,
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:334
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
BaseType ::GridType GridType
Definition: blockvectorfunction/blockvectorfunction.hh:45
BaseType ::ScalarProductType ScalarProductType
Definition: blockvectorfunction/blockvectorfunction.hh:51
ThisType & operator=(const ThisType &)=delete
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 ::DofType DofType
Definition: blockvectorfunction/blockvectorfunction.hh:47
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 ::DofVectorType DofVectorType
Definition: blockvectorfunction/blockvectorfunction.hh:46
DofVectorType & allocateDofStorage(const DiscreteFunctionSpaceType &space, DofContainerType *otherData=nullptr)
Definition: blockvectorfunction/blockvectorfunction.hh:176
DofVectorType & dofVector()
Definition: blockvectorfunction/blockvectorfunction.hh:123
DofVectorType & dofVector_
Definition: blockvectorfunction/blockvectorfunction.hh:186
ISTLBlockVectorDiscreteFunction(const ThisType &other)
Copy constructor.
Definition: blockvectorfunction/blockvectorfunction.hh:83
DofContainerType & blockVector()
convenience method for usage with ISTL solvers
Definition: blockvectorfunction/blockvectorfunction.hh:117
BaseType ::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition: blockvectorfunction/blockvectorfunction.hh:44
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
const std::string & name() const
obtain the name of the discrete function
Definition: common/discretefunction.hh:685
ScalarProductType & scalarProduct()
returns ScalarProduct to be used with ISTLInverseOp
Definition: blockvectorfunction/blockvectorfunction.hh:129
DofContainerType DofStorageType
Definition: blockvectorfunction/blockvectorfunction.hh:49
const DofVectorType & dofVector() const
Definition: blockvectorfunction/blockvectorfunction.hh:126
const DofContainerType & blockVector() const
convenience method for usage with ISTL solvers
Definition: blockvectorfunction/blockvectorfunction.hh:120
DiscreteFunctionSpaceType ::BlockMapperType BlockMapperType
Definition: blockvectorfunction/blockvectorfunction.hh:134
ISTLBlockVectorDiscreteFunction(ThisType &&other)
Move constructor.
Definition: blockvectorfunction/blockvectorfunction.hh:92
DofVectorType ::DofContainerType DofContainerType
Definition: blockvectorfunction/blockvectorfunction.hh:48
void assign(const DiscreteFunctionType &g)
Definition: common/discretefunction.hh:809
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:578
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
ParallelScalarProduct< DiscreteFunctionInterfaceType > ScalarProductType
Definition: common/discretefunction.hh:596
BaseType ::DofType DofType
Definition: common/discretefunction.hh:643
Traits ::DofVectorType DofVectorType
type of DofVector
Definition: common/discretefunction.hh:625
DiscreteFunctionSpaceType ::GridType GridType
type of the underlying grid
Definition: common/discretefunction.hh:122
Definition: common/discretefunction.hh:1064
Definition: cachedcommmanager.hh:47
Definition: dofmanager.hh:271
discrete function space