-
Notifications
You must be signed in to change notification settings - Fork 0
/
pParticles_GM_orig.cpp
164 lines (106 loc) · 3.38 KB
/
pParticles_GM_orig.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
// pParticles
// Attempt to replicate
// Gallouët, T.O., Mérigot, Q.
// A Lagrangian Scheme à la Brenier for the Incompressible Euler Equations.
// Found Comput Math 18, 835–865 (2018).
// https://doi.org/10.1007/s10208-017-9355-y
// Simple explicit method
#include"pParticles.h"
#include"linear.h"
#include"simu.h"
sim_data simu;
int main() {
const int init_iters = 200;
const FT init_tol2 = 1e-6;
const int inner_iters= 10;
const FT inner_tol = 1e-5;
const FT turn_time = 2 * M_PI * 0.2 ; // one whole turn
// const FT total_time = turn_time; // once
const FT total_time = 2 * turn_time; // twice
const std::string particle_file("particles.dat");
const std::string diagram_file("diagram.dat");
Triangulation T;
cout << "Creating point cloud" << endl;
simu.do_perturb(1e-3);
create( T , 1.0 );
number( T );
// set_vels_rotating( T );
// set_vels_Lamb_Oseen( T );
volumes( T );
linear algebra( T );
algebra.copy( sfield_list::vol, sfield_list::vol0);
algebra.copy( sfield_list::I, sfield_list::I0);
// Init loop!
int iter=1;
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 ) ;
set_vels_Gresho( T );
cout << "Init loop converged in " << iter << " steps " << endl;
volumes( T );
algebra.copy( sfield_list::vol, sfield_list::vol0);
FT d0;
FT dt=0.001;
cout << "Time step, dt = ";
cin >> dt ;
cout << endl << dt << endl;
simu.set_dt( dt );
// Setting a spring period that includes several Dt, in
// order spring forces be properly sampled
// FT spring_period = 10 * dt;
FT spring_to_dt;
cout << "Spring period / dt = ";
cin >> spring_to_dt;
cout << endl << spring_to_dt << endl;
// 31 dt is the value for G&M first simulation,
// "Beltrami flow in the square"
FT spring_period = spring_to_dt * dt;
// FT spring_period = 80 * dt;
FT omega = 2 * M_PI / spring_period ;
cout << " omega = " << omega << endl ;
FT spring = omega*omega; // factor that appears in the spring force
draw( T , particle_file);
draw_diagram( T , diagram_file );
std::ofstream log_file;
log_file.open("main.log");
log_file << " # step time iters kin_energy L2_velocity " << endl;
do {
simu.next_step();
simu.advance_time( );
backup( T );
int iter = 1;
volumes( T );
algebra.u_star( );
FT displ = move( T , dt , d0 );
cout
<< "********" << endl
<< "Iter " << iter
<< " . Moved from previous (rel.): " << displ <<
" ; from original (rel.): " << d0
<< endl ;
algebra.solve_for_weights();
algebra.copy( 0.5 * spring , sfield_list::w , sfield_list::p);
// copy_weights( T ) ;
// volumes( T );
algebra.clear_vfield( vfield_list::gradp );
algebra.u_add_spring_force( spring , dt );
algebra.copy( vfield_list::Ustar , vfield_list::U );
draw( T , particle_file );
draw_diagram( T , diagram_file );
log_file
<< simu.current_step() << " "
<< simu.time() << " "
<< iter-1 << " "
<< kinetic_E(T) << " "
<< L2_vel_Gresho(T) << " "
<< endl ;
} while ( simu.time() < total_time );
log_file.close();
return 0;
}