-
Notifications
You must be signed in to change notification settings - Fork 0
/
printFunctions.cu
403 lines (300 loc) · 12.6 KB
/
printFunctions.cu
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
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "typeDefinition.cuh"
//#include "globalVariables.cuh"
#include "./common/CudaSafeCall.h"
// Print a 1D slice of data
void print1D(const char *path, stateVar g_h, paramVar *param) {
int i, j, idx;
i = param->nx/2;
//Print data
FILE *fp1;
fp1 = fopen(path,"w+");
// Notice we are not saving the ghost points
for (j=0;j<param->ny;j++) {
idx = i + param->nx * j;
fprintf(fp1, "%d\t %f\n", j, (float)g_h.u[idx]);
}
fclose (fp1);
printf("1D data file created\n");
}
// Print a 2D slice of data
void print2DGnuplot(const char *path, stateVar g_h, paramVar *param) {
int i, j, idx;
//Print data
FILE *fp1;
fp1 = fopen(path,"w+");
// Notice we are not saving the ghost points
for (j=0;j<param->ny;j++) {
for (i=0;i<param->nx;i++) {
idx = i + param->nx * j;
fprintf(fp1, "%d\t %d\t %f\n", i, j, (float)g_h.u[idx]);
}
fprintf(fp1,"\n");
}
fclose (fp1);
printf("2D GNU format data file created\n");
}
// Print a 2D slice of data
void print2D2column(const char *path, stateVar g_h, paramVar *param) {
int i, j, idx;
//Print data
FILE *fp1;
fp1 = fopen(path,"w+");
// Notice we are not saving the ghost points
for (j=0;j<param->ny;j++) {
for (i=0;i<param->nx;i++) {
idx = i + param->nx * j;
fprintf(fp1,"%f %f\n", (float)g_h.u[idx], (float)g_h.v[idx]);
}
}
fclose (fp1);
printf("2D data file created\n");
}
void print2DSubWindow(const char *path, stateVar g_h, paramVar *param) {
int i, j, idx;
int xmin = floor(param->tipx)-param->tipOffsetX-1;
int xmax = floor(param->tipx)+param->tipOffsetX+1;
int ymin = floor(param->tipy)-param->tipOffsetY-1;
int ymax = floor(param->tipy)+param->tipOffsetY+1;
//Print data
FILE *fp1;
fp1 = fopen(path,"w+");
// Save a window
for (j=ymin;j<ymax;j++) {
for (i=xmin;i<xmax;i++) {
idx = i + param->nx * j;
fprintf(fp1,"%f %f\n", (float)g_h.u[idx], (float)g_h.v[idx]);
}
}
fclose (fp1);
printf("2D data file created\n");
}
// Voltage time tracing
void printVoltageInTime(const char *path, std::vector<electrodeVar> &sol,
paramVar *param) {
int i;
//Print data
FILE *fp1;
fp1 = fopen(path,"w+");
for (i=0;i<sol.size();i++) {
fprintf(fp1, "%f\t", i*(float)param->dt*param->itPerFrame);
fprintf(fp1, "%f\t", (float)sol[i].e0);
fprintf(fp1, "%f\t", (float)sol[i].e1);
}
fclose (fp1);
printf("Voltage time series file created\n");
}
// Voltage time tracing
void printContourLengthInTime(const char *path, std::vector<REAL> &sol,
paramVar *param) {
int i;
//Print data
FILE *fp1;
fp1 = fopen(path,"w+");
for (i=0;i<sol.size();i++) {
fprintf(fp1, "%f\t", i*(float)param->dt*param->itPerFrame);
fprintf(fp1, "%f\t", (float)sol[i]);
}
fclose (fp1);
printf("Voltage time series file created\n");
}
void printTip(const char *path1, const char *path2, int *tip_count,
vec5dyn *tip_vector, paramVar *param) {
// The contour_vector device array is emptyed every iteration.
// The data is downloaded to a single file.
// The number of points downloaded in each iteration is also recorded.
//Print data
FILE *fp1, *fp2;
if (param->firstIterTip==true) {
fp1 = fopen(path1,"w+");
fp2 = fopen(path2,"w+");
param->firstIterTip = false;
} else {
fp1 = fopen(path1,"a+"); // Write on the same data file
fp2 = fopen(path2,"a+");
}
int *tip_pts;
tip_pts = (int*)malloc(sizeof(int));
CudaSafeCall(cudaMemcpy(tip_pts,tip_count,sizeof(int),cudaMemcpyDeviceToHost));
if (*tip_pts > TIPVECSIZE ) {
printf("ERROR: NUMBER OF TIP POINTS EXCEEDS tip_vector SIZE\n");
exit(0);
}
vec5dyn *tip_array;
tip_array = (vec5dyn*)malloc((*tip_pts)*sizeof(vec5dyn));
CudaSafeCall(cudaMemcpy(tip_array,tip_vector,(*tip_pts)*sizeof(vec5dyn),cudaMemcpyDeviceToHost));
if (*tip_pts > 0) {
for (size_t i = 0;i<(*tip_pts);i++) {
fprintf(fp1,"%f %f %f %f %f\n",tip_array[i].x,tip_array[i].y,
tip_array[i].vx,tip_array[i].vy,tip_array[i].t);
}
fprintf(fp2,"%d\n", *tip_pts);
}
fclose (fp1);
fclose (fp2);
free(tip_pts);
free(tip_array);
printf("Tip files created\n");
}
void printContour(const char *path1, const char *path2,
int *contour_count, float3 *contour_vector, paramVar *param) {
// The contour_vector device array is emptyed every iteration.
// The data is downloaded to a single file.
// The number of points downloaded in each iteration is also recorded.
//Print data
FILE *fp1, *fp2;
if (param->firstIterContour==true) {
fp1 = fopen(path1,"w+");
fp2 = fopen(path2,"w+");
param->firstIterContour = false;
} else {
fp1 = fopen(path1,"a+"); // Write on the same data file
fp2 = fopen(path2,"a+");
}
int *contour_pts;
contour_pts = (int*)malloc(sizeof(int));
CudaSafeCall(cudaMemcpy(contour_pts,contour_count,sizeof(int),cudaMemcpyDeviceToHost));
// printf("No. pts = %d\n",*contour_pts);
if (*contour_pts > param->nx*param->ny ) {
printf("ERROR: NUMBER OF CONTOUR POINTS EXCEEDS contour_vector SIZE\n");
exit(0);
}
float3 *contour_array;
contour_array = (float3*)malloc((*contour_pts)*sizeof(float3));
CudaSafeCall(cudaMemcpy(contour_array,contour_vector,(*contour_pts)*sizeof(float3),cudaMemcpyDeviceToHost));
if (*contour_pts > 0) {
for (size_t i = 0;i<(*contour_pts);i++) {
fprintf(fp1,"%f %f %f\n",contour_array[i].x,contour_array[i].y,contour_array[i].z);
}
fprintf(fp2,"%d\n", *contour_pts);
}
fclose (fp1);
fclose (fp2);
free(contour_pts);
free(contour_array);
printf("Contour files created\n");
}
void printSym(const char *path, std::vector<REAL3> &clist, std::vector<REAL3> &philist) {
//Print data
FILE *fp1;
fp1 = fopen(path,"w+");
for (size_t i=0;i<(clist.size());i++) {
fprintf(fp1,"%f %f %f %f %f %f\n",
clist[i].x,clist[i].y,clist[i].t,philist[i].x,philist[i].y,philist[i].t);
}
fclose (fp1);
printf("Symmetry files created\n");
}
void printParameters(fileVar strAdress, paramVar *param) {
// Reading and writing (printing) functions have to have the same order.
/*------------------------------------------------------------------------
* Create dat file
*------------------------------------------------------------------------
*/
char resultsPath[100];
char strDirParamCSV[] = "dataparamcsv.csv";
memcpy(resultsPath,strAdress.paramFile,sizeof(resultsPath));
strcat(strAdress.paramFile,strDirParamCSV);
//Print data
FILE *fp1;
fp1 = fopen(strAdress.paramFile,"w+");
/*------------------------------------------------------------------------
* Create CSV file
*------------------------------------------------------------------------
*/
fprintf(fp1,"Initial condition path:,%s\n", param->load ? strAdress.read : "NA");
fprintf(fp1,"Results file path:,%s\n", param->save ? resultsPath : "NA");
fprintf(fp1,"Save every sampling period:,%d\n", param->saveEveryIt ? 1 : 0);
fprintf(fp1,"plot tip on screen:,%d\n", param->plotTip ? 1 : 0);
fprintf(fp1,"Save tip in to data file:,%d\n", param->recordTip ? 1 : 0);
fprintf(fp1,"Plot contours on screen:,%d\n", param->plotContour ? 1 : 0);
fprintf(fp1,"Save contours to data file:,%d\n", param->recordContour ? 1 : 0);
fprintf(fp1,"Pacing stimulus:,%d\n", param->stimulate ? 1 : 0);
fprintf(fp1,"Plot time series:,%d\n", param->plotTimeSeries ? 1 : 0);
fprintf(fp1,"Record time series:,%d\n", param->recordTimeSeries ? 1 : 0);
fprintf(fp1,"Reduce symmetry:,%d\n", param->reduceSym ? 1 : 0);
fprintf(fp1,"Solid boundary:,%d\n", param->solidSwitch ? 1 : 0);
fprintf(fp1,"Neumann BCs:,%d\n", param->neumannBC ? 1 : 0);
fprintf(fp1,"Gate diffusion:,%d\n", param->gateDiff ? 1 : 0);
fprintf(fp1,"Tip trajectory algorithm:, %d\n", param->tipAlgorithm);
fprintf(fp1,"Anisotropic tisue:,%d\n", param->anisotropy ? 1 : 0);
fprintf(fp1,"Tip gradient:,%d\n", param->tipGrad ? 1 : 0);
fprintf(fp1,"Contour mode (space APD or refractory):,%d\n", param->contourMode);
fprintf(fp1,"Laplacian order:,%d\n", param->lap4 ? 1 : 0);
fprintf(fp1,"Scheme order for time integration (Euler or RK4):,%d\n", param->timeIntOrder);
fprintf(fp1,"Conduction block clock:,%d\n", param->clock ? 1 : 0);
fprintf(fp1,"Conduction block counterclock:,%d\n", param->counterclock ? 1 : 0);
fprintf(fp1,"# grid points X =,%d\n", param->nx);
fprintf(fp1,"# grid points Y =,%d\n", param->ny);
fprintf(fp1,"Physical Lx length,%f\n", (float)param->Lx);
fprintf(fp1,"Physical Ly length,%f\n", (float)param->Ly);
fprintf(fp1,"Physical dx,%f\n", (float)param->hx);
fprintf(fp1,"Physical dy,%f\n", (float)param->hy);
fprintf(fp1,"Time step:,%f\n", param->reduceSym ? 2.0*(float)param->dt : param->dt);
fprintf(fp1,"Diffusion parallel component:,%f\n", (float)param->diff_par);
fprintf(fp1,"Diffusion perpendicular component:,%f\n", (float)param->diff_per);
fprintf(fp1,"Initial fiber angle:,%f\n", (float)param->degrad);
fprintf(fp1,"Diffusion Dxx:,%f\n", (float)param->Dxx);
fprintf(fp1,"Diffusion Dyy:,%f\n", (float)param->Dyy);
fprintf(fp1,"Diffusion Dxy:,%f\n", (float)param->Dxy);
fprintf(fp1,"rxy (2*Dxy*dt/(4*dx*dy)):,%f\n", (float)param->rxy);
fprintf(fp1,"rbx (hx*Dxy/(Dxx*dy)):,%f\n", (float)param->rbx);
fprintf(fp1,"rby (hy*Dxy/(Dyy*dx)):,%f\n", (float)param->rby);
fprintf(fp1,"rx (Dxx*dt/(dx*dx)):,%f\n", (float)param->rx);
fprintf(fp1,"ry (Dyy*dt/(dy*dy)):,%f\n", (float)param->ry);
fprintf(fp1,"Gate r-scale:,%f\n", (float)param->rscale);
fprintf(fp1,"invdx (1/(2*hx)),%f\n", (float)param->invdx);
fprintf(fp1,"invdy (1/(2*hy)),%f\n", (float)param->invdy);
fprintf(fp1,"qx4 (dt*hx*hx*Dyy/12):,%f\n", (float)param->qx4);
fprintf(fp1,"qy4 (dt*hy*hx*Dxx/12):,%f\n", (float)param->qy4);
fprintf(fp1,"fx4 (dt*hx*hx/12):,%f\n", (float)param->fx4);
fprintf(fp1,"fy4 (dt*hy*hy/12):,%f\n", (float)param->fy4);
fprintf(fp1,"Physical time limit:,%f\n", (float)param->physicalTimeLim);
fprintf(fp1,"Start recording time:,%f\n", (float)param->startRecTime);
fprintf(fp1,"Number of electrodes,%d\n", param->eSize);
fprintf(fp1,"Electrode position x:,%f\n", (float)param->point.x);
fprintf(fp1,"Electrode position y:,%f\n", (float)param->point.y);
fprintf(fp1,"Stimulus period (ms):,%f\n", param->stimPeriod);
fprintf(fp1,"Stimulus magnitude:,%f\n", (float)param->stimMag);
fprintf(fp1,"Stimulus duration (ms):,%f\n", (float)param->stimDuration);
fprintf(fp1,"Voltage threshold for fibrillation:,%f\n", (float)param->fibThreshold);
fprintf(fp1,"Fibrillation terminated by pacing:,%d\n", param->fibTerminated ? 1 : 0);
fprintf(fp1,"Number of LEAP shocks applied:,%d\n", param->leapShocks);
fprintf(fp1,"Number of points in circles:,%d\n",param->nc);
fprintf(fp1,"Stimulus position x:,%f\n",(float)param->stcx);
fprintf(fp1,"Stimulus position y:,%f\n",(float)param->stcy);
fprintf(fp1,"Stimulus area radius:,%f\n",(float)param->rdomStim);
fprintf(fp1,"APD area radius:,%f\n",(float)param->rdomAPD);
fprintf(fp1,"Tip offset x,%d\n",param->tipOffsetX);
fprintf(fp1,"Tip offset y,%d\n",param->tipOffsetY);
fprintf(fp1,"Integral area radius:,%f\n",(float)param->rdomTrapz);
fprintf(fp1,"Dirichlet BC value:,%f\n",(float)param->boundaryVal);
fprintf(fp1,"Iterations per frame:,%d\n", param->itPerFrame);
fprintf(fp1,"Sampling period (ms):,%f\n", param->sample);
fprintf(fp1,"Min signal range,%f\n", (float)param->minVarColor);
fprintf(fp1,"Max signal range,%f\n", (float)param->maxVarColor);
fprintf(fp1,"Secondary window size x,%d\n", param->wnx);
fprintf(fp1,"Secondary window size y,%d\n", param->wny);
fprintf(fp1,"Secondary window min signal 1,%f\n", (float)param->uMin);
fprintf(fp1,"Secondary window max signal 1,%f\n", (float)param->uMax);
fprintf(fp1,"Secondary window min signal 2,%f\n", (float)param->vMin);
fprintf(fp1,"Secondary window max signal 2,%f\n", (float)param->vMax);
fprintf(fp1,"Last tip point X,%f\n", (float)param->tipx);
fprintf(fp1,"Last tip point Y,%f\n", (float)param->tipy);
fprintf(fp1,"Contour threshold 1:,%f\n", (float)param->contourThresh1);
fprintf(fp1,"Contour threshold 2:,%f\n", (float)param->contourThresh2);
fprintf(fp1,"Contour threshold 3:,%f\n", (float)param->contourThresh3);
fprintf(fp1,"Filament voltage threshold:,%f\n", (float)param->Uth);
fprintf(fp1,"time scale (tc):,%f\n", (float)param->tc);
fprintf(fp1,"alpha:,%f\n", (float)param->alpha);
fprintf(fp1,"beta:,%f\n", (float)param->beta);
fprintf(fp1,"gamma:,%f\n", (float)param->gamma);
fprintf(fp1,"delta:,%f\n", (float)param->delta);
fprintf(fp1,"epsilon:,%f\n", (float)param->eps);
fprintf(fp1,"mu:,%f\n", (float)param->mu);
fprintf(fp1,"theta:,%f\n", (float)param->theta);
fclose (fp1);
printf("Parameter files created\n");
}