def compute_and_save_steady_states(n, v0=5): for k in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: if not os.path.isfile( 'C:/Users/Bill/Documents/Python/hemo/hemo/data/networks100/G_%i_%i.gpickle' % (n, k)): continue G = nx.read_gpickle( 'C:/Users/Bill/Documents/Python/hemo/hemo/data/networks100/G_%i_%i.gpickle' % (n, k)) sims.create_source(G) importlib.reload(system) def obj(y): return system.dydt(y, 1) y0 = np.zeros(2 * len(G.edges())) if k == 1: start = time.time() print('Solver output for n=%i, k=%i:' % (n, k)) y = scipy.optimize.newton_krylov(obj, y0, verbose=True) end = time.time() print('Solved in %.01f seconds' % (end - start)) else: y = scipy.optimize.newton_krylov(obj, y0, verbose=False) np.save( 'C:/Users/Bill/Documents/Python/hemo/hemo/data/networks100/steady_states_v0_%.0f/%i_%i' % (n, k, v0), y)
def solve_for_steady_state(G): start = time.time() sims.create_source(G) importlib.reload(system) def obj(y): return system.dydt(y, 1) y0 = np.zeros(2 * len(G.edges())) y = scipy.optimize.root(obj, y0, method='krylov') end = time.time() print('Solved in %.0f seconds.' % (end - start)) return y['x']
def run_sim(n, k=0, symmetric=False): if symmetric: G = nx.read_gpickle( 'C:/Users/Bill/Documents/Python/hemo/hemo/data/networks/G_%i_symm.gpickle' % n) else: G = nx.read_gpickle( 'C:/Users/Bill/Documents/Python/hemo/hemo/data/networks/G_%i_%i.gpickle' % (n, k)) sims.create_source(G) importlib.reload(system) times = np.linspace(0, 450, 450 + 1) y0 = np.zeros(2 * len(G.edges())) soln = scipy.integrate.odeint(system.dydt, y0, times) #wt = get_Wt(G, times, soln) return times, soln
def run_example_sim(n): G = create_network_multiple_sources_and_sinks(n) sims.create_source(G) importlib.reload(system) times = np.linspace(0, 3600, 3600 + 1) y0 = np.zeros(2 * len(G.edges())) soln = scipy.integrate.odeint(system.dydt, y0, times) wt = get_Wt(G, times, soln) plt.figure(1) plt.plot(times / 60, wt) plt.xlabel('time (min)') plt.ylabel('w(t)') plt.show() plt.figure(2) radii = [G[src][sink]['radius'] for src, sink in G.edges()] plt.hist(radii) plt.show()
def get_wt(G, y): wt = 0 n_edges = len(G.edges()) for src, sink in G.edges(): wt += 30 * G[src][sink]['volume'] * y[n_edges + G[src][sink]['idx']] return wt radius, steady_state = [], [] for k in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]: for n in [4, 5, 6, 7, 8, 9, 10]: G = nx.read_gpickle( 'C:/Users/Bill/Documents/Python/hemo/hemo/data/networks/G_%i_%i.gpickle' % (n, k)) sims.create_source(G) importlib.reload(system) def obj(y): return system.dydt(y, 1) y0 = np.zeros(2 * len(G.edges())) y = scipy.optimize.root(obj, y0, method='krylov') radius.append( np.mean( [10**4 * G[src][sink]['radius'] for src, sink in G.edges()])) steady_state.append(get_wt(G, y['x'])) for k in [0, 1, 2, 3]: n = 11 G = nx.read_gpickle(