In Ubermag, boundary conditions are set by passing bc
argument to the mesh. The value of the bc
argument is a string. The following boudary conditions (BC) are allowed:
bc=''
)bc='x'
, bc='xy'
, bc='xyz'
, bc='y'
,...)bc='neumann'
) - experimentalbc='dirichlet'
) - experimentalTo demonstrate boundary conditions, we are going to use the following 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)
By default, boudary conditions are open (empty string):
mesh.bc
''
We can now ask the mesh for neigbouring cells. If we ask for the neighbours of a cell, which is not at the boundary, we expect to get 6 neighbouring cell indices.
mesh.neighbours((2, 2, 2))
[(1, 2, 2), (3, 2, 2), (2, 1, 2), (2, 3, 2), (2, 2, 1), (2, 2, 3)]
On the other hand, if we ask for neighbours of a cell which is at the corner of the sample:
mesh.neighbours((0, 0, 0))
[(1, 0, 0), (0, 1, 0), (0, 0, 1)]
we get only three neighbouring cell indices.
Now, let us define a mesh with periodic boundary conditions. The periodic boudary conditions are defined by passing a string to bc
. String consists of characters 'x'
, 'y'
, and/or 'z'
, depending on the directions in which the mesh is periodic. For instance, if our mesh is periodic in x and y directions, we pass bc='xy'
.
mesh = df.Mesh(region=region, n=n, bc="xy")
We can have a look at the neghbouring cells again. For a cell in the middle of the sample, there are 6 neighbours as expected:
mesh.neighbours((2, 2, 2))
[(1, 2, 2), (3, 2, 2), (2, 1, 2), (2, 3, 2), (2, 2, 1), (2, 2, 3)]
However, if we now ask for neighbours of a corner cell:
mesh.neighbours((0, 0, 0))
[(19, 0, 0), (1, 0, 0), (0, 19, 0), (0, 1, 0), (0, 0, 1)]
we get 5 neighbouring cells:
(19, 0, 0)
and (1, 0, 0)
,(0, 19, 0)
and (0, 1, 0)
, and(0, 0, 1)
,because our mesh is not periodic in the z-direction.
Neumann and Dirichlet BC are defined by passing bc='neumann'
or bc='dirichet'
, respectively.
IMPORTANT: At the moment, only Neumann BC with zero value are supported and defining BC in a more general way will be included in the future releases of discretisedfield
.
Here we just include an example of defining Neumann BC:
$$\frac{df}{d\mathbf{n}} = 0$$mesh = df.Mesh(region=region, n=n, bc="neumann")
mesh