dune-pdelab  2.0.0
common/constraintstransformation.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 #ifndef DUNE_PDELAB_GRIDFUNCTIONSPACE_CONSTRAINTSTRANSFORMATION_HH
4 #define DUNE_PDELAB_GRIDFUNCTIONSPACE_CONSTRAINTSTRANSFORMATION_HH
5 
6 #include <dune/common/tuples.hh>
8 
9 namespace Dune {
10  namespace PDELab {
11 
15 
17  template<typename DI, typename CI, typename F>
19  : public unordered_map<CI,unordered_map<CI,F> >
20  {
21 
23 
24  public:
26  typedef F ElementType;
27  typedef F Field;
28 
30  : public unordered_map<DI,unordered_map<DI,F> >
31  {
32 
33  public:
34 
35  typedef F ElementType;
36  typedef F Field;
37 
39 
41  {
42  // if any row is not empty, there are non-Dirichlet constraints
43  // TODO: replace with std::any_of + lambda after 2.0 release
44  typedef typename LocalTransformation::const_iterator It;
45  for (It it = this->begin(),
46  end = this->end();
47  it != end;
48  ++it)
49  if (!it->second.empty())
50  return true;
51  return false;
52  }
53 
54  };
55 
57  typedef typename ConstraintsTransformation::mapped_type RowType;
58 
60  : _contains_non_dirichlet_constraints(false)
61  {}
62 
63  void clear()
64  {
65  BaseT::clear();
66  _contains_non_dirichlet_constraints = false;
67  }
68 
69  template<typename IndexCache>
70  void import_local_transformation(const LocalTransformation& local_transformation, const IndexCache& index_cache)
71  {
72  typedef typename IndexCache::ContainerIndex ContainerIndex;
73  typedef typename ConstraintsTransformation::iterator GlobalConstraintIterator;
74  typedef typename ConstraintsTransformation::mapped_type GlobalConstraint;
75  typedef typename LocalTransformation::const_iterator LocalConstraintIterator;
76  typedef typename LocalTransformation::mapped_type::const_iterator LocalEntryIterator;
77 
78  for (LocalConstraintIterator lc_it = local_transformation.begin(),
79  lc_end = local_transformation.end();
80  lc_it != lc_end;
81  ++lc_it)
82  {
83  const ContainerIndex& ci = index_cache.containerIndex(lc_it->first);
84 
85  std::pair<GlobalConstraintIterator,bool> r =
86  this->insert(make_pair(ci,GlobalConstraint()));
87 
88  GlobalConstraint& global_constraint = r.first->second;
89 
90  // Don't modify an existing Dirichlet constraint
91  if (!r.second && global_constraint.empty())
92  continue;
93 
94  // The new constraint is a Dirichlet constraint
95  // Clear out any existing entries in the global constraint and stop
96  if (lc_it->second.empty())
97  {
98  global_constraint.clear();
99  continue;
100  }
101 
102  // We have a non-Dirichlet constraint
103  _contains_non_dirichlet_constraints = true;
104 
105  // Accumulate new entries into global constraint
106  for (LocalEntryIterator le_it = lc_it->second.begin(),
107  le_end = lc_it->second.end();
108  le_it != le_end;
109  ++le_it)
110  {
111  global_constraint[index_cache.containerIndex(le_it->first)] = le_it->second;
112  }
113  }
114  }
115 
117  {
118  return _contains_non_dirichlet_constraints;
119  }
120 
121  private:
122 
123  bool _contains_non_dirichlet_constraints;
124 
125  };
126 
127  class EmptyTransformation : public ConstraintsTransformation<char,char,char>
128  {
129 
130  public:
131 
133  {
134  return false;
135  }
136 
137  };
138 
140  } // namespace PDELab
141 } // namespace Dune
142 
143 #endif // DUNE_PDELAB_GRIDFUNCTIONSPACE_CONSTRAINTSTRANSFORMATION_HH
Definition: common/constraintstransformation.hh:29
Provide common name for std::unordered_map and std::unordered_multimap classes in Dune::PDELab namesp...
bool containsNonDirichletConstraints() const
Definition: common/constraintstransformation.hh:132
bool containsNonDirichletConstraints() const
Definition: common/constraintstransformation.hh:116
Definition: common/constraintstransformation.hh:127
a class holding transformation for constrained spaces
Definition: common/constraintstransformation.hh:18
F ElementType
export ElementType
Definition: common/constraintstransformation.hh:26
ConstraintsTransformation()
Definition: common/constraintstransformation.hh:59
bool containsNonDirichletConstraints() const
Definition: common/constraintstransformation.hh:40
unordered_map< DI, F > RowType
Definition: common/constraintstransformation.hh:38
F Field
Definition: common/constraintstransformation.hh:27
ConstraintsTransformation::mapped_type RowType
export RowType
Definition: common/constraintstransformation.hh:57
void import_local_transformation(const LocalTransformation &local_transformation, const IndexCache &index_cache)
Definition: common/constraintstransformation.hh:70
F ElementType
Definition: common/constraintstransformation.hh:35
Definition: unordered_map.hh:46
void clear()
Definition: common/constraintstransformation.hh:63
F Field
Definition: common/constraintstransformation.hh:36