1 #ifndef DUNE_FEM_MANAGEDVECTORFUNCTION_HH 2 #define DUNE_FEM_MANAGEDVECTORFUNCTION_HH 3 4 #include <memory> 5 #include <string> 6 7 #include <dune/fem/function/vectorfunction/vectorfunction.hh> 8 #include <dune/fem/space/common/dofmanager.hh> 9 #include <dune/fem/space/mapper/nonblockmapper.hh> 10 11 namespace Dune 12 { 13 14 namespace Fem 15 { 16 17 // MemObject 18 // --------- 19 20 struct MemObject 21 { 22 template< class DofContainer, class DiscreteFunctionSpace > 23 DofContainer &allocate ( const DiscreteFunctionSpace &space ) 24 { 25 typedef MutableBlockVector< DofContainer, DiscreteFunctionSpace::localBlockSize > DofVector; 26 auto result = allocateManagedDofStorage( space.gridPart().grid(), space.blockMapper(), static_cast< DofVector * >( nullptr ) ); 27 interface_.reset( result.first ); 28 return result.second->array(); 29 } 30 enableDofCompressionDune::Fem::MemObject31 void enableDofCompression () 32 { 33 if( interface_ ) 34 interface_->enableDofCompression(); 35 } 36 37 private: 38 std::unique_ptr< DofStorageInterface > interface_; 39 }; 40 41 42 43 44 // ManagedDiscreteFunction 45 // ----------------------- 46 47 template< class DiscreteFunctionSpace, 48 class Vector > 49 class ManagedDiscreteFunction 50 < VectorDiscreteFunction< DiscreteFunctionSpace, Vector > > 51 : private MemObject, 52 public VectorDiscreteFunction< DiscreteFunctionSpace, Vector > 53 { 54 typedef VectorDiscreteFunction< DiscreteFunctionSpace, Vector > BaseType; 55 typedef ManagedDiscreteFunction< BaseType > ThisType; 56 57 public: 58 typedef ThisType DiscreteFunctionType; 59 60 typedef typename BaseType :: DiscreteFunctionSpaceType DiscreteFunctionSpaceType; 61 typedef typename BaseType :: DofVectorType DofVectorType; 62 typedef typename BaseType :: DofContainerType DofContainerType; 63 64 typedef typename DiscreteFunctionSpaceType :: GridPartType :: GridType GridType; 65 66 using BaseType :: name; 67 ManagedDiscreteFunction(const std::string & name,const DiscreteFunctionSpaceType & dfSpace)68 ManagedDiscreteFunction ( const std::string &name, const DiscreteFunctionSpaceType &dfSpace ) 69 : BaseType( name, dfSpace, MemObject::allocate< DofContainerType >( dfSpace ) ) 70 {} 71 ManagedDiscreteFunction(const BaseType & other)72 explicit ManagedDiscreteFunction ( const BaseType &other ) 73 : BaseType( other.name(), other.space(), MemObject::allocate< DofContainerType >( other.space() ) ) 74 { 75 BaseType :: assign ( other ); 76 } 77 ManagedDiscreteFunction(const ThisType & other)78 ManagedDiscreteFunction ( const ThisType &other ) 79 : BaseType( other.name(), other.space(), MemObject::allocate< DofContainerType >( other.space() ) ) 80 { 81 BaseType :: assign ( other ); 82 } 83 84 ManagedDiscreteFunction ( ThisType && ) = default; 85 enableDofCompression()86 void enableDofCompression () { MemObject::enableDofCompression(); } 87 }; 88 89 } // namespace Fem 90 91 } // namespace Dune 92 93 #endif // #ifndef DUNE_FEM_MANAGEDVECTORFUNCTION_HH 94