Skip to content

Commit e3254a1

Browse files
Added and updtd examples for long particle
1 parent 48fff3f commit e3254a1

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

examples/neb_micromagnetic/elongated_particle/elongated_particle_along_z.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import print_function
21
import pytest
32

43
"""
@@ -46,7 +45,6 @@
4645
from fidimag.common import CuboidMesh
4746
from fidimag.micro import UniformExchange, UniaxialAnisotropy, Demag
4847
from fidimag.common.nebm_geodesic import NEBM_Geodesic
49-
from fidimag.common.nebm_cartesian import NEBM_Cartesian
5048
import numpy as np
5149

5250
# Material Parameters ---------------------------------------------------------
@@ -78,7 +76,7 @@ def relax_neb(sim, k, maxst, simname, initial_images, interpolations,
7876
'linear' or 'rotation' (Rodrigues formulae)
7977
"""
8078

81-
method_dict = {'Cartesian': NEBM_Cartesian, 'Geodesic': NEBM_Geodesic}
79+
method_dict = {'Geodesic': NEBM_Geodesic}
8280

8381
neb = method_dict[method](sim,
8482
initial_images,
@@ -139,7 +137,7 @@ def test_energy_barrier_cylinder():
139137
init_im = [(0, 0, -1), (0, 0.9, 0.1), (0, 0, 1)]
140138
interp = [8, 8]
141139

142-
for method in ['Geodesic', 'Cartesian']:
140+
for method in ['Geodesic']:
143141
relax_neb(elongated_part_sim(),
144142
1e4, 2000,
145143
'neb_cylinder_z-axis_{}'.format(method),
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# FIDIMAG:
2+
from fidimag.micro import Sim
3+
from fidimag.common import CuboidMesh
4+
from fidimag.micro import UniformExchange, UniaxialAnisotropy, Demag
5+
from fidimag.common.nebm_FS import NEBM_FS
6+
import numpy as np
7+
import logging
8+
import matplotlib.pyplot as plt
9+
10+
# Material Parameters ---------------------------------------------------------
11+
12+
A = 10e-12
13+
Kx = 3e5
14+
Ms = 3.98e5
15+
16+
# Mesh ------------------------------------------------------------------------
17+
18+
# Define an elongated cylinder along the y direction
19+
def cylinder(r, centre, radius):
20+
if (r[0] - centre[0]) ** 2. + (r[1] - centre[1]) ** 2 <= radius ** 2.:
21+
return Ms
22+
else:
23+
return 0
24+
25+
# Finite differences mesh
26+
mesh = CuboidMesh(nx=6, ny=6, nz=35,
27+
dx=2, dy=2, dz=2,
28+
unit_length=1e-9)
29+
30+
centre = (np.max(mesh.coordinates[:, 0]) * 0.5,
31+
np.max(mesh.coordinates[:, 1]) * 0.5)
32+
33+
34+
# Prepare simulation ----------------------------------------------------------
35+
36+
def elongated_part_sim():
37+
sim = Sim(mesh)
38+
sim.Ms = lambda r: cylinder(r, centre, 8)
39+
sim.add(UniformExchange(A=A))
40+
sim.add(UniaxialAnisotropy(Kx, axis=(0, 0, 1))) # Anisotropy along y
41+
sim.add(Demag())
42+
43+
return sim
44+
45+
46+
# -----------------------------------------------------------------------------
47+
48+
init_im = [(0, 0, -1), (0, 0.9, 0.1), (0, 0, 1)]
49+
interp = [10, 10]
50+
51+
sim = elongated_part_sim()
52+
nebm = NEBM_FS(sim, init_im, interpolations=interp, name='neb_cylinder_z-axis_FS',
53+
interpolation_method='rotation', spring_constant=1e5)
54+
55+
# dt = integrator.stepsize means after every integrator step, the images
56+
# are rescaled. We can run more integrator steps if we decrease the
57+
# stepsize, e.g. dt=1e-3 and integrator.stepsize=1e-4
58+
nebm.integrator.maxSteps = 10
59+
nebm.integrator.run_for(10,
60+
# save_vtks_every=save_every,
61+
# save_npys_every=save_every,
62+
)
63+
64+
bandEnergies = np.loadtxt('neb_cylinder_z-axis_FS_energy.ndt')[:, 1:]
65+
bandDistances = np.loadtxt('neb_cylinder_z-axis_FS_dYs.ndt')[:, 1:]
66+
67+
# Get the Matplotlib logger
68+
mpl_logger = logging.getLogger('matplotlib')
69+
# Set the logging level to 'WARNING' or higher
70+
mpl_logger.setLevel(logging.WARNING)
71+
pil_logger = logging.getLogger('PIL')
72+
pil_logger.setLevel(logging.WARNING)
73+
74+
f, ax = plt.subplots()
75+
print(bandDistances[1])
76+
dist = [1] + list(np.cumsum(bandDistances[1]))
77+
ax.plot(dist, bandEnergies[0], 'o--')
78+
79+
st = -1
80+
dist = [0] + list(np.cumsum(bandDistances[st]))
81+
ax.plot(dist, bandEnergies[st], 'o-')
82+
plt.show()
83+

0 commit comments

Comments
 (0)