ubermag / help

Repository for raising issues and requesting help on Ubermag
BSD 2-Clause "Simplified" License
11 stars 3 forks source link

When drawing with mpl(), the result is inconsistent with the preset function model #106

Closed code-whale closed 3 years ago

code-whale commented 3 years ago

Dear Ubermag Team, When I use mpl() for drawing, I find that the output norm is inconsistent with my definition, and the specific difference is shown in the figure below: image From the image, we can see that the lengths of the red and blue arrows are not consistent, but in the norm function I defined, the lengths of the two should be consistent. To confirm this, I open the generated OMF file with muview, and find that the length of the two files is the same in muview. Can you tell me the reason for the difference in the result of mpl() drawing? Is my code wrong? This is the result of opening the same OMF file in muview image I attach my code below:


mu0 = 4 * np.pi * 1e-7
A = 30e-12
Ms = 1.4e6
def ms2_fun(pos):
    x,y,z=pos
    if -75e-9<=x<=-25e-9 and -40e-9<y<-20e-9:
        return 0
    elif -75e-9<=x<=-25e-9 and 20e-9<y<40e-9:
        return 0
    elif -175e-9<=x<=-125e-9 and -40e-9<y<-20e-9:
        return 0
    elif -175e-9<=x<=-125e-9 and 20e-9<y<40e-9:
        return 0
    elif 25e-9<=x<=75e-9 and -40e-9<y<-20e-9:
        return 0
    elif 25e-9<=x<=75e-9 and 20e-9<y<40e-9:
        return 0
    elif 125e-9<=x<=175e-9 and -40e-9<y<-20e-9:
        return 0
    elif 125e-9<=x<=175e-9 and 20e-9<y<40e-9:
        return 0
    else:
        return Ms
Lx = 400e-9
Ly =120e-9
Lz = 4e-9
mesh = df.Mesh(p1=(-Lx /2, -Ly /2, -Lz /2), p2=(Lx /2, Ly /2, Lz / 2),cell=(1e-9, 1e-9, 4e-9),bc='x')

system = mm.System(name='different_DMIandK')

np.random.seed(42)
def init_random(pos):
    m = 2 * np.random.random((1, 3)) - 1
    return m
system.energy = mm.Exchange(A=A)
system.dynamics=mm.Precession(gamma0=2.211e5)+mm.Damping(alpha=0.3) 
system.m = df.Field(mesh,dim=3, value=(0,0,-1), norm=ms2_fun)
ad=oc.MinDriver()
ad.drive(system)
marijanbeg commented 3 years ago

Hi @code-whale, thank you for your question. I am not sure I understand correctly what is the issue you are reporting (and I am not a muview expert :/).

What I assume the problem could be is that you are initialising the magnetisation in (0, 0, -1) direction and have only exchange energy term. After relaxing, you get the same state. Then you cut a z-plane and plot. mpl tries to find an in-plane component of magnetisation (x and y components) and plot the arrows. This can be tricky for matplotlib because x and y components are "zero" and it could pick up numerical noise and amplify them.

We provide vector_scale argument you can pass to mpl function to adjust this. Please have a look at the attached file:

plotting-issue (1).pdf

If this does not answer your question, please feel free to reopen it.