Skip to content

Commit 9fff56b

Browse files
committed
Added srf_join tool, changed srf2stoch to add option to determine rupture initiation time as per RWG, also modified BBP python code to add the parameter used by srf2stoch
1 parent 2fcefec commit 9fff56b

10 files changed

Lines changed: 730 additions & 14 deletions

File tree

bbp/comps/hfsims.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2024, University of Southern California
5+
Copyright (c) 2026, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -81,6 +81,7 @@ def __init__(self, i_r_velmodel, i_r_srcfile, i_r_srffile, i_r_stations,
8181
self.rvsig = None
8282
self.c_zero = None
8383
self.use_mrf = use_mrf
84+
self.tinit_slip_weight = None
8485

8586
# Switch to MRF file if requested
8687
if self.use_mrf:
@@ -213,6 +214,9 @@ def run(self):
213214
else:
214215
self.c_zero = config.C_ZERO
215216

217+
# Set up tinit_slip_weight
218+
self.tinit_slip_weight = config.TINIT_SLIP_WEIGHT
219+
216220
# Calculate rvfac
217221
if "common_seed" in config.CFGDICT:
218222
rvfac = calculate_rvfac(self.mean_rvfac, self.range_rvfac,
@@ -245,6 +249,8 @@ def run(self):
245249

246250
progstring = ("%s " %
247251
(os.path.join(install.A_GP_BIN_DIR, "srf2stoch")) +
252+
"tinit_slip_weight=%d " %
253+
(self.tinit_slip_weight) +
248254
"infile=%s outfile=%s " %
249255
(a_srffile, a_slipfile) +
250256
"target_dx=%f target_dy=%f " %

bbp/comps/hfsims_cfg.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2022, University of Southern California
5+
Copyright (c) 2026, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -131,5 +131,8 @@ def __init__(self, a_srcfile=None):
131131
# Extra parameter used by hfsims V6.0.5
132132
self.SPAR_EXP = 0.5
133133

134+
# Extra parameter used by srf2stoch from 2025-12-11
135+
self.TINIT_SLIP_WEIGHT = 1
136+
134137
if __name__ == "__main__":
135138
print("Test Config Class: %s" % (__file__))

bbp/src/gp/GenRandV5.0/srf_gethypo.c

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,22 @@ int inbin = 0;
2020
float hlon, hlat, hdep;
2121
float tmin = 1.0e+15;
2222

23+
/* 2025-12-04
24+
Added option to check slip-rate function to determine/modify rupture initation time.
25+
Parameters below are used for these options. Default is now to use options but can
26+
be skipped by setting "check_tinit=0".
27+
*/
28+
int check_tinit = 1;
29+
float *stfp, tt;
30+
int it, nt, itmax, it_chk_tt;
31+
double tmp_d, max_sliprate_d, min_sliprate_d;
32+
double tol_d = 1.0e-20;
33+
2334
sprintf(infile,"stdin");
2435

2536
setpar(ac,av);
2637
getpar("infile","s",infile);
38+
getpar("check_tinit","d",&check_tinit);
2739
endpar();
2840

2941
read_srf(&srf1,infile,inbin);
@@ -32,14 +44,64 @@ apval_ptr1 = srf1.srf_apnts.apntvals;
3244

3345
for(ip=0;ip<srf1.srf_apnts.np;ip++)
3446
{
35-
if(apval_ptr1[ip].tinit < tmin)
47+
48+
/* 2025-12-04
49+
Added option to check slip-rate function to determine/modify rupture initation
50+
time. This is only important if the slip-rate is given with some number of leading zeros.
51+
Default is now to use this option, but can be skipped by setting "check_tinit=0".
52+
*/
53+
54+
if(check_tinit)
55+
{
56+
tt = 1.0e+15;
57+
if(apval_ptr1[ip].nt1 > 0 || apval_ptr1[ip].nt2 > 0)
58+
{
59+
tt = apval_ptr1[ip].tinit;
60+
61+
if(apval_ptr1[ip].slip1*apval_ptr1[ip].slip1 >= apval_ptr1[ip].slip2*apval_ptr1[ip].slip2)
62+
{
63+
stfp = apval_ptr1[ip].stf1;
64+
nt = apval_ptr1[ip].nt1;
65+
}
66+
else
67+
{
68+
stfp = apval_ptr1[ip].stf2;
69+
nt = apval_ptr1[ip].nt2;
70+
}
71+
72+
max_sliprate_d = -1.0;
73+
for(it=0;it<nt;it++)
74+
{
75+
tmp_d = (double)(stfp[it])*(double)(stfp[it]);
76+
if(tmp_d > max_sliprate_d)
77+
{
78+
max_sliprate_d = tmp_d;
79+
itmax = it;
80+
}
81+
}
82+
83+
min_sliprate_d = tol_d*max_sliprate_d;
84+
85+
it_chk_tt = 1;
86+
tmp_d = (double)(stfp[it_chk_tt])*(double)(stfp[it_chk_tt]);
87+
while(tmp_d < min_sliprate_d && it_chk_tt < itmax)
88+
it_chk_tt++;
89+
90+
if(tt < (it_chk_tt-1)*apval_ptr1[ip].dt)
91+
tt = tt + (it_chk_tt-1)*apval_ptr1[ip].dt;
92+
}
93+
} /* end "check_tinit" */
94+
else
95+
tt = apval_ptr1[ip].tinit;
96+
97+
if(tt < tmin)
3698
{
3799
hlon = apval_ptr1[ip].lon;
38100
hlat = apval_ptr1[ip].lat;
39101
hdep = apval_ptr1[ip].dep;
40-
tmin = apval_ptr1[ip].tinit;
102+
tmin = tt;
41103
}
42104
}
43105

44-
fprintf(stdout,"%.5f\t%.5f\t%.5f\n",hlon,hlat,hdep);
106+
fprintf(stdout,"%.5f\t%.5f\t%.5f\t%.5f\n",hlon,hlat,hdep,tmin);
45107
}

bbp/src/gp/StandRupFormat/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ srf2stoch
66
srf2xyz
77
srf2mrf
88
srf_downsample
9+
srf_join

bbp/src/gp/StandRupFormat/function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void get_moment_rate(struct standrupformat *,struct velmodel *,int);
5555
void read_velmodel(char *,struct velmodel *);
5656

5757
void sum_srf(struct standrupformat *,struct standrupformat *,struct standrupformat *,float *);
58-
void join_srf(struct standrupformat *,struct standrupformat *,struct standrupformat *);
58+
void join_srf(struct standrupformat *srf0,struct standrupformat *srf1,struct standrupformat *srf2,int pflag,int ac,char **av);
5959
void select_depths_srf(struct standrupformat *,struct standrupformat *,float *,float *);
6060
void scale_srf(struct standrupformat *,struct standrupformat *,float *);
6161

bbp/src/gp/StandRupFormat/makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ FFLAGS = ${UFLAGS} -ffixed-line-length-132
3636

3737
##### make options
3838

39-
all: srf2stoch generic_slip2srf fault_seg2gsf srf2moment srf2xyz srf2mrf srf_downsample
39+
all: srf2stoch generic_slip2srf fault_seg2gsf srf2moment srf2xyz srf2mrf srf_downsample srf_join
4040

4141
test_header : test_header.c ${OBJS} ${GEOPROJ_OBJS}
4242
$(CC) $(CFLAGS) -o test_header test_header.c ${LDLIBS} ${GEOPROJ_OBJS}
@@ -74,6 +74,10 @@ srf_downsample : srf_downsample.c ${OBJS} ${GEOPROJ_OBJS}
7474
${CC} -o srf_downsample srf_downsample.c ${LDLIBS} ${INCPAR} ${GEOPROJ_OBJS}
7575
cp srf_downsample ../bin/
7676

77+
srf_join : srf_join.c ${OBJS} ${GEOPROJ_OBJS}
78+
${CC} ${CFLAGS} -o srf_join srf_join.c ${LDLIBS} ${INCPAR} ${GEOPROJ_OBJS}
79+
cp srf_join ../bin/.
80+
7781
${OBJS} : ${HEADS}
7882

7983
clean :

bbp/src/gp/StandRupFormat/srf2stoch_sub.c

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ float target_dy = -1.0;
3232
float avgstk = -1.0e+15;
3333
int revstk;
3434

35+
/* 2025-12-11
36+
Added options to check slip-rate function to determine/modify rupture initation time and
37+
to slip-weight the averaging of tinit. Parameters below are used for these options.
38+
Default is now to use both options, but can be skipped by setting "check_tinit=0" and/or
39+
"tinit_slip_weight=0".
40+
*/
41+
int tinit_slip_weight = 1;
42+
int check_tinit = 1;
43+
float *stfp;
44+
int it, nt, itmax, it_chk_tt;
45+
double tmp_d, max_sliprate_d, min_sliprate_d;
46+
double tol_d = 1.0e-20;
47+
3548
debug = 1;
3649

3750
setpar(param_string_len, param_string);
@@ -44,6 +57,10 @@ if(target_dy < 0.0)
4457
mstpar("dy","f",&dy);
4558

4659
getpar("avgstk","f",&avgstk);
60+
61+
getpar("check_tinit","d",&check_tinit);
62+
getpar("tinit_slip_weight","d",&tinit_slip_weight);
63+
4764
endpar();
4865

4966
if(avgstk > -1.0e+14)
@@ -173,6 +190,47 @@ fprintf(stderr,"id= %d is= %d kp= %d noff= %d\n",id,is,kp,noff);
173190

174191
tt = srf->srf_apnts.apntvals[kp].tinit;
175192

193+
/* 2025-12-11
194+
Added option to check slip-rate function to determine/modify rupture initation
195+
time. This is only important if the slip-rate is given with some number of leading zeros.
196+
Default is now to use this option, but can be skipped by setting "check_tinit=0".
197+
*/
198+
if(check_tinit && (apval_ptr[kp].nt1 > 0 || apval_ptr[kp].nt2 > 0))
199+
{
200+
if(apval_ptr[kp].slip1*apval_ptr[kp].slip1 >= apval_ptr[kp].slip2*apval_ptr[kp].slip2)
201+
{
202+
stfp = apval_ptr[kp].stf1;
203+
nt = apval_ptr[kp].nt1;
204+
}
205+
else
206+
{
207+
stfp = apval_ptr[kp].stf2;
208+
nt = apval_ptr[kp].nt2;
209+
}
210+
211+
max_sliprate_d = -1.0;
212+
for(it=0;it<nt;it++)
213+
{
214+
tmp_d = (double)(stfp[it])*(double)(stfp[it]);
215+
if(tmp_d > max_sliprate_d)
216+
{
217+
max_sliprate_d = tmp_d;
218+
itmax = it;
219+
}
220+
}
221+
222+
min_sliprate_d = tol_d*max_sliprate_d;
223+
224+
it_chk_tt = 1;
225+
tmp_d = (double)(stfp[it_chk_tt])*(double)(stfp[it_chk_tt]);
226+
while(tmp_d < min_sliprate_d && it_chk_tt < itmax)
227+
it_chk_tt++;
228+
229+
if(tt < (it_chk_tt-1)*apval_ptr[kp].dt)
230+
tt = tt + (it_chk_tt-1)*apval_ptr[kp].dt;
231+
}
232+
/* end "check_tinit" */
233+
176234
if(mrf_flag == 1)
177235
{
178236
dmu = (apval_ptr[kp].vs)*(apval_ptr[kp].vs)*(apval_ptr[kp].den);
@@ -278,19 +336,38 @@ fprintf(stderr,"id= %d is= %d kp= %d noff= %d\n",id,is,kp,noff);
278336
m = (long long)ix*nxsum + j + (iy*nysum + k)*(long long)nx*nxsum;
279337

280338
sp[ip] = sp[ip] + slip[m];
281-
ti[ip] = ti[ip] + tinit[m];
339+
340+
/* 2025-12-11
341+
Added option to slip-weight the averaging of tinit (similar to that done for trise).
342+
Default is now to use this option, but can be skipped by setting "tinit_slip_weight=0".
343+
*/
344+
if(tinit_slip_weight)
345+
ti[ip] = ti[ip] + tinit[m]*slip[m];
346+
else
347+
ti[ip] = ti[ip] + tinit[m];
348+
282349
tr[ip] = tr[ip] + trise[m]*slip[m];
283350
sum = sum + slip[m];
284351
}
285352
}
286353

287354
sp[ip] = sp[ip]*fac;
288-
ti[ip] = ti[ip]*fac;
355+
356+
if(tinit_slip_weight == 0)
357+
ti[ip] = ti[ip]*fac;
289358

290359
if(sum > 0.0)
360+
{
291361
tr[ip] = tr[ip]/sum;
362+
if(tinit_slip_weight)
363+
ti[ip] = ti[ip]/sum;
364+
}
292365
else
366+
{
293367
tr[ip] = 1.0e-05;
368+
if(tinit_slip_weight)
369+
ti[ip] = 1.0e-05;
370+
}
294371
}
295372
}
296373

bbp/src/gp/StandRupFormat/srf_gethypo.c

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "function.h"
44
#include "defs.h"
55

6-
main(int ac,char **av)
6+
int main(int ac,char **av)
77
{
88
int i, ip, j;
99
char infile[1024];
@@ -17,10 +17,22 @@ int inbin = 0;
1717
float hlon, hlat, hdep;
1818
float tmin = 1.0e+15;
1919

20+
/* 2025-12-04
21+
Added option to check slip-rate function to determine/modify rupture initation time.
22+
Parameters below are used for these options. Default is now to use options but can
23+
be skipped by setting "check_tinit=0".
24+
*/
25+
int check_tinit = 1;
26+
float *stfp, tt;
27+
int it, nt, itmax, it_chk_tt;
28+
double tmp_d, max_sliprate_d, min_sliprate_d;
29+
double tol_d = 1.0e-20;
30+
2031
sprintf(infile,"stdin");
2132

2233
setpar(ac,av);
2334
getpar("infile","s",infile);
35+
getpar("check_tinit","d",&check_tinit);
2436
endpar();
2537

2638
read_srf(&srf1,infile,inbin);
@@ -29,12 +41,62 @@ apval_ptr1 = srf1.srf_apnts.apntvals;
2941

3042
for(ip=0;ip<srf1.srf_apnts.np;ip++)
3143
{
32-
if(apval_ptr1[ip].tinit < tmin)
44+
45+
/* 2025-12-04
46+
Added option to check slip-rate function to determine/modify rupture initation
47+
time. This is only important if the slip-rate is given with some number of leading zeros.
48+
Default is now to use this option, but can be skipped by setting "check_tinit=0".
49+
*/
50+
51+
if(check_tinit)
52+
{
53+
tt = 1.0e+15;
54+
if(apval_ptr1[ip].nt1 > 0 || apval_ptr1[ip].nt2 > 0)
55+
{
56+
tt = apval_ptr1[ip].tinit;
57+
58+
if(apval_ptr1[ip].slip1*apval_ptr1[ip].slip1 >= apval_ptr1[ip].slip2*apval_ptr1[ip].slip2)
59+
{
60+
stfp = apval_ptr1[ip].stf1;
61+
nt = apval_ptr1[ip].nt1;
62+
}
63+
else
64+
{
65+
stfp = apval_ptr1[ip].stf2;
66+
nt = apval_ptr1[ip].nt2;
67+
}
68+
69+
max_sliprate_d = -1.0;
70+
for(it=0;it<nt;it++)
71+
{
72+
tmp_d = (double)(stfp[it])*(double)(stfp[it]);
73+
if(tmp_d > max_sliprate_d)
74+
{
75+
max_sliprate_d = tmp_d;
76+
itmax = it;
77+
}
78+
}
79+
80+
min_sliprate_d = tol_d*max_sliprate_d;
81+
82+
it_chk_tt = 1;
83+
tmp_d = (double)(stfp[it_chk_tt])*(double)(stfp[it_chk_tt]);
84+
while(tmp_d < min_sliprate_d && it_chk_tt < itmax)
85+
it_chk_tt++;
86+
87+
if(tt < (it_chk_tt-1)*apval_ptr1[ip].dt)
88+
tt = tt + (it_chk_tt-1)*apval_ptr1[ip].dt;
89+
}
90+
} /* end "check_tinit" */
91+
else
92+
tt = apval_ptr1[ip].tinit;
93+
94+
if(tt < tmin)
3395
{
3496
hlon = apval_ptr1[ip].lon;
3597
hlat = apval_ptr1[ip].lat;
3698
hdep = apval_ptr1[ip].dep;
37-
tmin = apval_ptr1[ip].tinit;
99+
tmin = tt;
38100
}
39101
}
40102

0 commit comments

Comments
 (0)