|
| 1 | +/* Version 1.0 - Zero offset CRS parameter inversion (RN, RNIP, BETA) with Very Fast Simulated Aneeling (VFSA) Global Optimization |
| 2 | +
|
| 3 | +This program the Non-Hyperbolic CRS approximation to fit data cube and get the parameters (Fomel, 2013). |
| 4 | +
|
| 5 | +Programer: Rodolfo A. C. Neves (Dirack) 19/09/2019 |
| 6 | +
|
| 7 | + |
| 8 | +
|
| 9 | +License: GPL-3.0 <https://www.gnu.org/licenses/gpl-3.0.txt>. |
| 10 | +
|
| 11 | + */ |
| 12 | + |
| 13 | +#include "vfsacrsnh_lib.h" |
| 14 | + |
| 15 | +int main(int argc, char* argv[]) |
| 16 | +{ |
| 17 | + |
| 18 | + float m0; // central CMP |
| 19 | + float om; // CMP axis origin |
| 20 | + float dm; // CMP sampling |
| 21 | + int nm; // Number of CMP's |
| 22 | + float oh; // Offset axis origin |
| 23 | + float dh; // Offset sampling |
| 24 | + int nh; // Number of Offsets |
| 25 | + int nt; // Number of time samples |
| 26 | + float ot; // Time axis origin |
| 27 | + float dt; // Time sampling |
| 28 | + bool verb; // Key to turn On/Off active mode |
| 29 | + float v0; // Near surface velocity |
| 30 | + float t0; // Normal ray time travel |
| 31 | + float cnew[3]; // Temporary parameters vector - actual iteration |
| 32 | + float c[3]; // Temporary parameters vector - last iteration |
| 33 | + float *otm; // Optimazed parameters |
| 34 | + float otrn, otrnip, otbeta, otsemb; // Optimazed parameters - actual iteration |
| 35 | + float deltaE, PM; // Metrópolis criteria |
| 36 | + float Em0=0; // Major semblance |
| 37 | + float u; // Random number |
| 38 | + float ***t; // Data cube A(m,h,t) |
| 39 | + int q, i; // loop counter |
| 40 | + float semb; // Semblance - actual iteration |
| 41 | + float RN, RNIP, BETA; // CRS parameters |
| 42 | + float semb0; // Inicial semblance value |
| 43 | + float c0; // VFSA damping factor |
| 44 | + float temp0; // inicial VFSA temperature |
| 45 | + float temp; // VFSA temperature |
| 46 | + int repeat; // perform VFSA optimization more than once |
| 47 | + |
| 48 | + /* RSF files I/O */ |
| 49 | + sf_file in, out; |
| 50 | + |
| 51 | + /* RSF files axis */ |
| 52 | + sf_axis ax,ay,az; |
| 53 | + |
| 54 | + sf_init(argc,argv); |
| 55 | + |
| 56 | + in = sf_input("in"); |
| 57 | + out = sf_output("out"); |
| 58 | + |
| 59 | + if (!sf_getfloat("m0",&m0)) m0=0; |
| 60 | + /* central CMP of the approximation (Km) */ |
| 61 | + |
| 62 | + if (!sf_getfloat("v0",&v0)) v0=1.5; |
| 63 | + /* Near surface velocity (Km/s) */ |
| 64 | + |
| 65 | + if (!sf_getfloat("t0",&t0)) t0=1.5; |
| 66 | + /* Normal ray traveltime (s) */ |
| 67 | + |
| 68 | + if (!sf_getfloat("c0",&c0)) c0=0.5; |
| 69 | + /* damping factor of VFSA */ |
| 70 | + |
| 71 | + if (!sf_getfloat("temp0",&temp0)) temp0=10; |
| 72 | + /* inicial VFSA temperature */ |
| 73 | + |
| 74 | + if(!sf_getint("repeat",&repeat)) repeat=1; |
| 75 | + /* How many times to perform VFSA global optimization */ |
| 76 | + |
| 77 | + if (!sf_histint(in,"n1",&nt)) sf_error("No n1= in input"); |
| 78 | + if (!sf_histfloat(in,"d1",&dt)) sf_error("No d1= in input"); |
| 79 | + if (!sf_histfloat(in,"o1",&ot)) sf_error("No o1= in input"); |
| 80 | + if (!sf_histint(in,"n2",&nh)) sf_error("No n2= in input"); |
| 81 | + if (!sf_histfloat(in,"d2",&dh)) sf_error("No d2= in input"); |
| 82 | + if (!sf_histfloat(in,"o2",&oh)) sf_error("No o2= in input"); |
| 83 | + if (!sf_histint(in,"n3",&nm)) sf_error("No n3= in input"); |
| 84 | + if (!sf_histfloat(in,"d3",&dm)) sf_error("No d3= in input"); |
| 85 | + if (!sf_histfloat(in,"o3",&om)) sf_error("No o3= in input"); |
| 86 | + |
| 87 | + if(! sf_getbool("verb",&verb)) verb=0; |
| 88 | + /* 1: active mode; 0: quiet mode */ |
| 89 | + |
| 90 | + if (verb) { |
| 91 | + |
| 92 | + sf_warning("Active mode on!!!"); |
| 93 | + sf_warning("Command line parameters: "); |
| 94 | + sf_warning("m0=%f v0=%f t0=%f c0=%f temp0=%f repeat=%i",m0,v0,t0,c0,temp0,repeat); |
| 95 | + sf_warning("Input file parameters: "); |
| 96 | + sf_warning("n1=%i d1=%f o1=%f",nt,dt,ot); |
| 97 | + sf_warning("n2=%i d2=%f o2=%f",nh,dh,oh); |
| 98 | + sf_warning("n3=%i d3=%f o3=%f",nm,dm,om); |
| 99 | + } |
| 100 | + |
| 101 | + c[0] = 0; |
| 102 | + c[1] = 0; |
| 103 | + c[2] = 0; |
| 104 | + cnew[0] = 0; |
| 105 | + cnew[1] = 0; |
| 106 | + cnew[2] = 0; |
| 107 | + |
| 108 | + srand(time(NULL)); |
| 109 | + |
| 110 | + /* Read seismic data cube */ |
| 111 | + t=sf_floatalloc3(nt,nh,nm); |
| 112 | + sf_floatread(t[0][0],nm*nh*nt,in); |
| 113 | + |
| 114 | + sf_fileclose(in); |
| 115 | + |
| 116 | + semb0=0; |
| 117 | + |
| 118 | + for(i=0;i<repeat;i++){ |
| 119 | + |
| 120 | + for (q=0; q <ITMAX; q++){ |
| 121 | + |
| 122 | + /* calculate VFSA temperature for this iteration */ |
| 123 | + temp=getVfsaIterationTemperature(q,c0,temp0); |
| 124 | + |
| 125 | + /* parameter disturbance */ |
| 126 | + disturbParameters(temp,cnew,c); |
| 127 | + |
| 128 | + RN = cnew[0]; |
| 129 | + RNIP = cnew[1]; |
| 130 | + BETA = cnew[2]; |
| 131 | + |
| 132 | + semb=0; |
| 133 | + |
| 134 | + /* Calculate semblance: Non-hyperbolic CRS approximation with data */ |
| 135 | + semb=semblance(m0,dm,om,oh,dh,dt,nt,t0,v0,RN,RNIP,BETA,t); |
| 136 | + |
| 137 | + |
| 138 | + /* VFSA parameters convergence condition */ |
| 139 | + if(fabs(semb) > fabs(semb0) ){ |
| 140 | + otsemb = semb; |
| 141 | + otrn = RN; |
| 142 | + otrnip = RNIP; |
| 143 | + otbeta = BETA; |
| 144 | + semb0 = semb; |
| 145 | + } |
| 146 | + |
| 147 | + /* VFSA parameters update condition */ |
| 148 | + deltaE = -semb - Em0; |
| 149 | + |
| 150 | + /* Metrópolis criteria */ |
| 151 | + PM = expf(-deltaE/temp); |
| 152 | + |
| 153 | + if (deltaE<=0){ |
| 154 | + c[0] = cnew[0]; |
| 155 | + c[1] = cnew[1]; |
| 156 | + c[2] = cnew[2]; |
| 157 | + Em0 = -semb; |
| 158 | + } else { |
| 159 | + u=getRandomNumberBetween0and1(); |
| 160 | + if (PM > u){ |
| 161 | + c[0] = cnew[0]; |
| 162 | + c[1] = cnew[1]; |
| 163 | + c[2] = cnew[2]; |
| 164 | + Em0 = -semb; |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + } /* loop over iterations */ |
| 169 | + |
| 170 | + } /* repeat VFSA global optimization */ |
| 171 | + |
| 172 | + free(t); |
| 173 | + |
| 174 | + /* Save optimized parameters in 'param' file */ |
| 175 | + otm=sf_floatalloc(8); |
| 176 | + otm[0] = otrn; |
| 177 | + otm[1] = otrnip; |
| 178 | + otm[2] = otbeta; |
| 179 | + otm[3] = otsemb; |
| 180 | + otm[4] = c0; |
| 181 | + otm[5] = temp0; |
| 182 | + otm[6] = t0; |
| 183 | + otm[7] = m0; |
| 184 | + |
| 185 | + /* Show optimized parameters on screen before save them */ |
| 186 | + sf_warning("Parâmetros otimizados:\n RN=%f, RNIP=%f, BETA=%f, SEMB=%f",otrn,otrnip,otbeta,otsemb); |
| 187 | + |
| 188 | + /* axis = sf_maxa(n,o,d)*/ |
| 189 | + ax = sf_maxa(8, 0, 1); |
| 190 | + ay = sf_maxa(1, 0, 1); |
| 191 | + az = sf_maxa(1, 0, 1); |
| 192 | + |
| 193 | + /* sf_oaxa(file, axis, axis index) */ |
| 194 | + sf_oaxa(out,ax,1); |
| 195 | + sf_oaxa(out,ay,2); |
| 196 | + sf_oaxa(out,az,3); |
| 197 | + sf_floatwrite(otm,8,out); |
| 198 | + |
| 199 | + sf_close(); |
| 200 | + exit(0); |
| 201 | +} |
0 commit comments