From f5e1d27d367ef3b56241ab232599fe007cb8ce2c Mon Sep 17 00:00:00 2001 From: Dengda98 Date: Tue, 3 Feb 2026 17:50:42 +0800 Subject: [PATCH] REFAC: remove `src_coefD(U)` from struct GRT_MODEL1D --- pygrt/C_extension/include/grt/common/model.h | 4 ---- .../C_extension/include/grt/dynamic/source.h | 13 +++++++------ .../include/grt/static/static_source.h | 19 ++++++++++--------- pygrt/C_extension/src/dynamic/source.c | 18 +++++++++--------- .../src/integral/kernel_template.c_ | 14 ++++++++------ pygrt/C_extension/src/static/static_source.c | 18 +++++++++--------- pygrt/c_structures.py | 2 -- 7 files changed, 43 insertions(+), 45 deletions(-) diff --git a/pygrt/C_extension/include/grt/common/model.h b/pygrt/C_extension/include/grt/common/model.h index 0c73f55f..537fd18e 100755 --- a/pygrt/C_extension/include/grt/common/model.h +++ b/pygrt/C_extension/include/grt/common/model.h @@ -74,10 +74,6 @@ typedef struct { cplx_t uiz_R_EV[2][2]; cplx_t uiz_R_EVL; - /* 震源处的震源系数 \f$ P_m, SV_m, SH_m */ - cplxChnlGrid src_coefD; - cplxChnlGrid src_coefU; - } GRT_MODEL1D; diff --git a/pygrt/C_extension/include/grt/dynamic/source.h b/pygrt/C_extension/include/grt/dynamic/source.h index f2d471d9..2f9ad013 100755 --- a/pygrt/C_extension/include/grt/dynamic/source.h +++ b/pygrt/C_extension/include/grt/dynamic/source.h @@ -17,16 +17,17 @@ /** * 根据公式(4.6.6),(4.6.15),(4.6.21,26),(4.8.34)计算不同震源不同阶数的震源系数, - * 数组形状代表在[i][j][p]时表示i类震源的 - * P(j=0),SV(j=1)的震源系数(分别对应q,w),且分为下行波(p=0)和上行波(p=1). + * 数组形状代表在[i][j]时表示i类震源的P(j=0),SV(j=1),SH(j=2)的震源系数(分别对应q,w,v). * - * @param[in,out] mod1d 模型结构体指针,结果保存在 src_coef + * @param[in] mod1d 模型结构体指针 + * @param[out] src_coefD 下行震源系数 + * @param[out] src_coefU 上行震源系数 * */ -void grt_source_coef(GRT_MODEL1D *mod1d); +void grt_source_coef(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU); /* P-SV 波的震源系数 */ -void grt_source_coef_PSV(GRT_MODEL1D *mod1d); +void grt_source_coef_PSV(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU); /* SH 波的震源系数 */ -void grt_source_coef_SH(GRT_MODEL1D *mod1d); +void grt_source_coef_SH(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU); diff --git a/pygrt/C_extension/include/grt/static/static_source.h b/pygrt/C_extension/include/grt/static/static_source.h index 13172ca5..9119b5ef 100644 --- a/pygrt/C_extension/include/grt/static/static_source.h +++ b/pygrt/C_extension/include/grt/static/static_source.h @@ -16,16 +16,17 @@ /** * 计算不同震源的静态震源系数,文献/书中仅提供剪切源的震源系数,其它震源系数重新推导 * - * 数组形状代表在[i][j][p]时表示i类震源的 - * P(j=0),SV(j=1)的震源系数(分别对应q,w),且分为下行波(p=0)和上行波(p=1). + * 数组形状代表在[i][j]时表示i类震源的P(j=0),SV(j=1),SH(j=2)的震源系数(分别对应q,w,v). + * + * @param[in] mod1d 模型结构体指针 + * @param[out] src_coefD 下行震源系数 + * @param[out] src_coefU 上行震源系数 * - * @param[in,out] mod1d 模型结构体指针,结果保存在 src_coef */ -void grt_static_source_coef(GRT_MODEL1D *mod1d); - +void grt_static_source_coef(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU); -/* P-SV 波的静态震源系数 */ -void grt_static_source_coef_PSV(GRT_MODEL1D *mod1d); +/* P-SV 波的静态震源系数 */ +void grt_static_source_coef_PSV(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU); -/* SH 波的静态震源系数 */ -void grt_static_source_coef_SH(GRT_MODEL1D *mod1d); \ No newline at end of file +/* SH 波的静态震源系数 */ +void grt_static_source_coef_SH(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU); diff --git a/pygrt/C_extension/src/dynamic/source.c b/pygrt/C_extension/src/dynamic/source.c index 0d764e59..33756640 100755 --- a/pygrt/C_extension/src/dynamic/source.c +++ b/pygrt/C_extension/src/dynamic/source.c @@ -63,18 +63,18 @@ inline GCC_ALWAYS_INLINE void _source_SH(const cplx_t xb, const cplx_t cbcb, con } -void grt_source_coef(GRT_MODEL1D *mod1d) +void grt_source_coef(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU) { // 先全部赋0 - memset(mod1d->src_coefD, 0, sizeof(cplxChnlGrid)); - memset(mod1d->src_coefU, 0, sizeof(cplxChnlGrid)); + memset(src_coefD, 0, sizeof(cplxChnlGrid)); + memset(src_coefU, 0, sizeof(cplxChnlGrid)); - grt_source_coef_PSV(mod1d); - grt_source_coef_SH(mod1d); + grt_source_coef_PSV(mod1d, src_coefD, src_coefU); + grt_source_coef_SH(mod1d, src_coefD, src_coefU); } -void grt_source_coef_PSV(GRT_MODEL1D *mod1d) +void grt_source_coef_PSV(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU) { size_t isrc = mod1d->isrc; cplx_t xa = mod1d->xa[isrc]; @@ -83,18 +83,18 @@ void grt_source_coef_PSV(GRT_MODEL1D *mod1d) cplx_t cbcb = mod1d->cbcb[isrc]; real_t k = mod1d->k; - _source_PSV(xa, caca, xb, cbcb, k, mod1d->src_coefD, mod1d->src_coefU); + _source_PSV(xa, caca, xb, cbcb, k, src_coefD, src_coefU); } -void grt_source_coef_SH(GRT_MODEL1D *mod1d) +void grt_source_coef_SH(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU) { size_t isrc = mod1d->isrc; cplx_t xb = mod1d->xb[isrc]; cplx_t cbcb = mod1d->cbcb[isrc]; real_t k = mod1d->k; - _source_SH(xb, cbcb, k, mod1d->src_coefD, mod1d->src_coefU); + _source_SH(xb, cbcb, k, src_coefD, src_coefU); } diff --git a/pygrt/C_extension/src/integral/kernel_template.c_ b/pygrt/C_extension/src/integral/kernel_template.c_ index 06b64a9c..56146ab8 100644 --- a/pygrt/C_extension/src/integral/kernel_template.c_ +++ b/pygrt/C_extension/src/integral/kernel_template.c_ @@ -192,8 +192,10 @@ void __BUILD_QWV__( RT_MATRIX *M_FA = &mod1d->M_FA; RT_MATRIX *M_FB = &mod1d->M_FB; - // 计算震源系数 - __grt_source_coef(mod1d); + // 计算震源系数 P_m, SV_m, SH_m + cplxChnlGrid src_coefD; + cplxChnlGrid src_coefU; + __grt_source_coef(mod1d, src_coefD, src_coefU); // 临时中转矩阵 (temperary) cplx_t tmpR2[2][2], tmp2x2[2][2], tmpRL, tmp2x2_uiz[2][2], tmpRL2; @@ -221,7 +223,7 @@ void __BUILD_QWV__( tmpRL = M_FB->invTL / (1.0 - M_BL->RDL * M_FB->RUL); tmpRL2 = mod1d->R_EVL * tmpRL; - grt_construct_qwv(ircvup, tmp2x2, tmpRL2, M_BL->RD, M_BL->RDL, mod1d->src_coefD, mod1d->src_coefU, QWV); + grt_construct_qwv(ircvup, tmp2x2, tmpRL2, M_BL->RD, M_BL->RDL, src_coefD, src_coefU, QWV); if(calc_uiz){ @@ -230,7 +232,7 @@ void __BUILD_QWV__( grt_cmat2x2_mul(mod1d->uiz_R_EV, tmp2x2_uiz, tmp2x2_uiz); tmpRL2 = mod1d->uiz_R_EVL * tmpRL; - grt_construct_qwv(ircvup, tmp2x2_uiz, tmpRL2, M_BL->RD, M_BL->RDL, mod1d->src_coefD, mod1d->src_coefU, QWV_uiz); + grt_construct_qwv(ircvup, tmp2x2_uiz, tmpRL2, M_BL->RD, M_BL->RDL, src_coefD, src_coefU, QWV_uiz); } } else { // A震源 B接收 @@ -255,7 +257,7 @@ void __BUILD_QWV__( tmpRL = M_AL->invTL / (1.0 - M_FA->RUL * M_AL->RDL); tmpRL2 = mod1d->R_EVL * tmpRL; - grt_construct_qwv(ircvup, tmp2x2, tmpRL2, M_FA->RU, M_FA->RUL, mod1d->src_coefD, mod1d->src_coefU, QWV); + grt_construct_qwv(ircvup, tmp2x2, tmpRL2, M_FA->RU, M_FA->RUL, src_coefD, src_coefU, QWV); if(calc_uiz){ @@ -264,7 +266,7 @@ void __BUILD_QWV__( grt_cmat2x2_mul(mod1d->uiz_R_EV, tmp2x2_uiz, tmp2x2_uiz); tmpRL2 = mod1d->uiz_R_EVL * tmpRL; - grt_construct_qwv(ircvup, tmp2x2_uiz, tmpRL2, M_FA->RU, M_FA->RUL, mod1d->src_coefD, mod1d->src_coefU, QWV_uiz); + grt_construct_qwv(ircvup, tmp2x2_uiz, tmpRL2, M_FA->RU, M_FA->RUL, src_coefD, src_coefU, QWV_uiz); } } // END if diff --git a/pygrt/C_extension/src/static/static_source.c b/pygrt/C_extension/src/static/static_source.c index 19c268cd..76eae716 100644 --- a/pygrt/C_extension/src/static/static_source.c +++ b/pygrt/C_extension/src/static/static_source.c @@ -61,32 +61,32 @@ inline GCC_ALWAYS_INLINE void _source_SH(const real_t k, cplxChnlGrid coefD, cpl } -void grt_static_source_coef(GRT_MODEL1D *mod1d) +void grt_static_source_coef(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU) { // 先全部赋0 - memset(mod1d->src_coefD, 0, sizeof(cplxChnlGrid)); - memset(mod1d->src_coefU, 0, sizeof(cplxChnlGrid)); + memset(src_coefD, 0, sizeof(cplxChnlGrid)); + memset(src_coefU, 0, sizeof(cplxChnlGrid)); - grt_static_source_coef_PSV(mod1d); - grt_static_source_coef_SH(mod1d); + grt_static_source_coef_PSV(mod1d, src_coefD, src_coefU); + grt_static_source_coef_SH(mod1d, src_coefD, src_coefU); } -void grt_static_source_coef_PSV(GRT_MODEL1D *mod1d) +void grt_static_source_coef_PSV(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU) { size_t isrc = mod1d->isrc; cplx_t delta = mod1d->delta[isrc]; real_t k = mod1d->k; - _source_PSV(delta, k, mod1d->src_coefD, mod1d->src_coefU); + _source_PSV(delta, k, src_coefD, src_coefU); } -void grt_static_source_coef_SH(GRT_MODEL1D *mod1d) +void grt_static_source_coef_SH(const GRT_MODEL1D *mod1d, cplxChnlGrid src_coefD, cplxChnlGrid src_coefU) { real_t k = mod1d->k; - _source_SH(k, mod1d->src_coefD, mod1d->src_coefU); + _source_SH(k, src_coefD, src_coefU); } diff --git a/pygrt/c_structures.py b/pygrt/c_structures.py index 7c6797d6..cdabad4e 100755 --- a/pygrt/c_structures.py +++ b/pygrt/c_structures.py @@ -140,8 +140,6 @@ class c_GRT_MODEL1D(Structure): ('R_EVL', CPLX), ('uiz_R_EV', CPLX * 4), ('uiz_R_EVL', CPLX), - - ('src_coef', CPLX * SRC_M_NUM * QWV_NUM * 2) ]