-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadentu.patch
475 lines (409 loc) · 16.4 KB
/
adentu.patch
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
diff --git src/adentu-atom-cuda.cu src/adentu-atom-cuda.cu
index c449253..466bb57 100644
--- src/adentu-atom-cuda.cu
+++ src/adentu-atom-cuda.cu
@@ -31,6 +31,7 @@
#include "adentu-cuda-utils.h"
extern "C" {
+ #include "vec3-cuda.h"
#include "adentu-atom-cuda.h"
}
@@ -62,9 +63,13 @@ void adentu_atom_cuda_set_init_vel (AdentuAtom *atoms, AdentuModel *model)
CUDA_CALL (cudaMemcpy (d_vel, atoms->vel, nAtoms * sizeof (vec3f), cudaMemcpyHostToDevice));
- dim3 gDim (1);
- dim3 bDim (nAtoms);
+ vRand3f_cuda (d_vel, nAtoms);
+
+
+ dim3 gDim ;
+ dim3 bDim ;
+ adentu_cuda_set_grid (&gDim, &bDim, nAtoms);
kernel1 <<<gDim, bDim>>> (d_vel, nAtoms, velInit);
CUDA_CALL (cudaMemcpy (atoms->vel, d_vel, nAtoms * sizeof (vec3f), cudaMemcpyDeviceToHost));
@@ -179,7 +184,8 @@ void adentu_atom_cuda_set_init_pos (AdentuAtom *atoms, AdentuGrid *grid)
curandGenerator_t gen;
curandCreateGenerator (&gen, CURAND_RNG_PSEUDO_DEFAULT);
- curandSetPseudoRandomGeneratorSeed (gen, time(NULL));
+ //curandSetPseudoRandomGeneratorSeed (gen, time(NULL));
+ curandSetPseudoRandomGeneratorSeed (gen, 1234567);
curandGenerateUniformDouble (gen, d_rands, nAtoms * 6);
curandDestroyGenerator (gen);
diff --git src/adentu-grid-cuda.cu src/adentu-grid-cuda.cu
index 2544004..a7ec6b3 100644
--- src/adentu-grid-cuda.cu
+++ src/adentu-grid-cuda.cu
@@ -124,6 +124,7 @@ void adentu_grid_cuda_set_atoms (AdentuGrid *grid,
CUDA_CALL (cudaFree (d_cellNAtoms));
CUDA_CALL (cudaFree (d_head));
CUDA_CALL (cudaFree (d_linked));
+
}
diff --git src/adentu.c src/adentu.c
index e5fb79e..6cd54ae 100644
--- src/adentu.c
+++ src/adentu.c
@@ -60,10 +60,15 @@ AdentuEventHandler *handler[] = {
int main (int argc, char *argv[])
{
+ g_message ("Reseting CUDA Device.");
+ adentu_usr_cuda_reset_device ();
+ g_message ("Initializing adentu.");
//set seeds
- srand (time (NULL));
- srand48 (time (NULL));
+ //srand (time (NULL));
+ //srand48 (time (NULL));
+ srand (1234567);
+ srand48 (1234567);
/* leer configuración */
@@ -94,8 +99,8 @@ int main (int argc, char *argv[])
/* creating grain grid */
AdentuGridConfig gc;
vecSet (gc.origin, 0.0, 0.0, 0.0);
- vecSet (gc.length, 128.0, 128.0, 128.0);
- vecSet (gc.cells, 8, 8, 8);
+ vecSet (gc.length, 3.1, 3.1, 3.1);
+ vecSet (gc.cells, 3, 3, 3);
gc.type = ADENTU_GRID_DEFAULT;
AdentuGrid g;
@@ -124,11 +129,11 @@ int main (int argc, char *argv[])
/* create grains */
AdentuAtomConfig ac;
- ac.nAtoms = 512;
+ ac.nAtoms = 27;
ac.type = ADENTU_ATOM_GRAIN;
ac.mass.from = ac.mass.to = 5.0;
ac.mass.rangeType = ADENTU_PROP_CONSTANT;
- ac.radii.from = ac.radii.to = 1.0;
+ ac.radii.from = ac.radii.to = 0.500000;
ac.radii.rangeType = ADENTU_PROP_CONSTANT;
AdentuAtom a;
@@ -140,16 +145,16 @@ int main (int argc, char *argv[])
m.grain = &a;
/* set atoms into grid */
- adentu_grid_set_atoms (&g, &a, &m.bCond);
+ //adentu_grid_set_atoms (&g, &a, &m.bCond);
/****************************************************/
/* creating fluid*/
- ac.nAtoms = 1024;
+ ac.nAtoms = 64;
ac.type = ADENTU_ATOM_FLUID;
ac.mass.from = ac.mass.to = 0.5;
ac.mass.rangeType = ADENTU_PROP_CONSTANT;
- ac.radii.from = ac.radii.to = 0.001;
+ ac.radii.from = ac.radii.to = 0.00000000000000;
ac.radii.rangeType = ADENTU_PROP_CONSTANT;
AdentuAtom f;
@@ -157,8 +162,8 @@ int main (int argc, char *argv[])
adentu_atom_set_init_vel (&f, &m);
//adentu_atom_set_init_pos (&f, &fg);
m.fluid = &f;
- adentu_grid_set_atoms (&fg, &f, &m.bCond);
- adentu_grid_set_atoms (&mpcg, &f, &m.bCond);
+ //adentu_grid_set_atoms (&fg, &f, &m.bCond);
+ //adentu_grid_set_atoms (&mpcg, &f, &m.bCond);
adentu_usr_cuda_set_atoms_pos (&m);
diff --git src/event/adentu-event-gfc.c src/event/adentu-event-gfc.c
index 9ec0994..b412131 100644
--- src/event/adentu-event-gfc.c
+++ src/event/adentu-event-gfc.c
@@ -129,14 +129,14 @@ void adentu_event_gfc_attend2 (AdentuModel *model,
if (fabs (pu - radius) > 10e-6)
{
- g_message ("Bad Prediction! - PU: %f != Radius: %f", pu, radius);
+ printf ("Bad Prediction! - PU: %f != Radius: %f\n", pu, radius);
//return ;
}
vec3f n;
vecScale (n, pos, pu);
- g_message ("radius: %f, pu: %f, pos: (%f, %f, %f), n: (%f, %f, %f), vecDot (n, n) = %f",
+ printf ("radius: %f, pu: %f, pos: (%f, %f, %f), n: (%f, %f, %f), vecDot (n, n) = %f\n",
radius, pu, pos.x, pos.y, pos.z, n.x, n.y, n.z, vecDot (n, n));
double VN = vecDot (n, vel);
diff --git src/event/adentu-event-ggc.c src/event/adentu-event-ggc.c
index 697cf72..c2b804d 100644
--- src/event/adentu-event-ggc.c
+++ src/event/adentu-event-ggc.c
@@ -120,14 +120,14 @@ void adentu_event_ggc_attend (AdentuModel *model,
if (fabs (pu - radius) > 10e-6)
{
- g_message ("Bad Prediction! - PU: %f != Radius: %f", pu, radius);
+ printf ("Bad Prediction! - PU: %f != Radius: %f\n", pu, radius);
//return ;
}
vec3f n;
vecScale (n, pos, pu);
- g_message ("radius: %f, pu: %f, pos: (%f, %f, %f), n: (%f, %f, %f), vecDot (n, n) = %f",
+ printf ("radius: %f, pu: %f, pos: (%f, %f, %f), n: (%f, %f, %f), vecDot (n, n) = %f\n",
radius, pu, pos.x, pos.y, pos.z, n.x, n.y, n.z, vecDot (n, n));
double VN = vecDot (n, vel);
diff --git src/usr/atoms-pos-cuda.cu src/usr/atoms-pos-cuda.cu
index 9ee1e38..f033c9e 100644
--- src/usr/atoms-pos-cuda.cu
+++ src/usr/atoms-pos-cuda.cu
@@ -36,6 +36,17 @@ extern "C" {
}
+
+
+extern "C"
+void adentu_usr_cuda_reset_device (void)
+{
+ cudaDeviceReset ();
+}
+
+
+
+
int set_fluid_cell_with_particles (vec3f *pos,
int nAtoms,
int Nfcg,
@@ -75,7 +86,7 @@ void adentu_usr_cuda_set_atoms_pos (AdentuModel *model)
double radius = grain->radius[0];
AdentuGrid *gGrid = model->gGrid;
- //AdentuGrid *fGrid = model->fGrid;
+ AdentuGrid *fGrid = model->fGrid;
vec3f g_origin = gGrid->origin;
//vec3f f_origin = fGrid->origin;
@@ -87,7 +98,7 @@ void adentu_usr_cuda_set_atoms_pos (AdentuModel *model)
//vec3i f_nCell = fGrid->nCell;
int g_tCell = gGrid->tCell;
- //int f_tCell = fGrid->tCell;
+ int f_tCell = fGrid->tCell;
vec3f g_h = gGrid->h;
//vec3f f_h = fGrid->h;
@@ -96,16 +107,21 @@ void adentu_usr_cuda_set_atoms_pos (AdentuModel *model)
int nFluids = fluid->n;
- if (g_tCell > nGrains)
+ if (g_tCell < nGrains)
g_error ("The number of atoms is greater than the number of grid cells.");
- if (g_h.x < radius ||
- g_h.y < radius ||
- g_h.z < radius)
+ if (g_h.x < radius*2 ||
+ g_h.y < radius*2 ||
+ g_h.z < radius*2)
g_error ("The size of the cells is less than the size of grain radius");
int *g_head = gGrid->head;
- //int *f_head = fGrid->head;
+ int *f_head = fGrid->head;
+
+ fGrid->linked = (int *) malloc (nFluids * sizeof (int));
+ //int *g_linked = gGrid->linked;
+ int *f_linked = fGrid->linked;
+ memset (f_linked, -1, nFluids * sizeof (int));
int *d_g_head = NULL;
//int *d_f_head = NULL;
@@ -155,6 +171,29 @@ void adentu_usr_cuda_set_atoms_pos (AdentuModel *model)
cudaMemcpyDeviceToHost));
+ /* print atoms in head */
+/* for (int c = 0; c < g_tCell; ++c )
+ {
+ printf ("head[%d] - atom: %d, pos: (%f, %f, %f)\n", c, g_head[c],
+ g_pos[c].x, g_pos[c].y, g_pos[c].z);
+ }
+
+ getchar ();
+
+ vec3f asdf;
+ for (int x = 0; x < g_tCell; ++x)
+ for (int y = x+1; y < g_tCell; ++y)
+ {
+ vecSub (asdf, g_pos[g_head[x]], g_pos[g_head[y]]);
+ if (vecMod (asdf) < 1.0)
+ g_error ("X: %d, Y: %d, VecMod(X, Y): %f\n", g_head[x], g_head[y],
+ vecMod (asdf));
+
+ }
+ getchar ();
+
+*/
+
int atom = 0;
for (int c = 0; c < g_tCell; ++c)
@@ -181,31 +220,68 @@ void adentu_usr_cuda_set_atoms_pos (AdentuModel *model)
}
+ for (int i = 0; i < nFluids; ++i)
+ printf (">%d pos (%f %f %f)\n", i, f_pos[i].x, f_pos[i].y, f_pos[i].z);
+
int awef = nFluids - atom;
while (awef)
- for (int c = 0; c < g_tCell; ++c)
- {
- if (gGrid->head[c] != -1)
- atom = set_fluid_cell_with_particles (f_pos,
- nFluids,
- 1,
- c,
- g_nCell,
- g_origin,
- g_h,
- atom,
- radius);
- else
- atom = set_fluid_cell_empty (f_pos,
- nFluids,
- 1,
- c,
- g_nCell,
- g_origin,
- g_h,
- atom);
- awef--;
- }
+ {
+ for (int c = 0; c < g_tCell; ++c)
+ {
+ if (gGrid->head[c] != -1)
+ atom = set_fluid_cell_with_particles (f_pos,
+ nFluids,
+ 1,
+ c,
+ g_nCell,
+ g_origin,
+ g_h,
+ atom,
+ radius);
+ else
+ atom = set_fluid_cell_empty (f_pos,
+ nFluids,
+ 1,
+ c,
+ g_nCell,
+ g_origin,
+ g_h,
+ atom);
+ awef--;
+ if (!awef)
+ break ;
+ }
+ }
+
+
+ for (int i = 0; i < nFluids; ++i)
+ printf (">%d pos (%f %f %f)\n", i, f_pos[i].x, f_pos[i].y, f_pos[i].z);
+
+
+ adentu_grid_cuda_set_atoms (gGrid, grain, &model->bCond);
+ adentu_grid_cuda_set_atoms (fGrid, fluid, &model->bCond);
+
+ g_message ("Differences between grains and fluids");
+ vec3f asdf;
+ for (int x = 0; x < f_tCell; ++x)
+ {
+ //g_message ("fCell: %d", x);
+ awef = f_head[x];
+ while (awef != -1)
+ {
+ //g_message ("awef: %d", awef);
+ for (int y = 0; y < g_tCell; ++y)
+ {
+ //g_message ("gGrid: %d", y);
+ vecSub (asdf, g_pos[g_head[y]], f_pos[awef]);
+ if (vecMod (asdf) < radius)
+ g_error ("cellF: %d, cellG: %d G:%d F:%d\n pos[g]: %f %f %f, pos[f]: %f %f %f",
+ x, y, y, awef, g_pos[y].x, g_pos[y].y, g_pos[y].z,
+ f_pos[x].x, f_pos[x].y, f_pos[x].z);
+ }
+ awef = f_linked[awef];
+ }
+ }
}
@@ -240,13 +316,19 @@ int set_fluid_cell_with_particles (vec3f *pos,
r = sqrt (d.x*d.x + d.y*d.y + d.z*d.z);
if (r > g_radius)
{
+ if (atom == 32)
+ printf ("d (%f, %f, %f), cell: %d, nCell: (%d, %d, %d)\n",
+ d.x, d.y, d.z, cell, nCell.x, nCell.y, nCell.z);
cPos.z = cell / (nCell.x * nCell.y);
cPos.y = (cell % (nCell.x * nCell.y)) / nCell.x;
cPos.x = (cell % (nCell.x * nCell.y)) % nCell.x;
-
+
vecSet (aPos, cPos.x * h.x + origin.x + h.x/2 + d.x,
cPos.y * h.y + origin.y + h.y/2 + d.y,
cPos.z * h.z + origin.z + h.z/2 + d.z);
+ if (atom == 32)
+ printf ("cPos (%d %d %d) aPos (%f %f %f)\n",
+ cPos.x, cPos.y, cPos.z, aPos.x, aPos.y, aPos.z);
pos[atom] = aPos;
++atom;
@@ -255,6 +337,7 @@ int set_fluid_cell_with_particles (vec3f *pos,
}
while (count < Nfcg);
+
return atom;
}
@@ -312,6 +395,9 @@ __global__ void adentu_usr_cuda_set_grain_pos_kernel (vec3f *pos,
vec3f aPos;
vec3i cPos;
+ if (idx == 2)
+ printf ("cell: %d, nCell: (%d, %d, %d)\n",
+ idx, nCell.x, nCell.y, nCell.z);
cPos.z = idx / (nCell.x * nCell.y);
cPos.y = (idx % (nCell.x * nCell.y)) / nCell.x;
@@ -320,6 +406,9 @@ __global__ void adentu_usr_cuda_set_grain_pos_kernel (vec3f *pos,
vecSet (aPos, cPos.x * h.x + origin.x + h.x/2,
cPos.y * h.y + origin.y + h.y/2,
cPos.z * h.z + origin.z + h.z/2);
+ if (idx == 2)
+ printf ("cPos (%d %d %d) aPos (%f %f %f)\n",
+ cPos.x, cPos.y, cPos.z, aPos.x, aPos.y, aPos.z);
pos[idx] = aPos;
head[idx] = idx;
diff --git src/usr/atoms-pos-cuda.h src/usr/atoms-pos-cuda.h
index 4dc1dfb..100485a 100644
--- src/usr/atoms-pos-cuda.h
+++ src/usr/atoms-pos-cuda.h
@@ -26,4 +26,6 @@
void adentu_usr_cuda_set_atoms_pos (AdentuModel *model);
+void adentu_usr_cuda_reset_device (void);
+
#endif /* __ADENTU_USR_ATOMS_POS_CUDA_H__ */
diff --git src/usr/print-event-info.c src/usr/print-event-info.c
index 591b785..93cff4c 100644
--- src/usr/print-event-info.c
+++ src/usr/print-event-info.c
@@ -43,7 +43,7 @@ void print_post_event (AdentuModel *model, AdentuEvent *event)
AdentuAtom *atom1, *atom2;
- printf ("pos> type: %s, time: %f ", AdentuEventTypeStr[event->type],
+ printf ("pos> type: %s, time: %.10f ", AdentuEventTypeStr[event->type],
event->time);
if (event->type == ADENTU_EVENT_BC_GRAIN ||
@@ -59,6 +59,7 @@ void print_post_event (AdentuModel *model, AdentuEvent *event)
printf (" Pos: ");
print3f (atom1->pos[owner]);
puts ("");
+ puts ("");
}
else
if (event->type == ADENTU_EVENT_GGC ||
@@ -80,6 +81,7 @@ void print_post_event (AdentuModel *model, AdentuEvent *event)
printf (" Partner Pos: ");
print3f (atom2->pos[owner]);
puts ("");
+ puts ("");
}
}
@@ -92,8 +94,8 @@ void print_pre_event (AdentuModel *model, AdentuEvent *event)
AdentuAtom *atom1, *atom2;
- printf ("pre> type: %s, time: %f ", AdentuEventTypeStr[event->type],
- event->time);
+ printf ("pre> type: %s, time: %.10f ", AdentuEventTypeStr[event->type],
+ model->elapsedTime);
if (event->type == ADENTU_EVENT_BC_GRAIN ||
event->type == ADENTU_EVENT_BC_FLUID)
diff --git src/vec3-cuda.cu src/vec3-cuda.cu
index d9d07e1..1bc4f39 100644
--- src/vec3-cuda.cu
+++ src/vec3-cuda.cu
@@ -45,8 +45,9 @@ void vRand3f_cuda (vec3f *d_v, int n)
curandState *d_states;
CUDA_CALL (cudaMalloc ((void **)&d_states, n * sizeof (curandState)));
- dim3 gDim (1);
- dim3 bDim (n);
+ dim3 gDim;
+ dim3 bDim;
+ adentu_cuda_set_grid (&gDim, &bDim, n);
set_seed<<<gDim, bDim>>> (d_states, time (NULL), n);
vRand3f_cuda_generate<<<gDim, bDim>>> (d_v, d_states, n);