This tutorial explains how you can create new hole shapes using the very flexible PointLineHole and the even easier to use FunctionLineHole. There is an alternative way of creating new hole shapes through programming, but this is a lot more difficult.
In simple words, you can use the PointLineHole to draw any line you want, which will then become a hole. It is easy to define these lines using math or python functions. How to do this is explained below with more detail. As an example of a hole defined with a mathematical function, here is a hole built using the function sin(x)/x.
How does the PointLineHole work
The PointLineHole creates many circular holes that are at closely spaced points along a line. If the circular holes are spaces closely enough, this will give the impression of a continuous line with a certain thickness. If there are not enough circles or points, the shape will become irregular, and the scattering will be inconsistent, as illustrated by the below image. So, make sure that the holes are spaced closely enough. But if you generate too many points, the execution time of the simulation might increase because the phonon position has to be checked against more points.
The FunctionLineHole is just a wrapper for PointLineHole where you provide a mathematical function that is used to generate the holes.
How to use a mathematical function to define a hole
The FunctionLineHole uses a mathematical function to define the hole shape. Let's use sin(x)/x as an example. Here is how this is coded.
With the x and y arguments can be used to position the hole in the structure. It is an offset between the origin of the simulation's coordinate system and the function's coordinate system. So if both are set to 0 the function will simply be drawn in the structure's coordinate system.
The function_range argument defines from what x value to what x value the function is plotted. For sin(x)/x-2pi and 2pi are good spots. You can see this example above. For demonstration purposes here, I will use a range of -2pi and pi. Notice how with an asymmetric range the origin of the function and therefore the reference point for its position is not at it's center.
The simplest way of defining the function is using a lambda function. Lambda functions are easy to use: Just write lambda x: and put the expression to be evaluated behind this. It is also possible to simply define a regular function, which we will come back to.
You can use size_x and size_y to define the size of the resulting structure. This will take into account the thickness of the hole so that the total hole size corresponds to what was put in. We will also come back to this.
The resolution is the distance in x between two adjacent points or circles. Pay attention that this is only the distance in x direction, so if the function is steep, the actual distance between the points will be significantly larger than this.
With rotation the function is rotated around its origin by the number of degrees specified.
Addressing singularities
You probably noticed that sin(x)/x cannot be evaluated at x=0 because of the division by x. Since only some points of the function are evaluated, this can be fine, but it can cause errors and should be addressed. A simple way to do this is by defining a python function like this:
For more control over the sizing of the function, you can set size_x and/or size_y to None (or omit them) and instead set the scaling through the function. Here is an example where the x scaling is controlled through the function:
Consider that the hole will be bigger than the function because of its thickness.
How to use PointLineHole
As mentioned, FunctionLineHole is just a wrapper for PointLineHole. This means that we can implement our own function for generating the points. Here is a simple example where we simply provide two hard-coded points:
This hole is best used with a python function to generate the list of points. Even with very basic programming knowledge, this hole can be a very versatile and powerful tool. This will be demonstrated through some following examples. You can also have a look at how FunctionLineHole in the code as another example.
Example 1 - Straight lines
This example, demonstrates how you can draw straight lines using this hole:
The size of the line in x and y are defined through dx and dy, resolution is used to define the distance between points, x and y position the center of the line. thickness and rotation work as expected. Now multiple lines can be used to generate more complex structures like letters:
If the shape is too big, the hole can end up with an "island" in the middle. For the scattering behavior this is not a problem, but the thermal conductivity calculation considers the structure's volume so it is recommended to fill the middle in like this for example: