Mesh pad#

Rarely, we need to extend the mesh in certain direction by adding more discretisation cells (e.g. when we want to compute the demagnetisation field using FFT and need to extend our mesh).

The method for padding a mesh is pad. It takes pad_width argument which is a dictionary. The keys of the dictionary are the strings denoting the axes in which we want to pad the mesh. On the other hand, the values are length-2 tuples of integers, where the first element is the number of discretisation cells we want to add in the negative direction, and the second element is the number of discretisation cells in the positive direction.

To demonstrate padding, let us first define the mesh:

import discretisedfield as df

p1 = (0, 0, 0)
p2 = (100e-9, 50e-9, 20e-9)
n = (20, 10, 4)

region = df.Region(p1=p1, p2=p2)
mesh = df.Mesh(region=region, n=n)

The number of discretisation cells in all 3 directions is:

array([20, 10,  4])

and the size of the region is

array([1.e-07, 5.e-08, 2.e-08])

Now, let us say we want to pad our mesh by:

  • one cell in the positive x-direction,

  • two cells in the negative y-direction, and

  • one cell in both z-directions.

pad_width disctionary would be:

pad_width = {"x": (0, 1), "y": (2, 0), "z": (1, 1)}

We pass this dictionary to pad:

padded_mesh = mesh.pad(pad_width=pad_width)

This method returns us a new mesh, with added discretisation cells:

array([21, 12,  6])

We see that we added one cell in the x-direction, two in the y-direction, and two in the z-direction.

Accordingly, our mesh region is now larger:

array([1.05e-07, 6.00e-08, 3.00e-08])