DUNE PDELab (git)

constraintstransformation.hh
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_CONSTRAINTS_COMMON_CONSTRAINTSTRANSFORMATION_HH
4#define DUNE_PDELAB_CONSTRAINTS_COMMON_CONSTRAINTSTRANSFORMATION_HH
5
6#include <algorithm>
7#include <unordered_map>
8
9namespace Dune {
10 namespace PDELab {
11
15
17 template<typename DI, typename CI, typename F>
19 : public std::unordered_map<CI,std::unordered_map<CI,F> >
20 {
21
22 typedef std::unordered_map<CI,std::unordered_map<CI,F> > BaseT;
23
24 public:
26 typedef F ElementType;
27 typedef F Field;
28
29 class LocalTransformation
30 : public std::unordered_map<DI,std::unordered_map<DI,F> >
31 {
32
33 public:
34
35 typedef F ElementType;
36 typedef F Field;
37
38 typedef std::unordered_map<DI,F> RowType;
39
40 bool containsNonDirichletConstraints() const
41 {
42 return std::any_of(
43 this->begin(), this->end(),
44 [] (const std::pair<DI,RowType> & c)
45 -> bool { return (!c.second.empty()); });
46 }
47
48 };
49
51 typedef typename ConstraintsTransformation::mapped_type RowType;
52
54 : _contains_non_dirichlet_constraints(false)
55 {}
56
57 void clear()
58 {
59 BaseT::clear();
60 _contains_non_dirichlet_constraints = false;
61 }
62
63 template<typename IndexCache>
64 void import_local_transformation(const LocalTransformation& local_transformation, const IndexCache& index_cache)
65 {
66 typedef typename IndexCache::ContainerIndex ContainerIndex;
67 typedef typename ConstraintsTransformation::iterator GlobalConstraintIterator;
68 typedef typename ConstraintsTransformation::mapped_type GlobalConstraint;
69
70 for (const auto& local_constraint : local_transformation)
71 {
72 const ContainerIndex& ci = index_cache.containerIndex(local_constraint.first);
73
74 std::pair<GlobalConstraintIterator,bool> r =
75 this->insert(make_pair(ci,GlobalConstraint()));
76
77 GlobalConstraint& global_constraint = r.first->second;
78
79 // Don't modify an existing Dirichlet constraint
80 if (!r.second && global_constraint.empty())
81 continue;
82
83 // The new constraint is a Dirichlet constraint
84 // Clear out any existing entries in the global constraint and stop
85 if (local_constraint.second.empty())
86 {
87 global_constraint.clear();
88 continue;
89 }
90
91 // We have a non-Dirichlet constraint
92 _contains_non_dirichlet_constraints = true;
93
94 // Accumulate new entries into global constraint
95 for (const auto& local_entry : local_constraint.second)
96 global_constraint[index_cache.containerIndex(local_entry.first)] = local_entry.second;
97 }
98 }
99
100 bool containsNonDirichletConstraints() const
101 {
102 return _contains_non_dirichlet_constraints;
103 }
104
105 private:
106
107 bool _contains_non_dirichlet_constraints;
108
109 };
110
111 class EmptyTransformation : public ConstraintsTransformation<char,char,char>
112 {
113
114 public:
115
116 bool containsNonDirichletConstraints() const
117 {
118 return false;
119 }
120
121 };
122
124 } // namespace PDELab
125} // namespace Dune
126
127#endif // DUNE_PDELAB_CONSTRAINTS_COMMON_CONSTRAINTSTRANSFORMATION_HH
a class holding transformation for constrained spaces
Definition: constraintstransformation.hh:20
ConstraintsTransformation::mapped_type RowType
export RowType
Definition: constraintstransformation.hh:51
F ElementType
export ElementType
Definition: constraintstransformation.hh:26
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)