DUNE-FEM (unstable)

vectorfunction.hh
1#ifndef DUNE_FEM_VECTORFUNCTION_HH
2#define DUNE_FEM_VECTORFUNCTION_HH
3
4#include <memory>
5#include <string>
6
7#include <dune/fem/common/stackallocator.hh>
8#include <dune/fem/function/blockvectors/defaultblockvectors.hh>
9#include <dune/fem/function/common/discretefunction.hh>
10#include <dune/fem/function/localfunction/mutable.hh>
11#include <dune/fem/storage/envelope.hh>
12
13namespace Dune
14{
15 namespace Fem
16 {
17
18 template < class DiscreteFunctionSpace, class Vector >
19 class VectorDiscreteFunction;
20
21#if HAVE_PETSC
22 template <class DiscreteFunctionSpace>
23 class PetscDiscreteFunction;
24#endif
25
26
27 template< typename DiscreteFunctionSpace, typename Vector >
28 struct DiscreteFunctionTraits< VectorDiscreteFunction< DiscreteFunctionSpace, Vector > >
29 : public DefaultDiscreteFunctionTraits< DiscreteFunctionSpace,
30 SimpleBlockVector< Vector, DiscreteFunctionSpace::localBlockSize > >
31 {
32 typedef VectorDiscreteFunction< DiscreteFunctionSpace, Vector > DiscreteFunctionType;
33 typedef MutableLocalFunction< DiscreteFunctionType > LocalFunctionType;
34 };
35
36
37
38 template < class DiscreteFunctionSpace, class Vector >
39 class VectorDiscreteFunction
40 : public DiscreteFunctionDefault<
41 VectorDiscreteFunction< DiscreteFunctionSpace, Vector > >
42 {
43 typedef VectorDiscreteFunction< DiscreteFunctionSpace, Vector > ThisType;
44 typedef DiscreteFunctionDefault< ThisType > BaseType;
45
46 public:
47 typedef Vector VectorType;
48 typedef typename BaseType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
49 typedef typename BaseType :: DofVectorType DofVectorType;
50 typedef typename DofVectorType :: DofContainerType DofContainerType;
51 typedef typename BaseType :: DofType DofType;
52
53 using BaseType::assign;
54
61 VectorDiscreteFunction( const std::string& name,
62 const DiscreteFunctionSpaceType& space,
63 VectorType& dofVector )
64 : BaseType( name, space ),
65 vec_(),
66 dofVector_( dofVector )
67 {}
68
70 VectorDiscreteFunction( const ThisType& other )
71 : BaseType( "copy of " + other.name(), other.space() ),
72 vec_(),
73 dofVector_( allocateDofVector( other.space() ) )
74 {
75 assign( other );
76 }
77
79 VectorDiscreteFunction( ThisType&& other )
80 : BaseType( static_cast< BaseType && >( other ) ),
81 vec_( std::move( other.vec_ ) ),
82 dofVector_( other.dofVector_ )
83 {}
84
85 VectorDiscreteFunction () = delete;
86 ThisType& operator= ( const ThisType& ) = delete;
87 ThisType& operator= ( ThisType&& ) = delete;
88
89#if HAVE_PETSC
90 void assign( const PetscDiscreteFunction< DiscreteFunctionSpaceType >& g )
91 {
92 g.dofVector().copyTo( dofVector() );
93 }
94#endif
95
97 DofVectorType& dofVector() { return dofVector_; }
98
100 const DofVectorType& dofVector() const { return dofVector_; }
101
102 protected:
103 // allocate managed dof storage
104 VectorType& allocateDofVector ( const DiscreteFunctionSpaceType& space )
105 {
106 vec_.reset( new VectorType( space.size() ) );
107 return *vec_;
108 }
109
110 // pointer to DofContainer
111 std::unique_ptr< VectorType > vec_;
112 // dof vector that stores reference to vector
113 DofVectorType dofVector_;
114 };
115
116 } // namespace Fem
117} // namespace Dune
118
119#include "managedvectorfunction.hh"
120
121#endif // #ifndef DUNE_FEM_VECTORFUNCTION_HH
discrete function space
Traits::DofVectorType DofVectorType
type of DofVector
Definition: discretefunction.hh:631
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
forward declaration
Definition: discretefunction.hh:51
Dune namespace.
Definition: alignedallocator.hh:13
void assign(T &dst, const T &src, bool mask)
masked Simd assignment (scalar version)
Definition: simd.hh:447
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)