-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.c
184 lines (177 loc) · 4.87 KB
/
common.c
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
/*
* =====================================================================================
*
* Filename: common.c
*
* Description:
*
* Version: 1.0
* Created: 2017년 04월 19일 11시 18분 46초
* Revision: none
* Compiler: gcc
*
* Author: Ph.D. Candidate KIM Hyeok (kh), [email protected]
* Company: Konkuk University
*
* =====================================================================================
*/
#include "common.h"
char *txtCorr = "##space-time corr\0";
int fwrite_matrix( FILE *fout, real **m, int xsize, int ysize, real *rt, real *ct)
{
int j;
int status;
real length = ysize;
if ((status = fwrite((char *) &length, sizeof(real), 1, fout)) != 1) {
fprintf(stderr, "fwrite 1 returned %d\n", status);
return (0);
}
fwrite((char *) ct, sizeof(real), ysize, fout);
for (j = 0; j < xsize; j++) {
fwrite((char *) &rt[j], sizeof(real), 1, fout);
fwrite((char *) (m[j]), sizeof(real), ysize, fout);
}
return (1);
}
real real_tensor_dot_r1r1(VecR3* _l,VecR3* _r) {
return (_l->x*_r->x)+(_l->y*_r->y)+(_l->z*_r->z);
}
void real_tensor_copy_r1r1(VecR3* lvalue,VecR3* rvalue) {
lvalue->x = rvalue->x;
lvalue->y = rvalue->y;
lvalue->z = rvalue->z;
}
void real_tensor_copy_r2r2(Rank2R3* lvalue,Rank2R3* rvalue) {
lvalue->xx = rvalue->xx;
lvalue->xy = rvalue->xy;
lvalue->xz = rvalue->xz;
lvalue->yx = rvalue->yx;
lvalue->yy = rvalue->yy;
lvalue->yz = rvalue->yz;
lvalue->zx = rvalue->zx;
lvalue->zy = rvalue->zy;
lvalue->zz = rvalue->zz;
}
void real_tensor_product_r1_r0r1(VecR3* lvalue,real a,VecR3* rvalue) {
lvalue->x = a*rvalue->x;
lvalue->y = a*rvalue->y;
lvalue->z = a*rvalue->z;
}
void real_tensor_setIdentity_r2(Rank2R3* _I) {
_I->xx = _I->yy = _I->zz = (real) 1.;
_I->xy = _I->yz = _I->zx = (real) 0.;
_I->yx = _I->zy = _I->xz = (real) 0.;
}
void real_tensor_scale_r1(VecR3* lvalue,real a ) {
real_tensor_product_r1_r0r1(lvalue, a, lvalue);
}
void real_tensor_projection_r2_r1(Rank2R3* _P, VecR3* _vect) {
real_tensor_product_r2_r1r1(_P, _vect,_vect);
real_tensor_scale_r2(_P, (real)1./real_tensor_dot_r1r1(_vect,_vect));
}
void real_tensor_product_r2_r1r1( Rank2R3* r2,
VecR3 *r1a, VecR3* r1b) {
r2->xx = r1a->x * r1b->x;
r2->xy = r1a->x * r1b->y;
r2->xz = r1a->x * r1b->z;
r2->yx = r1a->y * r1b->x;
r2->yy = r1a->y * r1b->y;
r2->yz = r1a->y * r1b->z;
r2->zx = r1a->z * r1b->x;
r2->zy = r1a->z * r1b->y;
r2->zz = r1a->z * r1b->z;
}
void real_tensor_product_r2_r0r2( Rank2R3* r2,
real a,
Rank2R3* r2b) {
r2->xx = a * r2b->xx;
r2->xy = a * r2b->xy;
r2->xz = a * r2b->xz;
r2->yx = a * r2b->yx;
r2->yy = a * r2b->yy;
r2->yz = a * r2b->yz;
r2->zx = a * r2b->zx;
r2->zy = a * r2b->zy;
r2->zz = a * r2b->zz;
}
void real_tensor_scale_r2(Rank2R3* lvalue,real a ) {
real_tensor_product_r2_r0r2(lvalue, a, lvalue);
}
void real_tensor_product_r2_r2r2( Rank2R3* r2,
Rank2R3 * r2a,
Rank2R3* r2b) {
r2->xx = r2a->xx * r2b->xx;
r2->xy = r2a->xy * r2b->xy;
r2->xz = r2a->xz * r2b->xz;
r2->yx = r2a->yx * r2b->yx;
r2->yy = r2a->yy * r2b->yy;
r2->yz = r2a->yz * r2b->yz;
r2->zx = r2a->zx * r2b->zx;
r2->zy = r2a->zy * r2b->zy;
r2->zz = r2a->zz * r2b->zz;
}
void real_tensor_sub_r2_r2r2( Rank2R3* r2,
Rank2R3 * r2a,
Rank2R3* r2b) {
r2->xx = r2a->xx - r2b->xx;
r2->xy = r2a->xy - r2b->xy;
r2->xz = r2a->xz - r2b->xz;
r2->yx = r2a->yx - r2b->yx;
r2->yy = r2a->yy - r2b->yy;
r2->yz = r2a->yz - r2b->yz;
r2->zx = r2a->zx - r2b->zx;
r2->zy = r2a->zy - r2b->zy;
r2->zz = r2a->zz - r2b->zz;
}
void real_tensor_add_r1_r1r1( VecR3* r1,
VecR3* r1a,
VecR3* r1b) {
r1->x = r1a->x + r1b->x;
r1->y = r1a->y + r1b->y;
r1->z = r1a->z + r1b->z;
}
void real_tensor_add_r2_r2r2( Rank2R3* r2,
Rank2R3* r2a,
Rank2R3* r2b) {
r2->xx = r2a->xx + r2b->xx;
r2->xy = r2a->xy + r2b->xy;
r2->xz = r2a->xz + r2b->xz;
r2->yx = r2a->yx + r2b->yx;
r2->yy = r2a->yy + r2b->yy;
r2->yz = r2a->yz + r2b->yz;
r2->zx = r2a->zx + r2b->zx;
r2->zy = r2a->zy + r2b->zy;
r2->zz = r2a->zz + r2b->zz;
}
void real_tensor_increase_r1_r1( VecR3* r1,
VecR3* r1inc) {
real_tensor_add_r1_r1r1(r1,r1,r1inc);
}
void real_tensor_increase_r2_r2( Rank2R3* r2,
Rank2R3* r2inc) {
real_tensor_add_r2_r2r2(r2,r2,r2inc);
}
void real_tensor_decrease_r2_r2( Rank2R3* r2,
Rank2R3* r2dec) {
real_tensor_sub_r2_r2r2(r2,r2,r2dec);
}
void real_tensor_zero_r2( Rank2R3* r2) {
r2->xx = 0.; r2->xy = 0.; r2->xz = 0.;
r2->yx = 0.; r2->yy = 0.; r2->yz = 0.;
r2->zx = 0.; r2->zy = 0.; r2->zz = 0.;
}
real real_tensor_avg_offdig_r2( Rank2R3* r2) {
return real_tensor_sum_offdig_r2(r2)/6.0;
}
real real_tensor_avg_dig_r2( Rank2R3* r2) {
return real_tensor_sum_dig_r2(r2)/3.0;
}
real real_tensor_sum_offdig_r2( Rank2R3* r2) {
return r2->xy +r2->xz + r2->yx + r2->yz + r2->zx + r2->zy;
}
real real_tensor_sum_dig_r2( Rank2R3* r2) {
return r2->xx + r2->yy + r2->zz;
}
void real_tensor_zero_r1( VecR3* r1) {
r1->x =0.; r1->y =0.; r1->z =0.;
}