dune-pdelab  2.0.0
directleaflocalordering.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 
4 #ifndef DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
5 #define DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
6 
7 #include <dune/typetree/leafnode.hh>
8 
9 #include <dune/common/nullptr.hh>
10 #include <dune/geometry/referenceelements.hh>
11 #include <dune/localfunctions/common/interfaceswitch.hh>
12 #include <dune/localfunctions/common/localkey.hh>
16 
17 #include <vector>
18 #include <numeric>
19 
20 namespace Dune {
21  namespace PDELab {
22 
25 
26  template<typename OrderingTag, typename FEM, typename GV, typename DI, typename CI>
28  : public TypeTree::LeafNode
29  , public PartitionInfoProvider
30  {
31 
32  template<typename>
33  friend class LeafGridViewOrdering;
34 
35  template<typename>
36  friend class LeafOrderingBase;
37 
38  template<typename size_type>
39  friend struct ::Dune::PDELab::impl::update_ordering_data;
40 
41  public:
42 
44 
45  private:
46 
47  typedef impl::GridFunctionSpaceOrderingData<typename Traits::SizeType> GFSData;
48 
49  public:
50 
51  void map_local_index(const typename Traits::SizeType geometry_type_index,
52  const typename Traits::SizeType entity_index,
53  typename Traits::TreeIndexView mi,
54  typename Traits::ContainerIndex& ci) const
55  {
56  DUNE_THROW(NotImplemented,"not implemented");
57  }
58 
59  template<typename ItIn, typename ItOut>
60  void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
61  {
62  // don't do anything - this is handled by the specialized GridViewOrdering
63  }
64 
65  template<typename CIOutIterator, typename DIOutIterator = DummyDOFIndexIterator>
66  typename Traits::SizeType
67  extract_entity_indices(const typename Traits::DOFIndex::EntityIndex& ei,
68  typename Traits::SizeType child_index,
69  CIOutIterator ci_out, const CIOutIterator ci_end,
70  DIOutIterator di_out = DIOutIterator()) const
71  {
72  const typename Traits::SizeType s = size(ei);
73 
74  // Handle DOF indices
75  for (typename Traits::SizeType i = 0; i < s; ++i, ++di_out)
76  di_out->treeIndex().push_back(i);
77 
78  // only return the size, as the tree visitor expects that from all leaf nodes.
79  // The actual index processing is done by the specialized GridViewOrdering.
80  return s;
81  }
82 
83  typename Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex& index) const
84  {
85  return size(
86  Traits::DOFIndexAccessor::GeometryIndex::geometryType(index),
87  Traits::DOFIndexAccessor::GeometryIndex::entityIndex(index)
88  );
89  }
90 
91  typename Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
92  {
93  typedef typename Traits::SizeType size_type;
94  if (_fixed_size)
95  return _gt_dof_sizes[geometry_type_index];
96  else if (_gt_used[geometry_type_index])
97  {
98  const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
99  return _entity_dof_offsets[index+1] - _entity_dof_offsets[index];
100  }
101  else
102  return 0;
103  }
104 
105  typename Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
106  {
107  DUNE_THROW(NotImplemented,"not implemented");
108  }
109 
110  typename Traits::SizeType offset(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
111  {
112  assert(child_index == 0);
113  return 0;
114  }
115 
116  DirectLeafLocalOrdering(const shared_ptr<const FEM>& fem, const GV& gv)
117  : _fem(fem)
118  , _gv(gv)
119  , _fixed_size(false)
120  , _container_blocked(false)
121  , _gfs_data(nullptr)
122  {
123  // Extract contained grid PartitionTypes from OrderingTag.
124  this->setPartitionSet(OrderingTag::partition_mask);
125  }
126 
127  const typename Traits::GridView& gridView() const
128  {
129  return _gv;
130  }
131 
132  const FEM& finiteElementMap() const
133  {
134  return *_fem;
135  }
136 
137  private:
138 
139  typedef FiniteElementInterfaceSwitch<
140  typename FEM::Traits::FiniteElement
141  > FESwitch;
142 
143 
144  void update_a_priori_fixed_size()
145  {
146  _fixed_size = (!OrderingTag::no_const_ordering_size) && _fem->fixedSize();
147  }
148 
149  template<typename It>
150  void update_fixed_size(It it, const It end)
151  {
152  assert(_fixed_size);
153 
154  _max_local_size = _fem->maxLocalSize();
155 
156  typedef typename Traits::SizeType size_type;
157  const size_type dim = Traits::GridView::dimension;
158  _codim_used.reset();
159  _gt_used.assign(GlobalGeometryTypeIndex::size(dim),false);
160  _gt_dof_sizes.assign(GlobalGeometryTypeIndex::size(dim),0);
161  for (; it != end; ++it)
162  {
163  size_type size = _fem->size(*it);
164  _gt_dof_sizes[GlobalGeometryTypeIndex::index(*it)] = size;
165  _gt_used[GlobalGeometryTypeIndex::index(*it)] = size > 0;
166  _codim_used[dim - it->dim()] = _codim_used[dim - it->dim()] || (size > 0);
167  }
168 
169  _codim_fixed_size.set();
170  }
171 
172 
173  void pre_collect_used_geometry_types_from_cell()
174  {
175  typedef typename Traits::SizeType size_type;
176  const size_type dim = Traits::GridView::dimension;
177 
178  _codim_used.reset();
179  _gt_used.assign(GlobalGeometryTypeIndex::size(dim),false);
180  _gt_dof_sizes.assign(GlobalGeometryTypeIndex::size(dim),0);
181  _local_gt_dof_sizes.resize(GlobalGeometryTypeIndex::size(dim));
182  _max_local_size = 0;
183  _fixed_size_possible = !OrderingTag::no_const_ordering_size;
184  }
185 
186 
187  void collect_used_geometry_types_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
188  {
189  FESwitch::setStore(_fe_store,_fem->find(cell));
190 
191  const typename FESwitch::Coefficients& coeffs =
192  FESwitch::coefficients(*_fe_store);
193 
194  _max_local_size = std::max(_max_local_size,coeffs.size());
195 
196  const ReferenceElement<typename Traits::GridView::ctype, Traits::GridView::dimension>& ref_el = ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
197 
198  for (std::size_t i = 0; i < coeffs.size(); ++i)
199  {
200  const LocalKey& key = coeffs.localKey(i);
201  GeometryType gt = ref_el.type(key.subEntity(),key.codim());
202  _gt_used[GlobalGeometryTypeIndex::index(gt)] = true;
203  _codim_used.set(key.codim());
204  }
205  }
206 
207 
208  template<typename It>
209  void allocate_entity_offset_vector(It it, const It end)
210  {
211  _gt_entity_offsets.assign(GlobalGeometryTypeIndex::size(GV::dimension) + 1,0);
212  for (; it != end; ++it)
213  {
214  if (_gt_used[GlobalGeometryTypeIndex::index(*it)])
215  _gt_entity_offsets[GlobalGeometryTypeIndex::index(*it) + 1] = _gv.indexSet().size(*it);
216  }
217  std::partial_sum(_gt_entity_offsets.begin(),_gt_entity_offsets.end(),_gt_entity_offsets.begin());
218  _entity_dof_offsets.assign(_gt_entity_offsets.back() + 1,0);
219 
220  // Don't claim fixed size for any codim for now
221  _codim_fixed_size.reset();
222  }
223 
224 
225  void extract_per_entity_sizes_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
226  {
227  if (this->_fixed_size_possible)
228  std::fill(_local_gt_dof_sizes.begin(),_local_gt_dof_sizes.end(),0);
229 
230  FESwitch::setStore(_fe_store,_fem->find(cell));
231 
232  const typename FESwitch::Coefficients& coeffs =
233  FESwitch::coefficients(*_fe_store);
234 
235  typedef typename Traits::SizeType size_type;
236 
237  const ReferenceElement<typename Traits::GridView::ctype,Traits::GridView::dimension>& ref_el =
238  ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
239 
240  for (std::size_t i = 0; i < coeffs.size(); ++i)
241  {
242  const LocalKey& key = coeffs.localKey(i);
243  GeometryType gt = ref_el.type(key.subEntity(),key.codim());
244  const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
245 
246  const size_type entity_index = _gv.indexSet().subIndex(cell,key.subEntity(),key.codim());
247  const size_type index = _gt_entity_offsets[geometry_type_index] + entity_index;
248  _local_gt_dof_sizes[geometry_type_index] = _entity_dof_offsets[index+1] = std::max(_entity_dof_offsets[index+1],static_cast<size_type>(key.index() + 1));
249  }
250 
252  {
253  for (size_type i = 0; i < _local_gt_dof_sizes.size(); ++i)
254  if (_local_gt_dof_sizes[i] > 0)
255  {
256  if (_gt_dof_sizes[i] == 0)
258  else if (_gt_dof_sizes[i] != _local_gt_dof_sizes[i])
259  {
260  _fixed_size_possible = false;
261  break;
262  }
263  }
264  }
265 
266  }
267 
268 
269  void finalize_non_fixed_size_update()
270  {
272  {
273  // free per-entity offsets
274  _entity_dof_offsets = std::vector<typename Traits::SizeType>();
275  _fixed_size = true;
276  _codim_fixed_size.set();
277  }
278  else
279  {
280  // convert per-entity sizes to offsets
281  std::partial_sum(_entity_dof_offsets.begin(),_entity_dof_offsets.end(),_entity_dof_offsets.begin());
282  _fixed_size = false;
283  _codim_fixed_size.reset();
284  }
285  }
286 
287 
288  typename Traits::SizeType maxLocalSize() const
289  {
290  return _max_local_size;
291  }
292 
293  private:
294 
295  bool update_gfs_data_size(typename Traits::SizeType& size, typename Traits::SizeType& block_count) const
296  {
297  return false;
298  }
299 
300  protected:
301 
302  shared_ptr<const FEM> _fem;
303  typename FESwitch::Store _fe_store;
304 
305  GV _gv;
309  const bool _container_blocked;
310 
313  std::vector<bool> _gt_used;
314 
315  std::vector<typename Traits::SizeType> _gt_entity_offsets;
316  std::vector<typename Traits::SizeType> _gt_dof_sizes;
317  std::vector<typename Traits::SizeType> _entity_dof_offsets;
318  std::vector<typename Traits::SizeType> _local_gt_dof_sizes;
319 
320  // This is only here to make the visitor happy that traverses all
321  // Orderings to manipulate the contained GFSData
322  GFSData* _gfs_data;
323 
324  };
325 
327 
328  } // namespace PDELab
329 } // namespace Dune
330 
331 #endif // DUNE_PDELAB_ORDERING_DIRECTLEAFLOCALORDERING_HH
Mixin class for providing information about contained grid partitions.
Definition: partitioninfoprovider.hh:22
Definition: directleaflocalordering.hh:27
LocalOrderingTraits< GV, DI, CI > Traits
Definition: directleaflocalordering.hh:43
std::vector< typename Traits::SizeType > _entity_dof_offsets
Definition: directleaflocalordering.hh:317
DI::size_type SizeType
Definition: ordering/utility.hh:201
Definition: ordering/utility.hh:208
void setPartitionSet(const std::bitset< 6 > &partitions)
Sets the set of contained partitions to the passed-in value.
Definition: partitioninfoprovider.hh:58
CI ContainerIndex
Definition: ordering/utility.hh:160
Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex &index) const
Definition: directleaflocalordering.hh:83
static const int dim
Definition: adaptivity.hh:82
GV _gv
Definition: directleaflocalordering.hh:305
bool _fixed_size
Definition: directleaflocalordering.hh:306
const Traits::GridView & gridView() const
Definition: directleaflocalordering.hh:127
DI::View::TreeIndex TreeIndexView
Definition: ordering/utility.hh:199
Gridview ordering for leaf spaces.
Definition: leafgridviewordering.hh:18
Traits::SizeType _max_local_size
Definition: directleaflocalordering.hh:308
Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
Definition: directleaflocalordering.hh:105
std::vector< typename Traits::SizeType > _local_gt_dof_sizes
Definition: directleaflocalordering.hh:318
std::vector< bool > _gt_used
Definition: directleaflocalordering.hh:313
void map_local_index(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, typename Traits::TreeIndexView mi, typename Traits::ContainerIndex &ci) const
Definition: directleaflocalordering.hh:51
GFSData * _gfs_data
Definition: directleaflocalordering.hh:322
Generic infrastructure for orderings for leaf spaces.
Definition: leaforderingbase.hh:21
GV GridView
Definition: ordering/utility.hh:214
bool _fixed_size_possible
Definition: directleaflocalordering.hh:307
Traits::SizeType offset(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index, const typename Traits::SizeType child_index) const
Definition: directleaflocalordering.hh:110
Traits::SizeType size(const typename Traits::SizeType geometry_type_index, const typename Traits::SizeType entity_index) const
Definition: directleaflocalordering.hh:91
std::vector< typename Traits::SizeType > _gt_dof_sizes
Definition: directleaflocalordering.hh:316
Traits::SizeType extract_entity_indices(const typename Traits::DOFIndex::EntityIndex &ei, typename Traits::SizeType child_index, CIOutIterator ci_out, const CIOutIterator ci_end, DIOutIterator di_out=DIOutIterator()) const
Definition: directleaflocalordering.hh:67
std::vector< typename Traits::SizeType > _gt_entity_offsets
Definition: directleaflocalordering.hh:315
FESwitch::Store _fe_store
Definition: directleaflocalordering.hh:303
Traits::CodimFlag _codim_fixed_size
Definition: directleaflocalordering.hh:312
const FEM & finiteElementMap() const
Definition: directleaflocalordering.hh:132
shared_ptr< const FEM > _fem
Definition: directleaflocalordering.hh:302
Traits::CodimFlag _codim_used
Definition: directleaflocalordering.hh:311
DirectLeafLocalOrdering(const shared_ptr< const FEM > &fem, const GV &gv)
Definition: directleaflocalordering.hh:116
std::bitset< max_dim > CodimFlag
Definition: ordering/utility.hh:194
const bool _container_blocked
Definition: directleaflocalordering.hh:309
const std::string s
Definition: function.hh:1103
void map_lfs_indices(const ItIn begin, const ItIn end, ItOut out) const
Definition: directleaflocalordering.hh:60