diff options
author | lbsa71 | 2007-10-30 09:05:31 +0000 |
---|---|---|
committer | lbsa71 | 2007-10-30 09:05:31 +0000 |
commit | 67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch) | |
tree | 20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs | |
parent | * Deleted .user file (diff) | |
download | opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2 opensim-SC_OLD-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz |
* Optimized usings
* Shortened type references
* Removed redundant 'this' qualifier
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs index 401cf95..8c16d7c 100644 --- a/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs +++ b/OpenSim/Region/Terrain.BasicTerrain/libTerrainBSD/Channel/Manipulators/NavierStokes.cs | |||
@@ -26,10 +26,6 @@ | |||
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | |||
33 | namespace libTerrain | 29 | namespace libTerrain |
34 | { | 30 | { |
35 | partial class Channel | 31 | partial class Channel |
@@ -42,7 +38,7 @@ namespace libTerrain | |||
42 | 38 | ||
43 | private static int nsIX(int i, int j, int N) | 39 | private static int nsIX(int i, int j, int N) |
44 | { | 40 | { |
45 | return ((i) + (N + 2) * (j)); | 41 | return ((i) + (N + 2)*(j)); |
46 | } | 42 | } |
47 | 43 | ||
48 | private static void nsSwap(ref double x0, ref double x) | 44 | private static void nsSwap(ref double x0, ref double x) |
@@ -62,10 +58,10 @@ namespace libTerrain | |||
62 | private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) | 58 | private void nsAddSource(int N, ref double[] x, ref double[] s, double dt) |
63 | { | 59 | { |
64 | int i; | 60 | int i; |
65 | int size = (N + 2) * (N + 2); | 61 | int size = (N + 2)*(N + 2); |
66 | for (i = 0; i < size; i++) | 62 | for (i = 0; i < size; i++) |
67 | { | 63 | { |
68 | x[i] += dt * s[i]; | 64 | x[i] += dt*s[i]; |
69 | } | 65 | } |
70 | } | 66 | } |
71 | 67 | ||
@@ -74,15 +70,15 @@ namespace libTerrain | |||
74 | int i; | 70 | int i; |
75 | for (i = 0; i <= N; i++) | 71 | for (i = 0; i <= N; i++) |
76 | { | 72 | { |
77 | x[nsIX(0, i, N)] = b == 1 ? -x[nsIX(1, i, N)] : x[nsIX(1, i, N)]; | 73 | 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)]; | 74 | 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)]; | 75 | 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)]; | 76 | x[nsIX(i, N + 1, N)] = b == 2 ? -x[nsIX(i, N, N)] : x[nsIX(i, N, N)]; |
81 | } | 77 | } |
82 | x[nsIX(0, 0, N)] = 0.5f * (x[nsIX(1, 0, N)] + x[nsIX(0, 1, N)]); | 78 | 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)]); | 79 | 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)]); | 80 | 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)]); | 81 | x[nsIX(N + 1, N + 1, N)] = 0.5f*(x[nsIX(N, N + 1, N)] + x[nsIX(N + 1, N, N)]); |
86 | } | 82 | } |
87 | 83 | ||
88 | private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) | 84 | private void nsLinSolve(int N, int b, ref double[] x, ref double[] x0, double a, double c) |
@@ -92,11 +88,11 @@ namespace libTerrain | |||
92 | { | 88 | { |
93 | for (j = 1; j <= N; j++) | 89 | for (j = 1; j <= N; j++) |
94 | { | 90 | { |
95 | x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a * | 91 | x[nsIX(i, j, N)] = (x0[nsIX(i, j, N)] + a* |
96 | (x[nsIX(i - 1, j, N)] + | 92 | (x[nsIX(i - 1, j, N)] + |
97 | x[nsIX(i + 1, j, N)] + | 93 | x[nsIX(i + 1, j, N)] + |
98 | x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) | 94 | x[nsIX(i, j - 1, N)] + x[nsIX(i, j + 1, N)]) |
99 | ) / c; | 95 | )/c; |
100 | } | 96 | } |
101 | } | 97 | } |
102 | 98 | ||
@@ -105,8 +101,8 @@ namespace libTerrain | |||
105 | 101 | ||
106 | private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) | 102 | private void nsDiffuse(int N, int b, ref double[] x, ref double[] x0, double diff, double dt) |
107 | { | 103 | { |
108 | double a = dt * diff * N * N; | 104 | double a = dt*diff*N*N; |
109 | nsLinSolve(N, b, ref x, ref x0, a, 1 + 4 * a); | 105 | nsLinSolve(N, b, ref x, ref x0, a, 1 + 4*a); |
110 | } | 106 | } |
111 | 107 | ||
112 | private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) | 108 | private void nsAdvect(int N, int b, ref double[] d, ref double[] d0, ref double[] u, ref double[] v, double dt) |
@@ -114,27 +110,27 @@ namespace libTerrain | |||
114 | int i, j, i0, j0, i1, j1; | 110 | int i, j, i0, j0, i1, j1; |
115 | double x, y, s0, t0, s1, t1, dt0; | 111 | double x, y, s0, t0, s1, t1, dt0; |
116 | 112 | ||
117 | dt0 = dt * N; | 113 | dt0 = dt*N; |
118 | 114 | ||
119 | for (i = 1; i <= N; i++) | 115 | for (i = 1; i <= N; i++) |
120 | { | 116 | { |
121 | for (j = 1; j <= N; j++) | 117 | for (j = 1; j <= N; j++) |
122 | { | 118 | { |
123 | x = i - dt0 * u[nsIX(i, j, N)]; | 119 | x = i - dt0*u[nsIX(i, j, N)]; |
124 | y = j - dt0 * v[nsIX(i, j, N)]; | 120 | y = j - dt0*v[nsIX(i, j, N)]; |
125 | 121 | ||
126 | if (x < 0.5) | 122 | if (x < 0.5) |
127 | x = 0.5; | 123 | x = 0.5; |
128 | if (x > N + 0.5) | 124 | if (x > N + 0.5) |
129 | x = N + 0.5; | 125 | x = N + 0.5; |
130 | i0 = (int)x; | 126 | i0 = (int) x; |
131 | i1 = i0 + 1; | 127 | i1 = i0 + 1; |
132 | 128 | ||
133 | if (y < 0.5) | 129 | if (y < 0.5) |
134 | y = 0.5; | 130 | y = 0.5; |
135 | if (y > N + 0.5) | 131 | if (y > N + 0.5) |
136 | y = N + 0.5; | 132 | y = N + 0.5; |
137 | j0 = (int)y; | 133 | j0 = (int) y; |
138 | j1 = j0 + 1; | 134 | j1 = j0 + 1; |
139 | 135 | ||
140 | s1 = x - i0; | 136 | s1 = x - i0; |
@@ -142,8 +138,8 @@ namespace libTerrain | |||
142 | t1 = y - j0; | 138 | t1 = y - j0; |
143 | t0 = 1 - t1; | 139 | t0 = 1 - t1; |
144 | 140 | ||
145 | d[nsIX(i, j, N)] = s0 * (t0 * d0[nsIX(i0, j0, N)] + t1 * d0[nsIX(i0, j1, N)]) + | 141 | 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)]); | 142 | s1*(t0*d0[nsIX(i1, j0, N)] + t1*d0[nsIX(i1, j1, N)]); |
147 | } | 143 | } |
148 | } | 144 | } |
149 | 145 | ||
@@ -158,7 +154,9 @@ namespace libTerrain | |||
158 | { | 154 | { |
159 | for (j = 1; j <= N; j++) | 155 | for (j = 1; j <= N; j++) |
160 | { | 156 | { |
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; | 157 | div[nsIX(i, j, N)] = -0.5* |
158 | (u[nsIX(i + 1, j, N)] - u[nsIX(i - 1, j, N)] + v[nsIX(i, j + 1, N)] - | ||
159 | v[nsIX(i, j - 1, N)])/N; | ||
162 | p[nsIX(i, j, N)] = 0; | 160 | p[nsIX(i, j, N)] = 0; |
163 | } | 161 | } |
164 | } | 162 | } |
@@ -172,8 +170,8 @@ namespace libTerrain | |||
172 | { | 170 | { |
173 | for (j = 1; j <= N; j++) | 171 | for (j = 1; j <= N; j++) |
174 | { | 172 | { |
175 | u[nsIX(i, j, N)] -= 0.5 * N * (p[nsIX(i + 1, j, N)] - p[nsIX(i - 1, j, N)]); | 173 | 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)]); | 174 | v[nsIX(i, j, N)] -= 0.5*N*(p[nsIX(i, j + 1, N)] - p[nsIX(i, j - 1, N)]); |
177 | } | 175 | } |
178 | } | 176 | } |
179 | 177 | ||
@@ -181,7 +179,8 @@ namespace libTerrain | |||
181 | nsSetBnd(N, 2, ref v); | 179 | nsSetBnd(N, 2, ref v); |
182 | } | 180 | } |
183 | 181 | ||
184 | private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, double dt) | 182 | private void nsDensStep(int N, ref double[] x, ref double[] x0, ref double[] u, ref double[] v, double diff, |
183 | double dt) | ||
185 | { | 184 | { |
186 | nsAddSource(N, ref x, ref x0, dt); | 185 | nsAddSource(N, ref x, ref x0, dt); |
187 | nsSwap(ref x0, ref x); | 186 | nsSwap(ref x0, ref x); |
@@ -190,7 +189,8 @@ namespace libTerrain | |||
190 | nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); | 189 | nsAdvect(N, 0, ref x, ref x0, ref u, ref v, dt); |
191 | } | 190 | } |
192 | 191 | ||
193 | private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, double dt) | 192 | private void nsVelStep(int N, ref double[] u, ref double[] v, ref double[] u0, ref double[] v0, double visc, |
193 | 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); |
@@ -236,17 +236,17 @@ namespace libTerrain | |||
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(map, N, ref dens); |
249 | nsDoublesToBuffer(this.map, N, ref dens_prev); | 249 | nsDoublesToBuffer(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 | { |
@@ -258,7 +258,7 @@ namespace libTerrain | |||
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 map); |
262 | } | 262 | } |
263 | 263 | ||
264 | /// <summary> | 264 | /// <summary> |
@@ -270,14 +270,14 @@ namespace libTerrain | |||
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(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 = 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 |
@@ -286,8 +286,8 @@ namespace libTerrain | |||
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(map, N, ref dens); |
290 | nsDoublesToBuffer(this.map, N, ref dens_prev); | 290 | nsDoublesToBuffer(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 | { |
@@ -301,7 +301,7 @@ namespace libTerrain | |||
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 map); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | } \ No newline at end of file | 307 | } \ No newline at end of file |