jInv.VisThis tutorial explores the plotting functionalities of jInv. We provide minimal examples for each viewer and explain the inputs and outputs. This document can also be used as a starting point to implement new viewers.
The general philosophy of our viewers is that we use a Cartesian coordinate system that is described by a mesh from jInv.Mesh. We aim at providing a consistent visualization across different mesh types. There are different types of objects that we commonly want to visualize:
jInv.Requirements: : Our visualization package is based on PyPlot.jl which must be installed.
In [1]:
using PyPlot
using jInv.Mesh
using jInvVis
In [2]:
domain = [-1 1.5 0 3]
n = [12,23]
M = getRegularMesh(domain,n)
xc = getCellCenteredGrid(M)
subplot(2,2,1)
viewImage2D(xc[:,1],M,vmin=-1,vmax=3)
xlabel("x")
ylabel("y")
title("viewImage2D - f(x,y) = x")
subplot(2,2,2)
viewImage2D(xc[:,2],M,vmin=-1,vmax=3)
colorbar()
title("viewImage2D - f(x,y) = y")
xlabel("x")
ylabel("y")
Out[2]:
In [9]:
domain = [0 1 0 1]
n = [13 15]
M = getRegularMesh(domain,n)
xc = getNodalGrid(M)
yc = [xc[:,1].^3-xc[:,2] xc[:,2]+xc[:,1]-1]
subplot(1,2,1)
plotGrid(M)
title("plotGrid - regular mesh")
xlabel("x"); ylabel("y")
subplot(1,2,2)
plotGrid(yc,M,color="r",linewidth=3)
title("plotGrid - deformed mesh")
xlabel("x");
In [4]:
domain = [0 1 0 1 0 1]
n = [4 6 8]
f(XYZ) = XYZ[:,1].*XYZ[:,2].*XYZ[:,3]
# construct a regular mesh on domain and discretize function
Mreg = getRegularMesh(domain,n)
xr = getCellCenteredGrid(Mreg)
fr = f(xr)
# get a tensor mesh with random cell sizes on the same domain
x0 = Mreg.x0;
h1 = rand(n[1]); h1 = (domain[2]-domain[1])*h1./sum(h1)
h2 = rand(n[2]); h2 = (domain[4]-domain[3])*h2./sum(h2)
h3 = rand(n[3]); h3 = (domain[6]-domain[5])*h3./sum(h3)
Mten = getTensorMesh3D(h1,h2,h3,x0)
xt = getCellCenteredGrid(Mten)
ft = f(xt)
subplot(1,2,1)
viewOrthoSlices2D(fr,Mreg,axis=true,cmap="gray",vmin=0,vmax=.5*maximum(fr))
title("viewOrthoSlice2D - regular mesh")
subplot(1,2,2)
viewOrthoSlices2D(ft,Mten,axis=true)
title("viewOrthoSlice2D - tensor mesh")
Out[4]:
In [5]:
subplot(1,3,1)
viewSlice2D(fr,Mreg,round(Int,Mreg.n[3]/2),cmap="gray",addLabel=true,vmin=0,vmax=.5*maximum(fr))
title("viewSlice2D - view=:xy")
subplot(1,3,2)
viewSlice2D(fr,Mreg,round(Int,Mreg.n[2]/2),view=:xz,addLabel=true,cmap="gray",vmin=0,vmax=.5*maximum(fr))
title("viewSlice2D - view=:xz")
subplot(1,3,3)
viewSlice2D(fr,Mreg,round(Int,Mreg.n[1]/2),view=:yz,addLabel=true,cmap="gray",vmin=0,vmax=.5*maximum(fr))
title("viewSlice2D - view=:yz")
Out[5]:
In [6]:
plotGrid(Mreg,spacing=[2,2,2])
title("plotGrid - regular mesh")
Out[6]:
In [7]:
xc = getNodalGrid(Mreg)
yn = [xc[:,1].^3-xc[:,2] xc[:,2]+xc[:,1]-1 xc[:,3]]
plotGrid(yn,Mreg)
title("plotGrid - deformed regular mesh")
Out[7]:
In [8]:
plotGrid(Mten,color="r")
title("plotGrid - tensor mesh")
Out[8]:
In [ ]: