-
Notifications
You must be signed in to change notification settings - Fork 13
Geometry tutorial and remove clickable stripe between images on the website #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DiegoDeGusem
wants to merge
10
commits into
dev
Choose a base branch
from
geometry-tutorial
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5cb21b9
Add geometry tutorial
DiegoDeGusem e6be2e9
Add tutorial to website
DiegoDeGusem a387f2b
Remove weird stripe in regions tutorial
DiegoDeGusem 9152ab4
Change the order and make shapes clickable
DiegoDeGusem 6f44eb9
Remove clickable stripe in plot_field
DiegoDeGusem 8053a8b
Remove markdown leftover
DiegoDeGusem db9b363
Make 2D
DiegoDeGusem a2f4d2e
Clear output of geometry tutorial notebook
ilateur e3a5edb
Don't set magnetization
ilateur 6f8dec5
Set geometry in actual center of the magnet
ilateur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| :nosearch: | ||
|
|
||
| Geometry | ||
| ======== | ||
|
|
||
| This tutorial will teach you how to set your geometry for your magnets. The ``geometry`` parameter can accept numpy arrays and functions. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| import numpy as np | ||
| from mumaxplus import Ferromagnet, Grid, World | ||
| import mumaxplus.util.shape as shape | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| We will first define the constants of our world and grid. The grid is comprised of 128 x 64 x 1 cells of each 1 x 1 x 1 nm³. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| nx, ny, nz = 128, 64, 1 | ||
| cx, cy, cz = 1e-9, 1e-9, 1e-9 | ||
| center = cx*(nx-1)/2, cy*(ny-1)/2, cz*(nz-1)/2 | ||
|
|
||
| Now we create a function to visualise the geometry. In the final images empty space will be shown as white while the magnetic material will be gray. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| def show_2D_geom(magnet): | ||
| geom = magnet.geometry[0,...] | ||
| im_extent = (-0.5*cx * 1e9, (nx*cx - 0.5*cx) * 1e9, -0.5*cy * 1e9, (ny*cy - 0.5*cy) * 1e9) | ||
| plt.imshow(geom, cmap="Greys", origin="lower", extent=im_extent, vmin=0, vmax=2) | ||
| plt.xlabel("x (nm)") | ||
| plt.ylabel("y (nm)") | ||
| plt.show() | ||
|
|
||
| 1. Numpy arrays | ||
| --------------- | ||
| Here we will be looking at setting the geometry with a numpy array. The array should have the same dimensions as our grid and should contain booleans. | ||
|
|
||
| 1.1 The full grid | ||
| ^^^^^^^^^^^^^^^^^ | ||
| If we want our magnet to be the entire grid we do not have to specify a geometry. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| world = World(cellsize=(cx, cy, cz)) | ||
| grid = Grid((nx, ny, nz)) | ||
|
JonathanMaes marked this conversation as resolved.
|
||
|
|
||
| magnet = Ferromagnet(world=world, grid=grid) | ||
|
|
||
| show_2D_geom(magnet) | ||
|
|
||
| .. image:: ../images/magnet_full.png | ||
| :align: center | ||
| :width: 600px | ||
|
|
||
| 1.2 Eliminating pixels | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| If we want to remove some pixels from the magnet we can create an array as big as our grid and set some values to 0 (or ``False``). Note that the array should have a shape of (nz, ny, nx). | ||
| Let's now remove a row of cells at the center of the magnet. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| world = World(cellsize=(cx, cy, cz)) | ||
| grid = Grid((nx, ny, nz)) | ||
|
|
||
| geom_array = np.ones(shape=(nz,ny,nx)) | ||
| geom_array[:,ny//2,:] = np.zeros(shape=(nz,nx)) | ||
|
|
||
| magnet = Ferromagnet(world=world, grid=grid, geometry=geom_array) | ||
|
|
||
| show_2D_geom(magnet) | ||
|
|
||
| .. image:: ../images/magnet_remove_line.png | ||
| :align: center | ||
| :width: 600px | ||
|
|
||
| 2. Functions | ||
| ------------ | ||
| We can also create our own functions to form geometries. The input of every function should be (x,y,z) where x, y and z are real space coordinates. The output of the function should be a boolean. | ||
|
|
||
| 2.1 Circle | ||
| ^^^^^^^^^^ | ||
| Here we create a circle with a radius of 20nm at the center of the grid. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| world = World(cellsize=(cx, cy, cz)) | ||
| grid = Grid((nx, ny, nz)) | ||
|
|
||
| geomfunc = lambda x, y, z: (x - center[0])**2 + (y - center[1])**2 < (20e-9)**2 | ||
|
|
||
| magnet = Ferromagnet(world=world, grid=grid, geometry=geomfunc) | ||
|
|
||
| show_2D_geom(magnet) | ||
|
|
||
| .. image:: ../images/magnet_cylinder.png | ||
| :align: center | ||
| :width: 600px | ||
|
|
||
| 2.2 Sawtooth | ||
| ^^^^^^^^^^^^ | ||
| Here we will cut a sawtooth pattern out of a magnet. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| world = World(cellsize=(cx, cy, cz)) | ||
| grid = Grid((nx, ny, nz)) | ||
|
|
||
| p = 25e-9 | ||
| a = 20e-9 | ||
|
|
||
| def saw(x,y,z): | ||
| func = a*(x/p - np.floor(0.5 + x/p)) + a/2-cy | ||
| return y > func | ||
|
|
||
| magnet = Ferromagnet(world=world, grid=grid, geometry=saw) | ||
|
|
||
| show_2D_geom(magnet) | ||
|
|
||
| .. image:: ../images/magnet_sawtooth.png | ||
| :align: center | ||
| :width: 600px | ||
|
|
||
| 3. Shapes | ||
| --------- | ||
| Let's end this tutoial by using the ``Shape`` class to generate a geometry. For more information on different shapes and shape manipulations see :doc:`Shapes <shapes>`. | ||
|
|
||
| 3.1 Sphere | ||
| ^^^^^^^^^^ | ||
| Here we create a spherical magnet with a diameter of 60nm. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| world = World(cellsize=(cx, cy, cz)) | ||
| grid = Grid((nx, ny, nz)) | ||
|
|
||
| circ = shape.Sphere(diam=20e-9) | ||
| circ.translate(*center) | ||
| magnet = Ferromagnet(world=world, grid=grid, geometry=circ) | ||
|
|
||
| show_2D_geom(magnet) | ||
|
|
||
| .. image:: ../images/magnet_sphere.png | ||
| :align: center | ||
| :width: 600px | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.