# Sample program written in rnpl as a language guide # This program solves 3D 2nd order wave equation # phi_tt = phi_xx + phi_yy + phi_zz # A=phi_x, B=phi_y, C=phy_t # This is how to set the memory size system parameter int memsiz := 2000000 parameter float xmin := 0 parameter float xmax := 100 parameter float ymin := 0 parameter float ymax := 100 parameter float zmin := 0 parameter float zmax := 100 parameter float amp := 1.0 parameter float cx := 50.0 parameter float cy := 50 parameter float cz := 50 parameter float sx parameter float sy parameter float sz rect coordinates t,x,y,z uniform rect grid g1 [1:Nx][1:Ny][1:Nz] {xmin:xmax}{ymin:ymax}{zmin:zmax} float phi on g1 at -1,0,1 attribute int out_gf encodeone := [1 0] operator D_LF(f,x) := (<0>f[1][0][0] - <0>f[-1][0][0])/(2*dx) operator D_LF(f,y) := (<0>f[0][1][0] - <0>f[0][-1][0])/(2*dy) operator D_LF(f,z) := (<0>f[0][0][1] - <0>f[0][0][-1])/(2*dz) operator D_LF(f,t) := (<1>f[0][0][0] - <-1>f[0][0][0])/(2*dt) operator D_LF(f,t,t) := (<1>f[0][0][0] - 2*<0>f[0][0][0] + <-1>f[0][0][0])/(dt*dt) operator D_LF(f,x,x) := (<0>f[1][0][0] - 2*<0>f[0][0][0] + <0>f[-1][0][0])/(dx*dx) operator D_LF(f,y,y) := (<0>f[0][1][0] - 2*<0>f[0][0][0] + <0>f[0][-1][0])/(dy*dy) operator D_LF(f,z,z) := (<0>f[0][0][1] - 2*<0>f[0][0][0] + <0>f[0][0][-1])/(dz*dz) evaluate residual phi { [1:Nx][1:Ny][1:1] := D_LF(phi,t); [1:Nx][1:Ny][Nz:Nz] := D_LF(phi,t); [1:Nx][1:1][1:Nz] := D_LF(phi,t); [1:Nx][Ny:Ny][1:Nz] := D_LF(phi,t); [1:1][1:Ny][1:Nz] := D_LF(phi,t); [Nx:Nx][1:Ny][1:Nz] := D_LF(phi,t); [2:Nx-1][2:Ny-1][2:Nz-1] := D_LF(phi,t,t) - D_LF(phi,x,x) - D_LF(phi,y,y) - D_LF(phi,z,z) } initialize phi { [1:Nx][1:Ny][1:Nz] := amp*exp(-(x-cx)^2/sx^2)*exp(-(y-cy)^2/sy^2)*exp(-(z-cz)^2/sz^2) } looper iterative auto update phi ##Save from here to end of file to separate file (w3d_0), edit and remove ##first '#' from every line. ## ##parameters for wave3d #tag := "3d_" #lambda := .3 #Nx0 := 32 #Ny0 := 32 #Nz0 := 32 #xmin := 0 #xmax := 10 #ymin := 0 #ymax := 10 #zmin := 0 #zmax := 10 #ser := 0 #fout := 1 #iter := 10 #epsiter := 1.0e-5 #rmod := 1 #amp := 1.0 #cx := 5.0 #cy := 5 #cz := 5 #sx := .8 #sy := .8 #sz := .8 #in_file := "w3d_in.sdf" #out_file := "w3d_out.sdf" #level:=0