Brendan Smithyman | January 2015
In [1]:
import numpy as np
import networkx
In [2]:
import matplotlib.pyplot as plt
import matplotlib.cm as cm
%matplotlib inline
import matplotlib
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png')
matplotlib.rcParams['savefig.dpi'] = 150 # Change this to adjust figure size
# Plotting options
font = {
'family': 'Bitstream Vera Sans',
'weight': 'normal',
'size': 8,
}
matplotlib.rc('font', **font)
In [3]:
cellSize = 1 # m
freqs = [1e2, 2e2, 3e2, 4e2] # Hz
density = 2700 # units of density
Q = np.inf # can be inf
nx = 164 # count
nz = 264 # count
freeSurf = [False, False, False, False] # t r b l
dims = (nx,nz) # tuple
nPML = 32
rho = np.fliplr(np.ones(dims) * density)
nfreq = len(freqs) # number of frequencies
nky = 48 # number of y-directional plane-wave components
nsp = nfreq * nky # total number of 2D subproblems
velocity = 2500 # m/s
vanom = 500 # m/s
cPert = np.zeros(dims)
cPert[(nx/2)-20:(nx/2)+20,(nz/2)-20:(nz/2)+20] = vanom
c = np.fliplr(np.ones(dims) * velocity)
cFlat = c
c += np.fliplr(cPert)
cTrue = c
srcs = np.array([np.ones(101)*32, np.zeros(101), np.linspace(32, 232, 101)]).T
recs = np.array([np.ones(101)*132, np.zeros(101), np.linspace(32, 232, 101)]).T
nsrc = len(srcs)
nrec = len(recs)
recmode = 'fixed'
geom = {
'src': srcs,
'rec': recs,
'mode': 'fixed',
}
cache = False
cacheDir = '.'
# Base configuration for all subproblems
systemConfig = {
'dx': cellSize, # m
'dz': cellSize, # m
'c': c.T, # m/s
'rho': rho.T, # density
'Q': Q, # can be inf
'nx': nx, # count
'nz': nz, # count
'freeSurf': freeSurf, # t r b l
'nPML': nPML,
'geom': geom,
'cache': cache,
'cacheDir': cacheDir,
'freqs': freqs,
'nky': nky,
}
In [4]:
class entryTracker(object):
def __init__(self):
self.entries = []
def __call__(self, entry):
self.entries.append(entry)
return len(self.entries) - 1
def __getitem__(self, slice):
return self.entries[slice]
In [6]:
def systemGraph(systemConfig):
G = networkx.DiGraph()
et = entryTracker()
basekey = et(systemConfig)
G.add_node(basekey)
for freq in systemConfig['freqs']:
freqkey = et({'freq': freq})
G.add_node(freqkey)
G.add_edge(freqkey, basekey)
for iky in xrange(systemConfig['nky']):
ikykey = et({'freq': freq, 'iky': iky})
G.add_node(ikykey)
G.add_edge(ikykey, freqkey)
return G, et
In [9]:
G, et = systemGraph(systemConfig)
networkx.draw_graphviz(G)
In [10]:
for item in networkx.topological_sort(G):
if 'freq' in et[item]:
if 'iky' in et[item]:
print('Freq: %(freq)f\t iky: %(iky)d'%et[item])
else:
print('Freq: %(freq)f'%et[item])
else:
print('Base')
In [11]:
node0 = G[0]
In [14]:
G.predecessors(0)
Out[14]:
In [10]:
# freqheads = G.predecessors(0)
# jobs = []
# for freqhead in freqheads:
# freq = et[freqhead]['freq']
# subprobs = G.predecessors(freqhead)
# nsp = len(subprobs)
# for subprob in subprobs:
# jobs[subprob] = lview.apply_async(dothingsfunction, et[0].copy().update(et[subprob]))