-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
439 lines (277 loc) · 8.78 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
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
// with mass matrix, and all
// plus, correction to quadratic consistency
// periodic boundary conditions
#include <CGAL/Timer.h>
// write out matrices
//#define WRITE
#define EXPLICIT
#include"main.h"
#include"sim_pars.h"
#include"linear.h"
#include"fields.h"
// Init global stuff.-
#include"periodic.h"
const FT LL=1; // length of original domain
Iso_rectangle domain(-LL/2, -LL/2, LL/2, LL/2);
// TODO: the two triangulations store different things.
// specific bases and faces should be implemented for each
sim_pars simu;
void create(void);
//const Eigen::IOFormat OctaveFmt(Eigen::StreamPrecision, 0, ", ", ";\n", "", "", "[", "];");
Triangulation Tp(domain); // particles
int main() {
// CGAL::Timer time;
//
// time.start();
cout << "Creating point cloud" << endl;
simu.read();
create();
if(simu.create_points()) {
set_alpha_circle( Tp , 0.5 );
number(Tp);
}
// areas(Tp);
// quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );
// volumes(Tp, simu.FEMp() );
// Delta(Tp);
// linear algebra(Tp);
// if(simu.create_points()) {
// nabla(Tp);
// Delta(Tp);
// }
set_vels_Gresho( Tp );
move_info(Tp);
// /// Prev test begin
//cout << "Calculating Lapl U" << endl;
//algebra.laplacian_v(kind::UOLD,kind::LAPLU);
//FT dt=simu.dt();
//cout << "Calculating Ustar implicitely" << endl;
//algebra.ustar_inv(kind::USTAR, dt , kind::UOLD, false);
//cout << "Solving PPE" << endl;
//algebra.PPE( kind::USTAR, dt, kind:: P );
//cout << "Calculating grad p" << endl;
//algebra.gradient(kind::P, kind::GRADP);
//algebra.mass_s(kind::DIVU);
//draw();
// return 1;
/// Prev test end
#ifdef WRITE
algebra.save_matrices();
#endif
// set_fields();
// set_vels();
const std::string particle_file("particles.dat");
draw(Tp, particle_file , true);
simu.advance_time();
simu.next_step();
// bool first_iter=true;
CGAL::Timer time;
time.start();
std::ofstream log_file, ints_file;
log_file.open("main.log");
ints_file.open("integrals.log");
bool overdamped = ( simu.mu() > 1 ) ; // high or low Re
for(;
simu.current_step() <= simu.Nsteps();
simu.next_step()) {
cout
<< "Step " << simu.current_step()
<< " . Time " << simu.time()
<< " ; t step " << simu.dt()
<< endl;
FT dt=simu.dt();
FT dt2 = dt / 2.0 ;
int iter=0;
FT displ=1e10;
FT min_displ=1e10;
int min_iter=0;
const int max_iter=10;
const FT max_displ= 1e-8; // < 0 : disable
// leapfrog, special first step.-
// if(simu.current_step() == 1) dt2 *= 0.5;
// dt2 *= 0.5;
move_info(Tp);
FT d0;
// iter loop
for( ; iter<max_iter ; iter++) {
cout << "Move iteration " << iter << " of " << max_iter << " ";
displ=move( Tp , dt2 , d0 );
cout << "Moved avg " << displ << " to half point" << endl;
if( (displ < max_displ) && (iter !=0) ) break;
areas(Tp);
quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );
nabla(Tp);
Delta(Tp);
linear algebra(Tp);
if( displ < min_displ) {
min_displ=displ;
min_iter=iter;
}
#ifdef EXPLICIT
cout << "Calculating Ustar explicitely" << endl;
algebra.laplacian_v(kind::UOLD,kind::LAPLU);
// u_star(Tp, dt2 , false );
// Use only with no forces or viscosity !!
u_star_inviscid( Tp );
#else
cout << "Calculating Ustar implicitely" << endl;
// algebra.ustar_inv(kind::USTAR, dt2 , kind::UOLD, false , false);
// algebra.alpha_inv(kind::ALPHA, dt2, kind::ALPHA0 );
algebra.ustar_inv(kind::USTAR, dt2 , kind::UOLD, overdamped , false);
#endif
cout << "Solving PPE" << endl;
algebra.PPE( kind::USTAR, dt2 , kind:: P );
cout << "Calculating grad p" << endl;
// full version:
// algebra.gradient(kind::P, kind::GRADP);
// lumped version:
algebra.gradient(kind::P, kind::GRADP, false);
cout << "Evolving U " << endl;
// u_new( dt );
u_new( Tp , dt2 );
} // iter loop
displ=move( Tp , dt , d0 );
// update_half_velocity( Tp , false );
update_half_velocity( Tp , overdamped );
areas(Tp);
quad_coeffs(Tp , simu.FEMp() ); volumes(Tp, simu.FEMp() );
if(simu.current_step()%simu.every()==0)
draw(Tp, particle_file , true);
log_file
<< simu.current_step() << " "
<< simu.time() << " "
<< " iters = " << iter-1
<< " T = " << kinetic_E( Tp )
<< " L2_vel = " << L2_vel_Gresho( Tp )
<< endl ;
integrals( Tp , ints_file); ints_file << " ";
fidelity( Tp , ints_file ); ints_file << endl;
simu.advance_time();
} // time loop
time.stop();
log_file.close();
ints_file.close();
cout << "Total runtime: " << time.time() << endl;
return 0;
}
void create(void) {
int N=simu.no_of_particles();
std::vector<Point> points;
points.reserve(N);
if(simu.create_points()) {
if(simu.at_random()) {
points.reserve(N);
CGAL::Random_points_in_square_2<Point,Creator> g(LL/2.0-0.0001);
CGAL::copy_n( g, N, std::back_inserter(points));
cout << N << " particles placed at random" << endl;
} else {
// if((plotting)&&(Nin%2==0)&&(spike)) {
// cout << "Please enter an odd number of particles" << endl;
// std::abort();
// }
int Nb=sqrt(N + 1e-12);
N=Nb*Nb;
simu.set_no_of_particles(N);
points.reserve(N);
cout << N << " particles placed on square lattice" << endl;
FT spacing=LL/FT(Nb+0);
FT side=LL-1*spacing;
points_on_square_grid_2(side/2.0, N, std::back_inserter(points),Creator());;
if(simu.perturb()) {
CGAL::perturb_points_2(
points.begin(), points.end(),
simu.pert_rel()* spacing );//,Creator());
cout << "each particle perturbed about " << simu.pert_rel()* spacing << endl;
}
}
cout << "Inserting" << endl;
Tp.insert(points.begin(), points.end());
} else {
int N=simu.no_of_particles();
char part_file[]="particles.dat";
cout << "reading from file : " << part_file << endl;
std::ifstream main_data;
main_data.open(part_file );
for(int i=0;i<N;i++) {
FT x,y;
main_data >> x;
main_data >> y;
// cout << x << " " << y << endl;
Vertex_handle vh=Tp.insert(Point(x,y));
#include"readin.h"
}
cout << "particles' data read" << endl;
main_data.close();
}
// straight from the manual.-
Triangulation::Covering_sheets cs = Tp.number_of_sheets();
cout << "Original covering (particles): " << cs[0] << ' ' << cs[1] << endl;
// return ;
Tp.convert_to_1_sheeted_covering();
cs = Tp.number_of_sheets();
cout << "Current covering (particles): " << cs[0] << ' ' << cs[1] << endl;
return ;
if ( Tp.is_triangulation_in_1_sheet() ) // = true
{
bool is_extensible = Tp.is_extensible_triangulation_in_1_sheet_h1()
|| Tp.is_extensible_triangulation_in_1_sheet_h2(); // = false
Tp.convert_to_1_sheeted_covering();
cs = Tp.number_of_sheets();
cout << "Current covering: " << cs[0] << ' ' << cs[1] << endl;
if ( is_extensible ) // = false
cout << "It is safe to change the triangulation here." << endl;
else {
cout << "It is NOT safe to change the triangulation here!" << endl;
abort();
}
// T.convert_to_9_sheeted_covering();
// cs = T.number_of_sheets();
// cout << "Current covering: " << cs[0] << ' ' << cs[1] << endl;
} else {
cout << "Triangulation not on one sheet!" << endl;
abort();
}
// cout << "It is (again) safe to modify the triangulation." << endl;
return ;
}
void number(Triangulation& T) {
int i=0;
for(F_v_it vit=T.vertices_begin();
vit != T.vertices_end();
vit++) {
// vit->indx.set(i); //or
vit->idx=i;
++i;
}
return;
}
// for (
// Periodic_point_iterator pit=
// T.periodic_points_begin(stored_cover);
// pit != T.periodic_points_end(stored_cover);
// ++pit)
// {
// // pt = *ptit;
// // if (! (pt[0].second.is_null() && pt[1].second.is_null() && pt[2].second.is_null()) )
// // {
// // Convert the current Periodic_triangle to a Triangle if it is
// // not strictly contained inside the original domain.
// // Note that this requires EXACT constructions to be exact!
// // t_bd = T.triangle(pt);
// //}
// Point p=pit->first;
// Offset os=pit->second;
// interior
// << p.x()+os[0]*LL << " "
// << p.y()+os[1]*LL << " "
// // << vit->indx()
// << endl;
// }
// for(F_v_it vit=T.vertices_begin();
// vit != T.vertices_end();
// vit++)
// interior
// << vit->point().x() << " "
// << vit->point().y() << " "
// << vit->indx() << endl;
// return;