.Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
PressureGauge.h
1 #ifndef __RPK_PRESSURE_GAUGE_H__
2 #define __RPK_PRESSURE_GAUGE_H__
3 
4 #include <boost/array.hpp>
5 #include <boost/circular_buffer.hpp>
6 #include <deque>
7 
8 namespace MDSimulation
9 {
10  const size_t PGAUGE_ORDER = 2;
11 
12  typedef std::pair<double, double> TimeSeries;
13 
20  {
21  public:
22 
23  #ifdef WINDOWED_PGAUGE
24  typedef std::deque<TimeSeries> BufferType;
25  #else
26  typedef boost::circular_buffer<TimeSeries> BufferType;
27  #endif
28 
32  PressureGauge();
33 
39  void AddSample(const double time, const double pressure);
40 
41 
48  double PressureTime() const;
49 
61  double SampleGauge(const double radius);
62 
67  double ComputePressure(const double currentTime,
68  const double radius,
69  const double drdt) const;
70 
75  double ComputeDpdt(const double currentTime,
76  const double radius,
77  const double dpdt) const;
78 
87  void Serialize(FILE* file, bool save = true);
88 
89  template <typename Writer>
90  void Serialize(Writer& pt) const;
91 
92  // void Read(const boost::property_tree::ptree& tree);
93 
94  bool IsReady() const;
95 
96  bool CanSample() const;
97 
98  void SetPressureStats(const double t, const double p, const double dpdt);
99 
100  private:
101 
102  // Circular buffer of pressure samples.
103  BufferType Buffer;
104 
105  boost::array<double, PGAUGE_ORDER> Coefficients;
106 
107  double SampleRadius;
108  double SampleTime;
109 
110  double LastPressure;
111  double LastDpdt;
112  double LastTime;
113  double CurrentPressure;
114  double CurrentDpdt;
115  double CurrentTime;
116 
117  bool Ready;
118  };
119 
120  template <typename Writer>
121  void PressureGauge::Serialize(Writer& writer) const
122  {
123  writer.StartObject();
124 
125  writer.String("LastPressure") , writer.Double(LastPressure);
126  writer.String("LastDpdt") , writer.Double(LastDpdt);
127  writer.String("LastTime") , writer.Double(LastTime);
128  writer.String("CurrentPressure") , writer.Double(CurrentPressure);
129  writer.String("CurrentDpdt") , writer.Double(CurrentDpdt);
130  writer.String("CurrentTime") , writer.Double(CurrentTime);
131 
132  // Write the buffer as an array of pairs. Each element of the array is
133  // an object with two values: "first" and "second".
134  writer.String("Buffer");
135  writer.BeginArray();
136  std::for_each(Buffer.begin(), Buffer.end(), [&writer](const TimeSeries& ts)
137  {
138  writer.BeginObject();
139  writer.String("first"), writer.Double(ts.first);
140  writer.String("second"), writer.Double(ts.second);
141  writer.EndObject();
142  });
143 
144  writer.EndArray();
145 
146  // End the pressure gauge object.
147  writer.EndObject();
148  }
149 }
150 
151 #endif
PressureGauge.h - pressure gauge class declaration Written by Alexander Bass, modified by Max I...
Definition: PressureGauge.h:19
void AddSample(const double time, const double pressure)
Add a sample to the pressure gauge.
Definition: PressureGauge.cpp:66
double PressureTime() const
Computes the time of the pressure sample that will be produced by a call to the SampleGauge function...
Definition: PressureGauge.cpp:125
double SampleGauge(const double radius)
Get the pressure at the given time.
Definition: PressureGauge.cpp:132
PressureGauge()
Default Constructor.
Definition: PressureGauge.cpp:56
void Serialize(FILE *file, bool save=true)
Serialize the pressure gauge to disk.
double ComputeDpdt(const double currentTime, const double radius, const double dpdt) const
Computes the rate of change of the pressure using the coefficients of the polynomial calculated from ...
Definition: PressureGauge.cpp:204
double ComputePressure(const double currentTime, const double radius, const double drdt) const
Compute the pressure at the given time.
Definition: PressureGauge.cpp:191