Skip to content
Snippets Groups Projects
Commit 0a919ffe authored by Daniel Brown's avatar Daniel Brown
Browse files

updating to work with py3

parent e49f8ff5
Branches
Tags
No related merge requests found
...@@ -216,15 +216,21 @@ def __gen_riemann_knm_cache(x, y, couplings, q1, q2, q1y=None, q2y=None, delta=( ...@@ -216,15 +216,21 @@ def __gen_riemann_knm_cache(x, y, couplings, q1, q2, q1y=None, q2y=None, delta=(
if q2y is None: if q2y is None:
q2y = q2 q2y = q2
it = np.nditer(couplings, flags=['refs_ok','f_index']) #it = np.nditer(couplings, flags=['refs_ok','f_index'])
cache = {} cache = {}
while not it.finished: #while not it.finished:
try: # try:
mode_in = [int(it.next()), int(it.next())] # mode_in = [int(it.next()), int(it.next())]
mode_out = [int(it.next()), int(it.next())] # mode_out = [int(it.next()), int(it.next())]
couplings = couplings.copy()
couplings.resize(int(couplings.size/4), 4)
for _ in couplings:
mode_in = _[:2]
mode_out = _[2:]
strx = "u1[%i,%i]" % (mode_in[0], mode_out[0]) strx = "u1[%i,%i]" % (mode_in[0], mode_out[0])
stry = "u2[%i,%i]" % (mode_in[1], mode_out[1]) stry = "u2[%i,%i]" % (mode_in[1], mode_out[1])
...@@ -239,8 +245,8 @@ def __gen_riemann_knm_cache(x, y, couplings, q1, q2, q1y=None, q2y=None, delta=( ...@@ -239,8 +245,8 @@ def __gen_riemann_knm_cache(x, y, couplings, q1, q2, q1y=None, q2y=None, delta=(
cache[stry] = u_star_u(q1y.z, q2y.z, q1y.w0, q2y.w0, mode_in[1], mode_out[1], y, y+delta[1]) cache[stry] = u_star_u(q1y.z, q2y.z, q1y.w0, q2y.w0, mode_in[1], mode_out[1], y, y+delta[1])
#Hg_in.Um(y) * Hg_out.Um(y).conjugate() #Hg_in.Um(y) * Hg_out.Um(y).conjugate()
except StopIteration: # except StopIteration:
break # break
return cache return cache
...@@ -254,7 +260,7 @@ def __gen_ROM_HG_knm_cache(weights, couplings, q1, q2, q1y=None, q2y=None): ...@@ -254,7 +260,7 @@ def __gen_ROM_HG_knm_cache(weights, couplings, q1, q2, q1y=None, q2y=None):
if q2y is None: if q2y is None:
q2y = q2 q2y = q2
it = np.nditer(couplings, flags=['refs_ok','f_index'])
cache = {} cache = {}
...@@ -266,10 +272,12 @@ def __gen_ROM_HG_knm_cache(weights, couplings, q1, q2, q1y=None, q2y=None): ...@@ -266,10 +272,12 @@ def __gen_ROM_HG_knm_cache(weights, couplings, q1, q2, q1y=None, q2y=None):
cache["w_ij_Q3Q4"] = weights.w_ij_Q3 + weights.w_ij_Q4 cache["w_ij_Q3Q4"] = weights.w_ij_Q3 + weights.w_ij_Q4
cache["w_ij_Q1Q2Q3Q4"] = weights.w_ij_Q1 + weights.w_ij_Q3 + weights.w_ij_Q2 + weights.w_ij_Q4 cache["w_ij_Q1Q2Q3Q4"] = weights.w_ij_Q1 + weights.w_ij_Q3 + weights.w_ij_Q2 + weights.w_ij_Q4
while not it.finished: couplings = couplings.copy()
try: couplings.resize(int(couplings.size/4), 4)
mode_in = [int(it.next()), int(it.next())]
mode_out = [int(it.next()), int(it.next())] for _ in couplings:
mode_in = _[:2]
mode_out = _[2:]
strx = "x[%i,%i]" % (mode_in[0], mode_out[0]) strx = "x[%i,%i]" % (mode_in[0], mode_out[0])
stry = "y[%i,%i]" % (mode_in[1], mode_out[1]) stry = "y[%i,%i]" % (mode_in[1], mode_out[1])
...@@ -280,8 +288,23 @@ def __gen_ROM_HG_knm_cache(weights, couplings, q1, q2, q1y=None, q2y=None): ...@@ -280,8 +288,23 @@ def __gen_ROM_HG_knm_cache(weights, couplings, q1, q2, q1y=None, q2y=None):
if stry not in cache: if stry not in cache:
cache[stry] = u_star_u(q1y.z, q2y.z, q1y.w0, q2y.w0, mode_in[1], mode_out[1], weights.EI["ym"].nodes) cache[stry] = u_star_u(q1y.z, q2y.z, q1y.w0, q2y.w0, mode_in[1], mode_out[1], weights.EI["ym"].nodes)
except StopIteration: # it = np.nditer(couplings, flags=['refs_ok','f_index'])
break # while not it.finished:
# try:
# mode_in = [int(it.next()), int(it.next())]
# mode_out = [int(it.next()), int(it.next())]
#
# strx = "x[%i,%i]" % (mode_in[0], mode_out[0])
# stry = "y[%i,%i]" % (mode_in[1], mode_out[1])
#
# if strx not in cache:
# cache[strx] = u_star_u(q1.z, q2.z, q1.w0, q2.w0, mode_in[0], mode_out[0], weights.EI["xm"].nodes)
#
# if stry not in cache:
# cache[stry] = u_star_u(q1y.z, q2y.z, q1y.w0, q2y.w0, mode_in[1], mode_out[1], weights.EI["ym"].nodes)
#
# except StopIteration:
# break
return cache return cache
...@@ -543,7 +566,7 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema ...@@ -543,7 +566,7 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema
maxtem = 0 maxtem = 0
c = couplings.flatten() c = couplings.flatten()
for i in range(0, c.size/2): for i in range(0, int(c.size/2)):
maxtem = max(sum(c[i*2:(i*2+2)]), maxtem) maxtem = max(sum(c[i*2:(i*2+2)]), maxtem)
global __fac_cache global __fac_cache
...@@ -559,7 +582,7 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema ...@@ -559,7 +582,7 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema
K = np.zeros((couplings.size/4,), dtype=np.complex128) K = np.zeros((couplings.size/4,), dtype=np.complex128)
it = np.nditer(couplings, flags=['refs_ok','f_index']) #it = np.nditer(couplings, flags=['refs_ok','f_index'])
i = 0 i = 0
...@@ -593,13 +616,16 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema ...@@ -593,13 +616,16 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema
if verbose: if verbose:
p = ProgressBar(maxval=couplings.size, widgets=["Knm (%s): " % method, Percentage(), Bar(), ETA()]) p = ProgressBar(maxval=couplings.size, widgets=["Knm (%s): " % method, Percentage(), Bar(), ETA()])
while not it.finished: _couplings = couplings.copy()
try: _couplings.resize(int(_couplings.size/4), 4)
for _ in _couplings:
mode_in = _[:2]
mode_out = _[2:]
if profile: if profile:
t0 = time.time() t0 = time.time()
mode_in = [int(it.next()), int(it.next())]
mode_out = [int(it.next()), int(it.next())]
if method == "riemann": if method == "riemann":
...@@ -621,25 +647,18 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema ...@@ -621,25 +647,18 @@ def knmHG(couplings, q1, q2, surface_map=None, q1y=None, q2y=None, method="riema
if verbose: if verbose:
p.update(i*4) p.update(i*4)
except StopIteration:
break
if profile: if profile:
return K.reshape(couplings.shape[:-1]), Ktime.reshape(couplings.shape[:-1]), cache_time return K.reshape(couplings.shape[:-1]), Ktime.reshape(couplings.shape[:-1]), cache_time
else: else:
return K.reshape(couplings.shape[:-1]) return K.reshape(couplings.shape[:-1])
def plot_knm_matrix(couplings, knm, cmap=None, show=True):
def plot_knm_matrix(couplings, knm):
import pylab as plt import pylab as plt
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
cax = ax.imshow(knm, interpolation='nearest') cax = ax.pcolormesh(abs(knm), cmap=cmap)
fig.colorbar(cax) fig.colorbar(cax)
numrows, numcols = knm.shape numrows, numcols = knm.shape
...@@ -648,21 +667,31 @@ def plot_knm_matrix(couplings, knm): ...@@ -648,21 +667,31 @@ def plot_knm_matrix(couplings, knm):
c_ = [] c_ = []
for d in c: for d in c:
c_.append("%i,%i"%(d[0], d[1])) c_.append("[%i,%i]"%(d[0], d[1]))
A = np.arange(1, len(c)+1)-0.5
ax.set_xticks(A)
ax.set_yticks(A)
ax.set_xticklabels(c_) ax.set_xticklabels(c_)
ax.set_yticklabels(c_) ax.set_yticklabels(c_)
ax.set_xlim(None, max(A)+0.5)
ax.set_ylim(None, max(A)+0.5)
def format_coord(x, y): def format_coord(x, y):
col = int(x+0.5) col = int(np.floor(x))
row = int(y+0.5) row = int(np.floor(y))
if col>=0 and col<numcols and row>=0 and row<numrows: if col>=0 and col<numcols and row>=0 and row<numrows:
z = knm[row,col] z = knm[row,col]
return 'x=%s, y=%s, z=%1.4f' % (c_[col], c_[row], z) return 'x=%s, y=%s, z=%1.4f' % (c_[col], c_[row], z)
else:
return 'x=%1.4f, y=%1.4f'%(x, y) return None
ax.format_coord = format_coord ax.format_coord = format_coord
plt.show() fig.tight_layout()
if show: plt.show()
return fig
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment