<jupyter_start><jupyter_text>Spatially varying parameters ObjectivesThe main objective of this tutorial is to demonstrate how spatially varying parameters can be used to model and simulate different geometries and/or materials using JOOMMF. Problem specificationThe geometry is a **cylinder** with- radius $r = 50 \,\text{nm}$ and- height $h = 100 \,\text{nm}$.The material parameters (similar to permalloy) are:- exchange energy constant $A = 1.3 \times 10^{-11} \,\text{J/m}$,- magnetisation saturation $M_\text{s} = 8 \times 10^{5} \,\text{A/m}$.Magnetisation dynamics are governed by the Landau-Lifshitz-Gilbert equation$$\frac{d\mathbf{m}}{dt} = \underbrace{-\gamma_{0}(\mathbf{m} \times \mathbf{H}_\text{eff})}_\text{precession} + \underbrace{\alpha\left(\mathbf{m} \times \frac{d\mathbf{m}}{dt}\right)}_\text{damping}$$where $\gamma_{0} = 2.211 \times 10^{5} \,\text{m}\,\text{A}^{-1}\,\text{s}^{-1}$ and Gilbert damping $\alpha=0.5$.We are interested in computing the equlibrium magnetisation state starting from the uniform magnetisation in the $(1, 1, 1)$ direction. SimulationIn the first step, we import the required `discretisedfield` and `oommfc` modules.<jupyter_code>import oommfc as oc
import discretisedfield as df<jupyter_output><empty_output><jupyter_text>We need to define the rectangular finite difference mesh that can contain the entire sphere.<jupyter_code>L = 100e-9  # mesh edge length (m)
d = 5e-9  # discretisation cell (m)
mesh = oc.Mesh(p1=(0, 0, 0), p2=(L, L, L), cell=(d, d, d))<jupyter_output><empty_output><jupyter_text>To illustrate the mesh and discretisation cell:<jupyter_code>%matplotlib inline
mesh<jupyter_output><empty_output><jupyter_text>As usual, we create the system object and define its Hamiltonian and dynamics equation.<jupyter_code>#System object
system = oc.System(name="cylinder")

# Hamiltonian
A = 1.3e-11  # exchange energy constant (J/m)
H = (0, 0, 0.2e-3/oc.mu0)  # external magnetic field (A/m)
system.hamiltonian = oc.Exchange(A) + oc.Demag() + oc.Zeeman(H)

# Dynamics
gamma = 2.211e5
alpha = 0.5
system.dynamics = oc.Precession(gamma) + oc.Damping(alpha)<jupyter_output><empty_output><jupyter_text>The Hamiltonian and dynamics equation are:<jupyter_code>system.hamiltonian
system.dynamics<jupyter_output><empty_output><jupyter_text>Defining cylinder geometryIn order to define cylinder geometry inside the rectangular mesh, we can define the saturation magnetisation function (we name it `Ms_function`), which depending on the position inside mesh $pos = (x, y, z)$ returns $M_\text{s}$ if the point is inside the culinder and $0$ otherwise:$$M_\text{s} =  \begin{cases}    8 \times 10^{5}, & \sqrt{x^{2} + y^{2}} \leq 50\,\text{nm} \\    0, & \sqrt{x^{2} + y^{2}} > 50\,\text{nm}. \\  \end{cases}$$<jupyter_code>import math

def Ms_function(pos):
    x, y, z = pos
    r = math.sqrt((x-L/2)**2 + (y-L/2)**2)
    if r <= 50e-9:
        return 8e5
    else:
        return 0<jupyter_output><empty_output><jupyter_text>Having the function defining the sphere geometry, we can now create the initial magnetisation field. The value of field should be the inital magnetisation $(1, 1, 1)$ and the norm should be the saturation magnetisation function we just created.<jupyter_code>system.m = df.Field(mesh, value=(1, 1, 1), norm=Ms_function)<jupyter_output><empty_output><jupyter_text>We can plot the initial magnetisation by slicing the cylinder geometry perpendicular to "z" and "x" axes.<jupyter_code>system.m.plot_plane("z")
system.m.plot_plane("x")<jupyter_output><empty_output><jupyter_text>Relaxing the magnetisationAfter we defined all requited parameters of the system, we can relax the system using `MinDriver`.<jupyter_code>td = oc.MinDriver()
td.drive(system)<jupyter_output>2018/6/26 11:53: Calling OOMMF (cylinder/cylinder.mif) ... [1.9s]<jupyter_text>And plot the magnetisation in the same slices as before.<jupyter_code>system.m.plot_plane("z")
system.m.plot_plane("x")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1351963746223565, 'fraction_numerical': 0.0256797583081571, 'mean_word_length': 5.523809523809524, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '469808', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1302, 'n_words': 387, 'path': 'docs/ipynb/spatially_varying_parameters.ipynb', 'repo_name': 'gamdow/oommfc', 'size': '3972'}