forked from eelcovv/gridpro2Foam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PeriodicStats.cpp
118 lines (94 loc) · 2.77 KB
/
PeriodicStats.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
#include "PeriodicStats.hpp"
#include <math.h>
#include <cstdlib>
PeriodicStats::PeriodicStats()
{ count=0;
dx=dy=dz=0.0;
l=m=n=0.0;
dxrot=dyrot=dzrot=0;
}
void PeriodicStats::AddPoint(Node *n1, Node *n2)
{
// obtain two nodes which are supposed to be rotational periodic
double dxl=fabs(n2->x-n1->x);
double dyl=fabs(n2->y-n1->y);
double dzl=fabs(n2->z-n1->z);
dx+=dxl;
dy+=dyl;
dz+=dzl;
if (n1==n2)
{ n1->y=n2->y=0;
n1->z=n2->z=0;
}
//if (dxl+dyl+dzl<1e-6) return;
printf("ANGLE %lg , DIST %lg %lg %lg\n", atan2(n1->z,n1->y)*180./M_PI-atan2(n2->z,n2->y)*180./M_PI, fabs(n2->x-n1->x), fabs(n2->y-n1->y), fabs(n2->z-n1->z));
l+=fabs(atan2(n1->z,n1->y)-atan2(n2->z,n2->y));
m+=fabs(atan2(n1->z,n1->x)-atan2(n2->z,n2->x));
n+=fabs(atan2(n1->y,n1->x)-atan2(n2->y,n2->x));
double periodicAngle = 360/11.;
double theta = -(atan2(n1->z,n1->y)>atan2(n2->z,n2->y)?-periodicAngle*M_PI/180.:periodicAngle*M_PI/180.);
//double x2=n1->x*cos(theta) - n1->z*sin(theta);
double z2=n1->z*cos(theta) - n1->y*sin(theta);
double y2=n1->z*sin(theta) + n1->y*cos(theta);
double m=fabs(atan2(n1->z,n1->y)-atan2(z2,y2));
//printf("Points x:%lg %lg, y:%lg,%lg, z: %lg %lg, m=%lg\n", n2->y, y2, n1->y, n2->y, n2->z, z2, m*180/M_PI);
//dxrot+=fabs(n2->x- x2);
dyrot+=fabs(n2->y- y2);
dzrot+=fabs(n2->z- z2);
n2->z=n1->z*cos(theta) - n1->y*sin(theta);
n2->y=n1->z*sin(theta) + n1->y*cos(theta);
if (fabs(n2->x-n1->x)+ fabs(n2->y-y2)+ fabs(n2->z-z2)>0.001)
{ printf("Error; point difference too large after rotation\n");
printf("deltaX= %lg, deltaY= %lg, deltaZ=%lg\n", fabs(n2->x-n1->x), fabs(n2->y-y2), fabs(n2->z-z2));
exit(1);
}
count ++;
}
double PeriodicStats::MeanDX()
{ if (count==0) return 0;
return dx/count;
}
double PeriodicStats::MeanDY()
{ if (count==0) return 0;
return dy/count;
}
double PeriodicStats::MeanDZ()
{ if (count==0) return 0;
return dz/count;
}
double PeriodicStats::MeanDXrot()
{ if (count==0) return 0;
return dxrot/count;
}
double PeriodicStats::MeanDYrot()
{ if (count==0) return 0;
return dyrot/count;
}
double PeriodicStats::MeanDZrot()
{ if (count==0) return 0;
return dzrot/count;
}
double PeriodicStats::MeanL()
{ if (count==0) return 0;
return l/count;
}
double PeriodicStats::MeanM()
{ if (count==0) return 0;
return m/count;
}
double PeriodicStats::MeanN()
{ if (count==0) return 0;
return n/count;
}
void PeriodicStats::Print()
{
printf("dx=%1.16lg\n", MeanDX());
printf("dy=%1.16lg\n", MeanDY());
printf("dz=%1.16lg\n", MeanDZ());
printf("dl=%1.16lg\n", MeanL()*180./M_PI);
printf("dm=%1.16lg\n", MeanM()*180./M_PI);
printf("dn=%1.16lg\n", MeanN()*180./M_PI);
printf("dxrot=%1.16lg\n", MeanDXrot());
printf("dyrot=%1.16lg\n", MeanDYrot());
printf("dzrot=%1.16lg\n", MeanDZrot());
}