Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jun 9, 2024
1 parent f305f0c commit 083ac07
Show file tree
Hide file tree
Showing 31 changed files with 611 additions and 459 deletions.
57 changes: 32 additions & 25 deletions demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
"%config InlineBackend.figure_formats = ['svg'] # output matplotlib plots as SVG\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"\n",
"pd.options.display.max_rows = 5\n",
"pd.options.display.float_format = '{:,.2e}'.format"
"pd.options.display.float_format = \"{:,.2e}\".format"
]
},
{
Expand Down Expand Up @@ -78,7 +79,7 @@
"gamma0 = mm.consts.gamma0 # gyromagnetic ratio (m/As)\n",
"alpha = 0.05 # Gilbert damping\n",
"\n",
"system = mm.System(name='vortex_dynamics')\n",
"system = mm.System(name=\"vortex_dynamics\")\n",
"\n",
"# Energy equation. We omit Zeeman energy term, because H=0.\n",
"system.energy = mm.Exchange(A=A) + mm.Demag()\n",
Expand All @@ -91,7 +92,7 @@
"def m_init(point):\n",
" x, y, _ = point\n",
" c = 1e9 # (1/m)\n",
" return (-c*y, c*x, 0.1)\n",
" return (-c * y, c * x, 0.1)\n",
"\n",
"\n",
"# Defining the geometry of the material as a circular disk\n",
Expand All @@ -104,10 +105,10 @@
"\n",
"\n",
"# Sample's centre is placed at origin\n",
"region = df.Region(p1=(-r, -r, -thickness/2), p2=(r, r, thickness/2))\n",
"region = df.Region(p1=(-r, -r, -thickness / 2), p2=(r, r, thickness / 2))\n",
"mesh = df.Mesh(region=region, cell=(5e-9, 5e-9, 10e-9))\n",
"\n",
"system.m = df.Field(mesh, nvdim=3, value=m_init, norm=Ms_func, valid='norm')"
"system.m = df.Field(mesh, nvdim=3, value=m_init, norm=Ms_func, valid=\"norm\")"
]
},
{
Expand Down Expand Up @@ -3984,7 +3985,7 @@
}
],
"source": [
"system.m.orientation.sel('z').mpl()"
"system.m.orientation.sel(\"z\").mpl()"
]
},
{
Expand Down Expand Up @@ -7973,7 +7974,7 @@
"md = oc.MinDriver()\n",
"md.drive(system)\n",
"\n",
"system.m.orientation.sel('z').mpl()"
"system.m.orientation.sel(\"z\").mpl()"
]
},
{
Expand Down Expand Up @@ -12054,7 +12055,7 @@
"system.energy += mm.Zeeman(H=H)\n",
"\n",
"md.drive(system)\n",
"system.m.orientation.sel('z').mpl()"
"system.m.orientation.sel(\"z\").mpl()"
]
},
{
Expand Down Expand Up @@ -16074,7 +16075,7 @@
}
],
"source": [
"system.m.orientation.sel('z').mpl()"
"system.m.orientation.sel(\"z\").mpl()"
]
},
{
Expand Down Expand Up @@ -16184,7 +16185,7 @@
}
],
"source": [
"system.table.data[['t', 'mx', 'my', 'mz', 'E']].head()"
"system.table.data[[\"t\", \"mx\", \"my\", \"mz\", \"E\"]].head()"
]
},
{
Expand Down Expand Up @@ -17843,7 +17844,7 @@
}
],
"source": [
"system.table.mpl(y=['mx', 'my', 'mz'])"
"system.table.mpl(y=[\"mx\", \"my\", \"mz\"])"
]
},
{
Expand Down Expand Up @@ -18612,7 +18613,9 @@
}
],
"source": [
"data[-1].hv(kdims=['x', 'y'], vdims=['x', 'y'], scalar_kw={'cmap': 'viridis', 'clim': (0, Ms)})"
"data[-1].hv(\n",
" kdims=[\"x\", \"y\"], vdims=[\"x\", \"y\"], scalar_kw={\"cmap\": \"viridis\", \"clim\": (0, Ms)}\n",
")"
]
},
{
Expand Down Expand Up @@ -18644,7 +18647,7 @@
"source": [
"import math\n",
"\n",
"m = system.m.orientation.sel('z')\n",
"m = system.m.orientation.sel(\"z\")\n",
"S = m.dot(m.diff(\"x\").cross(m.diff(\"y\"))).integrate() / (4 * math.pi)\n",
"S"
]
Expand Down Expand Up @@ -18681,7 +18684,7 @@
}
],
"source": [
"df.tools.topological_charge(system.m.sel('z'), method='berg-luescher')"
"df.tools.topological_charge(system.m.sel(\"z\"), method=\"berg-luescher\")"
]
},
{
Expand Down Expand Up @@ -18795,7 +18798,9 @@
}
],
"source": [
"data[-1].register_callback(lambda f: df.tools.topological_charge_density(f.sel('z'))).hv(kdims=['x', 'y'])"
"data[-1].register_callback(\n",
" lambda f: df.tools.topological_charge_density(f.sel(\"z\"))\n",
").hv(kdims=[\"x\", \"y\"])"
]
},
{
Expand Down Expand Up @@ -18833,9 +18838,9 @@
}
],
"source": [
"rho = df.tools.topological_charge_density(system.m.sel('z'))\n",
"r = system.m.sel('z').mesh.coordinate_field()\n",
"R = (r*rho).integrate()/rho.integrate()\n",
"rho = df.tools.topological_charge_density(system.m.sel(\"z\"))\n",
"r = system.m.sel(\"z\").mesh.coordinate_field()\n",
"R = (r * rho).integrate() / rho.integrate()\n",
"R"
]
},
Expand All @@ -18856,15 +18861,17 @@
" x_coords = []\n",
" y_coords = []\n",
"\n",
" r = drive[0].sel('z').mesh.coordinate_field()\n",
" \n",
" r = drive[0].sel(\"z\").mesh.coordinate_field()\n",
"\n",
" for m in drive:\n",
" tcd = df.tools.topological_charge_density(m.sel('z'))\n",
" centre_of_mass = (r*tcd).integrate()/tcd.integrate()\n",
" tcd = df.tools.topological_charge_density(m.sel(\"z\"))\n",
" centre_of_mass = (r * tcd).integrate() / tcd.integrate()\n",
" x_coords.append(centre_of_mass[0])\n",
" y_coords.append(centre_of_mass[1])\n",
"\n",
" return pd.DataFrame({'t': drive.table.data['t'], 'pos x': x_coords, 'pos y': y_coords})"
" return pd.DataFrame(\n",
" {\"t\": drive.table.data[\"t\"], \"pos x\": x_coords, \"pos y\": y_coords}\n",
" )"
]
},
{
Expand Down Expand Up @@ -23148,8 +23155,8 @@
],
"source": [
"fig, ax = plt.subplots()\n",
"data[-1][0].orientation.sel('z').mpl(ax=ax, scalar_kw={'clim': (0, 1)})\n",
"ax.plot(pos_pol_plus['pos x']*1e9, pos_pol_plus['pos y']*1e9, c='yellow')"
"data[-1][0].orientation.sel(\"z\").mpl(ax=ax, scalar_kw={\"clim\": (0, 1)})\n",
"ax.plot(pos_pol_plus[\"pos x\"] * 1e9, pos_pol_plus[\"pos y\"] * 1e9, c=\"yellow\")"
]
},
{
Expand Down
61 changes: 34 additions & 27 deletions examples/07-tutorial-standard-problem3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,27 @@
"source": [
"import numpy as np\n",
"\n",
"\n",
"# Function for initiaising the flower state.\n",
"def m_init_flower(pos):\n",
" x, y, z = pos[0]/1e-9, pos[1]/1e-9, pos[2]/1e-9\n",
" x, y, z = pos[0] / 1e-9, pos[1] / 1e-9, pos[2] / 1e-9\n",
" mx = 0\n",
" my = 2*z - 1\n",
" mz = -2*y + 1\n",
" my = 2 * z - 1\n",
" mz = -2 * y + 1\n",
" norm_squared = mx**2 + my**2 + mz**2\n",
" if norm_squared <= 0.05:\n",
" return (1, 0, 0)\n",
" else:\n",
" return (mx, my, mz)\n",
"\n",
"\n",
"# Function for initialising the vortex state.\n",
"def m_init_vortex(pos):\n",
" x, y, z = pos[0]/1e-9, pos[1]/1e-9, pos[2]/1e-9\n",
" x, y, z = pos[0] / 1e-9, pos[1] / 1e-9, pos[2] / 1e-9\n",
" mx = 0\n",
" my = np.sin(np.pi/2 * (x-0.5))\n",
" mz = np.cos(np.pi/2 * (x-0.5))\n",
" \n",
" my = np.sin(np.pi / 2 * (x - 0.5))\n",
" mz = np.cos(np.pi / 2 * (x - 0.5))\n",
"\n",
" return (mx, my, mz)"
]
},
Expand Down Expand Up @@ -104,28 +106,31 @@
" print(\"L={:7}, {} \".format(L, m_init.__name__), end=\"\")\n",
" N = 16 # discretisation in one dimension\n",
" cubesize = 100e-9 # cube edge length (m)\n",
" cellsize = cubesize/N # discretisation in all three dimensions.\n",
" lex = cubesize/L # exchange length.\n",
" \n",
" cellsize = cubesize / N # discretisation in all three dimensions.\n",
" lex = cubesize / L # exchange length.\n",
"\n",
" Km = 1e6 # magnetostatic energy density (J/m**3)\n",
" Ms = np.sqrt(2*Km/mm.consts.mu0) # magnetisation saturation (A/m)\n",
" Ms = np.sqrt(2 * Km / mm.consts.mu0) # magnetisation saturation (A/m)\n",
" A = 0.5 * mm.consts.mu0 * Ms**2 * lex**2 # exchange energy constant\n",
" K = 0.1*Km # Uniaxial anisotropy constant\n",
" K = 0.1 * Km # Uniaxial anisotropy constant\n",
" u = (0, 0, 1) # Uniaxial anisotropy easy-axis\n",
"\n",
" p1 = (0, 0, 0) # Minimum sample coordinate.\n",
" p2 = (cubesize, cubesize, cubesize) # Maximum sample coordinate.\n",
" cell = (cellsize, cellsize, cellsize) # Discretisation.\n",
" mesh = df.Mesh(p1=(0, 0, 0), p2=(cubesize, cubesize, cubesize),\n",
" cell=(cellsize, cellsize, cellsize)) # Create a mesh object.\n",
" mesh = df.Mesh(\n",
" p1=(0, 0, 0),\n",
" p2=(cubesize, cubesize, cubesize),\n",
" cell=(cellsize, cellsize, cellsize),\n",
" ) # Create a mesh object.\n",
"\n",
" system = mm.System(name='stdprob3')\n",
" system = mm.System(name=\"stdprob3\")\n",
" system.energy = mm.Exchange(A=A) + mm.UniaxialAnisotropy(K=K, u=u) + mm.Demag()\n",
" system.m = df.Field(mesh, nvdim=3, value=m_init, norm=Ms)\n",
"\n",
" md = oc.MinDriver()\n",
" md.drive(system, overwrite=True)\n",
" \n",
"\n",
" return system"
]
},
Expand Down Expand Up @@ -166,7 +171,7 @@
"source": [
"# NBVAL_IGNORE_OUTPUT\n",
"system = minimise_system_energy(8, m_init_vortex)\n",
"system.m.sel('y').mpl()"
"system.m.sel(\"y\").mpl()"
]
},
{
Expand Down Expand Up @@ -202,7 +207,7 @@
"source": [
"# NBVAL_IGNORE_OUTPUT\n",
"system = minimise_system_energy(8, m_init_flower)\n",
"system.m.sel('y').mpl()"
"system.m.sel(\"y\").mpl()"
]
},
{
Expand Down Expand Up @@ -253,15 +258,16 @@
"for L in L_array:\n",
" vortex = minimise_system_energy(L, m_init_vortex)\n",
" flower = minimise_system_energy(L, m_init_flower)\n",
" vortex_energies.append(vortex.table.data.tail(1)['E'][0])\n",
" flower_energies.append(flower.table.data.tail(1)['E'][0])\n",
" vortex_energies.append(vortex.table.data.tail(1)[\"E\"][0])\n",
" flower_energies.append(flower.table.data.tail(1)[\"E\"][0])\n",
"\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.figure(figsize=(8, 4))\n",
"plt.plot(L_array, vortex_energies, 'o-', label='vortex')\n",
"plt.plot(L_array, flower_energies, 'o-', label='flower')\n",
"plt.xlabel('L (lex)')\n",
"plt.ylabel('E (J)')\n",
"plt.plot(L_array, vortex_energies, \"o-\", label=\"vortex\")\n",
"plt.plot(L_array, flower_energies, \"o-\", label=\"flower\")\n",
"plt.xlabel(\"L (lex)\")\n",
"plt.ylabel(\"E (J)\")\n",
"plt.grid()\n",
"plt.legend();"
]
Expand Down Expand Up @@ -303,15 +309,16 @@
"# NBVAL_IGNORE_OUTPUT\n",
"from scipy.optimize import bisect\n",
"\n",
"\n",
"def energy_difference(L):\n",
" vortex = minimise_system_energy(L, m_init_vortex)\n",
" flower = minimise_system_energy(L, m_init_flower)\n",
" return (vortex.table.data.tail(1)['E'][0] -\n",
" flower.table.data.tail(1)['E'][0])\n",
" return vortex.table.data.tail(1)[\"E\"][0] - flower.table.data.tail(1)[\"E\"][0]\n",
"\n",
"\n",
"cross_section = bisect(energy_difference, 8.4, 8.6, xtol=0.02)\n",
"\n",
"print(f'\\nThe energy crossing occurs at {cross_section}*lex')"
"print(f\"\\nThe energy crossing occurs at {cross_section}*lex\")"
]
},
{
Expand Down
Loading

0 comments on commit 083ac07

Please sign in to comment.