svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22935:23022
[blender.git] / intern / smoke / intern / FLUID_3D.h
1 //////////////////////////////////////////////////////////////////////
2 // This file is part of Wavelet Turbulence.
3 // 
4 // Wavelet Turbulence is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 // 
9 // Wavelet Turbulence is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 // 
14 // You should have received a copy of the GNU General Public License
15 // along with Wavelet Turbulence.  If not, see <http://www.gnu.org/licenses/>.
16 // 
17 // Copyright 2008 Theodore Kim and Nils Thuerey
18 // 
19 // FLUID_3D.h: interface for the FLUID_3D class.
20 //
21 //////////////////////////////////////////////////////////////////////
22
23 #ifndef FLUID_3D_H
24 #define FLUID_3D_H
25
26 #include <cstdlib>
27 #include <cmath>
28 #include <iostream>
29 #include "OBSTACLE.h"
30 // #include "WTURBULENCE.h"
31 #include "VEC3.h"
32
33 using namespace std;
34 using namespace BasicVector;
35 class WTURBULENCE;
36
37 class FLUID_3D  
38 {
39         public:
40                 FLUID_3D(int *res, /* int amplify, */ float *p0, float dt);
41                 FLUID_3D() {};
42                 virtual ~FLUID_3D();
43
44                 void initBlenderRNA(float *alpha, float *beta);
45                 
46                 // create & allocate vector noise advection 
47                 void initVectorNoise(int amplify);
48
49                 void addSmokeColumn();
50                 static void addSmokeTestCase(float* field, Vec3Int res, float value);
51
52                 void step();
53                 void addObstacle(OBSTACLE* obstacle);
54
55                 const float* xVelocity() { return _xVelocity; }; 
56                 const float* yVelocity() { return _yVelocity; }; 
57                 const float* zVelocity() { return _zVelocity; }; 
58
59                 int xRes() const { return _xRes; };
60                 int yRes() const { return _yRes; };
61                 int zRes() const { return _zRes; };
62
63         public:  
64                 // dimensions
65                 int _xRes, _yRes, _zRes, _maxRes;
66                 Vec3Int _res;
67                 size_t _totalCells;
68                 int _slabSize;
69                 float _dx;
70                 float _p0[3];
71                 float _p1[3];
72                 float _totalTime;
73                 int _totalSteps;
74                 int _totalImgDumps;
75                 int _totalVelDumps;
76
77     void artificialDamping(float* field);
78
79                 // fields
80                 float* _density;
81                 float* _densityOld;
82                 float* _heat;
83                 float* _heatOld;
84                 float* _xVelocity;
85                 float* _yVelocity;
86                 float* _zVelocity;
87                 float* _xVelocityOld;
88                 float* _yVelocityOld;
89                 float* _zVelocityOld;
90                 float* _xForce;
91                 float* _yForce;
92                 float* _zForce;
93                 unsigned char*  _obstacles;
94
95                 // CG fields
96                 int _iterations;
97
98                 // simulation constants
99                 float _dt;
100                 float _vorticityEps;
101                 float _heatDiffusion;
102                 float *_alpha; // for the buoyancy density term <-- as pointer to get blender RNA in here
103                 float *_beta; // was _buoyancy <-- as pointer to get blender RNA in here
104                 float _tempAmb; /* ambient temperature */
105
106                 // WTURBULENCE object, if active
107                 // WTURBULENCE* _wTurbulence;
108
109                 // boundary setting functions
110                 void copyBorderAll(float* field);
111
112                 // timestepping functions
113                 void wipeBoundaries();
114                 void addForce();
115                 void addVorticity();
116                 void addBuoyancy(float *heat, float *density);
117
118                 // solver stuff
119                 void project();
120                 void diffuseHeat();
121                 void solvePressure(float* field, float* b, unsigned char* skip);
122                 void solvePressurePre(float* field, float* b, unsigned char* skip);
123                 void solveHeat(float* field, float* b, unsigned char* skip);
124
125                 // handle obstacle boundaries
126                 void setObstacleBoundaries(float *_pressure);
127                 void setObstaclePressure(float *_pressure);
128
129         public:
130                 // advection, accessed e.g. by WTURBULENCE class
131                 void advectMacCormack();
132
133                 // boundary setting functions
134                 static void copyBorderX(float* field, Vec3Int res);
135                 static void copyBorderY(float* field, Vec3Int res);
136                 static void copyBorderZ(float* field, Vec3Int res);
137                 static void setNeumannX(float* field, Vec3Int res);
138                 static void setNeumannY(float* field, Vec3Int res);
139                 static void setNeumannZ(float* field, Vec3Int res);
140                 static void setZeroX(float* field, Vec3Int res);
141                 static void setZeroY(float* field, Vec3Int res);
142                 static void setZeroZ(float* field, Vec3Int res);
143                 static void setZeroBorder(float* field, Vec3Int res) {
144                         setZeroX(field, res);
145                         setZeroY(field, res);
146                         setZeroZ(field, res);
147                 };
148
149                 // static advection functions, also used by WTURBULENCE
150                 static void advectFieldSemiLagrange(const float dt, const float* velx, const float* vely,  const float* velz,
151                                 float* oldField, float* newField, Vec3Int res);
152                 static void advectFieldMacCormack(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, 
153                                 float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const unsigned char* obstacles);
154
155                 // maccormack helper functions
156                 static void clampExtrema(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
157                                 float* oldField, float* newField, Vec3Int res);
158                 static void clampOutsideRays(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
159                                 float* oldField, float* newField, Vec3Int res, const unsigned char* obstacles, const float *oldAdvection);
160
161                 // output helper functions
162                 // static void writeImageSliceXY(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
163                 // static void writeImageSliceYZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
164                 // static void writeImageSliceXZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
165                 // static void writeProjectedIntern(const float *field, Vec3Int res, int dir1, int dir2, string prefix, int picCnt, float scale=1.); 
166 };
167
168 #endif