{ "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'`,...) assuming that the names of geometric dimensions are `'x'`, `'y'`, and `'z'`\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": [ "## 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`. When the geometric dimensions are x, y, and z, the string can consist 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": 3, "metadata": {}, "outputs": [], "source": [ "mesh = df.Mesh(region=region, n=n, bc=\"xy\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 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": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Mesh\n", "" ], "text/plain": [ "Mesh(Region(pmin=[0.0, 0.0, 0.0], pmax=[1e-07, 5e-08, 2e-08], dims=['x', 'y', 'z'], units=['m', 'm', 'm']), n=[20, 10, 4], bc=neumann)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh = df.Mesh(region=region, n=n, bc=\"neumann\")\n", "mesh" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }