In [ ]:
import numpy, matplotlib.pyplot as plt
%matplotlib inline
plt.xkcd();
In [ ]:
# Figure 1
def plot_grid(ni,nj,hi,hj,symmetric=True):
isc,jsc,iec,jec = 0.5,0.5,ni-.5,nj-.5
isd,jsd,ied,jed = isc-hi,jsc-hj,iec+hi,jec+hj
if symmetric:
IsdB,IedB,JsdB,JedB,IscB,IecB,JscB,JecB = isd-.5,ied+.5,jsd-.5,jed+.5,isc-.5,iec+.5,jsc-.5,jec+.5
else:
IsdB,IedB,JsdB,JedB,IscB,IecB,JscB,JecB = isd+.5,ied+.5,jsd+.5,jed+.5,isc+.5,iec+.5,jsc+.5,jec+.5
#XsdB,XedB,YsdB,YedB = isd-.5,ied+.5,jsd-.5,jed+.5
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax2 = ax1.twiny()
ax3 = ax1.twinx()
for ax in [ax1,ax2,ax3]:
ax.set_xlim(isd-1,ied+1)
ax.set_ylim(jsd-1,ied+1)
# Halos of data domain
#for x in numpy.arange(IsdB,IedB+1): ax1.plot([x,x],[JsdB,JedB],'k')
for x in numpy.arange(IsdB,IscB): ax1.plot([x,x],[jsd-.5,JedB],'b')
for x in numpy.arange(IecB+1,IedB+1): ax1.plot([x,x],[jsd-.5,JedB],'b')
for x in numpy.arange(IscB,IecB+1):
ax1.plot([x,x],[jsd-.5,jsc-.5],'b')
ax1.plot([x,x],[JecB,JedB],'b')
#for y in numpy.arange(JsdB,JedB+1): ax1.plot([IsdB,IedB],[y,y],'k')
for y in numpy.arange(JsdB,JscB): ax1.plot([isd-.5,IedB],[y,y],'b')
for y in numpy.arange(JecB+1,JedB+1): ax1.plot([isd-.5,IedB],[y,y],'b')
for y in numpy.arange(JscB,JecB+1):
ax1.plot([isd-.5,isc-.5],[y,y],'b')
ax1.plot([IecB,IedB],[y,y],'b')
# Computational domain
for x in numpy.arange(IscB,IecB+1): ax2.plot([x,x],[jsc-.5,jec+.5],'r')
for y in numpy.arange(JscB,JecB+1): ax2.plot([isc-.5,iec+.5],[y,y],'r')
for y in numpy.arange(jsd,jed+1):
for x in numpy.arange(isd,ied+1):
ax2.plot(x,y,'xb')
for y in numpy.arange(jsc,jec+1):
for x in numpy.arange(isc,iec+1):
ax2.plot(x,y,'xr')
for y in numpy.arange(JsdB,JedB+1):
for x in numpy.arange(IsdB,IedB+1):
ax2.plot(x,y,'ob')
for y in numpy.arange(JscB,JecB+1):
for x in numpy.arange(IscB,IecB+1):
ax2.plot(x,y,'or')
text_opts={'horizontalalignment':'center','verticalalignment':'center','backgroundcolor':'w'}
ax1.set_xticks([IsdB,IscB,IecB,IedB])
ax1.set_xticklabels(['IsdB','IscB','IecB','IedB'])
ax1.set_yticks([JsdB,JscB,JecB,JedB])
ax1.set_yticklabels(['JsdB','JscB','JecB','JedB'])
ax1.set_xlabel('q-/u-point I')
ax1.set_ylabel('q-/v-point J')
ax2.set_xticks([isd,isc,iec,ied])
ax2.set_xticklabels(['isd','isc','iec','ied'])
ax2.set_xlabel('h-/v-point i')
ax3.set_yticks([jsd,jsc,jec,jed])
ax3.set_yticklabels(['jsd','jsc','jec','jed'])
ax3.set_ylabel('h-/u-point j')
for ax in [ax1,ax2,ax3]:
ax.spines['bottom'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
plot_grid(5,5,2,2,symmetric=False)
plt.savefig('Horizontal_NE_indexing_nonsym.png',bbox_inches='tight')
In [ ]:
plot_grid(5,5,2,2)
plt.savefig('Horizontal_NE_indexing_sym.png',bbox_inches='tight')