質問編集履歴
3
出力されたものをアップしました
title
CHANGED
File without changes
|
body
CHANGED
@@ -223,6 +223,12 @@
|
|
223
223
|
}
|
224
224
|
```
|
225
225
|
|
226
|
+
### 出力
|
227
|
+
-0.039956
|
228
|
+
-0.039956
|
229
|
+
-0.039956
|
230
|
+
-0.039956
|
231
|
+
↑これがずっと続きます
|
226
232
|
|
227
233
|
### 補足情報(FW/ツールのバージョンなど)
|
228
234
|
|
2
剰余を用いて周期境界を表しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -111,9 +111,119 @@
|
|
111
111
|
}
|
112
112
|
|
113
113
|
```
|
114
|
+
変更後のソースコード
|
115
|
+
```
|
116
|
+
#include<stdio.h>
|
117
|
+
#include<stdlib.h>
|
118
|
+
#include<time.h>
|
114
119
|
|
115
120
|
|
121
|
+
int main(void)
|
122
|
+
{
|
123
|
+
int x_scale, y_scale, step;
|
124
|
+
x_scale = 50; //x方向長さ
|
125
|
+
y_scale = 50; //y方向長さ
|
126
|
+
step = 1; //計算回数
|
116
127
|
|
128
|
+
double yuragi, q, b, D, side, slant,v,w;
|
129
|
+
yuragi = 0.3; //
|
130
|
+
q = 0.1; //跳躍により移動する砂の量
|
131
|
+
b = 1.0; //跳躍距離のパラメータ
|
132
|
+
D = 0.1; //転がりにより移動する砂の量のパラメータ(転がり出る砂の量=Dh)
|
133
|
+
side = 2.0; //転がり計算の時に使うパラメータ
|
134
|
+
slant = 1.0; //同上
|
135
|
+
|
136
|
+
srand(time(NULL));
|
137
|
+
|
138
|
+
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 (跳躍距離)
|
139
|
+
L_0 = 3; //風速に対応するパラメータ
|
140
|
+
i = (x_scale + (x % x_scale))%(x_scale);
|
141
|
+
j = (y_scale + (y % y_scale))%(y_scale);
|
142
|
+
i_1 = (x_scale + ((x - 1) % x_scale))%(x_scale);
|
143
|
+
i_2 = (x_scale + ((x + 1) % x_scale))%(x_scale);
|
144
|
+
j_1 = (y_scale + ((y - 1) % y_scale))%(y_scale);
|
145
|
+
j_2 = (y_scale + ((y + 1) % y_scale))%(y_scale);
|
146
|
+
i_0 = (x_scale + ((x + L) % x_scale))%(x_scale);
|
147
|
+
|
148
|
+
|
149
|
+
double h[50][50]; //[x,y]における砂の高さ(積載量)
|
150
|
+
|
151
|
+
|
152
|
+
FILE*fp;
|
153
|
+
fp=fopen("output.dat", "w");
|
154
|
+
for (y = 0;y < y_scale;y++)
|
155
|
+
{
|
156
|
+
for (x = 0;x < x_scale;x++)
|
157
|
+
{
|
158
|
+
h[x][y] = 2.85 + (yuragi * rand() / (double)RAND_MAX); //各座標のhの初期値を2.85~3.15の間で乱数で取る
|
159
|
+
}
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
for (t = 1; t <= step; t++)
|
164
|
+
{
|
165
|
+
|
166
|
+
for (k = 1; k < 2500; k++) //跳躍計算
|
167
|
+
{
|
168
|
+
v = (int)(50 * rand() / (double)RAND_MAX);
|
169
|
+
w = (int)(50 * rand() / (double)RAND_MAX);
|
170
|
+
x = v;
|
171
|
+
y = w;
|
172
|
+
L = L_0 + (b * (int)h[(i)][(j)]);
|
173
|
+
|
174
|
+
if (h[i][j] > 0)
|
175
|
+
{
|
176
|
+
h[(i)][(j)] -= q;
|
177
|
+
h[(i_0)][(j)] += q;
|
178
|
+
}
|
179
|
+
else
|
180
|
+
{
|
181
|
+
continue;
|
182
|
+
}
|
183
|
+
|
184
|
+
}
|
185
|
+
|
186
|
+
for (y = 0;y < y_scale ;y++)
|
187
|
+
{
|
188
|
+
for (x = 0;x < x_scale ;x++)
|
189
|
+
{
|
190
|
+
if (h[i][j] > h[(i_1)][(j)] &&
|
191
|
+
h[i][j] > h[(i_2)][(j)] && h[i][j] > h[(i)][(j_1)] &&
|
192
|
+
h[i][j] > h[i][(j_2)] && h[i][j] > h[(i_1)][(j_1)] &&
|
193
|
+
h[i][j] > h[i_1][(j_2)] && h[i][j] > h[(i_2)][(j_1)] &&
|
194
|
+
h[i][j] > h[i_2][(j_2)])
|
195
|
+
{
|
196
|
+
h[(i_1)][(j)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
197
|
+
h[(i_2)][(j)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
198
|
+
h[(i)][(j_1)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
199
|
+
h[(i)][(j_2)] += D * h[i][j] * (1.0 / 4.0) * (side / (side + slant));
|
200
|
+
h[(i_1)][(j_1)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
201
|
+
h[(i_1)][(j_2)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
202
|
+
h[(i_2)][(j_1)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
203
|
+
h[(i_2)][(j_2)] += D * h[i][j] * (1.0 / 4.0) * (slant / (side + slant));
|
204
|
+
h[i][j] -= D * h[i][j];
|
205
|
+
}
|
206
|
+
else {
|
207
|
+
continue;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
for (y = 0;y < y_scale;y++) {
|
214
|
+
for(x = 0; x < x_scale; x++ ){
|
215
|
+
printf("%f\n",h[i][j]);
|
216
|
+
fprintf(fp, "%f\n",h[i][j]);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
}
|
221
|
+
|
222
|
+
fclose(fp);
|
223
|
+
}
|
224
|
+
```
|
225
|
+
|
226
|
+
|
117
227
|
### 補足情報(FW/ツールのバージョンなど)
|
118
228
|
|
119
229
|
Visual Studio Codeで作成しています。
|
1
プログラムを見やすいように編集しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,8 +11,7 @@
|
|
11
11
|
|
12
12
|
### 該当のソースコード
|
13
13
|
|
14
|
-
|
14
|
+
```
|
15
|
-
ソースコード
|
16
15
|
#include<stdio.h>
|
17
16
|
#include<stdlib.h>
|
18
17
|
#include<time.h>
|
@@ -111,8 +110,10 @@
|
|
111
110
|
fclose(fp);
|
112
111
|
}
|
113
112
|
|
113
|
+
```
|
114
114
|
|
115
115
|
|
116
|
+
|
116
117
|
### 補足情報(FW/ツールのバージョンなど)
|
117
118
|
|
118
119
|
Visual Studio Codeで作成しています。
|