aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs')
-rw-r--r--OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs612
1 files changed, 306 insertions, 306 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
index 8a111ed..1cd213b 100644
--- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
+++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs
@@ -1,307 +1,307 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32 32
33namespace libTerrain 33namespace libTerrain
34{ 34{
35 partial class Channel 35 partial class Channel
36 { 36 {
37 // Navier Stokes Algorithms ported from 37 // Navier Stokes Algorithms ported from
38 // "Real-Time Fluid Dynamics for Games" by Jos Stam. 38 // "Real-Time Fluid Dynamics for Games" by Jos Stam.
39 // presented at GDC 2003. 39 // presented at GDC 2003.
40 40
41 // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd) 41 // Poorly ported from C++. (I gave up making it properly native somewhere after nsSetBnd)
42 42
43 private static int nsIX(int i, int j, int N) 43 private static int nsIX(int i, int j, int N)
44 { 44 {
45 return ((i) + (N + 2) * (j)); 45 return ((i) + (N + 2) * (j));
46 } 46 }
47 47
48 private static void nsSwap(ref double x0, ref double x) 48 private static void nsSwap(ref double x0, ref double x)
49 { 49 {
50 double tmp = x0; 50 double tmp = x0;
51 x0 = x; 51 x0 = x;
52 x = tmp; 52 x = tmp;
53 } 53 }
54 54
55 private static void nsSwap(ref double[] x0, ref double[] x) 55 private static void nsSwap(ref double[] x0, ref double[] x)
56 { 56 {
57 double[] tmp = x0; 57 double[] tmp = x0;
58 x0 = x; 58 x0 = x;
59 x = tmp; 59 x = tmp;
60 } 60 }
61 61
62 private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) 62 private void nsAddSource(int N, ref double[] x, ref double[] s, double dt)
63 { 63 {
64 int i; 64 int i;
65 int size = (N + 2) * (N + 2); 65 int size = (N + 2) * (N + 2);
66 for (i = 0; i < size; i++) 66 for (i = 0; i < size; i++)
67 { 67 {
68 x[i] += dt * s[i]; 68 x[i] += dt * s[i];
69 } 69 }
70 } 70 }
71 71
72 private void nsSetBnd(int N, int b, ref double[] x) 72 private void nsSetBnd(int N, int b, ref double[] x)
73 { 73 {
74 int i; 74 int i;
75 for (i = 0; i <= N; i++) 75 for (i = 0; i <= N; i++)
76 { 76 {
77 x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)]; 77 x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)];
78 x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)]; 78 x[nsIX(0, N + 1, N)] = b == 1 ? -x[nsIX(N, i, N)] : x[nsIX(N, i, N)];
79 x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)]; 79 x[nsIX(i, 0, N)] = b == 2 ? -x[nsIX(i, 1, N)] : x[nsIX(i, 1, N)];
80 x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)]; 80 x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)];
81 } 81 }
82 x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]); 82 x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]);
83 x[nsIX(0, N + 1, N)] = 0.5f * (x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]); 83 x[nsIX(0, N + 1, N)] = 0.5f * (x[nsIX(1, N + 1, N)] + x[nsIX(0, N, N)]);
84 x[nsIX(N + 1, 0, N)] = 0.5f * (x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]); 84 x[nsIX(N + 1, 0, N)] = 0.5f * (x[nsIX(N, 0, N)] + x[nsIX(N + 1, 1, N)]);
85 x[nsIX(N + 1, N + 1, N)] = 0.5f * (x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]); 85 x[nsIX(N + 1, N + 1, N)] = 0.5f * (x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]);
86 } 86 }
87 87
88 private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) 88 private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c)
89 { 89 {
90 int i, j; 90 int i, j;
91 for (i = 1; i <= N; i++) 91 for (i = 1; i <= N; i++)
92 { 92 {
93 for (j = 1; j <= N; j++) 93 for (j = 1; j <= N; j++)
94 { 94 {
95 x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a * 95 x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a *
96 (x[nsIX(i - 1, j, N)] + 96 (x[nsIX(i - 1, j, N)] +
97 x[nsIX(i + 1, j, N)] + 97 x[nsIX(i + 1, j, N)] +
98 x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) 98 x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)])
99 ) / c; 99 ) / c;
100 } 100 }
101 } 101 }
102 102
103 nsSetBnd(N, b, ref x); 103 nsSetBnd(N, b, ref x);
104 } 104 }
105 105
106 private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) 106 private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt)
107 { 107 {
108 double a = dt * diff * N * N; 108 double a = dt * diff * N * N;
109 nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a); 109 nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a);
110 } 110 }
111 111
112 private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) 112 private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt)
113 { 113 {
114 int i, j, i0, j0, i1, j1; 114 int i, j, i0, j0, i1, j1;
115 double x, y, s0, t0, s1, t1, dt0; 115 double x, y, s0, t0, s1, t1, dt0;
116 116
117 dt0 = dt * N; 117 dt0 = dt * N;
118 118
119 for (i = 1; i <= N; i++) 119 for (i = 1; i <= N; i++)
120 { 120 {
121 for (j = 1; j <= N; j++) 121 for (j = 1; j <= N; j++)
122 { 122 {
123 x = i - dt0 * u[nsIX(i, j, N)]; 123 x = i - dt0 * u[nsIX(i, j, N)];
124 y = j - dt0 * v[nsIX(i, j, N)]; 124 y = j - dt0 * v[nsIX(i, j, N)];
125 125
126 if (x < 0.5) 126 if (x < 0.5)
127 x = 0.5; 127 x = 0.5;
128 if (x > N + 0.5) 128 if (x > N + 0.5)
129 x = N + 0.5; 129 x = N + 0.5;
130 i0 = (int)x; 130 i0 = (int)x;
131 i1 = i0 + 1; 131 i1 = i0 + 1;
132 132
133 if (y < 0.5) 133 if (y < 0.5)
134 y = 0.5; 134 y = 0.5;
135 if (y > N + 0.5) 135 if (y > N + 0.5)
136 y = N + 0.5; 136 y = N + 0.5;
137 j0 = (int)y; 137 j0 = (int)y;
138 j1 = j0 + 1; 138 j1 = j0 + 1;
139 139
140 s1 = x - i0; 140 s1 = x - i0;
141 s0 = 1 - s1; 141 s0 = 1 - s1;
142 t1 = y - j0; 142 t1 = y - j0;
143 t0 = 1 - t1; 143 t0 = 1 - t1;
144 144
145 d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) + 145 d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) +
146 s1 * (t0 * d0[nsIX(i1, j0, N)] + t1 * d0[nsIX(i1, j1, N)]); 146 s1 * (t0 * d0[nsIX(i1, j0, N)] + t1 * d0[nsIX(i1, j1, N)]);
147 } 147 }
148 } 148 }
149 149
150 nsSetBnd(N, b, ref d); 150 nsSetBnd(N, b, ref d);
151 } 151 }
152 152
153 public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div) 153 public void nsProject(int N, ref double[] u, ref double[] v, ref double[] p, ref double[] div)
154 { 154 {
155 int i, j; 155 int i, j;
156 156
157 for (i = 1; i <= N; i++) 157 for (i = 1; i <= N; i++)
158 { 158 {
159 for (j = 1; j <= N; j++) 159 for (j = 1; j <= N; j++)
160 { 160 {
161 div[nsIX(i, j, N)] = -0.5 * (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - v[nsIX(i, j - 1, N)]) / N; 161 div[nsIX(i, j, N)] = -0.5 * (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - v[nsIX(i, j - 1, N)]) / N;
162 p[nsIX(i, j, N)] = 0; 162 p[nsIX(i, j, N)] = 0;
163 } 163 }
164 } 164 }
165 165
166 nsSetBnd(N, 0, ref div); 166 nsSetBnd(N, 0, ref div);
167 nsSetBnd(N, 0, ref p); 167 nsSetBnd(N, 0, ref p);
168 168
169 nsLinSolve(N, 0, ref p, ref div, 1, 4); 169 nsLinSolve(N, 0, ref p, ref div, 1, 4);
170 170
171 for (i = 1; i <= N; i++) 171 for (i = 1; i <= N; i++)
172 { 172 {
173 for (j = 1; j <= N; j++) 173 for (j = 1; j <= N; j++)
174 { 174 {
175 u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]); 175 u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]);
176 v[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]); 176 v[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]);
177 } 177 }
178 } 178 }
179 179
180 nsSetBnd(N, 1, ref u); 180 nsSetBnd(N, 1, ref u);
181 nsSetBnd(N, 2, ref v); 181 nsSetBnd(N, 2, ref v);
182 } 182 }
183 183
184 private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt) 184 private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt)
185 { 185 {
186 nsAddSource(N, ref x, ref x0, dt); 186 nsAddSource(N, ref x, ref x0, dt);
187 nsSwap(ref x0, ref x); 187 nsSwap(ref x0, ref x);
188 nsDiffuse(N, 0, ref x, ref x0, diff, dt); 188 nsDiffuse(N, 0, ref x, ref x0, diff, dt);
189 nsSwap(ref x0, ref x); 189 nsSwap(ref x0, ref x);
190 nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); 190 nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt);
191 } 191 }
192 192
193 private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt) 193 private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt)
194 { 194 {
195 nsAddSource(N, ref u, ref u0, dt); 195 nsAddSource(N, ref u, ref u0, dt);
196 nsAddSource(N, ref v, ref v0, dt); 196 nsAddSource(N, ref v, ref v0, dt);
197 nsSwap(ref u0, ref u); 197 nsSwap(ref u0, ref u);
198 nsDiffuse(N, 1, ref u, ref u0, visc, dt); 198 nsDiffuse(N, 1, ref u, ref u0, visc, dt);
199 nsSwap(ref v0, ref v); 199 nsSwap(ref v0, ref v);
200 nsDiffuse(N, 2, ref v, ref v0, visc, dt); 200 nsDiffuse(N, 2, ref v, ref v0, visc, dt);
201 nsProject(N, ref u, ref v, ref u0, ref v0); 201 nsProject(N, ref u, ref v, ref u0, ref v0);
202 nsSwap(ref u0, ref u); 202 nsSwap(ref u0, ref u);
203 nsSwap(ref v0, ref v); 203 nsSwap(ref v0, ref v);
204 nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt); 204 nsAdvect(N, 1, ref u, ref u0, ref u0, ref v0, dt);
205 nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt); 205 nsAdvect(N, 2, ref v, ref v0, ref u0, ref v0, dt);
206 nsProject(N, ref u, ref v, ref u0, ref v0); 206 nsProject(N, ref u, ref v, ref u0, ref v0);
207 } 207 }
208 208
209 private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles) 209 private void nsBufferToDoubles(ref double[] dens, int N, ref double[,] doubles)
210 { 210 {
211 int i; 211 int i;
212 int j; 212 int j;
213 213
214 for (i = 1; i <= N; i++) 214 for (i = 1; i <= N; i++)
215 { 215 {
216 for (j = 1; j <= N; j++) 216 for (j = 1; j <= N; j++)
217 { 217 {
218 doubles[i - 1, j - 1] = dens[nsIX(i, j, N)]; 218 doubles[i - 1, j - 1] = dens[nsIX(i, j, N)];
219 } 219 }
220 } 220 }
221 } 221 }
222 222
223 private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens) 223 private void nsDoublesToBuffer(double[,] doubles, int N, ref double[] dens)
224 { 224 {
225 int i; 225 int i;
226 int j; 226 int j;
227 227
228 for (i = 1; i <= N; i++) 228 for (i = 1; i <= N; i++)
229 { 229 {
230 for (j = 1; j <= N; j++) 230 for (j = 1; j <= N; j++)
231 { 231 {
232 dens[nsIX(i, j, N)] = doubles[i - 1, j - 1]; 232 dens[nsIX(i, j, N)] = doubles[i - 1, j - 1];
233 } 233 }
234 } 234 }
235 } 235 }
236 236
237 private void nsSimulate(int N, int rounds, double dt, double diff, double visc) 237 private void nsSimulate(int N, int rounds, double dt, double diff, double visc)
238 { 238 {
239 int size = (N * 2) * (N * 2); 239 int size = (N * 2) * (N * 2);
240 240
241 double[] u = new double[size]; // Force, X axis 241 double[] u = new double[size]; // Force, X axis
242 double[] v = new double[size]; // Force, Y axis 242 double[] v = new double[size]; // Force, Y axis
243 double[] u_prev = new double[size]; 243 double[] u_prev = new double[size];
244 double[] v_prev = new double[size]; 244 double[] v_prev = new double[size];
245 double[] dens = new double[size]; 245 double[] dens = new double[size];
246 double[] dens_prev = new double[size]; 246 double[] dens_prev = new double[size];
247 247
248 nsDoublesToBuffer(this.map, N, ref dens); 248 nsDoublesToBuffer(this.map, N, ref dens);
249 nsDoublesToBuffer(this.map, N, ref dens_prev); 249 nsDoublesToBuffer(this.map, N, ref dens_prev);
250 250
251 for (int i = 0; i < rounds; i++) 251 for (int i = 0; i < rounds; i++)
252 { 252 {
253 u_prev = u; 253 u_prev = u;
254 v_prev = v; 254 v_prev = v;
255 dens_prev = dens; 255 dens_prev = dens;
256 256
257 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); 257 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
258 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); 258 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
259 } 259 }
260 260
261 nsBufferToDoubles(ref dens, N, ref this.map); 261 nsBufferToDoubles(ref dens, N, ref this.map);
262 } 262 }
263 263
264 /// <summary> 264 /// <summary>
265 /// Performs computational fluid dynamics on a channel 265 /// Performs computational fluid dynamics on a channel
266 /// </summary> 266 /// </summary>
267 /// <param name="rounds">The number of steps to perform (Recommended: 20)</param> 267 /// <param name="rounds">The number of steps to perform (Recommended: 20)</param>
268 /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param> 268 /// <param name="dt">Delta Time - The time between steps (Recommended: 0.1)</param>
269 /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param> 269 /// <param name="diff">Fluid diffusion rate (Recommended: 0.0)</param>
270 /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param> 270 /// <param name="visc">Fluid viscosity (Recommended: 0.0)</param>
271 public void navierStokes(int rounds, double dt, double diff, double visc) 271 public void navierStokes(int rounds, double dt, double diff, double visc)
272 { 272 {
273 nsSimulate(this.h, rounds, dt, diff, visc); 273 nsSimulate(this.h, rounds, dt, diff, visc);
274 } 274 }
275 275
276 public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret) 276 public void navierStokes(int rounds, double dt, double diff, double visc, ref double[,] uret, ref double[,] vret)
277 { 277 {
278 int N = this.h; 278 int N = this.h;
279 279
280 int size = (N * 2) * (N * 2); 280 int size = (N * 2) * (N * 2);
281 281
282 double[] u = new double[size]; // Force, X axis 282 double[] u = new double[size]; // Force, X axis
283 double[] v = new double[size]; // Force, Y axis 283 double[] v = new double[size]; // Force, Y axis
284 double[] u_prev = new double[size]; 284 double[] u_prev = new double[size];
285 double[] v_prev = new double[size]; 285 double[] v_prev = new double[size];
286 double[] dens = new double[size]; 286 double[] dens = new double[size];
287 double[] dens_prev = new double[size]; 287 double[] dens_prev = new double[size];
288 288
289 nsDoublesToBuffer(this.map, N, ref dens); 289 nsDoublesToBuffer(this.map, N, ref dens);
290 nsDoublesToBuffer(this.map, N, ref dens_prev); 290 nsDoublesToBuffer(this.map, N, ref dens_prev);
291 291
292 for (int i = 0; i < rounds; i++) 292 for (int i = 0; i < rounds; i++)
293 { 293 {
294 u_prev = u; 294 u_prev = u;
295 v_prev = v; 295 v_prev = v;
296 dens_prev = dens; 296 dens_prev = dens;
297 297
298 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt); 298 nsVelStep(N, ref u, ref v, ref u_prev, ref v_prev, visc, dt);
299 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt); 299 nsDensStep(N, ref dens, ref dens_prev, ref u, ref v, diff, dt);
300 } 300 }
301 301
302 nsBufferToDoubles(ref u, N, ref uret); 302 nsBufferToDoubles(ref u, N, ref uret);
303 nsBufferToDoubles(ref v, N, ref vret); 303 nsBufferToDoubles(ref v, N, ref vret);
304 nsBufferToDoubles(ref dens, N, ref this.map); 304 nsBufferToDoubles(ref dens, N, ref this.map);
305 } 305 }
306 } 306 }
307} \ No newline at end of file 307} \ No newline at end of file