From 142fa82eb901249405c4f54d1e33002c8c160b00 Mon Sep 17 00:00:00 2001 From: Dengda98 Date: Thu, 26 Jun 2025 12:29:48 +0800 Subject: [PATCH] allow zero vs for computing sythetic seismogram and stress (Dynamic & Static) --- pygrt/C_extension/src/dynamic/grt_stress.c | 4 ++-- pygrt/C_extension/src/dynamic/grt_syn.c | 17 +++++++++++++---- pygrt/C_extension/src/static/stgrt_stress.c | 9 ++++++++- pygrt/C_extension/src/static/stgrt_syn.c | 18 +++++++++++++++++- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/pygrt/C_extension/src/dynamic/grt_stress.c b/pygrt/C_extension/src/dynamic/grt_stress.c index 1a7d063c..225915e3 100644 --- a/pygrt/C_extension/src/dynamic/grt_stress.c +++ b/pygrt/C_extension/src/dynamic/grt_stress.c @@ -145,8 +145,8 @@ int main(int argc, char **argv){ float rho=hd.user3; float Qainv=hd.user4; float Qbinv=hd.user5; - if(va <= 0.0 || vb <= 0.0 || rho <= 0.0){ - fprintf(stderr, "[%s] " BOLD_RED "Error! read necessary header value from \"%s\" error.\n" DEFAULT_RESTORE, command, s_filepath); + if(va <= 0.0 || vb < 0.0 || rho <= 0.0){ + fprintf(stderr, "[%s] " BOLD_RED "Error! Bad rcv_va, rcv_vb or rcv_rho in \"%s\" header.\n" DEFAULT_RESTORE, command, s_filepath); exit(EXIT_FAILURE); } // 申请内存 diff --git a/pygrt/C_extension/src/dynamic/grt_syn.c b/pygrt/C_extension/src/dynamic/grt_syn.c index 84dd186b..6ef8df8b 100644 --- a/pygrt/C_extension/src/dynamic/grt_syn.c +++ b/pygrt/C_extension/src/dynamic/grt_syn.c @@ -239,14 +239,23 @@ static void check_grn_exist(const char *name){ exit(EXIT_FAILURE); } // 检查文件的同时将src_mu计算出来 - if(src_mu == 0.0){ + if(src_mu == 0.0 && mult_src_mu){ SACHEAD hd; read_SAC_HEAD(command, buffer, &hd); - double vb, rho; + double va, vb, rho; + va = hd.user6; vb = hd.user7; rho = hd.user8; - if(vb <= 0.0 || rho <= 0.0){ - fprintf(stderr, "[%s] " BOLD_RED "Error! read necessary header value from \"%s\" error.\n" DEFAULT_RESTORE, command, buffer); + if(va <= 0.0 || vb < 0.0 || rho <= 0.0){ + fprintf(stderr, "[%s] " BOLD_RED "Error! Bad src_va, src_vb or src_rho in \"%s\" header.\n" DEFAULT_RESTORE, command, buffer); + exit(EXIT_FAILURE); + } + if(vb == 0.0){ + fprintf(stderr, "[%s] " BOLD_RED + "Error! Zero src_vb in \"%s\" header. " + "Maybe you try to use -Su but the source is in the liquid. " + "Use -S instead.\n" + DEFAULT_RESTORE, command, buffer); exit(EXIT_FAILURE); } src_mu = vb*vb*rho*1e10; diff --git a/pygrt/C_extension/src/static/stgrt_stress.c b/pygrt/C_extension/src/static/stgrt_stress.c index b2347133..4dcaed17 100644 --- a/pygrt/C_extension/src/static/stgrt_stress.c +++ b/pygrt/C_extension/src/static/stgrt_stress.c @@ -136,6 +136,10 @@ int main(int argc, char **argv){ fprintf(stderr, "[%s] " BOLD_RED "Error! Unable to read src property from \"%s\". \n" DEFAULT_RESTORE, command, line); exit(EXIT_FAILURE); } + if(src_va <= 0.0 || src_vb < 0.0 || src_rho <= 0.0){ + fprintf(stderr, "[%s] " BOLD_RED "Error! Bad src_va, src_vb or src_rho from \"%s\".\n" DEFAULT_RESTORE, command, line); + exit(EXIT_FAILURE); + } } else if(iline == 2){ // 读取场点物性参数 @@ -143,7 +147,10 @@ int main(int argc, char **argv){ fprintf(stderr, "[%s] " BOLD_RED "Error! Unable to read rcv property from \"%s\". \n" DEFAULT_RESTORE, command, line); exit(EXIT_FAILURE); } - + if(rcv_va <= 0.0 || rcv_vb < 0.0 || rcv_rho <= 0.0){ + fprintf(stderr, "[%s] " BOLD_RED "Error! Bad rcv_va, rcv_vb or rcv_rho in line %d from \"%s\".\n" DEFAULT_RESTORE, command, iline, line); + exit(EXIT_FAILURE); + } rcv_mu = rcv_vb*rcv_vb*rcv_rho*1e10; rcv_lam = rcv_va*rcv_va*rcv_rho*1e10 - 2.0*rcv_mu; } diff --git a/pygrt/C_extension/src/static/stgrt_syn.c b/pygrt/C_extension/src/static/stgrt_syn.c index b2ba778b..c1975a7c 100644 --- a/pygrt/C_extension/src/static/stgrt_syn.c +++ b/pygrt/C_extension/src/static/stgrt_syn.c @@ -350,7 +350,19 @@ int main(int argc, char **argv){ fprintf(stderr, "[%s] " BOLD_RED "Error! Unable to read src property from \"%s\". \n" DEFAULT_RESTORE, command, line); exit(EXIT_FAILURE); } - src_mu = src_vb*src_vb*src_rho*1e10; + if(src_va <= 0.0 || src_vb < 0.0 || src_rho <= 0.0){ + fprintf(stderr, "[%s] " BOLD_RED "Error! Bad src_va, src_vb or src_rho from \"%s\".\n" DEFAULT_RESTORE, command, line); + exit(EXIT_FAILURE); + } + if(src_vb == 0.0 && mult_src_mu){ + fprintf(stderr, "[%s] " BOLD_RED + "Error! Zero src_vb from \"%s\". " + "Maybe you try to use -Su but the source is in the liquid. " + "Use -S instead.\n" + DEFAULT_RESTORE, command, line); + exit(EXIT_FAILURE); + src_mu = src_vb*src_vb*src_rho*1e10; + } if(mult_src_mu) M0 *= src_mu; } @@ -360,6 +372,10 @@ int main(int argc, char **argv){ fprintf(stderr, "[%s] " BOLD_RED "Error! Unable to read rcv property from \"%s\". \n" DEFAULT_RESTORE, command, line); exit(EXIT_FAILURE); } + if(rcv_va <= 0.0 || rcv_vb < 0.0 || rcv_rho <= 0.0){ + fprintf(stderr, "[%s] " BOLD_RED "Error! Bad rcv_va, rcv_vb or rcv_rho in line %d from \"%s\".\n" DEFAULT_RESTORE, command, iline, line); + exit(EXIT_FAILURE); + } } else if(iline == 3){ // 根据列长度判断是否有位移空间导数