dune-pdelab  2.7-git
leaflocalordering.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_LEAFLOCALORDERING_HH
5 #define DUNE_PDELAB_ORDERING_LEAFLOCALORDERING_HH
6 
7 #include <dune/typetree/leafnode.hh>
8 
9 #include <dune/geometry/referenceelements.hh>
10 #include <dune/localfunctions/common/interfaceswitch.hh>
11 #include <dune/localfunctions/common/localkey.hh>
13 
14 namespace Dune {
15  namespace PDELab {
16 
19 
20  template<typename OrderingTag, typename FEM, typename ES, typename DI, typename CI>
22  : public TypeTree::LeafNode
23  , public LocalOrderingBase<ES,DI,CI>
24  {
25 
26  template<typename>
28 
29  template<typename>
31 
33 
34  public:
35 
36  typedef typename BaseT::Traits Traits;
37 
38  LeafLocalOrdering(const std::shared_ptr<const FEM>& fem, const ES& es, bool backend_blocked, typename BaseT::GFSData* gfs_data)
39  : BaseT(*this,backend_blocked,gfs_data)
40  , _fem(fem)
41  , _es(es)
42  {}
43 
44  const typename Traits::EntitySet& entitySet() const
45  {
46  return _es;
47  }
48 
49  const typename Traits::GridView& gridView() const
50  {
51  return _es.gridView();
52  }
53 
54  const FEM& finiteElementMap() const
55  {
56  return *_fem;
57  }
58 
59  template<typename CodimMask>
60  void collect_used_codims(CodimMask& codims) const
61  {
62  for (typename ES::dim_type codim = 0; codim <= ES::dimension; ++codim)
63  if (_fem->hasDOFs(codim))
64  codims.set(codim);
65  }
66 
68  {
69  this->_fixed_size = _fem->fixedSize();
70  }
71 
73  {
74  this->_fixed_size_possible = true;
75  }
76 
77  using BaseT::size;
78 
88  typename Traits::SizeType
89  size(const typename Traits::ContainerIndex& suffix,
90  const typename Traits::DOFIndex::EntityIndex &index) const {
91  return this->node_size(*this,suffix,index);
92  }
93 
94  private:
95 
96  typedef FiniteElementInterfaceSwitch<
97  typename FEM::Traits::FiniteElement
98  > FESwitch;
99 
100  void collect_used_geometry_types_from_cell(const typename Traits::EntitySet::Element& cell)
101  {
102  FESwitch::setStore(_pfe,_fem->find(cell));
103 
104  const typename FESwitch::Coefficients& coeffs =
105  FESwitch::coefficients(*_pfe);
106 
107  this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
108 
109  const auto& ref_el =
110  ReferenceElements<typename Traits::EntitySet::Traits::CoordinateField,Traits::EntitySet::dimension>::general(cell.type());
111 
112  for (std::size_t i = 0; i < coeffs.size(); ++i)
113  {
114  const LocalKey& key = coeffs.localKey(i);
115  Dune::GeometryType gt = ref_el.type(key.subEntity(),key.codim());
116  this->_gt_used[GlobalGeometryTypeIndex::index(gt)] = true;
117  this->_codim_used.set(key.codim());
118  }
119  }
120 
121 
122  void extract_per_entity_sizes_from_cell(const typename Traits::EntitySet::Element& cell,
123  std::vector<typename Traits::SizeType>& gt_sizes)
124  {
125  if (this->_fixed_size_possible)
126  std::fill(gt_sizes.begin(),gt_sizes.end(),0);
127 
128  FESwitch::setStore(_pfe,_fem->find(cell));
129 
130  const typename FESwitch::Coefficients& coeffs =
131  FESwitch::coefficients(*_pfe);
132 
133  this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
134 
135  typedef typename Traits::SizeType size_type;
136 
137  const auto& ref_el =
138  ReferenceElements<typename Traits::EntitySet::Traits::CoordinateField,Traits::EntitySet::dimension>::general(cell.type());
139 
140  for (std::size_t i = 0; i < coeffs.size(); ++i)
141  {
142  const LocalKey& key = coeffs.localKey(i);
143  GeometryType gt = ref_el.type(key.subEntity(),key.codim());
144  const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
145 
146  const size_type entity_index = _es.indexSet().subIndex(cell,key.subEntity(),key.codim());
147  const size_type index = this->_gt_entity_offsets[geometry_type_index] + entity_index;
148  gt_sizes[geometry_type_index] = this->_entity_dof_offsets[index] = std::max(this->_entity_dof_offsets[index],static_cast<size_type>(key.index() + 1));
149  }
150 
151  if (this->_fixed_size_possible)
152  {
153  for (size_type i = 0; i < gt_sizes.size(); ++i)
154  {
155  if (this->_gt_dof_offsets[i] == this->GT_UNUSED)
156  this->_gt_dof_offsets[i] = gt_sizes[i];
157  else if (this->_gt_dof_offsets[i] != gt_sizes[i])
158  {
159  this->_fixed_size_possible = false;
160  break;
161  }
162  }
163  }
164  }
165 
166  std::shared_ptr<const FEM> _fem;
167  ES _es;
168  typename FESwitch::Store _pfe;
169 
170  };
171 
172  template<typename GFS, typename Transformation, typename Params>
173  struct leaf_gfs_to_local_ordering_descriptor<GFS,Transformation,LeafOrderingTag<Params> >
174  {
175 
176  static const bool recursive = false;
177 
178  typedef LeafLocalOrdering<
179  typename GFS::Traits::OrderingTag,
180  typename GFS::Traits::FiniteElementMap,
181  typename GFS::Traits::EntitySet,
182  typename Transformation::DOFIndex,
183  typename Transformation::ContainerIndex
185 
186  typedef std::shared_ptr<transformed_type> transformed_storage_type;
187 
188  static transformed_type transform(const GFS& gfs, const Transformation& t)
189  {
190  return transformed_type(gfs.finiteElementMapStorage(),gfs.entitySet(),false,&const_cast<GFS*>(gfs));
191  }
192 
193  static transformed_storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t)
194  {
195  return std::make_shared<transformed_type>(gfs->finiteElementMapStorage(),gfs->entitySet(),false,const_cast<GFS*>(gfs.get()));
196  }
197 
198  };
199 
201 
202  } // namespace PDELab
203 } // namespace Dune
204 
205 #endif // DUNE_PDELAB_ORDERING_LEAFLOCALORDERING_HH
std::size_t index
Definition: interpolate.hh:97
For backward compatibility – Do not use this!
Definition: adaptivity.hh:28
Tag indicating a standard ordering for a leaf GridfunctionSpace.
Definition: gridfunctionspace/tags.hh:185
Definition: leaflocalordering.hh:24
const FEM & finiteElementMap() const
Definition: leaflocalordering.hh:54
Traits::SizeType size(const typename Traits::ContainerIndex &suffix, const typename Traits::DOFIndex::EntityIndex &index) const
Returns the size for a given suffix.
Definition: leaflocalordering.hh:89
const Traits::EntitySet & entitySet() const
Definition: leaflocalordering.hh:44
const Traits::GridView & gridView() const
Definition: leaflocalordering.hh:49
void collect_used_codims(CodimMask &codims) const
Definition: leaflocalordering.hh:60
BaseT::Traits Traits
Definition: leaflocalordering.hh:36
LeafLocalOrdering(const std::shared_ptr< const FEM > &fem, const ES &es, bool backend_blocked, typename BaseT::GFSData *gfs_data)
Definition: leaflocalordering.hh:38
void setup_fixed_size_possible()
Definition: leaflocalordering.hh:72
void update_a_priori_fixed_size()
Definition: leaflocalordering.hh:67
LeafLocalOrdering< typename GFS::Traits::OrderingTag, typename GFS::Traits::FiniteElementMap, typename GFS::Traits::EntitySet, typename Transformation::DOFIndex, typename Transformation::ContainerIndex > transformed_type
Definition: leaflocalordering.hh:184
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: leaflocalordering.hh:188
std::shared_ptr< transformed_type > transformed_storage_type
Definition: leaflocalordering.hh:186
static transformed_storage_type transform_storage(std::shared_ptr< const GFS > gfs, const Transformation &t)
Definition: leaflocalordering.hh:193
Entity-wise orderings.
Definition: localorderingbase.hh:30
std::vector< typename Traits::SizeType > _gt_entity_offsets
Definition: localorderingbase.hh:448
bool _fixed_size_possible
Definition: localorderingbase.hh:438
Traits::SizeType node_size(const Node &node, typename Traits::ContainerIndex suffix, const typename Traits::DOFIndex::EntityIndex &index) const
Gives the size for a given entity and suffix.
Definition: localorderingbase.hh:287
Traits::SizeType size(const typename Traits::DOFIndex::EntityIndex &index) const
Definition: localorderingbase.hh:229
friend struct collect_used_geometry_types_from_cell
Definition: localorderingbase.hh:46
bool _fixed_size
Definition: localorderingbase.hh:437
std::vector< bool > _gt_used
Definition: localorderingbase.hh:446
Traits::CodimFlag _codim_used
Definition: localorderingbase.hh:445
friend struct extract_per_entity_sizes_from_cell
Definition: localorderingbase.hh:49
impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: localorderingbase.hh:69
std::vector< typename Traits::SizeType > _gt_dof_offsets
Definition: localorderingbase.hh:449
static constexpr auto GT_UNUSED
Definition: localorderingbase.hh:65
std::size_t _max_local_size
Definition: localorderingbase.hh:440
std::vector< typename Traits::SizeType > _entity_dof_offsets
Definition: localorderingbase.hh:450
CI ContainerIndex
Definition: ordering/utility.hh:176
DI::size_type SizeType
Definition: ordering/utility.hh:218
Definition: ordering/utility.hh:224
typename ES::GridView GridView
Definition: ordering/utility.hh:227
ES EntitySet
Definition: ordering/utility.hh:226