# Sample program written in rnpl as a language guide # This program solves 1D 2nd order wave equation # phi_tt = phi_xx (string with endpoints fixed) # Phi=phi_x Pi=phi_t # This is how to set the memory size system parameter int memsiz := 1000000 parameter float xmin := 0 parameter float xmax := 100 parameter float amp := 1.0 parameter float cent parameter float sigma rect coordinates t,x uniform rect grid g1 [1:Nx] {xmin:xmax} #uniform rect grid g1 float phi on g1 at -1,0,1 attribute int out_gf encodeone := [1 0] operator D_LF(f,x,x) := (<0>f[1] - 2*<0>f[0] + <0>f[-1])/(dx*dx) operator D_LF(f,t,t) := (<1>f[0] - 2*<0>f[0] + <-1>f[0])/(dt*dt) operator D_LF(f,t) := (<1>f[0] - <-1>f[0])/(2*dt) evaluate residual phi { [1:1] := D_LF(phi,t); [2:Nx-1] := D_LF(phi,t,t) - D_LF(phi,x,x); [Nx:Nx] := D_LF(phi,t) } #evaluate residual phi { [0:0] := D_LF(phi,t); # [1:Nx-2] := D_LF(phi,t,t) - D_LF(phi,x,x); # [Nx-1:Nx-1] := D_LF(phi,t) } initialize phi {[1:Nx] := amp*exp(-(x-cent)^2/sigma^2)} looper iterative auto update phi ##Save from here to end of file to separate file (w1d_0), edit and remove ##first '#' from every line. ## ##parameters for wave1d #tag := "1d_" #lambda := .8 #Nx0 := 100 #level := 0 #xmin := 0 #xmax := 10 #ser := 0 #fout := 1 #iter := 1000 #epsiter := 1.0e-5 #rmod := 10 #amp := 1.0 #cent := 5.0 #sigma := 0.8 #in_file := "w_in.sdf" #out_file := "w_out.sdf"