EPANET  3.0
EPANET Development Project
pattern.h
Go to the documentation of this file.
1 /* EPANET 3
2  *
3  * Copyright (c) 2016 Open Water Analytics
4  * Licensed under the terms of the MIT License (see the LICENSE file for details).
5  *
6  */
7 
10 
11 #ifndef PATTERN_H_
12 #define PATTERN_H_
13 
14 #include "Elements/element.h"
15 
16 #include <string>
17 #include <vector>
18 
19 class MemPool;
20 
28 
29 class Pattern: public Element
30 {
31  public:
32 
33  enum PatternType {FIXED_PATTERN, VARIABLE_PATTERN};
34 
35  // Constructor/Destructor
36  Pattern(std::string name_, int type_);
37  virtual ~Pattern();
38 
39  // Pattern factory
40  static Pattern* factory(int type_, std::string name_, MemPool* memPool);
41 
42  // Methods
43  void setTimeInterval(int t) { interval = t; }
44  void addFactor(double f) { factors.push_back(f); }
45  int timeInterval() { return interval; }
46  int size() { return factors.size(); }
47  double factor(int i) { return factors[i]; }
48  double currentFactor();
49  virtual void init(int interval, int tstart) = 0;
50  virtual int nextTime(int t) = 0;
51  virtual void advance(int t) = 0;
52 
53  // Properties
54  int type;
55 
56  protected:
57  std::vector<double> factors;
59  int interval;
60 };
61 
62 //------------------------------------------------------------------------------
63 
68 
69 class FixedPattern : public Pattern
70 {
71  public:
72 
73  // Constructor/Destructor
74  FixedPattern(std::string name_);
75  ~FixedPattern();
76 
77  // Methods
78  void init(int interval, int tstart);
79  int nextTime(int t);
80  void advance(int t);
81 
82  private:
83  int startTime;
84 };
85 
86 //------------------------------------------------------------------------------
87 
92 
93 class VariablePattern : public Pattern
94 {
95  public:
96 
97  // Constructor/Destructor
98  VariablePattern(std::string name_);
99  ~VariablePattern();
100 
101  // Methods
102  void addTime(int t) { times.push_back(t); }
103  int time(int i) { return times[i]; }
104  void init(int interval, int tstart);
105  int nextTime(int t);
106  void advance(int t);
107 
108  private:
109  std::vector<int> times;
110 };
111 
112 #endif
Abstract parent class for all pipe network components.
Definition: element.h:19
Describes the Element class.
A Pattern where factors change at varying time intervals.
Definition: pattern.h:93
A Pattern where factors change at fixed time intervals.
Definition: pattern.h:69
A simple pooled memory allocator.
Definition: mempool.h:21
int interval
fixed time interval (sec)
Definition: pattern.h:59
int currentIndex
index of current pattern interval
Definition: pattern.h:58
int type
type of time pattern
Definition: pattern.h:54
std::vector< double > factors
sequence of multiplier factors
Definition: pattern.h:57
A set of multiplier factors associated with points in time.
Definition: pattern.h:29