Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FLUID_3D.h « intern « smoke « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ab121ef506eff24a1f5f328b99aae9a31b462051 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//////////////////////////////////////////////////////////////////////
// This file is part of Wavelet Turbulence.
// 
// Wavelet Turbulence is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// Wavelet Turbulence is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with Wavelet Turbulence.  If not, see <http://www.gnu.org/licenses/>.
// 
// Copyright 2008 Theodore Kim and Nils Thuerey
// 
// FLUID_3D.h: interface for the FLUID_3D class.
//
//////////////////////////////////////////////////////////////////////
// Heavy parallel optimization done. Many of the old functions now
// take begin and end parameters and process only specified part of the data.
// Some functions were divided into multiple ones.
//		- MiikaH
//////////////////////////////////////////////////////////////////////

#ifndef FLUID_3D_H
#define FLUID_3D_H

#include <cstdlib>
#include <cmath>
#include <iostream>
#include "OBSTACLE.h"
// #include "WTURBULENCE.h"
#include "VEC3.h"

using namespace std;
using namespace BasicVector;
class WTURBULENCE;

class FLUID_3D  
{
	public:
		FLUID_3D(int *res, /* int amplify, */ float *p0, float dt);
		FLUID_3D() {};
		virtual ~FLUID_3D();

		void initBlenderRNA(float *alpha, float *beta);
		
		// create & allocate vector noise advection 
		void initVectorNoise(int amplify);

		void addSmokeColumn();
		static void addSmokeTestCase(float* field, Vec3Int res);

		void step();
		void addObstacle(OBSTACLE* obstacle);

		const float* xVelocity() { return _xVelocity; }; 
		const float* yVelocity() { return _yVelocity; }; 
		const float* zVelocity() { return _zVelocity; }; 

		int xRes() const { return _xRes; };
		int yRes() const { return _yRes; };
		int zRes() const { return _zRes; };

	public:  
		// dimensions
		int _xRes, _yRes, _zRes, _maxRes;
		Vec3Int _res;
		size_t _totalCells;
		int _slabSize;
		float _dx;
		float _p0[3];
		float _p1[3];
		float _totalTime;
		int _totalSteps;
		int _totalImgDumps;
		int _totalVelDumps;

		void artificialDampingSL(int zBegin, int zEnd);
		void artificialDampingExactSL(int pos);

		// fields
		float* _density;
		float* _densityOld;
		float* _heat;
		float* _heatOld;
		float* _xVelocity;
		float* _yVelocity;
		float* _zVelocity;
		float* _xVelocityOld;
		float* _yVelocityOld;
		float* _zVelocityOld;
		float* _xForce;
		float* _yForce;
		float* _zForce;
		unsigned char*  _obstacles;

		// Required for proper threading:
		float* _xVelocityTemp;
		float* _yVelocityTemp;
		float* _zVelocityTemp;
		float* _heatTemp;
		float* _densityTemp;

		// CG fields
		int _iterations;

		// simulation constants
		float _dt;
		float _vorticityEps;
		float _heatDiffusion;
		float *_alpha; // for the buoyancy density term <-- as pointer to get blender RNA in here
		float *_beta; // was _buoyancy <-- as pointer to get blender RNA in here
		float _tempAmb; /* ambient temperature */

		// WTURBULENCE object, if active
		// WTURBULENCE* _wTurbulence;

		// boundary setting functions
		void copyBorderAll(float* field, int zBegin, int zEnd);

		// timestepping functions
		void wipeBoundaries(int zBegin, int zEnd);
		void wipeBoundariesSL(int zBegin, int zEnd);
		void addForce(int zBegin, int zEnd);
		void addVorticity(int zBegin, int zEnd);
		void addBuoyancy(float *heat, float *density, int zBegin, int zEnd);

		// solver stuff
		void project();
		void diffuseHeat();
		void solvePressure(float* field, float* b, unsigned char* skip);
		void solvePressurePre(float* field, float* b, unsigned char* skip);
		void solveHeat(float* field, float* b, unsigned char* skip);


		// handle obstacle boundaries
		void setObstacleBoundaries(float *_pressure, int zBegin, int zEnd);
		void setObstaclePressure(float *_pressure, int zBegin, int zEnd);

	public:
		// advection, accessed e.g. by WTURBULENCE class
		//void advectMacCormack();
		void advectMacCormackBegin(int zBegin, int zEnd);
		void advectMacCormackEnd1(int zBegin, int zEnd);
		void advectMacCormackEnd2(int zBegin, int zEnd);

		// boundary setting functions
		static void copyBorderX(float* field, Vec3Int res, int zBegin, int zEnd);
		static void copyBorderY(float* field, Vec3Int res, int zBegin, int zEnd);
		static void copyBorderZ(float* field, Vec3Int res, int zBegin, int zEnd);
		static void setNeumannX(float* field, Vec3Int res, int zBegin, int zEnd);
		static void setNeumannY(float* field, Vec3Int res, int zBegin, int zEnd);
		static void setNeumannZ(float* field, Vec3Int res, int zBegin, int zEnd);
		static void setZeroX(float* field, Vec3Int res, int zBegin, int zEnd);
		static void setZeroY(float* field, Vec3Int res, int zBegin, int zEnd);
		static void setZeroZ(float* field, Vec3Int res, int zBegin, int zEnd);
		static void setZeroBorder(float* field, Vec3Int res, int zBegin, int zEnd) {
			setZeroX(field, res, zBegin, zEnd);
			setZeroY(field, res, zBegin, zEnd);
			setZeroZ(field, res, zBegin, zEnd);
		};

		

		// static advection functions, also used by WTURBULENCE
		static void advectFieldSemiLagrange(const float dt, const float* velx, const float* vely,  const float* velz,
				float* oldField, float* newField, Vec3Int res, int zBegin, int zEnd);
		static void advectFieldMacCormack1(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, 
				float* oldField, float* tempResult, Vec3Int res, int zBegin, int zEnd);
		static void advectFieldMacCormack2(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, 
				float* oldField, float* newField, float* tempResult, float* temp1,Vec3Int res, const unsigned char* obstacles, int zBegin, int zEnd);


		// temp ones for testing
		/*static void advectFieldMacCormack(const float dt, const float* xVelocity, const float* yVelocity, const float* zVelocity, 
				float* oldField, float* newField, float* temp1, float* temp2, Vec3Int res, const unsigned char* obstacles);*/
		/*static void advectFieldSemiLagrange2(const float dt, const float* velx, const float* vely,  const float* velz,
				float* oldField, float* newField, Vec3Int res);*/

		// maccormack helper functions
		static void clampExtrema(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
				float* oldField, float* newField, Vec3Int res, int zBegin, int zEnd);
		static void clampOutsideRays(const float dt, const float* xVelocity, const float* yVelocity,  const float* zVelocity,
				float* oldField, float* newField, Vec3Int res, const unsigned char* obstacles, const float *oldAdvection, int zBegin, int zEnd);



		// output helper functions
		// static void writeImageSliceXY(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
		// static void writeImageSliceYZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
		// static void writeImageSliceXZ(const float *field, Vec3Int res, int slice, string prefix, int picCnt, float scale=1.);
		// static void writeProjectedIntern(const float *field, Vec3Int res, int dir1, int dir2, string prefix, int picCnt, float scale=1.); 
};

#endif