-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
260 lines (227 loc) · 5.34 KB
/
main.cpp
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
#include "commonData.h"
#include "keyboard.h"
#include "main.h"
#include <time.h>
#include <pthread.h>
#include <omp.h>
#include <sys/time.h>
//#include "viennacl/vector.hpp"
#define WG //WG - With Graphics
//#undef WG
int grid_size;
int nthreads;
#ifndef WG
int main(int argc, char** argv)
{
grid_size = GRID_SIZE;
nthreads = NTHREADS;
if(argc>=2){
nthreads = atoi(argv[1]);
grid_size = atoi(argv[2]);
}
omp_set_num_threads(nthreads);
struct timeval tt1, tt2;
initMain();
int i=pthread_getconcurrency();
int it=0;
int ni= 0;
while(ni++<NO_OF_ITERATIONS){
gettimeofday(&tt1, NULL);
animate();
gettimeofday(&tt2, NULL);
int milliSeconds = (tt2.tv_sec - tt1.tv_sec) * 1000 + (tt2.tv_usec - tt1.tv_usec)/1000;
cout<<"Iteration "<<it<<" : "<<milliSeconds<<"ms"<<endl<<endl;
it++;
}
return 0;
}
#endif
void animate()
{
fluidSim->simulate(timestep);
}
void initMain(void)
{
sGrid->initGridStag();
fluidSim->init(sGrid);
fluidSim->initFluidBody(fBT);// 2: indicates dam break center
print->init(sGrid);
render->init(sGrid);
}
void initParticles()
{
sGrid->fluidParticles.clear();
}
/*------------------Code Below this is used when rendered is ON---------*/
void display ( void ) ;
void preDisplay ( );
void postDisplay ( );
void openGlutWindow ( char* windowName) ;
void reshape ( int w, int h ) ;
void idleFun();
#ifdef WG
int main(int argc, char** argv)
{
grid_size = GRID_SIZE;
nthreads = NTHREADS;
if(argc>=2){
nthreads = atoi(argv[1]);
grid_size = atoi(argv[2]);
}
omp_set_num_threads(nthreads);
/*#pragma omp parallel
{
cout<<"Hello"<<endl;
}*/
//int i=0;
/*matrix<double > temp;
temp.resize(10,10);
#pragma omp parallel for
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
cout<<temp(i,j);
*/
glutInit(&argc, argv);
initMain ();
int i=pthread_getconcurrency();
char windowName[]=" Liquid_Simulator-LevelSet+Surface" ;
openGlutWindow(windowName);
glutMainLoop();
return 0;
}
#endif
void display(void){
preDisplay();
static bool flag[10]={false,false,false,false,false,true};//boundary grid particles surface vector mat
char output1 = ' ';
bool anyUpdation = false;
switch(output1){
case'~':
flag[0] = !flag[0];
//render->renderBoundary
break;
case '!':
flag[1] = !flag[1];
//render->renderGrid();
break;
case '@':
flag[2] = !flag[2];
//render->renderParticles();
break;
case '#':
flag[3] = !flag[3];
//render->renderSurfaceBoundary();
break;
case '$':
flag[4] = !flag[4];
//render->renderVector2D(sGrid->u,sGrid->v);
break;
case '%':
flag[5] = !flag[5];
//render->renderMat(sGrid->distanceLevelSet,1);
break;
/*case '^':
flag[6] = !flag[6];
//render->renderMat(sGrid->isFluidBoundary,1);
break;*/
}
if(anyUpdation){
cout<<"Flags :"<<" ~"<<flag[0]<<" !"<<flag[1]<<" @"<<flag[2]<<" #"<<flag[3]<<
" $"<<flag[4]<<" %"<<flag[5]/*<<" ^"<<flag[6]*/<<" +"<<endl;
anyUpdation = false;
}
extern int swich;
if(swich==0){
//render->renderBoundary();
render->renderGrid();
render->renderParticles();
render->renderSurfaceBoundary();
}
else if(swich==1){
render->renderMat(sGrid->p,2);
}
else if(swich==2){
render->renderMat(sGrid->distanceLevelSet,2);
}
else if(swich==3){
render->renderBoundary();
render->renderGrid();
render->renderVector2D(sGrid->u,sGrid->v);
}
/*if(flag[0])
render->renderBoundary();
if(flag[1])
render->renderGrid();
if(flag[2])
render->renderParticles();
if(flag[3])
render->renderSurfaceBoundary();
if(flag[4])
render->renderVector2D(sGrid->u,sGrid->v); */
//if(flag[5])
//render->renderMat(sGrid->distanceLevelSet,2);
//render->renderMat(sGrid->p,2);
/*if(flag[6])
render->renderMat(sGrid->isFluidBoundary,1);
*/
output1 = ' ';
postDisplay();
}
void idleFun ( void )
{
extern bool isPause ;
if(!isPause){
struct timeval tt1, tt2;
static int it = 0;
static struct timeval tt3, tt4;
gettimeofday(&tt4, NULL);
gettimeofday(&tt1, NULL);
animate();
gettimeofday(&tt2, NULL);
int milliSeconds2 = (tt4.tv_sec - tt3.tv_sec) * 1000 + (tt4.tv_usec - tt3.tv_usec)/1000;
cout<<"Rander Time Frame "<<it-1<<" : "<<milliSeconds2<<"ms"<<endl;
int milliSeconds = (tt2.tv_sec - tt1.tv_sec) * 1000 + (tt2.tv_usec - tt1.tv_usec)/1000;
cout<<"Iteration "<<it<<" : "<<milliSeconds<<"ms"<<endl<<endl;
gettimeofday(&tt3, NULL);
it++;
glutSetWindow ( winId );
glutPostRedisplay ( );
}
}
void reshape (int w, int h)
{
glutSetWindow(winId);
glutReshapeWindow(w ,h);
winSizeX = w;
winSizeY = h;
}
void preDisplay()
{
glViewport ( 0, 0, winSizeX, winSizeY);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho( 0, zoomFactor, 0, zoomFactor , 0,1 ); //better to use ortho..
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
void postDisplay()
{
glutSwapBuffers();
}
void openGlutWindow(char* windowName)
{
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE );
glutInitWindowSize (winSizeX, winSizeY);
glutInitWindowPosition (570, 100);
winId = glutCreateWindow (&windowName[2]);
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
glutDisplayFunc(display);
// glutSpecialFunc(&SpecialKeyPressed);
glutKeyboardFunc(&KeyPressed);
glutReshapeFunc(reshape);
glutIdleFunc(idleFun);
}