DUNE PDELab (git)

leaflocalordering.hh
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>
12#include <dune/pdelab/ordering/localorderingbase.hh>
13
14namespace Dune {
15 namespace PDELab {
16
19
20 template<typename OrderingTag, typename FEM, typename ES, typename DI, typename CI>
21 class LeafLocalOrdering
22 : public TypeTree::LeafNode
23 , public LocalOrderingBase<ES,DI,CI>
24 {
25
26 template<typename>
27 friend struct collect_used_geometry_types_from_cell_visitor;
28
29 template<typename>
30 friend struct extract_per_entity_sizes_from_cell_visitor;
31
32 typedef LocalOrderingBase<ES,DI,CI> BaseT;
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
67 void update_a_priori_fixed_size()
68 {
69 this->_fixed_size = _fem->fixedSize();
70 }
71
72 void setup_fixed_size_possible()
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 // notice that we keep the finite element alive on this scope (important if rvalue)
103 const auto& fe = _fem->find(cell);
104 const typename FESwitch::Coefficients& coeffs = FESwitch::coefficients(fe);
105
106 this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
107
108 const auto& ref_el =
110
111 for (std::size_t i = 0; i < coeffs.size(); ++i)
112 {
113 const LocalKey& key = coeffs.localKey(i);
114 Dune::GeometryType gt = ref_el.type(key.subEntity(),key.codim());
115 this->_gt_used[GlobalGeometryTypeIndex::index(gt)] = true;
116 this->_codim_used.set(key.codim());
117 }
118 }
119
120
121 void extract_per_entity_sizes_from_cell(const typename Traits::EntitySet::Element& cell,
122 std::vector<typename Traits::SizeType>& gt_sizes)
123 {
124 if (this->_fixed_size_possible)
125 std::fill(gt_sizes.begin(),gt_sizes.end(),0);
126
127 // notice that we keep the finite element alive on this scope (important if rvalue)
128 const auto& fe = _fem->find(cell);
129 const typename FESwitch::Coefficients& coeffs = FESwitch::coefficients(fe);
130
131 this->_max_local_size = std::max(this->_max_local_size,coeffs.size());
132
133 typedef typename Traits::SizeType size_type;
134
135 const auto& ref_el =
137
138 for (std::size_t i = 0; i < coeffs.size(); ++i)
139 {
140 const LocalKey& key = coeffs.localKey(i);
141 GeometryType gt = ref_el.type(key.subEntity(),key.codim());
142 const size_type geometry_type_index = GlobalGeometryTypeIndex::index(gt);
143
144 const size_type entity_index = _es.indexSet().subIndex(cell,key.subEntity(),key.codim());
145 const size_type index = this->_gt_entity_offsets[geometry_type_index] + entity_index;
146 gt_sizes[geometry_type_index] = this->_entity_dof_offsets[index] = std::max(this->_entity_dof_offsets[index],static_cast<size_type>(key.index() + 1));
147 }
148
149 if (this->_fixed_size_possible)
150 {
151 for (size_type i = 0; i < gt_sizes.size(); ++i)
152 {
153 if (this->_gt_dof_offsets[i] == this->GT_UNUSED)
154 this->_gt_dof_offsets[i] = gt_sizes[i];
155 else if (this->_gt_dof_offsets[i] != gt_sizes[i])
156 {
157 this->_fixed_size_possible = false;
158 break;
159 }
160 }
161 }
162 }
163
164 std::shared_ptr<const FEM> _fem;
165 ES _es;
166
167 };
168
169 template<typename GFS, typename Transformation, typename Params>
170 struct leaf_gfs_to_local_ordering_descriptor<GFS,Transformation,LeafOrderingTag<Params> >
171 {
172
173 static const bool recursive = false;
174
175 typedef LeafLocalOrdering<
176 typename GFS::Traits::OrderingTag,
177 typename GFS::Traits::FiniteElementMap,
178 typename GFS::Traits::EntitySet,
179 typename Transformation::DOFIndex,
180 typename Transformation::ContainerIndex
181 > transformed_type;
182
183 typedef std::shared_ptr<transformed_type> transformed_storage_type;
184
185 static transformed_type transform(const GFS& gfs, const Transformation& t)
186 {
187 return transformed_type(gfs.finiteElementMapStorage(),gfs.entitySet(),false,&const_cast<GFS*>(gfs));
188 }
189
190 static transformed_storage_type transform_storage(std::shared_ptr<const GFS> gfs, const Transformation& t)
191 {
192 return std::make_shared<transformed_type>(gfs->finiteElementMapStorage(),gfs->entitySet(),false,const_cast<GFS*>(gfs.get()));
193 }
194
195 };
196
198
199 } // namespace PDELab
200} // namespace Dune
201
202#endif // DUNE_PDELAB_ORDERING_LEAFLOCALORDERING_HH
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
static constexpr std::size_t index(const GeometryType &gt)
Compute the index for the given geometry type over all dimensions.
Definition: typeindex.hh:138
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
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
static const Coefficients & coefficients(const FiniteElement &fe)
access coefficients
Definition: interfaceswitch.hh:45
FiniteElement::Traits::Coefficients Coefficients
export the type of the coefficients
Definition: interfaceswitch.hh:36
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:156
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)