33import numpy as np
44
55
6- def skyrmion_number_centre_slice (sim ):
6+ def skyrmion_number_slice (sim , at = None , zIndex = None ):
77 """
8- Returns the skyrmion number calculated on the x-y plane at the central z
8+ Returns the skyrmion number calculated on the x-y plane at a specific z
99 co-ordinate.
1010
1111 The current fidimag skyrmion number function finds the skyrmion number for
@@ -16,24 +16,54 @@ def skyrmion_number_centre_slice(sim):
1616 Arguments:
1717 sim: LLG object with cuboidal mesh.
1818
19+ Optional Arguments:
20+ If neither of these arguments are specified, this function raises a
21+ ValueError.
22+
23+ at: None, "top", "centre", or "bottom" denoting where to slice in
24+ British English. https://en.wikipedia.org/wiki/Strike_It_Lucky
25+ zIndex: Integer (not a float), or None denoting the index at which to
26+ slice. Overrides "at" if not None. Bound by zIndex~[0, sim.mesh.nz-1]
27+
1928 Returns:
2029 skyrmionNumber (a float)
2130 """
2231
32+ # Deal with inputs.
33+ if zIndex is None :
34+ if at is "bottom" :
35+ zIndex = 0
36+
37+ elif at is "centre" :
38+ # Find the layer number that corresponds to the centre of the mesh,
39+ # preferring the lower layer in a tie.
40+ zIndex = sim .mesh .nz / 2.
41+ if sim .mesh .nz % 2 == 0 :
42+ zIndex -= 0.5
43+ zIndex -= 0.5
44+
45+ elif at is "top" :
46+ zIndex = sim .mesh .nz - 1 # Indeces start at 0.
47+
48+ else :
49+ raise ValueError ("[skyrmion_number_slice]: Either "
50+ "'at=bottom|centre|top' or 'zIndex'=[integer] "
51+ "must be passed as arguments." )
52+
53+ elif zIndex > sim .mesh .nz - 1 or zIndex < 0 :
54+ raise ValueError ("[skyrmion_number_slice]: 'zIndex={}' must be an "
55+ "integer between 0 and sim.mesh.nz - 1, which is "
56+ "'{}' for this simulation object."
57+ .format (zIndex , sim .mesh .nz - 1 ))
58+
2359 # Find the "length" of a slice in terms of the spin array.
2460 xyLength = sim .mesh .nx * sim .mesh .ny * 3 # The 3 represents (x,y,z).
2561
26- # Find the layer number that corresponds to the centre of the mesh,
27- # preferring the lower layer in a tie.
28- zCentre = sim .mesh .nz / 2.
29- if sim .mesh .nz % 2 == 0 :
30- zCentre -= 0.5
31- zCentre -= 0.5
32-
33- # Obtain slice of spins cleverly. This also works if the domain is flat.
34- spinSlice = sim .spin [int (xyLength * zCentre ):int (xyLength * (zCentre + 1 ))]
62+ # Obtain slice of spins cleverly. This also works if the domain is flat
63+ # (i.e. nz=1, zIndex=0)
64+ spinSlice = sim .spin [int (xyLength * zIndex ):int (xyLength * (zIndex + 1 ))]
3565
36- # Compute the skyrmion number for our spin slice instead .
66+ # Compute the skyrmion number for our spin slice.
3767 if sim ._micromagnetic is True :
3868 return fidimag .extensions .micro_clib .compute_skyrmion_number (\
3969 spinSlice , sim ._skx_number , sim .mesh .nx , sim .mesh .ny ,
0 commit comments