dune-pdelab  2.0.0
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 GV, typename DI, typename CI>
22  : public TypeTree::LeafNode
23  , public LocalOrderingBase<GV,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 shared_ptr<const FEM>& fem, const GV& gv, bool backend_blocked, typename BaseT::GFSData* gfs_data)
39  : BaseT(*this,backend_blocked,gfs_data)
40  , _fem(fem)
41  , _gv(gv)
42  {
43  // Extract contained grid PartitionTypes from OrderingTag.
44  this->setPartitionSet(OrderingTag::partition_mask);
45  }
46 
47  const typename Traits::GridView& gridView() const
48  {
49  return _gv;
50  }
51 
52  const FEM& finiteElementMap() const
53  {
54  return *_fem;
55  }
56 
58  {
59  this->_fixed_size = (!OrderingTag::no_const_ordering_size) && _fem->fixedSize();
60  }
61 
63  {
64  this->_fixed_size_possible = !OrderingTag::no_const_ordering_size;
65  }
66 
67  private:
68 
69  typedef FiniteElementInterfaceSwitch<
70  typename FEM::Traits::FiniteElement
71  > FESwitch;
72 
73  void collect_used_geometry_types_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell)
74  {
75  FESwitch::setStore(_pfe,_fem->find(cell));
76 
77  const typename FESwitch::Coefficients& coeffs =
78  FESwitch::coefficients(*_pfe);
79 
80  this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
81 
82  const ReferenceElement<typename Traits::GridView::ctype,Traits::GridView::dimension>& ref_el =
83  ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
84 
85  for (std::size_t i = 0; i < coeffs.size(); ++i)
86  {
87  const LocalKey& key = coeffs.localKey(i);
88  Dune::GeometryType gt = ref_el.type(key.subEntity(),key.codim());
89  this->_gt_used[GlobalGeometryTypeIndex::index(gt)] = true;
90  this->_codim_used.set(key.codim());
91  }
92  }
93 
94 
95  void extract_per_entity_sizes_from_cell(const typename Traits::GridView::template Codim<0>::Entity& cell,
96  std::vector<typename Traits::SizeType>& gt_sizes)
97  {
98  if (this->_fixed_size_possible)
99  std::fill(gt_sizes.begin(),gt_sizes.end(),0);
100 
101  FESwitch::setStore(_pfe,_fem->find(cell));
102 
103  const typename FESwitch::Coefficients& coeffs =
104  FESwitch::coefficients(*_pfe);
105 
106  this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
107 
108  typedef typename Traits::SizeType size_type;
109 
110  const ReferenceElement<typename Traits::GridView::ctype,Traits::GridView::dimension>& ref_el =
111  ReferenceElements<typename Traits::GridView::ctype,Traits::GridView::dimension>::general(cell.type());
112 
113  for (std::size_t i = 0; i < coeffs.size(); ++i)
114  {
115  const LocalKey& key = coeffs.localKey(i);
116  GeometryType gt = ref_el.type(key.subEntity(),key.codim());
117  const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
118 
119  const size_type entity_index = _gv.indexSet().subIndex(cell,key.subEntity(),key.codim());
120  const size_type index = this->_gt_entity_offsets[geometry_type_index] + entity_index;
121  gt_sizes[geometry_type_index] = this->_entity_dof_offsets[index] = std::max(this->_entity_dof_offsets[index],static_cast<size_type>(key.index() + 1));
122  }
123 
124  if (this->_fixed_size_possible)
125  {
126  for (size_type i = 0; i < gt_sizes.size(); ++i)
127  if (gt_sizes[i] > 0)
128  {
129  if (this->_gt_dof_offsets[i] == 0)
130  this->_gt_dof_offsets[i] = gt_sizes[i];
131  else if (this->_gt_dof_offsets[i] != gt_sizes[i])
132  {
133  this->_fixed_size_possible = false;
134  break;
135  }
136  }
137  }
138  }
139 
140  shared_ptr<const FEM> _fem;
141  GV _gv;
142  typename FESwitch::Store _pfe;
143 
144  };
145 
146  template<typename GFS, typename Transformation, typename Params>
147  struct leaf_gfs_to_local_ordering_descriptor<GFS,Transformation,LeafOrderingTag<Params> >
148  {
149 
150  static const bool recursive = false;
151 
152  typedef LeafLocalOrdering<
153  typename GFS::Traits::OrderingTag,
154  typename GFS::Traits::FiniteElementMap,
155  typename GFS::Traits::GridView,
156  typename Transformation::DOFIndex,
157  typename Transformation::ContainerIndex
159 
160  typedef shared_ptr<transformed_type> transformed_storage_type;
161 
162  static transformed_type transform(const GFS& gfs, const Transformation& t)
163  {
164  return transformed_type(gfs.finiteElementMapStorage(),gfs.gridView(),false,&const_cast<GFS*>(gfs));
165  }
166 
167  static transformed_storage_type transform_storage(shared_ptr<const GFS> gfs, const Transformation& t)
168  {
169  return make_shared<transformed_type>(gfs->finiteElementMapStorage(),gfs->gridView(),false,const_cast<GFS*>(gfs.get()));
170  }
171 
172  };
173 
175 
176  } // namespace PDELab
177 } // namespace Dune
178 
179 #endif // DUNE_PDELAB_ORDERING_LEAFLOCALORDERING_HH
LeafLocalOrdering< typename GFS::Traits::OrderingTag, typename GFS::Traits::FiniteElementMap, typename GFS::Traits::GridView, typename Transformation::DOFIndex, typename Transformation::ContainerIndex > transformed_type
Definition: leaflocalordering.hh:158
DI::size_type SizeType
Definition: ordering/utility.hh:201
LeafLocalOrdering(const shared_ptr< const FEM > &fem, const GV &gv, bool backend_blocked, typename BaseT::GFSData *gfs_data)
Definition: leaflocalordering.hh:38
Definition: ordering/utility.hh:208
Tag indicating a standard ordering for a leaf GridfunctionSpace.
Definition: gridfunctionspace/tags.hh:216
void setPartitionSet(const std::bitset< 6 > &partitions)
Sets the set of contained partitions to the passed-in value.
Definition: partitioninfoprovider.hh:58
Definition: leaflocalordering.hh:21
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: leaflocalordering.hh:162
const Traits::GridView & gridView() const
Definition: leaflocalordering.hh:47
Definition: localorderingbase.hh:20
impl::GridFunctionSpaceOrderingData< typename Traits::SizeType > GFSData
Definition: localorderingbase.hh:63
static transformed_storage_type transform_storage(shared_ptr< const GFS > gfs, const Transformation &t)
Definition: leaflocalordering.hh:167
shared_ptr< transformed_type > transformed_storage_type
Definition: leaflocalordering.hh:160
std::vector< typename Traits::SizeType > _gt_entity_offsets
Definition: localorderingbase.hh:360
Traits::CodimFlag _codim_used
Definition: localorderingbase.hh:357
bool _fixed_size
Definition: localorderingbase.hh:349
GV GridView
Definition: ordering/utility.hh:214
BaseT::Traits Traits
Definition: leaflocalordering.hh:36
std::vector< bool > _gt_used
Definition: localorderingbase.hh:358
void setup_fixed_size_possible()
Definition: leaflocalordering.hh:62
std::size_t _max_local_size
Definition: localorderingbase.hh:352
const FEM & finiteElementMap() const
Definition: leaflocalordering.hh:52
bool _fixed_size_possible
Definition: localorderingbase.hh:350
std::vector< typename Traits::SizeType > _gt_dof_offsets
Definition: localorderingbase.hh:361
std::vector< typename Traits::SizeType > _entity_dof_offsets
Definition: localorderingbase.hh:362
void update_a_priori_fixed_size()
Definition: leaflocalordering.hh:57