FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
filter_sequence.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8#include <deque>
9
10namespace FEAT
11{
12 namespace LAFEM
13 {
29 template<typename Filter_>
30 class FilterSequence : public std::deque<std::pair<String, Filter_>>
31 {
32 public:
34 typedef std::deque<std::pair<String, Filter_>> BaseClass;
35
37 typedef Filter_ InnerFilterType;
39 typedef typename Filter_::DataType DataType;
41 typedef typename Filter_::IndexType IndexType;
42
44 typedef typename Filter_::VectorType VectorType;
45
47 typedef typename BaseClass::iterator iterator;
49 typedef typename BaseClass::const_iterator const_iterator;
50
52 template <typename DT2_, typename IT2_>
54
56 template <typename DT2_, typename IT2_>
58
59 public:
62 {
63 }
64
69 {
70 }
71
79 explicit FilterSequence(const std::deque<String>& ids_)
80 {
81 for(auto it = ids_.begin(); it != ids_.end(); ++it)
82 {
83 String id(*it);
84 InnerFilterType new_filter;
85 BaseClass::push_back(std::make_pair<String, Filter_>(std::move(id), std::move(new_filter)));
86 }
87 }
88
90 BaseClass(std::forward<BaseClass>(other))
91 {
92 }
93
96 {
97 if(this != &other)
98 {
99 static_cast<BaseClass&>(*this) = std::forward<BaseClass>(other);
100 }
101
102 return *this;
103 }
104
107 {
108 FilterSequence result;
109 result.resize(this->size());
110
111 for(size_t i(0); i < result.size(); ++i)
112 {
113 result.at(i).first = this->at(i).first;
114 result.at(i).second.clone(this->at(i).second, clone_mode);
115 }
116
117 return result;
118 }
119
121 void clone(const FilterSequence& other, CloneMode clone_mode = CloneMode::Deep)
122 {
123 BaseClass::clear();
124
125 for(const_iterator it(other.begin()); it != other.end(); ++it)
126 {
127 BaseClass::push_back(std::make_pair<String, InnerFilterType>(it->first, it->second->clone(clone_mode)));
128 }
129 }
130
134 template<typename OtherFilter_>
136 {
137 BaseClass::clear();
138
139 BaseClass::resize(other.size());
140
141 for(size_t i(0); i < this->size(); ++i)
142 {
143 this->at(i).first = other.at(i).first;
144 this->at(i).second.convert(other.at(i).second);
145 }
146 }
147
149 std::size_t bytes() const
150 {
151 std::size_t my_bytes(0);
152
153 for(size_t i(0); i < this->size(); ++i)
154 {
155 my_bytes += this->at(i).second.bytes();
156 }
157
158 return my_bytes;
159 }
160
161 Filter_& find_or_add(const String& name)
162 {
163 for(iterator it(BaseClass::begin()); it != BaseClass::end(); ++it)
164 {
165 if(it->first == name)
166 return it->second;
167 }
168 // if we come out here, we have to add a new sub-filter
169 this->push_back(std::make_pair(name, Filter_()));
170 return this->back().second;
171 }
172
173
175 template<typename Vector_>
176 void filter_rhs(Vector_& vector) const
177 {
178 for(const_iterator it(BaseClass::begin()); it != BaseClass::end(); ++it)
179 it->second.filter_rhs(vector);
180 }
181
183 template<typename Vector_>
184 void filter_sol(Vector_& vector) const
185 {
186 for(const_iterator it(BaseClass::begin()); it != BaseClass::end(); ++it)
187 it->second.filter_sol(vector);
188 }
189
191 template<typename Vector_>
192 void filter_def(Vector_& vector) const
193 {
194 for(const_iterator it(BaseClass::begin()); it != BaseClass::end(); ++it)
195 it->second.filter_def(vector);
196 }
197
199 template<typename Vector_>
200 void filter_cor(Vector_& vector) const
201 {
202 for(const_iterator it(BaseClass::begin()); it != BaseClass::end(); ++it)
203 it->second.filter_cor(vector);
204 }
205
207 template<typename Matrix_>
208 void filter_mat(Matrix_& matrix) const
209 {
210 for(const_iterator it(BaseClass::begin()); it != BaseClass::end(); ++it)
211 it->second.filter_mat(matrix);
212 }
213 }; // class FilterSequence
214
215 } // namespace LAFEM
216} // namespace FEAT
Sequence of filters of the same type.
FilterSequence & operator=(FilterSequence &&other)
move-assign operator
void clone(const FilterSequence &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another FilterSequence.
Filter_ InnerFilterType
The type of the filter that gets applied in sequence.
std::deque< std::pair< String, Filter_ > > BaseClass
Our baseclass.
FilterSequence(const std::deque< String > &ids_)
Constructs a FilterSequence of empty filters.
void convert(const FilterSequence< OtherFilter_ > &other)
Converts another FilterSequence to this type.
void filter_mat(Matrix_ &matrix) const
Applies the filter onto a system matrix.
virtual ~FilterSequence()
Empty virtual destructor.
BaseClass::const_iterator const_iterator
Use the baseclass' const_iterator.
FilterSequence()
Empty default constructor.
void filter_def(Vector_ &vector) const
Applies the filter onto a defect vector.
Filter_::DataType DataType
The filter's floating point type.
void filter_cor(Vector_ &vector) const
Applies the filter onto a correction vector.
Filter_::IndexType IndexType
The filter's index type.
FilterSequence clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
void filter_rhs(Vector_ &vector) const
Applies the filter onto the right-hand-side vector.
void filter_sol(Vector_ &vector) const
Applies the filter onto the solution vector.
std::size_t bytes() const
Returns the total amount of bytes allocated.
Filter_::VectorType VectorType
The type of vector the filter can be applied to.
BaseClass::iterator iterator
Use the baseclass' iterator.
String class implementation.
Definition: string.hpp:46
FEAT namespace.
Definition: adjactor.hpp:12