lbm_reference
ParticleSystem.h
Go to the documentation of this file.
1 //! \file ParticleSystem.h
2 //! \date Mar 12, 2009
3 //! \author Florian Rathgeber
4 
5 #ifndef PARTICLESYSTEM_H_
6 #define PARTICLESYSTEM_H_
7 
8 #ifndef RealType
9 #define RealType float
10 #endif
11 
12 #include <irrlicht/irrlicht.h>
13 
14 #include "../lbm/LBM.h"
15 #include "Emitter.h"
16 
17 using namespace irr;
18 
19 //! Common namespace for all classes related to the particle system
20 
21 namespace particles {
22 
23 struct Sphere {
24 
25  Sphere( float x,
26  float y,
27  float z,
28  float radius,
29  float u_x = 0.0,
30  float u_y = 0.0,
31  float u_z = 0.0,
32  scene::IMeshSceneNode* n = 0 ) :
33  pos( x, y, z ), r( radius ), u( u_x, u_y, u_z ), node( n ) {}
34 
35  void move() {
36  pos += u;
37  if ( node )
38  node->setPosition( pos );
39  }
40 
41  bool isPointInside( const core::vector3df& p ) {
42  return (p.X - pos.X) * (p.X - pos.X)
43  + (p.Y - pos.Y) * (p.Y - pos.Y)
44  + (p.Z - pos.Z) * (p.Z - pos.Z) < r * r;
45  }
46 
47  core::vector3df pos;
48  float r;
49  core::vector3df u;
50  scene::IMeshSceneNode* node;
51 };
52 
53 //! Particle system that handles creation, movement and visualization of
54 //! particles.
55 
56 //! Irrlicht 3D engine is used for OpenGL visualization.
57 
59 
60 public:
61 
62  // ============================ //
63  // Constructors and destructors //
64  // ============================ //
65 
66  //! Default constructor
67 
68  //! Does nothing.
69 
71 
72  //! Constructor that initializes the particle system according to given
73  //! configuration file
74 
75  //! \param[in] configFileName Path to configuration file to parse
76 
77  ParticleSystem ( std::string configFileName );
78 
79  //! Destructor
80 
81  //! Does nothing.
82 
83  virtual ~ParticleSystem () {}
84 
85  //! Set up the particle system according to configuration options
86 
87  //! \param[in] base Root block of the parsed configuration file
88 
89  void setup( ConfBlock& base );
90 
91  //! Main simulation loop
92 
93  void run();
94 
95 protected:
96 
97  // ========================= //
98  // Internal helper functions //
99  // ========================= //
100 
101  //! Go over all particles and update position, color and size
102 
103  inline void updateParticles();
104 
105  //! Go over all emitters and emit new particles
106 
107  inline void emitParticles();
108 
109  //! Generate a black body color table
110 
111  //! \param[in] maxTemp Maximum emitted particle temperature
112 
113  void generateBlackBodyColorTable( float maxTemp );
114 
115  float getTime( timeval &start, timeval &end ) {
116  return (float) ( end.tv_sec - start.tv_sec )
117  + (float) ( end.tv_usec - start.tv_usec ) / 1000000.;
118  }
119 
120  // ============ //
121  // Data members //
122  // ============ //
123 
124  //! Lattice Boltzmann fluid solver
126 
127  //! Vector containing all emitters of the particle system
128  std::vector< Emitter > emitters_;
129 
130  //! Domain size in x-direction
131  int sizeX_;
132 
133  //! Domain size in y-direction
134  int sizeY_;
135 
136  //! Domain size in z-direction
137  int sizeZ_;
138 
139  //! Total simulation timesteps
141 
142  //! Total number of generated particles
144 
145  //! Thermal conservation coefficient
146  float alpha_;
147 
148  //! Thermal transferability coefficient
149  float beta_;
150 
151  //! Temperature threshold for a fire particle to turn into a smoke particle
152  float smokeTemp_;
153 
154  //! Ambient temperature
155  float ambTemp_;
156 
157  //! Thermal expansion coefficient
158  float k_;
159 
160  //! Vector of inversed gravity
161  core::vector3df gravity_;
162 
163  //! Basic particle size
164  float sizeBase_;
165 
166  //! Variable particle size, multiplied with a factor depending on lifetime
167  float sizeVar_;
168 
169  //! Number of sprites assigned to each particle
171 
172  //! Table of a precomputed Gaussian distribution
173  std::vector<float> gaussTable_;
174 
175  //! Black body color table
176  std::vector< video::SColor > bbColorTable_;
177 
178  //! Irrlicht OpenGL device
179  IrrlichtDevice* device_;
180 
181  //! Irrlicht scene manager
182  scene::ISceneManager* smgr_;
183 
184  //! Irrlicht OpenGL video driver
185  video::IVideoDriver* drvr_;
186 
187  //! Vector of particle textures
188  std::vector< video::ITexture* > textures_;
189 
190  //! Vector of axis-aligned cuboid obstacles
191  std::vector< core::aabbox3df > obstacles_;
192 
193  std::vector< Sphere > spheres_;
194 
195  std::string updFileName_;
196  std::string irrFileName_;
197 
198  std::string screenshots_;
200 
202 };
203 
204 } // namespace particles
205 
206 #endif /* PARTICLESYSTEM_H_ */