%matplotlib inline
from matplotlib import pyplot as plt
from cavity_flow2d import cavity_flow2D
File "<ipython-input-4-17d64559292d>", line 1 %matplotlib inline ^ SyntaxError: invalid syntax
nx, ny = 128, 128
x = cavity_flow2D(nx, ny, 1, 1.0, 1.0)
Solved
Z = x[...].reshape(nx,ny,4)
fig, axs = plt.subplots(2,2, figsize=(10,8))
titles = ['u', 'v', 'vorticity', 'temperature']
for idx, ax in enumerate(axs.ravel()):
cs = ax.contourf(Z[:,:,idx], 100)
fig.colorbar(cs, ax=ax, shrink=0.9)
ax.set_title(titles[idx])
from petsc4py import PETSc
PETSc.Options().setValue('-snes_monitor', 'cavity.conv')
PETSc.Options().setValue('-snes_view', 'ascii:cavity.conv::append')
PETSc.Options().setValue('-pc_type', 'lu')
We can attach the debugger to the notebook kernel process:
gdb -p <proc id>
and use this to debug the PETSc process.
nx, ny = 32, 32
x = cavity_flow2D(nx, ny, 1, 1.0, 1.0)
with file('cavity.conv', 'r') as f:
print ''.join(f.readlines())
Solved 0 SNES Function norm 5.477314536447e+00 1 SNES Function norm 1.816293390980e-01 2 SNES Function norm 1.615679527132e-06 3 SNES Function norm 2.545415244619e-14 SNES Object: 1 MPI processes type: newtonls maximum iterations=50, maximum function evaluations=10000 tolerances: relative=1e-08, absolute=1e-50, solution=1e-08 total number of linear solver iterations=3 total number of function evaluations=4 SNESLineSearch Object: 1 MPI processes type: bt interpolation: cubic alpha=1.000000e-04 maxstep=1.000000e+08, minlambda=1.000000e-12 tolerances: relative=1.000000e-08, absolute=1.000000e-15, lambda=1.000000e-08 maximum iterations=40 KSP Object: 1 MPI processes type: gmres GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement GMRES: happy breakdown tolerance 1e-30 maximum iterations=10000, initial guess is zero tolerances: relative=1e-05, absolute=1e-50, divergence=10000 left preconditioning using PRECONDITIONED norm type for convergence test PC Object: 1 MPI processes type: lu LU: out-of-place factorization tolerance for zero pivot 2.22045e-14 matrix ordering: nd factor fill ratio given 5, needed 5.02244 Factored matrix follows: Mat Object: 1 MPI processes type: seqaij rows=4096, cols=4096, bs=4 package used to perform factorization: petsc total: nonzeros=401152, allocated nonzeros=401152 total number of mallocs used during MatSetValues calls =0 using I-node routines: found 1024 nodes, limit used is 5 linear system matrix = precond matrix: Mat Object: 1 MPI processes type: seqaij rows=4096, cols=4096, bs=4 total: nonzeros=79872, allocated nonzeros=79872 total number of mallocs used during MatSetValues calls =0 using I-node routines: found 1024 nodes, limit used is 5
Z = x[...].reshape(nx,ny,4)
fig, axs = plt.subplots(2,2, figsize=(10,8))
titles = ['u', 'v', 'vorticity', 'temperature']
for idx, ax in enumerate(axs.ravel()):
cs = ax.contourf(Z[:,:,idx], 100)
fig.colorbar(cs, ax=ax, shrink=0.9)
ax.set_title(titles[idx])
from IPython.parallel import Client
c = Client()
view = c[:]
%load_ext parallelmagic
view.activate()
view.block = True
%autopx
%autopx enabled
from cavity_flow2d import cavity_flow2D
nx, ny = 32, 32
x = cavity_flow2D(nx, ny, 1, 1.0, 1.0)
da = PETSc.DMDA().create([nx,ny],dof=4, stencil_width=1, stencil_type='star')
xn = da.createNaturalVec()
da.globalToNatural(x, xn)
from petsc4py import PETSc
sc, X = PETSc.Scatter.toZero(x)
sc.begin(xn, X, True, 'forward')
sc.end(xn, X, True, 'forward')
if not rank: Z = X[...].reshape(nx,ny,4)
else: Z = None
x.getLocalSize()
Out[0:17]: 1024
Out[1:17]: 1024
Out[2:17]: 1024
Out[3:17]: 1024
X.getLocalSize()
Out[0:18]: 0
Out[1:18]: 0
Out[2:18]: 0
Out[3:18]: 4096
rank = PETSc.COMM_WORLD.Get_rank()
%autopx
%autopx disabled
Z = view['Z'][view['rank'].index(0)]
fig, axs = plt.subplots(2,2, figsize=(10,8))
titles = ['u', 'v', 'vorticity', 'temperature']
for idx, ax in enumerate(axs.ravel()):
cs = ax.contourf(Z[:,:,idx], 100)
fig.colorbar(cs, ax=ax, shrink=0.9)
ax.set_title(titles[idx])