.Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
RPK.h
1 #ifndef __RPK_RPK_H__
2 #define __RPK_RPK_H__
3 
4 #include "../Constants/Constants.h"
5 #include "../InfoStruct/InfoStruct.h"
6 #include "../Math/Functions.h"
7 #include "../Particle/Particle.h"
8 #include "../Units/Units.h"
9 #include "../Vector/Vector.hpp"
10 #include "PressureGauge.h"
11 
12 #include "rapidjson/document.h"
13 #include "rapidjson/prettywriter.h"
14 
15 #include <boost/numeric/odeint.hpp>
16 #include <boost/numeric/ublas/vector.hpp>
17 #include <math.h>
18 #include <stdio.h>
19 
20 namespace MDSimulation
21 {
22  const int DIM = 2;
23 
24  namespace odeint = boost::numeric::odeint;
25 
26  typedef boost::numeric::ublas::vector<double> state_type;
27  typedef boost::numeric::ublas::matrix<double> matrix_type;
28  typedef odeint::runge_kutta_fehlberg78<state_type> error_stepper_type;
29  typedef odeint::controlled_runge_kutta<error_stepper_type> controlled_stepper_type;
30 
40  // Numerical solution to Rayleigh-Plesset equation for bubble collapse
41  class RPK
42  {
43  private:
44 
45  const double& CurrentTime;
46 
47  double kR; // Interpolation coefficient, aka velocity = R'
48 
49  state_type Time;
50  state_type PrevRadius;
51  state_type NextRadius;
52 
53  std::vector<double> Times;
54  std::vector<double> Radii;
55  std::vector<double> Velocities;
56 
57  controlled_stepper_type ControlledSolver;
58 
59  // Constants computed using the InfoStruct data. These are kept around for
60  // performance reasons.
61  double R03;
62  double a3;
63  double P0;
64  double Density;
65  double Viscosity;
66  double SurfaceTension;
67  double SpeedOfSound;
68  double Omega;
69 
70  // Coefficients for the linear interpolation of the polytropic exponent.
71  double A;
72  double B;
73 
74  double TimeStep;
75 
76  // Pressure interpolation coefficients
77  double ComputedPressure; // Pressure used by the RPK function (ideal or pgauge)
78  double ComputedDpdt;
79 
80  PressureGauge PGauge;
81 
82  InfoStruct Info;
83 
84  double StepSize;
85 
86  FILE* Actual;
87 
93  void Init(const std::string& outDir = "");
94 
95  public:
96 
108  RPK(const double& currentTime, const InfoStruct& info, const std::string& outDir = "");
109 
113  ~RPK();
114 
118  double NextStep();
119 
123  void AddSample(const double time, const double pressure);
124 
129  double R(const double time) const;
130 
135  double V(const double time) const;
136 
143  double VSmart(const double time) const;
144 
148  double d2Rdt2() const;
149 
153  double NextStepTime();
154 
159  void ReadPressureGauge();
160 
170  double FindCrossingTime(const Particle& n) const;
171 
177  template <typename Writer>
178  void Serialize(Writer& writer) const;
179 
184  // void Read(const boost::property_tree::ptree& tree);
185 
190  state_type operator()(const state_type& x, state_type& dxdt, const double t) const;
191 
195  double AcousticPressure(const double time) const;
196 
200  double AcousticPressureDerivative(const double time) const;
201  };
202 
203  template <typename Writer>
204  void RPK::Serialize(Writer& writer) const
205  {
206 
207  writer.String("kR") , writer.Double(kR);
208  writer.String("Time") , writer.Double(Time);
209  writer.String("Time") , writer.Double(Time);
210  writer.String("TimeStep") , writer.Double(TimeStep);
211  writer.String("A") , writer.Double(A);
212  writer.String("B") , writer.Double(B);
213  writer.String("R03") , writer.Double(R03);
214  writer.String("a3") , writer.Double(a3);
215  writer.String("P0") , writer.Double(P0);
216  writer.String("Density") , writer.Double(Density);
217  writer.String("Viscosity") , writer.Double(Viscosity);
218  writer.String("SurfaceTension") , writer.Double(SurfaceTension);
219  writer.String("SpeedOfSound") , writer.Double(SpeedOfSound);
220  writer.String("Omega") , writer.Double(Omega);
221 
222  writer.String("PGauge");
223  PGauge.Serialize<Writer>(writer);
224  }
225 }
226 
227 #endif
228 
void AddSample(const double time, const double pressure)
Add a sample to the pressure gauge.
Definition: RPK.cpp:77
~RPK()
Clean up the dynamically allocated memory for the solver methods.
Definition: RPK.cpp:72
void Serialize(Writer &writer) const
New serialization method that makes use of the ptree library.
Definition: RPK.h:204
PressureGauge.h - pressure gauge class declaration Written by Alexander Bass, modified by Max I...
Definition: PressureGauge.h:19
double NextStepTime()
Definition: RPK.cpp:110
This module defines the RPK class.
Definition: RPK.h:41
double FindCrossingTime(const Particle &n) const
Definition: RPK.cpp:337
double AcousticPressureDerivative(const double time) const
Compute the derivative of the acoustic pressure at the given time.
Definition: RPK.cpp:324
state_type operator()(const state_type &x, state_type &dxdt, const double t) const
Deserialization method that can read in the data produced by the serialize method.
Definition: RPK.cpp:209
double AcousticPressure(const double time) const
Compute the acoustic pressure at the given time.
Definition: RPK.cpp:311
double R(const double time) const
Definition: RPK.cpp:85
void ReadPressureGauge()
Reads the pressure gauge to update the current pressure and dpdt value.
double VSmart(const double time) const
Smarter version of the velocity calculation that uses the computed velocities for each end of the cur...
Definition: RPK.cpp:97
double V(const double time) const
Definition: RPK.cpp:92
double d2Rdt2() const
Definition: RPK.cpp:103
void Serialize(FILE *file, bool save=true)
Serialize the pressure gauge to disk.
Defines the structure used to hold the configurable constants of the simulation.
Definition: InfoStruct.h:36
Definition of a basic particle type.
Definition: Particle.h:23
RPK(const double &currentTime, const InfoStruct &info, const std::string &outDir="")
Create a new RPK equation using the given InfoStruct for the various constants needed.
Definition: RPK.cpp:60
double NextStep()
Definition: RPK.cpp:116