2 FLUIDS v.1 - SPH Fluid Simulator for CPU and GPU
3 Copyright (C) 2008. Rama Hoetzlein, http://www.rchoetzlein.com
6 This software is provided 'as-is', without any express or implied
7 warranty. In no event will the authors be held liable for any damages
8 arising from the use of this software.
10 Permission is granted to anyone to use this software for any purpose,
11 including commercial applications, and to alter it and redistribute it
12 freely, subject to the following restrictions:
14 1. The origin of this software must not be misrepresented; you must not
15 claim that you wrote the original software. If you use this software
16 in a product, an acknowledgment in the product documentation would be
17 appreciated but is not required.
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20 3. This notice may not be removed or altered from any source distribution.
32 #include "common_defs.h"
36 typedef signed int xref;
38 #define MAX_NEIGHBOR 80
43 #define PNT_DRAWMODE 0
46 #define PNT_DRAWSIZE 1
56 #define POINT_GRAV_POS 5
57 #define PLANE_GRAV_DIR 6
78 class PointSet : public GeomX {
84 virtual void Initialize ( int mode, int max );
85 virtual void Draw ( float* view_mat, float rad );
86 virtual void Reset ();
87 virtual int AddPoint ();
88 virtual int AddPointReuse ();
89 Point* GetPoint ( int n ) { return (Point*) GetElem(0, n); }
90 int NumPoints () { return NumElem(0); }
93 virtual float GetValue ( float x, float y, float z );
94 virtual Vector3DF GetGradient ( float x, float y, float z );
95 // virtual float GetValue ( float x, float y, float z, Vector3DF& dir );
96 virtual DWORD GetColor ( float x, float y, float z );
100 virtual void Advance ();
101 virtual void Emit ( float spacing );
104 virtual void AddVolume ( Vector3DF min, Vector3DF max, float spacing );
107 void SetParam (int p, float v ) { m_Param[p] = v; }
108 void SetParam (int p, int v ) { m_Param[p] = (float) v; }
109 float GetParam ( int p ) { return (float) m_Param[p]; }
110 Vector3DF GetVec ( int p ) { return m_Vec[p]; }
111 void SetVec ( int p, Vector3DF v ) { m_Vec[p] = v; }
112 void Toggle ( int p ) { m_Toggle[p] = !m_Toggle[p]; }
113 bool GetToggle ( int p ) { return m_Toggle[p]; }
115 float GetDT() { return (float) m_DT; }
117 // Spatial Subdivision
118 void Grid_Setup ( Vector3DF min, Vector3DF max, float sim_scale, float cell_size, float border );
120 void Grid_InsertParticles ();
121 void Grid_Draw ( float* view_mat );
122 void Grid_FindCells ( Vector3DF p, float radius );
123 int Grid_FindCell ( Vector3DF p );
124 Vector3DF GetGridRes () { return m_GridRes; }
125 Vector3DF GetGridMin () { return m_GridMin; }
126 Vector3DF GetGridMax () { return m_GridMax; }
127 Vector3DF GetGridDelta () { return m_GridDelta; }
128 int GetGridCell ( int x, int y, int z );
129 Point* firstGridParticle ( int gc, int& p );
130 Point* nextGridParticle ( int& p );
131 unsigned short* getNeighborTable ( int n, int& cnt );
137 double m_Param [ MAX_PARAM ]; // see defines above
138 Vector3DF m_Vec [ MAX_PARAM ];
139 bool m_Toggle [ MAX_PARAM ];
146 std::vector< int > m_Grid;
147 std::vector< int > m_GridCnt;
148 int m_GridTotal; // total # cells
149 Vector3DF m_GridMin; // volume of grid (may not match domain volume exactly)
151 Vector3DF m_GridRes; // resolution in each axis
152 Vector3DF m_GridSize; // physical size in each axis
153 Vector3DF m_GridDelta;
154 float m_GridCellsize;
158 unsigned short m_NC[65536]; // neighbor table (600k)
159 unsigned short m_Neighbor[65536][MAX_NEIGHBOR];
160 float m_NDist[65536][MAX_NEIGHBOR];