{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mesh subregions\n", "\n", "Often we need to define subregions in the mesh. For instance, this can be useful when we have two or more different materials in our mesh and it can make our life easier later when we start defining fields and assigning different parameters to different subregions.\n", "\n", "As before, the region of the mesh we are going to use as an example is:\n", "\n", "$$\\mathbf{p}_{1} = (0, 0, 0)$$\n", "$$\\mathbf{p}_{2} = (l_{x}, l_{y}, l_{z})$$\n", "\n", "with $l_{x} = 100 \\,\\text{nm}$, $l_{y} = 50 \\,\\text{nm}$, and $l_{z} = 20 \\,\\text{nm}$, and we discretise it with cell $(5\\,\\text{nm}, 5\\,\\text{nm}, 5\\,\\text{nm})$.\n", "\n", "Subregions in the mesh are defined by passing `subregions` attribute. It is a Python dictionary, whose keys are the names of subregions, whereas the values are the subregion objects. Names of subregions must be valid Python variable name strings (no spaces, no dashes, etc.) and the subregions are the region objects we introduced already.\n", "\n", "As an example, let us say we have two subregions of the same size, stacked on top of each other in the z-direction. More precisely, points `p1` and `p2` of two subregions would be:\n", "\n", "**Subregion 1:**\n", "\n", "$\\mathbf{p}_{1} = (0, 0, 0)$\n", "\n", "$\\mathbf{p}_{2} = (l_{x}, l_{y}, l_{z}/2)$\n", "\n", "**Subregion 2:**\n", "\n", "$\\mathbf{p}_{1} = (0, 0, l_{z}/2)$\n", "\n", "$\\mathbf{p}_{2} = (l_{x}, l_{y}, l_{z})$\n", "\n", "Let us name our subregions 1 and 2 to be \"bottom_subregion\" and \"top_subregion\". Accordingly, subregions dictionary is:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import discretisedfield as df\n", "\n", "lx, ly, lz = 100e-9, 50e-9, 20e-9\n", "\n", "subregions = {\n", " \"bottom_region\": df.Region(p1=(0, 0, 0), p2=(lx, ly, lz / 2)),\n", " \"top_region\": df.Region(p1=(0, 0, lz / 2), p2=(lx, ly, lz)),\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Having the subregions dictionary, we can now pass it to our mesh:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "cell = (5e-9, 5e-9, 5e-9)\n", "\n", "region = df.Region(p1=(0, 0, 0), p2=(lx, ly, lz))\n", "mesh = df.Mesh(region=region, cell=cell, subregions=subregions)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The mesh with two subregions is now defined. Please note that it is your responsibility that the subregions are well defined and \"make sense\". If they overlap or do not cover the entire mesh region, no errors or warnings will be raised. This gives a lot of freedom to users on how they can define the subregions, but also some responsibilities." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "Mesh\n", "