Commenting out code from commit 22457 by Genscher for PointCache.
[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                 int _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* _pressure;
85                 float* _xVelocity;
86                 float* _yVelocity;
87                 float* _zVelocity;
88                 float* _xVelocityOld;
89                 float* _yVelocityOld;
90                 float* _zVelocityOld;
91                 float* _xForce;
92                 float* _yForce;
93                 float* _zForce;
94                 float* _divergence;
95                 float* _xVorticity;
96                 float* _yVorticity;
97                 float* _zVorticity;
98                 float* _vorticity;
99                 float* _h;
100                 float* _Precond;
101                 unsigned char*  _obstacles;
102
103                 // CG fields
104                 float* _residual;
105                 float* _direction;
106                 float* _q;
107                 int _iterations;
108
109                 // simulation constants
110                 float _dt;
111                 float _vorticityEps;
112                 float _heatDiffusion;
113                 float *_alpha; // for the buoyancy density term <-- as pointer to get blender RNA in here
114                 float *_beta; // was _buoyancy <-- as pointer to get blender RNA in here
115                 float _tempAmb; /* ambient temperature */
116
117                 // WTURBULENCE object, if active
118                 // WTURBULENCE* _wTurbulence;
119
120                 // boundary setting functions
121                 void copyBorderAll(float* field);
122
123                 // timestepping functions
124                 void wipeBoundaries();
125                 void addForce();
126                 void addVorticity();
127                 void addBuoyancy(float *heat, float *density);
128
129                 // solver stuff
130                 void project();
131                 void diffuseHeat();
132                 void solvePressure(float* field, float* b, unsigned char* skip);
133                 void solvePressurePre(float* field, float* b, unsigned char* skip);
134                 void solveHeat(float* field, float* b, unsigned char* skip);
135
136                 // handle obstacle boundaries
137                 void setObstacleBoundaries();
138                 void setObstaclePressure();
139
140         public:
141                 // advection, accessed e.g. by WTURBULENCE class
142                 void advectMacCormack();
143
144                 // boundary setting functions
145                 static void copyBorderX(float* field, Vec3Int res);
146                 static void copyBorderY(float* field, Vec3Int res);
147                 static void copyBorderZ(float* field, Vec3Int res);
148                 static void setNeumannX(float* field, Vec3Int res);
149                 static void setNeumannY(float* field, Vec3Int res);
150                 static void setNeumannZ(float* field, Vec3Int res);
151                 static void setZeroX(float* field, Vec3Int res);
152                 static void setZeroY(float* field, Vec3Int res);
153                 static void setZeroZ(float* field, Vec3Int res);
154                 static void setZeroBorder(float* field, Vec3Int res) {
155                         setZeroX(field, res);
156                         setZeroY(field, res);
157                         setZeroZ(field, res);
158                 };
159
160                 // static advection functions, also used by WTURBULENCE
161                 static void advectFieldSemiLagrange(const float dt, const float* velx, const float* vely,  const float* velz,
162                                 float* oldField, float* newField, Vec3Int res);
163                 static void advectFieldMacCormack(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, 
164                                 float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const unsigned char* obstacles);
165
166                 // maccormack helper functions
167                 static void clampExtrema(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
168                                 float* oldField, float* newField, Vec3Int res);
169                 static void clampOutsideRays(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
170                                 float* oldField, float* newField, Vec3Int res, const unsigned char* obstacles, const float *oldAdvection);
171
172                 // output helper functions
173                 // static void writeImageSliceXY(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
174                 // static void writeImageSliceYZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
175                 // static void writeImageSliceXZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
176                 // static void writeProjectedIntern(const float *field, Vec3Int res, int dir1, int dir2, string prefix, int picCnt, float scale=1.); 
177 };
178
179 #endif