1 #ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_LEGENDRE_HH
2 #define DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_LEGENDRE_HH
3 
4 #include <dune/grid/common/gridenums.hh>
5 
6 #include <dune/fem/operator/matrix/istlmatrixadapter.hh>
7 #include <dune/fem/space/common/capabilities.hh>
8 #include <dune/fem/space/common/commoperations.hh>
9 #include <dune/fem/space/common/defaultcommhandler.hh>
10 #include <dune/fem/space/common/localrestrictprolong.hh>
11 #include <dune/fem/space/discontinuousgalerkin/localrestrictprolong.hh>
12 
13 #include <dune/fem/space/shapefunctionset/selectcaching.hh>
14 #include <dune/fem/space/basisfunctionset/hpdg/legendre.hh>
15 
16 #include "blockmapper.hh"
17 #include "space.hh"
18 
19 namespace Dune
20 {
21 
22   namespace Fem
23   {
24 
25     namespace hpDG
26     {
27 
28       // Internal forward declaration
29       // ----------------------------
30 
31       template< class FunctionSpace, class GridPart, int order, class Storage = Fem::CachingStorage >
32       class LegendreDiscontinuousGalerkinSpace;
33 
34       template< class FunctionSpace, class GridPart, int order, class Storage = Fem::CachingStorage >
35       class HierarchicLegendreDiscontinuousGalerkinSpace;
36 
37 
38 #ifndef DOXYGEN
39 
40       // LegendreDiscontinuousGalerkinSpaceTraits
41       // ----------------------------------------
42 
43       template< class FunctionSpace, class GridPart, int order, bool hierarchicalOrdering, class Storage >
44       struct LegendreDiscontinuousGalerkinSpaceTraits
45       {
46         // select space implementation depending on basis function ordering
47         typedef typename std::conditional< hierarchicalOrdering,
48             HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage >,
49             LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage > >::type  DiscreteFunctionSpaceType;
50 
51         using FunctionSpaceType = FunctionSpace;
52 
53         using GridPartType = GridPart;
54 
55         using BasisFunctionSetsType = hpDG::LegendreBasisFunctionSets< FunctionSpaceType, GridPartType, order, hierarchicalOrdering, Storage >;
56         using BasisFunctionSetType = typename BasisFunctionSetsType::BasisFunctionSetType;
57 
58         static const int codimension = BasisFunctionSetType::EntityType::codimension;
59 
60         using BlockMapperType = hpDG::DiscontinuousGalerkinBlockMapper< GridPartType, BasisFunctionSetsType >;
61         static const int localBlockSize = BasisFunctionSetsType::localBlockSize;
62 
63         typedef Hybrid::IndexRange< int, localBlockSize > LocalBlockIndices;
64 
65         template< class DiscreteFunction, class Operation = Dune::Fem::DFCommunicationOperation::Copy >
66         struct CommDataHandle
67         {
68           using OperationType = Operation;
69           using Type = Dune::Fem::DefaultCommunicationHandler< DiscreteFunction, Operation >;
70         };
71       };
72 
73 #endif // #ifndef DOXYGEN
74 
75 
76 
77       // LegendreDiscontinuousGalerkinSpace
78       // ----------------------------------
79 
80       /** \brief Implementation of an \f$hp\f$-adaptive discrete function space using product Legendre polynomials
81        *
82        *  \tparam FunctionSpace  a Dune::Fem::FunctionSpace
83        *  \tparam GridPart  a Dune::Fem::GridPart
84        *  \tparam order  maximum polynomial order per coordinate
85        *  \tparam Storage  for certain caching features
86        *
87        *  \ingroup DiscreteFunctionSpace_Implementation_Legendre
88        */
89       template< class FunctionSpace, class GridPart, int order, class Storage >
90       class LegendreDiscontinuousGalerkinSpace
91       : public hpDG::DiscontinuousGalerkinSpace< LegendreDiscontinuousGalerkinSpaceTraits< FunctionSpace, GridPart, order, false, Storage > >
92       {
93         using BaseType = hpDG::DiscontinuousGalerkinSpace< LegendreDiscontinuousGalerkinSpaceTraits< FunctionSpace, GridPart, order, false, Storage > >;
94 
95       public:
96         using GridPartType = typename BaseType::GridPartType;
97         using BasisFunctionSetsType = typename BaseType::BasisFunctionSetsType;
98 
LegendreDiscontinuousGalerkinSpace(GridPartType & gridPart,const Dune::InterfaceType interface=Dune::InteriorBorder_All_Interface,const Dune::CommunicationDirection direction=Dune::ForwardCommunication)99         explicit LegendreDiscontinuousGalerkinSpace ( GridPartType &gridPart,
100                                                       const Dune::InterfaceType interface = Dune::InteriorBorder_All_Interface,
101                                                       const Dune::CommunicationDirection direction = Dune::ForwardCommunication )
102           : BaseType( gridPart, BasisFunctionSetsType{}, order, interface, direction )
103         {}
104 
105         template< class Function >
LegendreDiscontinuousGalerkinSpace(GridPartType & gridPart,Function function,const Dune::InterfaceType interface=Dune::InteriorBorder_All_Interface,const Dune::CommunicationDirection direction=Dune::ForwardCommunication)106         LegendreDiscontinuousGalerkinSpace ( GridPartType &gridPart, Function function,
107                                              const Dune::InterfaceType interface = Dune::InteriorBorder_All_Interface,
108                                              const Dune::CommunicationDirection direction = Dune::ForwardCommunication )
109           : BaseType( gridPart, BasisFunctionSetsType{}, order, function, interface, direction )
110         {}
111       };
112 
113       // HierarchicLegendreDiscontinuousGalerkinSpace
114       // --------------------------------------------
115 
116       /** \brief Implementation of an \f$hp\f$-adaptive discrete function space using product Legendre polynomials
117        *
118        *  \tparam FunctionSpace  a Dune::Fem::FunctionSpace
119        *  \tparam GridPart  a Dune::Fem::GridPart
120        *  \tparam order  maximum polynomial order per coordinate
121        *  \tparam Storage  for certain caching features
122        *
123        *  \ingroup DiscreteFunctionSpace_Implementation_Legendre
124        */
125       template< class FunctionSpace, class GridPart, int order, class Storage >
126       class HierarchicLegendreDiscontinuousGalerkinSpace
127       : public hpDG::DiscontinuousGalerkinSpace< LegendreDiscontinuousGalerkinSpaceTraits< FunctionSpace, GridPart, order, true, Storage > >
128       {
129         using BaseType = hpDG::DiscontinuousGalerkinSpace< LegendreDiscontinuousGalerkinSpaceTraits< FunctionSpace, GridPart, order, true, Storage > >;
130 
131       public:
132         using GridPartType = typename BaseType::GridPartType;
133         using EntityType   = typename BaseType::EntityType;
134         using BasisFunctionSetsType = typename BaseType::BasisFunctionSetsType;
135 
HierarchicLegendreDiscontinuousGalerkinSpace(GridPartType & gridPart,const Dune::InterfaceType interface=Dune::InteriorBorder_All_Interface,const Dune::CommunicationDirection direction=Dune::ForwardCommunication)136         explicit HierarchicLegendreDiscontinuousGalerkinSpace ( GridPartType &gridPart,
137                                                                 const Dune::InterfaceType interface = Dune::InteriorBorder_All_Interface,
138                                                                 const Dune::CommunicationDirection direction = Dune::ForwardCommunication )
139           : BaseType( gridPart, BasisFunctionSetsType{}, order, interface, direction )
140         {}
141 
142         template <class Function,
143                   std::enable_if_t<
144                     std::is_arithmetic<
145                       decltype(Function(std::declval<const EntityType>()))>::value,int> i=0>
HierarchicLegendreDiscontinuousGalerkinSpace(GridPartType & gridPart,Function function,const Dune::InterfaceType interface=Dune::InteriorBorder_All_Interface,const Dune::CommunicationDirection direction=Dune::ForwardCommunication)146         HierarchicLegendreDiscontinuousGalerkinSpace ( GridPartType &gridPart, Function function,
147                                                        const Dune::InterfaceType interface = Dune::InteriorBorder_All_Interface,
148                                                        const Dune::CommunicationDirection direction = Dune::ForwardCommunication )
149           : BaseType( gridPart, BasisFunctionSetsType{}, order, function, interface, direction )
150         {}
151       };
152 
153      } // namespace hpDG
154 
155 
156 
157 #ifndef DOXYGEN
158 
159      // DefaultLocalRestrictProlong
160      // ---------------------------
161 
162     template< class FunctionSpace, class GridPart, int order, class Storage >
163     class DefaultLocalRestrictProlong< hpDG::LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage > >
164     : public DiscontinuousGalerkinLocalRestrictProlong< hpDG::LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage >, false >
165     {
166       using BaseType = DiscontinuousGalerkinLocalRestrictProlong< hpDG::LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage >, false >;
167 
168     public:
DefaultLocalRestrictProlong(const typename BaseType::DiscreteFunctionSpaceType & space)169       explicit DefaultLocalRestrictProlong ( const typename BaseType::DiscreteFunctionSpaceType &space )
170         : BaseType( space )
171       {}
172     };
173 
174 
175      // DefaultLocalRestrictProlong
176      // ---------------------------
177 
178     template< class FunctionSpace, class GridPart, int order, class Storage >
179     class DefaultLocalRestrictProlong< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage > >
180     : public DiscontinuousGalerkinLocalRestrictProlong< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage >, false >
181     {
182       using BaseType = DiscontinuousGalerkinLocalRestrictProlong< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, order, Storage >, false >;
183 
184     public:
DefaultLocalRestrictProlong(const typename BaseType::DiscreteFunctionSpaceType & space)185       explicit DefaultLocalRestrictProlong ( const typename BaseType::DiscreteFunctionSpaceType &space )
186         : BaseType( space )
187       {}
188     };
189 
190 
191 #endif // #ifndef DOXYGEN
192 
193 
194     namespace Capabilities
195     {
196       ////////////////////////////////////////////////////////////////////
197       //  hpDG::LegendreDiscontinuousGalerkinSpace
198       ////////////////////////////////////////////////////////////////////
199 
200       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
201       struct hasStaticPolynomialOrder< hpDG::LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
202       {
203         static const bool v = true;
204         static const int order = polOrder;
205       };
206 
207       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
208       struct isLocalized< hpDG::LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
209       {
210         static const bool v = true;
211       };
212 
213       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
214       struct isAdaptive< hpDG::LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
215       {
216         static const bool v = true;
217       };
218 
219       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
220       struct viewThreadSafe< hpDG::LegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
221       {
222         static const bool v = true;
223       };
224 
225       ////////////////////////////////////////////////////////////////////
226       //  hpDG::HierarchicLegendreDiscontinuousGalerkinSpace
227       ////////////////////////////////////////////////////////////////////
228 
229       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
230       struct hasStaticPolynomialOrder< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
231       {
232         static const bool v = true;
233         static const int order = polOrder;
234       };
235 
236       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
237       struct isLocalized< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
238       {
239         static const bool v = true;
240       };
241 
242       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
243       struct isAdaptive< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
244       {
245         static const bool v = true;
246       };
247 
248       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
249       struct viewThreadSafe< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
250       {
251         static const bool v = true;
252       };
253 
254       template< class FunctionSpace, class GridPart, int polOrder, class Storage >
255       struct isHierarchic< hpDG::HierarchicLegendreDiscontinuousGalerkinSpace< FunctionSpace, GridPart, polOrder, Storage > >
256       {
257         static const bool v = true;
258       };
259 
260     } // namespace Capabilities
261 
262   } // namespace Fem
263 
264 } // namespace Dune
265 
266 #endif // #ifndef DUNE_FEM_HPDG_SPACE_DISCONTINUOUSGALERKIN_LEGENDRE_HH
267