AutoPas  3.0.0
Loading...
Searching...
No Matches
IteratorBehavior.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <set>
10
13
14namespace autopas {
15inline namespace options {
20class IteratorBehavior : public Option<IteratorBehavior> {
21 public:
25 using Value_t = unsigned int;
26
30 enum Value : Value_t {
34 owned = 0b00001,
38 halo = 0b00010,
42 ownedOrHalo = 0b00011,
46 dummy = 0b00100,
54 forceSequential = 0b01000,
58 containerOnly = 0b10000,
59 };
60
61 // sanity checks
62 // combined values should be equivalent to the disjunction of their elements
63 static_assert((owned | halo) == ownedOrHalo, "Iterator behaviors are defined with non matching values!");
64 static_assert((owned | halo | dummy) == ownedOrHaloOrDummy,
65 "Iterator behaviors are defined with non matching values!");
66 // forceSequential must not overlap with anything else
67 static_assert((ownedOrHaloOrDummy & forceSequential) == 0,
68 "Iterator behaviors are defined with non matching values!");
69 // containerOnly must not overlap with anything else
70 static_assert(((ownedOrHaloOrDummy | forceSequential) & containerOnly) == 0,
71 "Iterator behaviors are defined with non matching values!");
72
76 IteratorBehavior() = default;
77
82 constexpr IteratorBehavior(Value option) : _value(option) {}
83
90 constexpr IteratorBehavior(Value_t option) : _value(static_cast<IteratorBehavior::Value>(option)) {}
91
96 constexpr operator Value() const { return _value; }
97
104 static std::set<IteratorBehavior> getDiscouragedOptions() {
107 }
108
113 static std::map<IteratorBehavior, std::string> getOptionNames() {
114 return {
115 {IteratorBehavior::owned, "owned"},
116 {IteratorBehavior::halo, "halo"},
117 {IteratorBehavior::ownedOrHalo, "ownedOrHalo"},
118 {IteratorBehavior::containerOnly, "containerOnly"},
119 {IteratorBehavior::dummy, "dummy"},
120 {IteratorBehavior::ownedOrHaloOrDummy, "ownedOrHaloOrDummy"},
121 {IteratorBehavior::forceSequential, "forceSequential"},
122 };
123 }
124
131 template <typename ParticleType>
132 bool contains(ParticleType &particle) {
133 switch (this->_value) {
135 return true;
137 return not particle.isDummy();
139 return particle.isHalo();
141 return particle.isOwned();
143 return particle.isDummy();
144 default:
145 utils::ExceptionHandler::exception("IteratorBehavior::contains() Unknown IteratorBehavior: {}.",
146 getOptionNames()[this->_value]);
147 return false;
148 }
149 }
150
151 private:
152 Value _value{Value(-1)};
153};
154} // namespace options
155} // namespace autopas
Class representing the choices for behaviors of iterators.
Definition: IteratorBehavior.h:20
Value
Different possibilities for iterator behaviors.
Definition: IteratorBehavior.h:30
@ owned
Iterate only over owned particles.
Definition: IteratorBehavior.h:34
@ halo
Iterate only over halo particles.
Definition: IteratorBehavior.h:38
@ ownedOrHalo
Iterate over both halo and owned particles.
Definition: IteratorBehavior.h:42
@ forceSequential
Force the iterator to behave like a sequential iterator even when created in a parallel region.
Definition: IteratorBehavior.h:54
@ dummy
Iterate only over dummy particles.
Definition: IteratorBehavior.h:46
@ containerOnly
Force the iterator to iterate over Container only.
Definition: IteratorBehavior.h:58
@ ownedOrHaloOrDummy
Iterate over both halo and owned particles and also dummy particles.
Definition: IteratorBehavior.h:50
IteratorBehavior()=default
Constructor.
static std::set< IteratorBehavior > getDiscouragedOptions()
Set of options that are very unlikely to be interesting.
Definition: IteratorBehavior.h:104
constexpr IteratorBehavior(Value option)
Constructor from value.
Definition: IteratorBehavior.h:82
constexpr IteratorBehavior(Value_t option)
Constructor from number value.
Definition: IteratorBehavior.h:90
unsigned int Value_t
Type used for the internal enum.
Definition: IteratorBehavior.h:25
bool contains(ParticleType &particle)
Check whether this iterator behavior covers the given particle.
Definition: IteratorBehavior.h:132
static std::map< IteratorBehavior, std::string > getOptionNames()
Provides a way to iterate over the possible choices of AcquisitionFunction.
Definition: IteratorBehavior.h:113
Base class for autopas options.
Definition: Option.h:25
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32