dune-pdelab  2.5-dev
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  private:
78 
79  typedef FiniteElementInterfaceSwitch<
80  typename FEM::Traits::FiniteElement
81  > FESwitch;
82 
83  void collect_used_geometry_types_from_cell(const typename Traits::EntitySet::Element& cell)
84  {
85  FESwitch::setStore(_pfe,_fem->find(cell));
86 
87  const typename FESwitch::Coefficients& coeffs =
88  FESwitch::coefficients(*_pfe);
89 
90  this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
91 
92  const auto& ref_el =
93  ReferenceElements<typename Traits::EntitySet::Traits::CoordinateField,Traits::EntitySet::dimension>::general(cell.type());
94 
95  for (std::size_t i = 0; i < coeffs.size(); ++i)
96  {
97  const LocalKey& key = coeffs.localKey(i);
98  Dune::GeometryType gt = ref_el.type(key.subEntity(),key.codim());
99  this->_gt_used[GlobalGeometryTypeIndex::index(gt)] = true;
100  this->_codim_used.set(key.codim());
101  }
102  }
103 
104 
105  void extract_per_entity_sizes_from_cell(const typename Traits::EntitySet::Element& cell,
106  std::vector<typename Traits::SizeType>& gt_sizes)
107  {
108  if (this->_fixed_size_possible)
109  std::fill(gt_sizes.begin(),gt_sizes.end(),0);
110 
111  FESwitch::setStore(_pfe,_fem->find(cell));
112 
113  const typename FESwitch::Coefficients& coeffs =
114  FESwitch::coefficients(*_pfe);
115 
116  this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
117 
118  typedef typename Traits::SizeType size_type;
119 
120  const auto& ref_el =
121  ReferenceElements<typename Traits::EntitySet::Traits::CoordinateField,Traits::EntitySet::dimension>::general(cell.type());
122 
123  for (std::size_t i = 0; i < coeffs.size(); ++i)
124  {
125  const LocalKey& key = coeffs.localKey(i);
126  GeometryType gt = ref_el.type(key.subEntity(),key.codim());
127  const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
128 
129  const size_type entity_index = _es.indexSet().subIndex(cell,key.subEntity(),key.codim());
130  const size_type index = this->_gt_entity_offsets[geometry_type_index] + entity_index;
131  gt_sizes[geometry_type_index] = this->_entity_dof_offsets[index] = std::max(this->_entity_dof_offsets[index],static_cast<size_type>(key.index() + 1));
132  }
133 
134  if (this->_fixed_size_possible)
135  {
136  for (size_type i = 0; i < gt_sizes.size(); ++i)
137  {
138  if (gt_sizes[i] > 0)
139  {
140  if (this->_gt_dof_offsets[i] == 0)
141  this->_gt_dof_offsets[i] = gt_sizes[i];
142  else if (this->_gt_dof_offsets[i] != gt_sizes[i])
143  {
144  this->_fixed_size_possible = false;
145  break;
146  }
147  }
148  else
149  {
150  // catch special case where some grid entities sometimes don't have any DOFs associated with
151  // them, but are const size if there are any DOFs, i.e. a pattern of #(DOFs) == 0 || #(DOFs) == c > 0
152  this->_fixed_size_possible = this->_fixed_size_possible && (this->_gt_dof_offsets[i] == 0);
153  }
154  }
155  }
156  }
157 
158  std::shared_ptr<const FEM> _fem;
159  ES _es;
160  typename FESwitch::Store _pfe;
161 
162  };
163 
164  template<typename GFS, typename Transformation, typename Params>
165  struct leaf_gfs_to_local_ordering_descriptor<GFS,Transformation,LeafOrderingTag<Params> >
166  {
167 
168  static const bool recursive = false;
169 
170  typedef LeafLocalOrdering<
171  typename GFS::Traits::OrderingTag,
172  typename GFS::Traits::FiniteElementMap,
173  typename GFS::Traits::EntitySet,
174  typename Transformation::DOFIndex,
175  typename Transformation::ContainerIndex
177 
178  typedef std::shared_ptr<transformed_type> transformed_storage_type;
179 
180  static transformed_type transform(const GFS& gfs, const Transformation& t)
181  {
182  return transformed_type(gfs.finiteElementMapStorage(),gfs.entitySet(),false,&const_cast<GFS*>(gfs));
183  }
184 
185  static transformed_storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t)
186  {
187  return std::make_shared<transformed_type>(gfs->finiteElementMapStorage(),gfs->entitySet(),false,const_cast<GFS*>(gfs.get()));
188  }
189 
190  };
191 
193 
194  } // namespace PDELab
195 } // namespace Dune
196 
197 #endif // DUNE_PDELAB_ORDERING_LEAFLOCALORDERING_HH
Definition: localorderingbase.hh:19
void update_a_priori_fixed_size()
Definition: leaflocalordering.hh:67
std::size_t SizeType
Definition: ordering/utility.hh:162
ES EntitySet
Definition: ordering/utility.hh:214
std::vector< typename Traits::SizeType > _entity_dof_offsets
Definition: localorderingbase.hh:360
const FEM & finiteElementMap() const
Definition: leaflocalordering.hh:54
static transformed_storage_type transform_storage(std::shared_ptr< const GFS > gfs, const Transformation &t)
Definition: leaflocalordering.hh:185
void collect_used_codims(CodimMask &codims) const
Definition: leaflocalordering.hh:60
bool _fixed_size_possible
Definition: localorderingbase.hh:348
Definition: leaflocalordering.hh:21
std::vector< typename Traits::SizeType > _gt_dof_offsets
Definition: localorderingbase.hh:359
For backward compatibility – Do not use this!
Definition: adaptivity.hh:27
typename ES::GridView GridView
Definition: ordering/utility.hh:215
LeafLocalOrdering(const std::shared_ptr< const FEM > &fem, const ES &es, bool backend_blocked, typename BaseT::GFSData *gfs_data)
Definition: leaflocalordering.hh:38
std::vector< bool > _gt_used
Definition: localorderingbase.hh:356
bool _fixed_size
Definition: localorderingbase.hh:347
Traits::CodimFlag _codim_used
Definition: localorderingbase.hh:355
Definition: ordering/utility.hh:208
const Traits::EntitySet & entitySet() const
Definition: leaflocalordering.hh:44
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: leaflocalordering.hh:180
std::vector< typename Traits::SizeType > _gt_entity_offsets
Definition: localorderingbase.hh:358
const Traits::GridView & gridView() const
Definition: leaflocalordering.hh:49
Tag indicating a standard ordering for a leaf GridfunctionSpace.
Definition: gridfunctionspace/tags.hh:183
LeafLocalOrdering< typename GFS::Traits::OrderingTag, typename GFS::Traits::FiniteElementMap, typename GFS::Traits::EntitySet, typename Transformation::DOFIndex, typename Transformation::ContainerIndex > transformed_type
Definition: leaflocalordering.hh:176
std::shared_ptr< transformed_type > transformed_storage_type
Definition: leaflocalordering.hh:178
std::size_t index
Definition: interpolate.hh:118
BaseT::Traits Traits
Definition: leaflocalordering.hh:36
void setup_fixed_size_possible()
Definition: leaflocalordering.hh:72
impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: localorderingbase.hh:61
std::size_t _max_local_size
Definition: localorderingbase.hh:350