In this tutorial we will go over creating a mesh, and the basics of numbering, counting, and naming conventions. With these skills you can move faster, and move between different meshes (hopefully) with ease!

We will go over the basics of using a *TensorMesh*, but these skills are transferable to the other meshes available in SimPEG. All of the mesh generation code is located in the *mesh* package in SimPEG (i.e. *SimPEG.mesh*). The following meshes are available for use:

```
'TensorMesh'
'Cyl1DMesh'
'LogicallyOrthogonalMesh'
'TreeMesh'
```

Each mesh code follows the guiding principles that are present in this tutorial, but the details, advantages and disadvantages differ between the implementations. Please read up on the documentation at http://simpeg.rtfd.org.

In [1]:

```
from SimPEG import *
print '\n'.join([m for m in dir(Mesh) if m[-4:] == 'Mesh' and 'Base' not in m])
```

To create a *TensorMesh* we need to create mesh tensors, the widths of each cell of the mesh in each dimension. We will call these tensors $h$, and these will be define the constant widths of cells in each dimension of the *TensorMesh*.

In [2]:

```
hx = np.r_[3,2,1,1,1,1,2,3]
hy = np.r_[3,1,1,3]
M = Mesh.TensorMesh([hx, hy])
M.plotGrid(centers=True)
```

In this simple mesh, the $h_x$ vector defines the widths of the cell in the $x$ dimension, and starts counting from the origin $(0,0)$. The resulting mesh is divided into cells, and the cell-centers are plotted above as red circles. Other terminology for this mesh are:

- cell-centers
- nodes
- faces
- edges

In [3]:

```
M.plotGrid(faces=True, nodes=True)
plt.title('Cell faces in the x- and y-directions.')
plt.legend(('Nodes', 'X-Faces', 'Y-Faces'))
```

Out[3]:

In [4]:

```
Mesh.TensorMesh([1,1,1]).plotGrid(faces=True, edges=True, centers=True)
```

When making variables that live in each of these locations, it is important to know how many of each variable type you are dealing with. SimPEG makes this pretty easy:

In [5]:

```
print M
```

In [6]:

```
count = {'numCells': M.nC,
'numCells_xDir': M.nCx,
'numCells_yDir': M.nCy,
'numCells_vector': M.vnC}
print 'This mesh has %(numCells)d cells, which is %(numCells_xDir)d*%(numCells_yDir)d!!' % count
print count
```

SimPEG also counts the nodes, faces, and edges.

```
Nodes: M.nN, M.nNx, M.nNy, M.nNz, M.vnN
Faces: M.nF, M.nFx, M.nFy, M.nFz, M.vnF, M.vnFx, M.vnFy, M.vnFz
Edges: M.nE, M.nEx, M.nEy, M.nEz, M.vnE, M.vnEx, M.vnEy, M.vnEz
```

Face and edge variables have different counts depending on the dimension of the direction that you are interested in. In a 4x5 mesh, for example, there is a 5x5 grid of x-faces, and a 4x6 grid of y-faces. You can count them below! As such, the vnF(x,y,z) and vnE(x,y,z) properties give the vector grid size.

In [7]:

```
Mesh.TensorMesh([4,5]).plotGrid(faces=True)
print Mesh.TensorMesh([4,5]).vnFx
print Mesh.TensorMesh([4,5]).vnFy
```

For tensor meshes, there are some additional functions that can come in handy. For example, creating mesh tensors can be a bit time consuming, these can be created speedily by just giving numbers and sizes of padding. See the example below, that follows this notation:

```
h1 = ( (numPad, sizeStart [, increaseFactor]), (numCore, sizeCode), (numPad, sizeStart [, increaseFactor]) )
```

In [9]:

```
h1 = (5, 10, 1.5), (20, 5), (3, 10)
M = Mesh.TensorMesh(Utils.meshTensors(h1, h1))
print M
M.plotGrid()
```