deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\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// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2010 - 2019 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#ifndef dealii_event_h
15#define dealii_event_h
16
17#include <deal.II/base/config.h>
18
19#include <algorithm>
20#include <iostream>
21#include <string>
22#include <vector>
23
25
26namespace Algorithms
27{
47 {
48 public:
54 static Event
55 assign(const std::string &name);
56
61 // static Event find(const std::string& name);
62
66 Event();
67
71 void
72 clear();
73
77 void
78 all();
79
83 Event &
84 operator+=(const Event &event);
85
89 Event &
90 operator-=(const Event &event);
91
96 bool
97 test(const Event &event) const;
98
102 bool
103 any() const;
104
108 template <class OS>
109 void
110 print(OS &os) const;
111
115 template <class OS>
116 static void
117 print_assigned(OS &os);
118
119 private:
125
129 std::vector<bool> flags;
130
134 // TODO: This static field must be guarded by a mutex to be thread-safe!
135 static std::vector<std::string> names;
136 };
137
141 namespace Events
142 {
146 extern const Event initial;
147
151 extern const Event remesh;
152
156 extern const Event bad_derivative;
157
161 extern const Event new_time;
162
166 extern const Event new_timestep_size;
167 } // namespace Events
168
169
170 //----------------------------------------------------------------------//
171
172
173 inline bool
175 {
176 if (all_true)
177 return true;
178 return std::find(flags.begin(), flags.end(), true) != flags.end();
179 }
180
181
182 inline bool
183 Event::test(const Event &event) const
184 {
185 // First, test all_true in this
186 if (all_true)
187 return true;
188
189 const unsigned int n = flags.size();
190 const unsigned int m = event.flags.size();
191 const unsigned int n_min = (n < m) ? n : m;
192
193 // Now, if all_true set in the
194 // other, then all must be true
195 // in this
196 if (event.all_true)
197 {
198 // Non existing flags are
199 // always assumed false
200 if (m > n)
201 return false;
202
203 // Test all flags separately
204 // and return false if one is
205 // not set
206 return std::find(flags.begin(), flags.end(), false) == flags.end();
207 }
208
209 // Finally, compare each flag
210 // separately
211 for (unsigned int i = 0; i < n_min; ++i)
212 if (event.flags[i] && !flags[i])
213 return false;
214 for (unsigned int i = n_min; i < m; ++i)
215 if (event.flags[i])
216 return false;
217 return true;
218 }
219
220
221
222 inline Event &
224 {
225 all_true |= event.all_true;
226 if (all_true)
227 return *this;
228
229 if (flags.size() < event.flags.size())
230 flags.resize(event.flags.size());
231 for (unsigned int i = 0; i < event.flags.size(); ++i)
232 flags[i] = flags[i] || event.flags[i];
233
234 return *this;
235 }
236
237
238 inline Event &
240 {
241 if (!event.any())
242 return *this;
243
244 all_true = false;
245 if (event.all_true)
246 {
247 std::fill(flags.begin(), flags.end(), false);
248 return *this;
249 }
250
251 if (flags.size() < event.flags.size())
252 flags.resize(event.flags.size());
253 for (unsigned int i = 0; i < event.flags.size(); ++i)
254 if (event.flags[i])
255 flags[i] = false;
256
257 return *this;
258 }
259
260
261 template <class OS>
262 inline void
263 Event::print(OS &os) const
264 {
265 if (all_true)
266 os << " ALL";
267
268 for (unsigned int i = 0; i < flags.size(); ++i)
269 if (flags[i])
270 os << ' ' << names[i];
271 }
272
273
274 template <class OS>
275 inline void
277 {
278 for (unsigned int i = 0; i < names.size(); ++i)
279 os << i << '\t' << names[i] << std::endl;
280 }
281
282
288 template <class OS>
289 OS &
290 operator<<(OS &o, const Event &e)
291 {
292 e.print(o);
293 return o;
294 }
295} // namespace Algorithms
296
298
299#endif
bool test(const Event &event) const
Definition event.h:183
bool any() const
Definition event.h:174
static std::vector< std::string > names
Definition event.h:135
void print(OS &os) const
Definition event.h:263
Event & operator+=(const Event &event)
Definition event.h:223
std::vector< bool > flags
Definition event.h:129
Event & operator-=(const Event &event)
Definition event.h:239
static void print_assigned(OS &os)
Definition event.h:276
#define DEAL_II_DEPRECATED
Definition config.h:294
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
const Event initial
Definition event.cc:69
const Event new_time
Definition event.cc:72
const Event new_timestep_size
Definition event.cc:73
const Event remesh
Definition event.cc:70
const Event bad_derivative
Definition event.cc:71
OutputOperator< VectorType > & operator<<(OutputOperator< VectorType > &out, unsigned int step)
Definition operator.h:163