DUNE-FEM (unstable)

blockvectorfunction.hh
1 #ifndef DUNE_FEM_BLOCKVECTORFUNCTION_HH
2 #define DUNE_FEM_BLOCKVECTORFUNCTION_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/localfunction/mutable.hh>
11 #include <dune/fem/function/blockvectorfunction/declaration.hh>
12 #include <dune/fem/function/blockvectors/defaultblockvectors.hh>
13 #include <dune/fem/space/common/dofmanager.hh>
14 
15 namespace Dune
16 {
17  namespace Fem
18  {
25  template< class DiscreteFunctionSpace,
26  class Block >
27  struct DiscreteFunctionTraits< ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpace, Block > >
28  : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace, ISTLBlockVector< Block > >
29  {
30  typedef ISTLBlockVectorDiscreteFunction< DiscreteFunctionSpace, Block > DiscreteFunctionType;
31  typedef MutableLocalFunction< DiscreteFunctionType > LocalFunctionType;
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;
49  typedef DofContainerType DofStorageType;
50 
51  typedef typename BaseType :: ScalarProductType ScalarProductType;
52 
53  using BaseType::assign;
54  using BaseType::name;
55 
62  const DiscreteFunctionSpaceType& space )
63  : BaseType( name, space ),
64  memObject_(),
65  dofVector_( allocateDofStorage( space ) )
66  {}
67 
75  const DiscreteFunctionSpaceType& space,
76  const DofContainerType& dofVector )
77  : BaseType( name, space ),
78  memObject_(),
79  dofVector_( allocateDofStorage( space, const_cast< DofContainerType* > (&dofVector) ) )
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
110  void assign( const PetscDiscreteFunction< DiscreteFunctionSpaceType >& g )
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 
123  DofVectorType& dofVector() { return dofVector_; }
124 
126  const DofVectorType& dofVector() const { return dofVector_; }
127 
129  ScalarProductType& scalarProduct() { return scalarProduct_ ; }
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
147  DofVectorType myArray_;
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
176  DofVectorType& allocateDofStorage ( const DiscreteFunctionSpaceType &space, DofContainerType* otherData = nullptr )
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
186  DofVectorType& dofVector_;
187  };
188 
189  } // namespace Fem
190 } // namespace Dune
191 
192 #endif // #ifndef DUNE_FEM_BLOCKVECTORFUNCTION_HH
discrete function space
Definition: discretefunction.hh:584
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
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: discretefunction.hh:709
Traits ::DofVectorType DofVectorType
type of DofVector
Definition: discretefunction.hh:631
DiscreteFunctionSpaceType ::GridType GridType
type of the underlying grid
Definition: discretefunction.hh:122
ISTLDofStorage(const GridType &grid, const BlockMapperType &mapper, DofContainerType *otherData=nullptr)
Constructor of ManagedDofStorage.
Definition: blockvectorfunction.hh:165
Definition: blockvectorfunction.hh:39
ISTLBlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space)
Constructor to use if the vector storing the dofs does not exist yet.
Definition: blockvectorfunction.hh:61
void enableDofCompression()
Enable this discrete function for dof compression, i.e. during grid changes a dof compression is done...
Definition: blockvectorfunction.hh:103
DofVectorType & dofVector()
Definition: blockvectorfunction.hh:123
ISTLBlockVectorDiscreteFunction(const ThisType &other)
Copy constructor.
Definition: blockvectorfunction.hh:83
DofContainerType & blockVector()
convenience method for usage with ISTL solvers
Definition: blockvectorfunction.hh:117
ISTLBlockVectorDiscreteFunction(const std::string &name, const DiscreteFunctionSpaceType &space, const DofContainerType &dofVector)
Constructor to use if the vector storing the dofs already exists.
Definition: blockvectorfunction.hh:74
const std::string & name() const
obtain the name of the discrete function
Definition: discretefunction.hh:691
ScalarProductType & scalarProduct()
returns ScalarProduct to be used with ISTLInverseOp
Definition: blockvectorfunction.hh:129
const DofVectorType & dofVector() const
Definition: blockvectorfunction.hh:126
const DofContainerType & blockVector() const
convenience method for usage with ISTL solvers
Definition: blockvectorfunction.hh:120
ISTLBlockVectorDiscreteFunction(ThisType &&other)
Move constructor.
Definition: blockvectorfunction.hh:92
void assign(const DiscreteFunctionType &g)
Definition: discretefunction.hh:815
Definition: dofmanager.hh:276
forward declaration
Definition: discretefunction.hh:51
SizeType size() const override
return size of underlying array
Definition: dofmanager.hh:341
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 12, 22:29, 2024)