-
Notifications
You must be signed in to change notification settings - Fork 0
/
pParticles_s.cpp
210 lines (134 loc) · 3.86 KB
/
pParticles_s.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
// pParticles
// no weigths are used, basically
// Pressure is used in order to enforce incompressibility
#include"pParticles.h"
#include"linear.h"
#include"simu.h"
sim_data simu;
int main() {
// TODO: read parameter file
const int init_iters = 0;
const FT init_tol2 = 1e-3;
const int inner_iters= 100;
const FT inner_tol = 1e-6;
const FT total_time = 2 * M_PI * 0.2 ; // one whole turn
const std::string particle_file("particles.dat");
const std::string diagram_file("diagram.dat");
Triangulation T;
cout << "Creating point cloud" << endl;
//simu.do_perturb(0.01);
create( T , 1.0 );
number( T );
// set_vels_rotating( T );
// set_vels_Lamb_Oseen( T );
linear algebra( T );
// Init loop!
int iter=0;
for( ; iter < init_iters ; ++iter) {
volumes( T );
copy_weights( T ) ;
// algebra.solve_for_weights();
FT dd = lloyds( T ) ;
cout << " init loop , iter " << iter << " dd = " << dd << endl;
if( dd < init_tol2) break;
}
copy_weights( T ) ;
cout << "Init loop converged in " << iter << " steps " << endl;
set_vels_Gresho( T );
volumes( T );
algebra.copy( sfield_list::I, sfield_list::I0);
FT d0;
FT dt=0.001;
cin >> dt ;
simu.set_dt( dt );
// half-step (for e.g. leapfrog)
FT dt2 = dt / 2.0 ;
// whole step
// FT dt2 = dt ;
// algebra.solve_for_weights();
draw( T , particle_file );
draw_diagram( T , diagram_file );
std::ofstream log_file;
log_file.open("main.log");
// special first iter.-
// cout << " First iter, free ";
// algebra.reset_p();
// FT displ1 = move( T , dt , d0 );
// volumes( T );
// simu.next_step(); simu.advance_time();
// draw( T , particle_file );
// draw_diagram( T , diagram_file );
do {
simu.next_step();
simu.advance_time( );
backup( T );
// copy_weights( T ) ;
// volumes( T );
// algebra.fill_Delta();
algebra.reset_s();
int iter = 1;
// algebra.fill_Delta_DD();
algebra.u_star( );
FT displ = 0; // move( T , dt2 , d0 );
// full-step corrector loop
for ( ; iter <= inner_iters ; iter++) {
displ = move( T , dt , d0 );
cout
<< "********" << endl
<< "Iter " << iter
<< " . Moved from previous (rel.): " << displ <<
" ; from original (rel.): " << d0
<< endl ;
volumes( T );
algebra.fill_Delta_DD();
// // whole step, special 1st time
// if( simu.current_step() == 1 ){
// algebra.p_equation( dt2 );
// algebra.u_add_press_grad( dt2/2 );
// } else
// {
// algebra.p_equation( dt );
// algebra.u_add_press_grad( dt2 );
// }
algebra.s_equation( dt );
algebra.u_add_s_grad( dt2 );
if( displ < inner_tol ) break;
////// testing ...
// backup( T );
//algebra.reset_p();
//algebra.u_star( );
///////////
//algebra.w_equation();
//algebra.solve_for_weights();
// volumes( T );
}
// algebra.u_add_press_grad( dt2 );
// draw( T , particle_file );
// draw_diagram( T , diagram_file );
// return 0;
// copy_weights( T ) ;
// displ = move( T , dt , d0 );
// volumes( T );
// algebra.fill_Delta_DD();
// algebra.p_equation( dt2 );
cout
<< "Whole step "
<< " : disp " << displ << endl ;
//algebra.w_equation();
//algebra.solve_for_weights();
// volumes( T );
// half-step:
// update_full_vel( T );
algebra.u_add_s_grad( dt );
draw( T , particle_file );
draw_diagram( T , diagram_file );
log_file
<< simu.current_step() << " "
<< simu.time() << " "
<< " iters = " << iter
<< " L2_vel = " << L2_vel_Gresho(T)
<< endl ;
} while ( simu.time() < total_time );
log_file.close();
return 0;
}