質問編集履歴
3
出力されたものをアップしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -448,6 +448,18 @@
|
|
448
448
|
|
449
449
|
|
450
450
|
|
451
|
+
### 出力
|
452
|
+
|
453
|
+
-0.039956
|
454
|
+
|
455
|
+
-0.039956
|
456
|
+
|
457
|
+
-0.039956
|
458
|
+
|
459
|
+
-0.039956
|
460
|
+
|
461
|
+
↑これがずっと続きます
|
462
|
+
|
451
463
|
|
452
464
|
|
453
465
|
### 補足情報(FW/ツールのバージョンなど)
|
2
剰余を用いて周期境界を表しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -224,7 +224,227 @@
|
|
224
224
|
|
225
225
|
```
|
226
226
|
|
227
|
-
|
227
|
+
変更後のソースコード
|
228
|
+
|
229
|
+
```
|
230
|
+
|
231
|
+
#include<stdio.h>
|
232
|
+
|
233
|
+
#include<stdlib.h>
|
234
|
+
|
235
|
+
#include<time.h>
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
int main(void)
|
242
|
+
|
243
|
+
{
|
244
|
+
|
245
|
+
int x_scale, y_scale, step;
|
246
|
+
|
247
|
+
x_scale = 50; //x方向長さ
|
248
|
+
|
249
|
+
y_scale = 50; //y方向長さ
|
250
|
+
|
251
|
+
step = 1; //計算回数
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
double yuragi, q, b, D, side, slant,v,w;
|
256
|
+
|
257
|
+
yuragi = 0.3; //
|
258
|
+
|
259
|
+
q = 0.1; //跳躍により移動する砂の量
|
260
|
+
|
261
|
+
b = 1.0; //跳躍距離のパラメータ
|
262
|
+
|
263
|
+
D = 0.1; //転がりにより移動する砂の量のパラメータ(転がり出る砂の量=Dh)
|
264
|
+
|
265
|
+
side = 2.0; //転がり計算の時に使うパラメータ
|
266
|
+
|
267
|
+
slant = 1.0; //同上
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
srand(time(NULL));
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
int x,y,i,j,i_1,i_2,j_1,j_2,i_0,s, t, L, k, L_0;//L=L_0 + bh (跳躍距離)
|
276
|
+
|
277
|
+
L_0 = 3; //風速に対応するパラメータ
|
278
|
+
|
279
|
+
i = (x_scale + (x % x_scale))%(x_scale);
|
280
|
+
|
281
|
+
j = (y_scale + (y % y_scale))%(y_scale);
|
282
|
+
|
283
|
+
i_1 = (x_scale + ((x - 1) % x_scale))%(x_scale);
|
284
|
+
|
285
|
+
i_2 = (x_scale + ((x + 1) % x_scale))%(x_scale);
|
286
|
+
|
287
|
+
j_1 = (y_scale + ((y - 1) % y_scale))%(y_scale);
|
288
|
+
|
289
|
+
j_2 = (y_scale + ((y + 1) % y_scale))%(y_scale);
|
290
|
+
|
291
|
+
i_0 = (x_scale + ((x + L) % x_scale))%(x_scale);
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
double h[50][50]; //[x,y]における砂の高さ(積載量)
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
FILE*fp;
|
304
|
+
|
305
|
+
fp=fopen("output.dat", "w");
|
306
|
+
|
307
|
+
for (y = 0;y < y_scale;y++)
|
308
|
+
|
309
|
+
{
|
310
|
+
|
311
|
+
for (x = 0;x < x_scale;x++)
|
312
|
+
|
313
|
+
{
|
314
|
+
|
315
|
+
h[x][y] = 2.85 + (yuragi * rand() / (double)RAND_MAX); //各座標のhの初期値を2.85~3.15の間で乱数で取る
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
for (t = 1; t <= step; t++)
|
326
|
+
|
327
|
+
{
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
for (k = 1; k < 2500; k++) //跳躍計算
|
332
|
+
|
333
|
+
{
|
334
|
+
|
335
|
+
v = (int)(50 * rand() / (double)RAND_MAX);
|
336
|
+
|
337
|
+
w = (int)(50 * rand() / (double)RAND_MAX);
|
338
|
+
|
339
|
+
x = v;
|
340
|
+
|
341
|
+
y = w;
|
342
|
+
|
343
|
+
L = L_0 + (b * (int)h[(i)][(j)]);
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
if (h[i][j] > 0)
|
348
|
+
|
349
|
+
{
|
350
|
+
|
351
|
+
h[(i)][(j)] -= q;
|
352
|
+
|
353
|
+
h[(i_0)][(j)] += q;
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
else
|
358
|
+
|
359
|
+
{
|
360
|
+
|
361
|
+
continue;
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
|
370
|
+
|
371
|
+
for (y = 0;y < y_scale ;y++)
|
372
|
+
|
373
|
+
{
|
374
|
+
|
375
|
+
for (x = 0;x < x_scale ;x++)
|
376
|
+
|
377
|
+
{
|
378
|
+
|
379
|
+
if (h[i][j] > h[(i_1)][(j)] &&
|
380
|
+
|
381
|
+
h[i][j] > h[(i_2)][(j)] && h[i][j] > h[(i)][(j_1)] &&
|
382
|
+
|
383
|
+
h[i][j] > h[i][(j_2)] && h[i][j] > h[(i_1)][(j_1)] &&
|
384
|
+
|
385
|
+
h[i][j] > h[i_1][(j_2)] && h[i][j] > h[(i_2)][(j_1)] &&
|
386
|
+
|
387
|
+
h[i][j] > h[i_2][(j_2)])
|
388
|
+
|
389
|
+
{
|
390
|
+
|
391
|
+
h[(i_1)][(j)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
392
|
+
|
393
|
+
h[(i_2)][(j)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
394
|
+
|
395
|
+
h[(i)][(j_1)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
396
|
+
|
397
|
+
h[(i)][(j_2)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
398
|
+
|
399
|
+
h[(i_1)][(j_1)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
400
|
+
|
401
|
+
h[(i_1)][(j_2)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
402
|
+
|
403
|
+
h[(i_2)][(j_1)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
404
|
+
|
405
|
+
h[(i_2)][(j_2)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
406
|
+
|
407
|
+
h[i][j] -= D * h[i][j];
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
else {
|
412
|
+
|
413
|
+
continue;
|
414
|
+
|
415
|
+
}
|
416
|
+
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
for (y = 0;y < y_scale;y++) {
|
426
|
+
|
427
|
+
for(x = 0; x < x_scale; x++ ){
|
428
|
+
|
429
|
+
printf("%f\n",h[i][j]);
|
430
|
+
|
431
|
+
fprintf(fp, "%f\n",h[i][j]);
|
432
|
+
|
433
|
+
}
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
fclose(fp);
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
```
|
228
448
|
|
229
449
|
|
230
450
|
|
1
プログラムを見やすいように編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,9 +24,7 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
|
27
|
+
```
|
28
|
-
|
29
|
-
ソースコード
|
30
28
|
|
31
29
|
#include<stdio.h>
|
32
30
|
|
@@ -224,6 +222,10 @@
|
|
224
222
|
|
225
223
|
|
226
224
|
|
225
|
+
```
|
226
|
+
|
227
|
+
|
228
|
+
|
227
229
|
|
228
230
|
|
229
231
|
|