{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mesh boundary conditions\n", "\n", "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:\n", "\n", "1. open BC (`bc=''`)\n", "2. periodic BC (`bc='x'`, `bc='xy'`, `bc='xyz'`, `bc='y'`,...)\n", "3. Neumann BC (`bc='neumann'`) - experimental\n", "4. Dirichlet BC (`bc='dirichlet'`) - experimental\n", "\n", "To demonstrate boundary conditions, we are going to use the following mesh:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import discretisedfield as df\n", "\n", "p1 = (0, 0, 0)\n", "p2 = (100e-9, 50e-9, 20e-9)\n", "n = (20, 10, 4)\n", "\n", "region = df.Region(p1=p1, p2=p2)\n", "mesh = df.Mesh(region=region, n=n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "By default, boudary conditions are open (empty string):" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "''" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.bc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(1, 2, 2), (3, 2, 2), (2, 1, 2), (2, 3, 2), (2, 2, 1), (2, 2, 3)]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.neighbours((2, 2, 2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On the other hand, if we ask for neighbours of a cell which is at the corner of the sample:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(1, 0, 0), (0, 1, 0), (0, 0, 1)]" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.neighbours((0, 0, 0))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "we get only three neighbouring cell indices.\n", "\n", "## Periodic boundary conditions\n", "\n", "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'`." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "mesh = df.Mesh(region=region, n=n, bc=\"xy\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(1, 2, 2), (3, 2, 2), (2, 1, 2), (2, 3, 2), (2, 2, 1), (2, 2, 3)]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.neighbours((2, 2, 2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However, if we now ask for neighbours of a corner cell:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(19, 0, 0), (1, 0, 0), (0, 19, 0), (0, 1, 0), (0, 0, 1)]" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.neighbours((0, 0, 0))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "we get 5 neighbouring cells:\n", "\n", "- 2 in the x-direction `(19, 0, 0)` and `(1, 0, 0)`,\n", "- 2 in the y-direction `(0, 19, 0)` and `(0, 1, 0)`, and\n", "- 1 in the z-direction `(0, 0, 1)`,\n", "\n", "because our mesh is not periodic in the z-direction.\n", "\n", "## Experimental: Neumann and Dirichet boundary conditions\n", "\n", "Neumann and Dirichlet BC are defined by passing `bc='neumann'` or `bc='dirichet'`, respectively.\n", "\n", "**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`.\n", "\n", "Here we just include an example of defining Neumann BC:\n", "\n", "$$\\frac{df}{d\\mathbf{n}} = 0$$" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Mesh\n", "