Reference documentation for deal.II version 9.5.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
event.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2010 - 2019 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16
17#ifndef dealii_event_h
18#define dealii_event_h
19
20#include <deal.II/base/config.h>
21
22#include <algorithm>
23#include <iostream>
24#include <string>
25#include <vector>
26
28
29namespace Algorithms
30{
49 class Event
50 {
51 public:
57 static Event
58 assign(const std::string &name);
59
64 // static Event find(const std::string& name);
65
69 Event();
70
74 void
75 clear();
76
80 void
81 all();
82
86 Event &
87 operator+=(const Event &event);
88
92 Event &
93 operator-=(const Event &event);
94
99 bool
100 test(const Event &event) const;
101
105 bool
106 any() const;
107
111 template <class OS>
112 void
113 print(OS &os) const;
114
118 template <class OS>
119 static void
120 print_assigned(OS &os);
121
122 private:
128
132 std::vector<bool> flags;
133
137 // TODO: This static field must be guarded by a mutex to be thread-safe!
138 static std::vector<std::string> names;
139 };
140
144 namespace Events
145 {
149 extern const Event initial;
150
154 extern const Event remesh;
155
159 extern const Event bad_derivative;
160
164 extern const Event new_time;
165
169 extern const Event new_timestep_size;
170 } // namespace Events
171
172
173 //----------------------------------------------------------------------//
174
175
176 inline bool
178 {
179 if (all_true)
180 return true;
181 return std::find(flags.begin(), flags.end(), true) != flags.end();
182 }
183
184
185 inline bool
186 Event::test(const Event &event) const
187 {
188 // First, test all_true in this
189 if (all_true)
190 return true;
191
192 const unsigned int n = flags.size();
193 const unsigned int m = event.flags.size();
194 const unsigned int n_min = (n < m) ? n : m;
195
196 // Now, if all_true set in the
197 // other, then all must be true
198 // in this
199 if (event.all_true)
200 {
201 // Non existing flags are
202 // always assumed false
203 if (m > n)
204 return false;
205
206 // Test all flags separately
207 // and return false if one is
208 // not set
209 return std::find(flags.begin(), flags.end(), false) == flags.end();
210 }
211
212 // Finally, compare each flag
213 // separately
214 for (unsigned int i = 0; i < n_min; ++i)
215 if (event.flags[i] && !flags[i])
216 return false;
217 for (unsigned int i = n_min; i < m; ++i)
218 if (event.flags[i])
219 return false;
220 return true;
221 }
222
223
224
225 inline Event &
227 {
228 all_true |= event.all_true;
229 if (all_true)
230 return *this;
231
232 if (flags.size() < event.flags.size())
233 flags.resize(event.flags.size());
234 for (unsigned int i = 0; i < event.flags.size(); ++i)
235 flags[i] = flags[i] || event.flags[i];
236
237 return *this;
238 }
239
240
241 inline Event &
243 {
244 if (!event.any())
245 return *this;
246
247 all_true = false;
248 if (event.all_true)
249 {
250 std::fill(flags.begin(), flags.end(), false);
251 return *this;
252 }
253
254 if (flags.size() < event.flags.size())
255 flags.resize(event.flags.size());
256 for (unsigned int i = 0; i < event.flags.size(); ++i)
257 if (event.flags[i])
258 flags[i] = false;
259
260 return *this;
261 }
262
263
264 template <class OS>
265 inline void
266 Event::print(OS &os) const
267 {
268 if (all_true)
269 os << " ALL";
270
271 for (unsigned int i = 0; i < flags.size(); ++i)
272 if (flags[i])
273 os << ' ' << names[i];
274 }
275
276
277 template <class OS>
278 inline void
280 {
281 for (unsigned int i = 0; i < names.size(); ++i)
282 os << i << '\t' << names[i] << std::endl;
283 }
284
285
291 template <class OS>
292 OS &
293 operator<<(OS &o, const Event &e)
294 {
295 e.print(o);
296 return o;
297 }
298} // namespace Algorithms
299
301
302#endif
bool test(const Event &event) const
Definition event.h:186
bool any() const
Definition event.h:177
static std::vector< std::string > names
Definition event.h:138
void print(OS &os) const
Definition event.h:266
Event & operator+=(const Event &event)
Definition event.h:226
std::vector< bool > flags
Definition event.h:132
Event & operator-=(const Event &event)
Definition event.h:242
static Event assign(const std::string &name)
Definition event.cc:28
static void print_assigned(OS &os)
Definition event.h:279
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
const Event initial
Definition event.cc:65
const Event new_time
Definition event.cc:68
const Event new_timestep_size
Definition event.cc:69
const Event remesh
Definition event.cc:66
const Event bad_derivative
Definition event.cc:67
OutputOperator< VectorType > & operator<<(OutputOperator< VectorType > &out, unsigned int step)
Definition operator.h:165