def runSim(case,fn,place,descrip): (fi,fc,descrip,conns) = writeFiles(case,fn) t0= time.clock() n0=PyNetwork(fi,fc,1) dt = n0.T/(float(n0.M)) V0 = n0.getTotalVolume() if case==0: n0.runForwardProblem(dt) elif case==1: n0.runForwardProblem(dt) elif case ==3: T = n0.T xx = np.linspace(0,T,n0.M+1) Q0 = (1+0.2*np.exp(-(xx-T/2)**2/(T/10)**2))*0.008 n0.setbVal(0,Q0) n0.runForwardProblem(dt) Vf = n0.getTotalVolume() tf = time.clock() simtime = tf-t0 writeSummaryInfo(case,place,n0,V0,Vf,simtime, descrip)
with open(place + "/info.txt", 'wb') as f: f.write("Case %d\n" % case) f.write(descrip + '\n') f.write("Code is at state...\n") f.write("pressurization time T_p for middle of each pipe\n") f.write("pipe T_p(s)\n") for i in range(0, Np): P = n0.pressureTimeSeries(i, n0.Ns[i] / 2) f.write("%d %.1f\n" % (i, (find(P > .1)[0]) * dt)) f.write("max pressure is %f m\n" % Pmax) def runSim(case, fn, place, descrip): (fi, fc, descrip, conns) = writeFiles(case, fn) t0 = time.clock() n0 = PyNetwork(fi, fc, 1) dt = n0.T / (float(n0.M)) V0 = n0.getTotalVolume() if case == 0: n0.runForwardProblem(dt) elif case == 1: n0.runForwardProblem(dt) elif case == 3: T = n0.T xx = np.linspace(0, T, n0.M + 1) Q0 = (1 + 0.2 * np.exp(-(xx - T / 2)**2 / (T / 10)**2)) * 0.008 n0.setbVal(0, Q0) n0.runForwardProblem(dt) Vf = n0.getTotalVolume() tf = time.clock() simtime = tf - t0
bv = [0.]*Nn r = [-1]*Nn r[0] = 0 bt[0] =1 q0s = [0]*Np h0s = [0.1*d for d in Ds_m] Mrs =[0.007]*Np print T print M Nstar =1 #measuring point for each pipe Hs =np.ndarray((Np,M/Mi*Nt)) fn = "../indata/Alameda_m3" oldinp = "../indata/Alamedanewer52.0.0.inp" (fi, fc) = rewritePipes(fn,oldinp, Ns, Ls_m, Mrs, Ds_m, jt, bt, bv, r, h0s, q0s, T, M, a,elevs_m) n1 = PyNetwork(fi,fc,1) dt = n1.T/float(n1.M) Q00 = 0.0087 for i in range(0,Np): d = n1.Ds[i] A0 = (d*d/4.)*np.ones(n1.Ns[i]) Q0 = 0*np.ones(n1.Ns[i]) n1.setIC(i,A0,Q0) Qb = Q00*np.ones(M+1) n1.setbVal(0,Qb) Ttot= 0 Vs = [n1.getTotalVolume()] for m in range(Nt): try: n1.runForwardProblem(dt)
Us =np.zeros((M/Mi*Nt,sum(Ns)))# #new prefix for .inp and .config files that will be used for actual runtime parameters fn = "../indata/Alameda_short" #write new files [fn].inp and [fn].config with new info #(fi, fc) = rewritePipes(fn,oldinp, Ns, Ls, Mrs, Ds, jt, bt, bv, r, h0s, q0s, T, M, a, elevs) (fi, fc) = writePipes(fn,conn, xs,ys, Ns, Ls, Mrs, Ds, jt, bt, bv, r, h0s, q0s, T, M, a, elevs) m2psi = 1.42 #conversion factor, meters to psi m32gal=264.172052 #conversion factor m^3 to gallons for J in range(10): for I in range(10): t0 = time.clock() h0 = 0.05*J*Ds[0]+0.005 orf = 0.05*I*Ds[0]+0.005 n1 = PyNetwork(fi,fc,1) p0 = PyPipe_ps(Ns[0],Ds[0],Ls[0],M,a) A0 = p0.AofH(h0, True) Q0 = 0 Qin = 0.0087 Qout = 0.001 Qin_t=Qin*np.ones(M+1) z = orf o = np.ones(Ns[0]) n1.setIC(1,A0*o,Q0*o) n1.setbVal(0,Qin_t) n1.setbVal(1,z*np.ones(M+1)) n1.setbVal(2,z*np.ones(M+1)) t0= time.clock()