void CreateMap() { //Our 'main' function int x,y,color; //Holds the result of slove for(y=0;y<HEIGHT;y++) //Main loop for map generation for(x=0;x<WIDTH;x++){ color=solve(translate_x(x),translate_y(y))*colorcount/100; #ifdef GRAPHICS gs_plot(x,y,colortable[color]); //Plot the coordinate to map #else crc+=colortable[color]; #endif } #ifdef GRAPHICS gs_update(); #endif }
int main(int argc, char* argv[]) { int nz,nx,na; float oz,ox,oa; float dz,dx,da; int iq; /* escape variables switch */ int ix; /* grid points in x */ int iz; /* grid points in z */ int ia; /* grid points in a */ int iter, niter; /* number of iterations */ int ix0, ix1, ixs; int iz0, iz1, izs; int ia0, ia1, ias; float a; /* angle */ float ***t; /* escape variable */ float **v,**vx,**vz; /* slowness, gradients */ float vel, velx, velz; float cs,sn; float new_val; float cvt,tol; sf_file in,out,slow,slowz,slowx; float sl_vti, sl_vti_inv; char is_P_SH_SV, *whatV; float Hp, Hq, p_gradH, dl_dsigma, da_dsigma; float vti_eps = 0.20, /*0.2, */ vti_gamma=0.20, /*0.2, */ vti_delta=-0.450; /*-0.45;*/ struct VTIStruct VTI; /* bool swap_dir_x=1, swap_dir_z=1; */ sf_init(argc,argv); in = sf_input("in"); out = sf_output("out"); if (!sf_getint("iq",&iq)) sf_error("Need iq="); /* switch for escape variable 0=x, 1=a, 2=t, 3=z, 4=l */ whatV = sf_getstring ("vti"); /* what to compute (p=qP, v=qSV, h=SH) */ if (NULL == whatV) { whatV = "p"; } else { if (whatV[0] != 'p' && whatV[0] != 'v' && whatV[0] != 'h') sf_error ("Need vti=p|v|h"); } is_P_SH_SV = whatV[0]; /* read input file parameters */ if (SF_FLOAT != sf_gettype(in)) sf_error("Need float"); if (!sf_histint(in,"n1",&nz)) sf_error("No n1="); if (!sf_histfloat(in,"d1",&dz)) sf_error("No d1="); if (!sf_histfloat(in,"o1",&oz)) sf_error("No o1="); if (!sf_histint(in,"n2",&nx)) sf_error("No n2="); if (!sf_histfloat(in,"d2",&dx)) sf_error("No d2="); if (!sf_histfloat(in,"o2",&ox)) sf_error("No o2="); if (!sf_histint(in,"n3",&na)) sf_error("No n3="); if (!sf_histfloat(in,"d3",&da)) sf_error("No d3="); if (!sf_histfloat(in,"o3",&oa)) sf_error("No o3="); /* angle in degrees */ if (!sf_getint("niter",&niter)) niter=50; /* number of Gauss-Seidel iterations */ if (!sf_getfloat("tol",&tol)) tol=0.000002*nx*nz; /* accuracy tolerance */ if (!sf_getfloat("vti_eps",&vti_eps)) vti_eps=0.0; if (!sf_getfloat("vti_gamma",&vti_gamma)) vti_gamma=0.0; if (!sf_getfloat("vti_delta",&vti_delta)) vti_delta=0.0; /* VTI constants Thomsen */ /* memory allocations */ /* Solution vector */ t = sf_floatalloc3(nz,nx,na); /* read input escape variable - initial guess */ sf_floatread(t[0][0],nz*nx*na,in); /* for (int ix=0; ix < nx; ix++) for (int iz=0; iz < nz; iz++) for (int ia=0; ia < na; ia++) t[ia][ix][iz] = 1e10f; */ /* read auxiliary slowness file */ slow = sf_input("vel"); v = sf_floatalloc2(nz,nx); sf_floatread(v[0],nz*nx,slow); /* read auxiliary slowness z-gradient file */ slowz = sf_input("velz"); vz = sf_floatalloc2(nz,nx); sf_floatread(vz[0],nz*nx,slowz); /* read auxiliary slowness x-gradient file */ slowx = sf_input("velx"); vx = sf_floatalloc2(nz,nx); sf_floatread(vx[0],nz*nx,slowx); /* convert to radians */ oa *= SF_PI/180.; da *= SF_PI/180.; ia0=0; ia1=na; ias=1; gsray_init(nz,nx,na, oz,ox,oa, dz,dx,da); /* Greenriver shale example alfa=3.29 beta=1.77 eps=0.195 gamma=0.18 delat=-0.45 */ vti_init_greenriver_c(&VTI); vti_c2thomsen(&VTI); for (iter=0; iter < niter; iter++) { cvt = 0.0; /* X_next - X_prev */ int num_fails = 0; /* Gauss-Seidel iteration on angle */ for (ia = ia0; ia != ia1; ia += ias) { a = oa + ia*da; cs = cosf(a); sn = sinf(a); /* assert (fabs(sn) > 1e-6 && fabs(cs) > 1e-6); Hq = -sn; Hp = -cs; */ vti_gauss_2_c(&VTI, v[0][0], vx[0][0], vz[0][0], vti_eps, vti_gamma, vti_delta); vti_c11_2_c1(&VTI); sl_vti = vti_slowness_c(&VTI, cs*cs, sn*sn, is_P_SH_SV, &sl_vti_inv); Svti(&VTI, sl_vti, sl_vti_inv, is_P_SH_SV, cs, sn, &Hp, &Hq, (float*)0, (float*)0, (float*)0);//&da_dsigma); if (1e-6 < Hq) { ix0=nx-2; ix1=-1; ixs=-1; for (iz = 0; iz < nz; iz++) boundary_mat(t,iz,nx-1,ia,iq); } else { ix0=1; ix1=nx; ixs=1; for (iz = 0; iz < nz; iz++) boundary_mat(t,iz,0,ia,iq); } if (1e-6 < Hp) { iz0=nz-2; iz1=-1; izs=-1; for (ix = 0; ix < nx; ix++) boundary_mat(t,nz-1,ix,ia,iq); } else { iz0=1; iz1=nz; izs=1; for (ix = 0; ix < nx; ix++) boundary_mat(t,0,ix,ia,iq); } /* loop over grid Z.X */ for (ix = ix0; ix != ix1; ix += ixs) { for (iz = iz0; iz != iz1; iz += izs) { vel = v[ix][iz]; velx = vx[ix][iz]; velz = vz[ix][iz]; vti_gauss_2_c(&VTI, vel, velx, velz, vti_eps, vti_gamma, vti_delta); vti_c11_2_c1(&VTI); sl_vti = vti_slowness_c(&VTI, cs*cs, sn*sn, is_P_SH_SV, &sl_vti_inv); Svti(&VTI, sl_vti, sl_vti_inv, is_P_SH_SV, cs, sn, &Hp, &Hq, &p_gradH, &dl_dsigma, &da_dsigma); vti_c2thomsen(&VTI); assert(fabs(VTI.eps - vti_eps) < 1e-6); assert(fabs(VTI.gamma - vti_gamma) < 1e-6); assert(fabs(VTI.delta - vti_delta) < 1e-6); /* Gauss-Seidel update new_val = gs_update(t,iz,ix,ia,ss,ssz,ssx,cs,sn,iq); */ new_val = gs_update(t,-Hp, -Hq, -da_dsigma, iz,ix,ia, p_gradH, dl_dsigma, iq); /* new_val = fmin(new_val, t[ia][ix][iz]); */ cvt += fabsf(t[ia][ix][iz]-new_val); /* t[ia][ix][iz] = fmin(new_val, t[ia][ix][iz]); */ t[ia][ix][iz] = new_val; /* if (t[ia][ix][iz] > 1000) num_fails++; */ } /* ix */ } /* iz */ } /* ia */ sf_warning("Iter = %d, Norm L1 = %g num fails = %d sweep=%g %g",iter,cvt/(nx*nz*na), num_fails,Hp,Hq); /* tol is tolerance for convergence */ if (cvt < tol) break; /* alternate updating direction on angle grid*/ if (0 == ia0) { ia0 = na-1; ia1 = -1; ias = -1; } else { ia0 = 0; ia1 = na; ias = 1; } } /* end G-S iterations */ /* output */ sf_floatwrite(t[0][0],nz*nx*na,out); exit(0); }