def plot_this(ynot,tspan,ode,rp): sol = stablab.Struct() sol.t = [] sol.y = [] def updateSol(tVal,yVals): sol.t.append(tVal) sol.y.append(yVals) return None integrator = complex_ode(ode) integrator.set_integrator('dopri5',atol=1e-10,rtol=1e-10) integrator.set_solout(updateSol) integrator.set_initial_value(ynot,tspan[0]) integrator.integrate(tspan[-1]) sol.t, sol.y = np.array(sol.t), np.array(sol.y) return sol
def RH_stable_model(p): """ Rankine Hugoniot conditions """ st = stablab.Struct() st.H_fun = H_stable_model st.left_H = 1e-6 st.right_H = 1000 st.H_ind_var = 's' p.tau_neg = full_gas_Hugoniot(p,st,p.S_neg) p.S_plus = p.S0 p.tau_plus = p.tau0 none = p.none mu = p.mu kappa = p.kappa S = p.S_neg tau = p.tau_neg press_neg = np.exp(S) / tau ** 2 - tau T_neg = np.exp(S) / tau p.T_neg = T_neg S = p.S_plus tau = p.tau_plus press_plus = np.exp(S) / tau ** 2 - tau T_plus = np.exp(S) / tau p.T_plus = T_plus p.spd = -np.sqrt((press_neg-press_plus)/(p.tau_plus-p.tau_neg)) p.m1 = 0 p.v_plus = -p.spd*p.tau_plus-p.m1 p.v_neg = -p.spd*p.tau_neg-p.m1 return p
np.exp(S) / tau ** 3 - 0.1e1) + tau / kappa * (-spd * (-0.2e1 * np.exp(S) / tau ** 2 + tau) + v_x * mu * v / tau ** 2 + T_x * kappa / tau ** 2 + v * (-0.3e1 * np.exp(S) / tau ** 3 - 0.1e1))) / spd, -lamda * v * tau / kappa, lamda * tau / kappa, v * tau / kappa * ((v_x * mu / tau ** 2 - 0.3e1 * np.exp(S) / tau ** 3 - 0.1e1) / spd + spd) - tau / kappa * ((-spd * (-0.2e1 * np.exp(S) / tau ** 2 + tau) + v_x * mu * v / tau ** 2 + T_x * kappa / tau ** 2 + v * (-0.3e1 * np.exp(S) / tau ** 3 - 0.1e1)) / spd + spd * v + v_x * mu / tau - np.exp(S) / tau ** 2 + tau), -v / kappa - tau / kappa * (spd - v / tau)] ]) return out if __name__ == "__main__": # parameters s = stablab.Struct() p = stablab.Struct() #s.solve = 'ode' s.solve = 'bvp' p.S_neg = -5 p.none = 1 p.mu = 1 p.kappa = 1 p.S0 = 0 p.tau0 = 1 # plus and minus infinity endstates p = RH_stable_model(p) # phase condition
def co_contour_adaptive(c, s, p, m, e, fun): c.lambda_steps = 0 # initialize structures out = np.zeros(c.max_pts, dtype=np.complex) pre_imag = np.zeros(c.max_pts, dtype=np.complex) # Kato basis for first two points delh = c.first_step h = 0 lamda = fun(np.linspace(h, delh, c.ksteps + 2)) basis_L, proj_L = c.basisL(c.Lproj, c.L, lamda, s, p, c.LA, 1, c.epsl) basis_R, proj_R = c.basisR(c.Rproj, c.R, lamda, s, p, c.RA, -1, c.epsr) # compute Evans function for 1st point out[0] = c.evans(basis_L[:, :, 0], basis_R[:, :, 0], lamda[0], s, p, m, e) hit_points = c.hit_points cnt = 0 temp = stablab.Struct() while h < 1: # hold on; # plot(real(lambda(end)),imag(lambda(end)),'.k','MarkerSize',18) # drawnow; # # hold on; # plot(real(temp.evans),imag(temp.evans),'.k','MarkerSize',18) # drawnow; temp.evans = c.evans(basis_L[:, :, -1], basis_R[:, :, -1], lamda[-1], s, p, m, e) # check relative error of image rel_err = abs(temp.evans - out[cnt]) / min(abs(temp.evans), abs(out[cnt])) # rel_err1 = abs(temp.evans-out(cnt))/min(abs(temp.evans),abs(out(cnt))) # rel_err2 = abs(conj(temp.evans)-out(cnt))/min(abs(temp.evans),abs(out(cnt))) # rel_err = min(rel_err1,rel_err2) # if rel_err2< rel_err1 # temp.evans = conj(temp.evans) # end # E = temp.evans # Eold = out(cnt) if rel_err < c.tol: if 'stats' in c: if c.stats == 'on': plt.plot(np.real(lamda[-1]), np.imag(lamda[-1]), '.k') plt.show() if cnt + 1 > c.max_pts: raise ValueError('Maximum number of allowed steps exceeded.') h += delh # pred = (2/3)*c.tol*delh/rel_err; pred = (4 / 3) * delh delh = min(min(pred, c.max_step), 1 - h) if hit_points.size != 0: if h + delh > hit_points[0]: delh = hit_points[0] - h hit_points = hit_points[1:] lamda = fun(np.linspace(h, h + delh, c.ksteps + 2)) basis_L, proj_L = c.basisL(c.Lproj, c.L, lamda, s, p, c.LA, 1, c.epsl, basis_L[:, :, -1], proj_L[:, :, -1]) basis_R, proj_R = c.basisR(c.Rproj, c.R, lamda, s, p, c.RA, -1, c.epsr, basis_R[:, :, -1], proj_R[:, :, -1]) cnt = cnt + 1 out[cnt] = temp.evans # m.options.AbsTol = e.abs_tol*abs(temp.evans); # m.options.RelTol = m.options.AbsTol; else: if 'stats' in c: if c.stats == 'on': plt.plot(np.real(lamda[-1]), np.imag(lamda[-1]), '.r') delh = 0.5 * delh if delh < c.min_step_size: raise ValueError( 'Required delh smaller than minimum step size specified') lamda = fun(np.linspace(h, h + delh, c.ksteps + 2)) basis_L, proj_L = c.basisL(c.Lproj, c.L, lamda, s, p, c.LA, 1, c.epsl, basis_L[:, :, 0], proj_L[:, :, 0]) basis_R, proj_R = c.basisR(c.Rproj, c.R, lamda, s, p, c.RA, -1, c.epsr, basis_R[:, :, 0], proj_R[:, :, 0]) out = out[0:cnt] pre_imag = pre_imag[0:cnt] return out, pre_imag