def errors(plot_results=True, T_final_years=1000.0, dt_years=100, Mz=101): """Test the bedrock temperature solver with Neumann B.C. at the base and Dirichlet B.C. at the top surface. """ T_final = convert(T_final_years, "years", "seconds") dt = convert(dt_years, "years", "seconds") Lz = 1000.0 dz = Lz / (Mz - 1.0) column = PISM.BedrockColumn("btu", ctx.config, dz, int(Mz)) z = np.linspace(-Lz, 0, Mz) T_base = 240.0 # Kelvin T_surface = 260.0 # Kelvin dT_base = (T_surface - T_base) / Lz T_steady = T_base + dT_base * (z - (-Lz)) Q_base = -K * dT_base T_exact = exact(Lz, dT_base, T_surface) t = 0.0 # initial condition x = T_exact(z, t) while t < T_final: x = column.solve(dt, Q_base, T_surface, x) t += dt T_exact_final = T_exact(z, t) if plot_results: t_years = convert(t, "seconds", "years") plt.figure() plt.xlabel("z, meters") plt.ylabel("T, K") plt.step(z, T_exact(z, 0), color="blue", label="initial condition") plt.step(z, T_exact_final, color="green", label="exact solution") plt.step(z, T_steady, "--", color="black", label="steady state profile") plt.grid(True) plt.step(z, x, label="T={} years".format(t_years), color="red") plt.legend(loc="best") errors = T_exact(z, t) - x max_error = np.max(np.fabs(errors)) avg_error = np.average(np.fabs(errors)) return max_error, avg_error