forked from ddcampayo/cpFEM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlloyds.cpp
More file actions
84 lines (47 loc) · 1.37 KB
/
lloyds.cpp
File metadata and controls
84 lines (47 loc) · 1.37 KB
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
#include"cpFEM.h"
#include"simu.h"
#include"data_kept.h"
// Lloyds algorithm
// Only one step
//
FT lloyds(Triangulation& T) {
cout << "Lloyds algorithm ... " << endl ;
// copy_weights( T );
// volumes( T );
// copy_weights( T );
vector<data_kept> prev;
FT dd2=0;
for(F_v_it fv=T.finite_vertices_begin();
fv!=T.finite_vertices_end();
fv++) {
int idx = fv->idx();
data_kept data(fv);
if(idx < 0 ) {
data.pos = fv->point().point();
prev.push_back (data);
continue;
}
Point rnow = fv->point().point(); // current point
Point rnew = fv->centroid.val();
Vector_2 disp2 = rnew - rnow;
FT rel_disp = sqrt(disp2.squared_length() ) / simu.h();
// cout << " rel disp of " << idx << " : " << rel_disp << endl ;
dd2 += rel_disp;
data.pos = rnew;
data.Dr = disp2;
prev.push_back(data);
}
dd2 /= simu.no_of_particles();
cout << "Moved relative displacement: " <<
sqrt(dd2)/simu.h() ;
cout << " . Mean displacement: " << dd2 << endl ;
T.clear(); // clears the triangulation !!
for(vector<data_kept>::iterator data=prev.begin();
data!=prev.end();
data++) {
// cout << "Inserting back at " << data->pos << endl ;
Vertex_handle fv=T.insert( wPoint( data->pos , data->w ) );
data->restore(fv);
}
return dd2;
}