Skip to content

Commit a475085

Browse files
authored
REFAC: define the data type of the INTEG-related arrays (#165)
1 parent 65a5454 commit a475085

File tree

15 files changed

+198
-228
lines changed

15 files changed

+198
-228
lines changed

pygrt/C_extension/include/grt/common/const.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ typedef double complex cplx_t;
125125

126126
typedef cplx_t QWVgrid[GRT_SRC_M_NUM][GRT_QWV_NUM];
127127
typedef cplx_t INTEGgrid[GRT_SRC_M_NUM][GRT_INTEG_NUM];
128+
typedef real_t r_INTEGgrid[GRT_SRC_M_NUM][GRT_INTEG_NUM];
129+
typedef size_t s_INTEGgrid[GRT_SRC_M_NUM][GRT_INTEG_NUM];
128130

129131
/** 不同震源类型在大小为 GRT_SRC_M_NUM 的数组中的索引 */
130132
enum {

pygrt/C_extension/include/grt/common/dwm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
real_t grt_discrete_integ(
4545
GRT_MODEL1D *mod1d, real_t dk, real_t kmax, real_t keps,
4646
size_t nr, real_t *rs,
47-
cplx_t sum_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
47+
INTEGgrid sum_J[nr],
4848
bool calc_upar,
49-
cplx_t sum_uiz_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
50-
cplx_t sum_uir_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
49+
INTEGgrid sum_uiz_J[nr],
50+
INTEGgrid sum_uir_J[nr],
5151
FILE *fstats, GRT_KernelFunc kerfunc);

pygrt/C_extension/include/grt/common/fim.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
real_t grt_linear_filon_integ(
5252
GRT_MODEL1D *mod1d, real_t k0, real_t dk0, real_t filondk, real_t kmax, real_t keps,
5353
size_t nr, real_t *rs,
54-
cplx_t sum_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
54+
INTEGgrid sum_J[nr],
5555
bool calc_upar,
56-
cplx_t sum_uiz_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
57-
cplx_t sum_uir_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
56+
INTEGgrid sum_uiz_J[nr],
57+
INTEGgrid sum_uir_J[nr],
5858
FILE *fstats, GRT_KernelFunc kerfunc);
5959

6060

pygrt/C_extension/include/grt/common/integral.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
* @param[out] SUM 该dk区间内的积分值
2525
*
2626
*/
27-
void grt_int_Pk(
28-
real_t k, real_t r,
29-
const QWVgrid QWV,
30-
bool calc_uir,
31-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM]);
27+
void grt_int_Pk(real_t k, real_t r, const QWVgrid QWV, bool calc_uir, INTEGgrid SUM);
3228

3329

3430

@@ -39,8 +35,7 @@ void grt_int_Pk(
3935
* @param[in] sum_J 积分结果
4036
* @param[out] tol Z、R、T分量结果
4137
*/
42-
void grt_merge_Pk(
43-
const cplx_t sum_J[GRT_SRC_M_NUM][GRT_INTEG_NUM], cplx_t tol[GRT_SRC_M_NUM][GRT_CHANNEL_NUM]);
38+
void grt_merge_Pk(const INTEGgrid sum_J, cplx_t tol[GRT_SRC_M_NUM][GRT_CHANNEL_NUM]);
4439

4540

4641

@@ -58,11 +53,7 @@ void grt_merge_Pk(
5853
* @param[out] SUM 该dk区间内的积分值
5954
*
6055
*/
61-
void grt_int_Pk_filon(
62-
real_t k, real_t r, bool iscos,
63-
const QWVgrid QWV,
64-
bool calc_uir,
65-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM]);
56+
void grt_int_Pk_filon(real_t k, real_t r, bool iscos, const QWVgrid QWV, bool calc_uir, INTEGgrid SUM);
6657

6758

6859
/**
@@ -77,8 +68,4 @@ void grt_int_Pk_filon(
7768
* @param[out] SUM 该三点区间内的积分值
7869
*
7970
*/
80-
void grt_int_Pk_sa_filon(
81-
const real_t k3[3], real_t r,
82-
const QWVgrid QWV3[3],
83-
bool calc_uir,
84-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM]);
71+
void grt_int_Pk_sa_filon(const real_t k3[3], real_t r, const QWVgrid QWV3[3], bool calc_uir, INTEGgrid SUM);

pygrt/C_extension/include/grt/common/iostats.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ int grt_extract_stats(FILE *bf0, FILE *af0);
5454
*/
5555
void grt_write_stats_ptam(
5656
FILE *f0,
57-
real_t Kpt[GRT_SRC_M_NUM][GRT_INTEG_NUM][GRT_PTAM_PT_MAX],
58-
cplx_t Fpt[GRT_SRC_M_NUM][GRT_INTEG_NUM][GRT_PTAM_PT_MAX]);
57+
r_INTEGgrid Kpt[GRT_PTAM_PT_MAX],
58+
INTEGgrid Fpt[GRT_PTAM_PT_MAX]);
5959

6060

6161
/**

pygrt/C_extension/include/grt/common/ptam.h

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,43 +47,9 @@
4747
void grt_PTA_method(
4848
GRT_MODEL1D *mod1d, real_t k0, real_t predk,
4949
size_t nr, real_t *rs,
50-
cplx_t sum_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
50+
INTEGgrid sum_J0[nr],
5151
bool calc_upar,
52-
cplx_t sum_uiz_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
53-
cplx_t sum_uir_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
52+
INTEGgrid sum_uiz_J0[nr],
53+
INTEGgrid sum_uir_J0[nr],
5454
FILE *ptam_fstatsnr[nr][2], GRT_KernelFunc kerfunc);
5555

56-
57-
58-
59-
60-
/**
61-
* 观察连续3个点的函数值的实部变化,判断是波峰(1)还是波谷(-1), 并计算对应值。
62-
*
63-
* @param[in] idx1 阶数索引
64-
* @param[in] idx2 积分类型索引
65-
* @param[in] arr 存有连续三个点的函数值的数组
66-
* @param[in] k 三个点的起始波数
67-
* @param[in] dk 三个点的波数间隔,这样使用k和dk定义了三个点的位置
68-
* @param[out] pk 估计的波峰或波谷处的波数
69-
* @param[out] value 估计的波峰或波谷处的函数值
70-
*
71-
* @return 波峰(1),波谷(-1),其它(0)
72-
*
73-
*/
74-
int grt_cplx_peak_or_trough(
75-
int idx1, int idx2, const cplx_t arr[GRT_PTAM_WINDOW_SIZE][GRT_SRC_M_NUM][GRT_INTEG_NUM],
76-
real_t k, real_t dk, real_t *pk, cplx_t *value);
77-
78-
79-
/**
80-
* 递归式地计算缩减序列的值,
81-
* \f[
82-
* M_i = 0.5\times (M_i + M_{i+1})
83-
* \f]
84-
*
85-
* @param[in] n1 数组长度
86-
* @param[in,out] arr 振荡的数组,最终收敛值在第一个,arr[0]
87-
*
88-
*/
89-
void grt_cplx_shrink(size_t n1, cplx_t *arr);

pygrt/C_extension/include/grt/common/safim.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
real_t grt_sa_filon_integ(
5353
GRT_MODEL1D *mod1d, real_t k0, real_t dk0, real_t tol, real_t kmax, real_t kref,
5454
size_t nr, real_t *rs,
55-
cplx_t sum_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
55+
INTEGgrid sum_J0[nr],
5656
bool calc_upar,
57-
cplx_t sum_uiz_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
58-
cplx_t sum_uir_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
57+
INTEGgrid sum_uiz_J0[nr],
58+
INTEGgrid sum_uir_J0[nr],
5959
FILE *fstats, GRT_KernelFunc kerfunc);
6060

6161

pygrt/C_extension/src/common/dwm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
real_t grt_discrete_integ(
2828
GRT_MODEL1D *mod1d, real_t dk, real_t kmax, real_t keps,
2929
size_t nr, real_t *rs,
30-
cplx_t sum_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
30+
INTEGgrid sum_J[nr],
3131
bool calc_upar,
32-
cplx_t sum_uiz_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
33-
cplx_t sum_uir_J[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
32+
INTEGgrid sum_uiz_J[nr],
33+
INTEGgrid sum_uir_J[nr],
3434
FILE *fstats, GRT_KernelFunc kerfunc)
3535
{
36-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM] = {0};
36+
INTEGgrid SUM = {0};
3737

3838
// 不同震源不同阶数的核函数 F(k, w)
3939
QWVgrid QWV = {0};

pygrt/C_extension/src/common/fim.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
real_t grt_linear_filon_integ(
2626
GRT_MODEL1D *mod1d, real_t k0, real_t dk0, real_t dk, real_t kmax, real_t keps,
2727
size_t nr, real_t *rs,
28-
cplx_t sum_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
28+
INTEGgrid sum_J0[nr],
2929
bool calc_upar,
30-
cplx_t sum_uiz_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
31-
cplx_t sum_uir_J0[nr][GRT_SRC_M_NUM][GRT_INTEG_NUM],
30+
INTEGgrid sum_uiz_J0[nr],
31+
INTEGgrid sum_uir_J0[nr],
3232
FILE *fstats, GRT_KernelFunc kerfunc)
3333
{
3434
// 从0开始,存储第二部分Filon积分的结果
35-
cplx_t (*sum_J)[GRT_SRC_M_NUM][GRT_INTEG_NUM] = (cplx_t(*)[GRT_SRC_M_NUM][GRT_INTEG_NUM])calloc(nr, sizeof(*sum_J));
36-
cplx_t (*sum_uiz_J)[GRT_SRC_M_NUM][GRT_INTEG_NUM] = (calc_upar)? (cplx_t(*)[GRT_SRC_M_NUM][GRT_INTEG_NUM])calloc(nr, sizeof(*sum_uiz_J)) : NULL;
37-
cplx_t (*sum_uir_J)[GRT_SRC_M_NUM][GRT_INTEG_NUM] = (calc_upar)? (cplx_t(*)[GRT_SRC_M_NUM][GRT_INTEG_NUM])calloc(nr, sizeof(*sum_uir_J)) : NULL;
35+
INTEGgrid *sum_J = (INTEGgrid *)calloc(nr, sizeof(*sum_J));
36+
INTEGgrid *sum_uiz_J = (calc_upar)? (INTEGgrid *)calloc(nr, sizeof(*sum_uiz_J)) : NULL;
37+
INTEGgrid *sum_uir_J = (calc_upar)? (INTEGgrid *)calloc(nr, sizeof(*sum_uir_J)) : NULL;
3838

39-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM];
39+
INTEGgrid SUM;
4040

4141
// 不同震源不同阶数的核函数 F(k, w)
4242
QWVgrid QWV = {0};
@@ -158,8 +158,8 @@ real_t grt_linear_filon_integ(
158158

159159
// -------------------------------------------------------------------------------
160160
// 计算余项, [2]表示k积分的第一个点和最后一个点
161-
cplx_t SUM_Gc[2][GRT_SRC_M_NUM][GRT_INTEG_NUM] = {0};
162-
cplx_t SUM_Gs[2][GRT_SRC_M_NUM][GRT_INTEG_NUM] = {0};
161+
INTEGgrid SUM_Gc[2] = {0};
162+
INTEGgrid SUM_Gs[2] = {0};
163163

164164

165165
// 计算来自第一个点和最后一个点的余项

pygrt/C_extension/src/common/integral.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@
1919

2020

2121

22-
void grt_int_Pk(
23-
real_t k, real_t r,
24-
// F(ki,w), 第一个维度表示不同震源,不同阶数,第二个维度3代表三类系数qm,wm,vm
25-
const QWVgrid QWV,
26-
// F(ki,w)Jm(ki*r)ki,第一个维度表示不同震源,不同阶数,第二个维度代表4种类型的F(k,w)Jm(kr)k的类型
27-
bool calc_uir,
28-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM])
22+
void grt_int_Pk(real_t k, real_t r, const QWVgrid QWV, bool calc_uir, INTEGgrid SUM)
2923
{
3024
real_t bjmk[GRT_MORDER_MAX+1] = {0};
3125
real_t kr = k*r;
@@ -70,11 +64,7 @@ void grt_int_Pk(
7064
}
7165

7266

73-
void grt_int_Pk_filon(
74-
real_t k, real_t r, bool iscos,
75-
const QWVgrid QWV,
76-
bool calc_uir,
77-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM])
67+
void grt_int_Pk_filon(real_t k, real_t r, bool iscos, const QWVgrid QWV, bool calc_uir, INTEGgrid SUM)
7868
{
7969
real_t phi0 = 0.0;
8070
if(! iscos) phi0 = - HALFPI; // 在cos函数中添加的相位差,用于计算sin函数
@@ -159,11 +149,7 @@ static cplx_t interg_quad_cos(
159149

160150

161151

162-
void grt_int_Pk_sa_filon(
163-
const real_t k3[3], real_t r,
164-
const QWVgrid QWV3[3],
165-
bool calc_uir,
166-
cplx_t SUM[GRT_SRC_M_NUM][GRT_INTEG_NUM])
152+
void grt_int_Pk_sa_filon(const real_t k3[3], real_t r, const QWVgrid QWV3[3], bool calc_uir, INTEGgrid SUM)
167153
{
168154
// 使用bessel递推公式 Jm'(x) = m/x * Jm(x) - J_{m+1}(x)
169155
// 考虑大震中距,忽略第一项,再使用bessel渐近公式
@@ -208,11 +194,7 @@ void grt_int_Pk_sa_filon(
208194

209195

210196

211-
void grt_merge_Pk(
212-
// F(ki,w)Jm(ki*r)ki,
213-
const cplx_t sum_J[GRT_SRC_M_NUM][GRT_INTEG_NUM],
214-
// 累积求和,Z、R、T分量
215-
cplx_t tol[GRT_SRC_M_NUM][GRT_CHANNEL_NUM])
197+
void grt_merge_Pk(const INTEGgrid sum_J, cplx_t tol[GRT_SRC_M_NUM][GRT_CHANNEL_NUM])
216198
{
217199
for(int i=0; i<GRT_SRC_M_NUM; ++i){
218200
int modr = GRT_SRC_M_ORDERS[i];

0 commit comments

Comments
 (0)