1 #ifndef DUNE_FEM_SPACE_PADAPTIVE_LAGRANGE_HH 2 #define DUNE_FEM_SPACE_PADAPTIVE_LAGRANGE_HH 3 4 #include <dune/fem/common/hybrid.hh> 5 #include <dune/fem/space/common/defaultcommhandler.hh> 6 #include <dune/fem/space/lagrange/shapefunctionset.hh> 7 #include <dune/fem/space/mapper/nonblockmapper.hh> 8 #include <dune/fem/space/lagrange/interpolation.hh> 9 10 #include "adaptmanager.hh" 11 #include "declaration.hh" 12 #include "generic.hh" 13 #include "mapper.hh" 14 #include "restrictprolong.hh" 15 16 17 namespace Dune 18 { 19 20 namespace Fem 21 { 22 23 /** \addtogroup PAdaptiveLagrangeSpace 24 * 25 * Provides access to base function sets for different element types in 26 * one grid and size of function space and maps from local to global dof 27 * number. 28 * 29 * \note This space can only be used with special index sets. If you want 30 * to use the PAdaptiveLagrangeSpace with an index set only 31 * supporting the index set interface you will have to use the 32 * IndexSetWrapper class to provide the required functionality. 33 * 34 * \note For adaptive calculations one has to use index sets that are 35 * capable of adaption (i.e. the method adaptive returns true). See also 36 * AdaptiveLeafIndexSet. 37 */ 38 39 // PAdaptiveLagrangeSpaceTraits 40 // ---------------------------- 41 42 template< class FunctionSpace, class GridPart, int maxPolOrder, class Storage > 43 struct PAdaptiveLagrangeSpaceTraits 44 { 45 static_assert((maxPolOrder > 0), "LagrangeSpace only defined for maxPolOrder > 0" ); 46 47 typedef PAdaptiveLagrangeSpace< FunctionSpace, GridPart, maxPolOrder, Storage > DiscreteFunctionSpaceType; 48 49 typedef FunctionSpace FunctionSpaceType; 50 typedef GridPart GridPartType; 51 52 static const int polynomialOrder = maxPolOrder; 53 54 static const bool continuousSpace = true ; 55 typedef Hybrid::IndexRange< int, FunctionSpaceType::dimRange > LocalBlockIndices; 56 57 typedef PAdaptiveLagrangeMapper< GridPartType, polynomialOrder > BlockMapperType; 58 59 typedef LagrangePointSet< GridPartType, polynomialOrder > CompiledLocalKeyType; 60 61 static const int codimension = 0; 62 63 private: 64 typedef typename GridPartType::template Codim< codimension >::EntityType EntityType; 65 66 static const int dimLocal = GridPartType::dimension; 67 typedef typename FunctionSpace::ScalarFunctionSpaceType ScalarFunctionSpaceType; 68 typedef typename ToNewDimDomainFunctionSpace< ScalarFunctionSpaceType, dimLocal >::Type ShapeFunctionSpaceType; 69 70 typedef LagrangeShapeFunctionInterface< ShapeFunctionSpaceType > ShapeFunctionType; 71 typedef SimpleShapeFunctionSet< ShapeFunctionType > SimpleShapeFunctionSetType; 72 73 public: 74 typedef SelectCachingShapeFunctionSet< SimpleShapeFunctionSetType, Storage > ScalarShapeFunctionSetType; 75 76 template< int pOrd > 77 struct ScalarShapeFunctionSetFactory 78 { 79 struct Type 80 { createObjectDune::Fem::PAdaptiveLagrangeSpaceTraits::ScalarShapeFunctionSetFactory::Type81 static ScalarShapeFunctionSetType *createObject ( const GeometryType &type ) 82 { 83 typedef LagrangeShapeFunctionFactory< ShapeFunctionSpaceType, maxPolOrder > SimpleShapeFunctionSetFactoryType; 84 return new ScalarShapeFunctionSetType( type, SimpleShapeFunctionSetType( SimpleShapeFunctionSetFactoryType( type, pOrd ) ) ); 85 } 86 deleteObjectDune::Fem::PAdaptiveLagrangeSpaceTraits::ScalarShapeFunctionSetFactory::Type87 static void deleteObject ( ScalarShapeFunctionSetType *object ) { delete object; } 88 }; 89 }; 90 91 typedef ShapeFunctionSetProxy< ScalarShapeFunctionSetType > ScalarShapeFunctionSetProxyType; 92 typedef VectorialShapeFunctionSet< ScalarShapeFunctionSetProxyType, typename FunctionSpaceType::RangeType > ShapeFunctionSetType; 93 94 typedef Dune::Fem::DefaultBasisFunctionSet< EntityType, ShapeFunctionSetType > BasisFunctionSetType; 95 96 template< class DiscreteFunction, class Operation = DFCommunicationOperation::Add > 97 struct CommDataHandle 98 { 99 typedef DefaultCommunicationHandler< DiscreteFunction, Operation > Type; 100 typedef Operation OperationType; 101 }; 102 }; 103 104 105 106 // PAdaptiveLagrangeSpace 107 // ---------------------- 108 109 /** \class PAdaptiveLagrangeSpace 110 * 111 * \ingroup PAdaptiveLagrangeSpace 112 * 113 * \brief Lagrange discrete function space 114 */ 115 template< class FunctionSpace, class GridPart, int maxPolOrder, class Storage = CachingStorage > 116 class PAdaptiveLagrangeSpace 117 : public GenericDiscreteFunctionSpace< PAdaptiveLagrangeSpaceTraits< FunctionSpace, GridPart, maxPolOrder, Storage > > 118 { 119 typedef PAdaptiveLagrangeSpace< FunctionSpace, GridPart, maxPolOrder, Storage > ThisType; 120 typedef GenericDiscreteFunctionSpace< PAdaptiveLagrangeSpaceTraits< FunctionSpace, GridPart, maxPolOrder, Storage > > BaseType; 121 122 public: 123 typedef ThisType PAdaptiveLagrangeSpaceType; 124 125 typedef typename BaseType::Traits Traits; 126 127 typedef typename BaseType::GridPartType GridPartType; 128 typedef typename BaseType::IntersectionType IntersectionType; 129 typedef typename BaseType::BasisFunctionSetType BasisFunctionSetType; 130 typedef typename BaseType::EntityType EntityType; 131 132 typedef typename BaseType::CompiledLocalKeyType CompiledLocalKeyType; 133 typedef CompiledLocalKeyType LagrangePointSetType; 134 135 typedef LagrangeLocalInterpolation< GridPartType, maxPolOrder, BasisFunctionSetType > InterpolationImplType; 136 typedef LocalInterpolationWrapper< ThisType > InterpolationType; 137 138 public: 139 using BaseType::blockMapper; 140 using BaseType::compiledLocalKey; 141 using BaseType::continuous; 142 using BaseType::gridPart; 143 using BaseType::order; 144 using BaseType::basisFunctionSet; 145 146 // default communication interface 147 static const InterfaceType defaultInterface = InteriorBorder_InteriorBorder_Interface; 148 // default communication direction 149 static const CommunicationDirection defaultDirection = ForwardCommunication; 150 151 /** \brief constructor 152 * 153 * \param[in] gridPart grid part for the Lagrange space 154 * \param[in] order dynamically set maximal polynomial order between 1 and maxPolOrder 155 * \param[in] commInterface communication interface to use (optional) 156 * \param[in] commDirection communication direction to use (optional) 157 */ PAdaptiveLagrangeSpace(GridPartType & gridPart,const int order,const InterfaceType commInterface=defaultInterface,const CommunicationDirection commDirection=defaultDirection)158 explicit PAdaptiveLagrangeSpace ( GridPartType &gridPart, 159 const int order, 160 const InterfaceType commInterface = defaultInterface, 161 const CommunicationDirection commDirection = defaultDirection ) 162 : BaseType( gridPart, order, commInterface, commDirection ) 163 {} 164 165 /** \brief constructor 166 * 167 * \param[in] gridPart grid part for the Lagrange space 168 * \param[in] commInterface communication interface to use (optional) 169 * \param[in] commDirection communication direction to use (optional) 170 */ PAdaptiveLagrangeSpace(GridPartType & gridPart,const InterfaceType commInterface=defaultInterface,const CommunicationDirection commDirection=defaultDirection)171 explicit PAdaptiveLagrangeSpace ( GridPartType &gridPart, 172 const InterfaceType commInterface = defaultInterface, 173 const CommunicationDirection commDirection = defaultDirection ) 174 : BaseType( gridPart, maxPolOrder, commInterface, commDirection ) 175 {} 176 177 // copy constructor needed for p-adaption PAdaptiveLagrangeSpace(const PAdaptiveLagrangeSpace & other)178 PAdaptiveLagrangeSpace ( const PAdaptiveLagrangeSpace &other ) 179 : BaseType( other ) 180 {} 181 182 /** @copydoc Dune::Fem::DiscreteFunctionSpaceInterface::continuous */ continuous(const IntersectionType & intersection) const183 bool continuous (const IntersectionType &intersection) const 184 { 185 if ( order() > 0 && intersection.conforming()) 186 { 187 return true; 188 if (intersection.neighbor()) 189 return (order(intersection.inside()) == order(intersection.outside())); 190 else 191 return true; 192 } 193 return false; 194 } 195 196 /** \brief provide access to the Lagrange point set for an entity 197 * 198 * \note This method is not part of the DiscreteFunctionSpaceInterface. It 199 * is unique to the LagrangeDiscreteFunctionSpace. 200 * 201 * \param[in] entity entity the Lagrange point set is requested for 202 * 203 * \returns LagrangePointSet 204 */ 205 template< class EntityType > lagrangePointSet(const EntityType & entity) const206 const CompiledLocalKeyType &lagrangePointSet ( const EntityType &entity ) const 207 { 208 return compiledLocalKey( entity.type(), blockMapper().polynomOrder( entity ) ); 209 } 210 interpolation() const211 InterpolationType interpolation () const 212 { 213 return InterpolationType( *this ); 214 } 215 216 [[deprecated]] interpolation(const EntityType & entity) const217 InterpolationImplType interpolation ( const EntityType &entity ) const 218 { 219 return localInterpolation( entity ); 220 } 221 localInterpolation(const EntityType & entity) const222 InterpolationImplType localInterpolation ( const EntityType &entity ) const 223 { 224 return InterpolationImplType( lagrangePointSet( entity ), basisFunctionSet( entity ) ); 225 } 226 227 }; 228 229 } // namespace Fem 230 231 } // namespace Dune 232 233 #endif // #ifndef DUNE_FEM_SPACE_PADAPTIVE_LAGRANGE_HH 234