WarpX
IntervalsParser.H
Go to the documentation of this file.
1 /* Copyright 2022 Andrew Myers, Burlen Loring, Luca Fedeli
2  * Maxence Thevenet, Remi Lehe, Revathi Jambunathan
3  *
4  * This file is part of WarpX.
5  *
6  * License: BSD-3-Clause-LBNL
7  */
8 
9 #ifndef WARPX_UTILS_PARSER_INTERVALSPARSER_H_
10 #define WARPX_UTILS_PARSER_INTERVALSPARSER_H_
11 
12 #include <limits>
13 #include <string>
14 #include <vector>
15 
16 namespace utils::parser
17 {
18 
24  {
25  public:
35  SliceParser (const std::string& instr, bool isBTD=false);
36 
44  bool contains (const int n) const;
45 
52  int nextContains (const int n) const;
53 
60  int previousContains (const int n) const;
61 
66  int getPeriod () const;
67 
72  int getStart () const;
73 
78  int getStop () const;
79 
84  int numContained() const;
85 
86  private:
87  bool m_isBTD = false;
88  int m_start = 0;
89  int m_stop = std::numeric_limits<int>::max();
90  int m_period = 1;
91  std::string m_separator = ":";
92 
93  };
94 
95 
102  {
103  public:
107  IntervalsParser () = default;
108 
116  IntervalsParser (const std::vector<std::string>& instr_vec);
117 
124  bool contains (const int n) const;
125 
132  int nextContains (const int n) const;
133 
140  int previousContains (const int n) const;
141 
148  int previousContainsInclusive (const int n) const;
149 
156  int localPeriod (const int n) const;
157 
162  bool isActivated () const;
163 
164  private:
165  std::vector<SliceParser> m_slices;
166  std::string m_separator = ",";
167  bool m_activated = false;
168  };
169 
176  {
177  public:
181  BTDIntervalsParser () = default;
182 
190  BTDIntervalsParser (const std::vector<std::string>& instr_vec);
191 
195  int NumSnapshots () const;
196 
202  int GetBTDIteration(int i_buffer) const;
203 
208  int GetFinalIteration() const;
209 
214  bool isActivated () const;
215 
216  private:
217  std::vector<int> m_btd_iterations;
218  std::vector<SliceParser> m_slices;
219  std::vector<int> m_slice_starting_i_buffer;
220  static constexpr char m_separator = ',';
221  bool m_activated = false;
222  };
223 }
224 
225 #endif // WARPX_UTILS_PARSER_INTERVALSPARSER_H_
int nextContains(const int n) const
A method that returns the smallest integer strictly greater than n such that contains(n) is true...
Definition: IntervalsParser.cpp:61
std::vector< int > m_slice_starting_i_buffer
Definition: IntervalsParser.H:219
std::vector< SliceParser > m_slices
Definition: IntervalsParser.H:165
std::vector< SliceParser > m_slices
Definition: IntervalsParser.H:218
int m_period
Definition: IntervalsParser.H:90
This class is a parser for multiple slices of the form x,y,z,... where x, y and z are slices of the f...
Definition: IntervalsParser.H:175
bool contains(const int n) const
A method that returns true if the input integer is contained in the slice. (e.g. if the list is initi...
Definition: IntervalsParser.cpp:54
int getStop() const
A method that returns the slice stop.
Definition: IntervalsParser.cpp:86
int m_start
Definition: IntervalsParser.H:88
int previousContains(const int n) const
A method that returns the greatest integer strictly smaller than n such that contains(n) is true...
Definition: IntervalsParser.cpp:71
int getStart() const
A method that returns the slice start.
Definition: IntervalsParser.cpp:83
This class is a parser for multiple slices of the form x,y,z,... where x, y and z are slices of the f...
Definition: IntervalsParser.H:101
bool m_isBTD
Definition: IntervalsParser.H:87
This class is a parser for slices of the form i:j:k where i, j and k are integers representing respec...
Definition: IntervalsParser.H:23
SliceParser(const std::string &instr, bool isBTD=false)
Constructor of the SliceParser class.
Definition: IntervalsParser.cpp:19
int n
Definition: run_libensemble_on_warpx.py:67
std::vector< int > m_btd_iterations
Definition: IntervalsParser.H:217
std::string m_separator
Definition: IntervalsParser.H:91
Definition: IntervalsParser.H:16
int getPeriod() const
A method that returns the slice period.
Definition: IntervalsParser.cpp:80
int m_stop
Definition: IntervalsParser.H:89
int numContained() const
A method that returns the number of integers contained by the slice.
Definition: IntervalsParser.cpp:89