Parameters for Vaccum

99 views
Skip to first unread message

RIYA MEHTA

unread,
Aug 12, 2026, 11:45:01 AMAug 12
to mumax2
Dear All,

I am trying to simulate two FM layers, separated by vacuum.
For vacuum, I allotted Msat and Aex as 0, but still can see spins in vacuum defined region.
May anyone please help with this.
Here is the code snippet and the muview image:

setgridsize(32, 32, 3)
setcellsize(1e-9, 1e-9, 1e-9)

// define two layers
defregion(1,zrange(0,1e-9))
defregion(2,zrange(1e-9,2e-9))
defregion(3,zrange(2e-9,3e-9))

Msat.SetRegion(1, 11e5)
Msat.SetRegion(2,0)
Msat.SetRegion(3, 11e5)

Aex.SetRegion(1, 13e-12)
Aex.SetRegion(2, 0)
Aex.SetRegion(3, 13e-12)
alpha = 0.1

m.setregion(1,uniform(1,0,0))
m.setregion(3,uniform(1,0,0))

OutputFormat = OVF2_TEXT
relax()         // high-energy states best minimized by relax()



Regards,
Riya
1.png

Josh Lauzier

unread,
Aug 13, 2026, 10:19:55 PMAug 13
to mumax2
Hi,

There are two things to be careful with. One, mumax centers (0,0,0) at the center of the simulation box. So your simulation is not 0-3nm, but -1.5e-9,1.5e-9. So something like:

defregion(1,zrange(-1.5e9,-0.5e-9))
defregion(2,zrange(-0.5e-9,0.5e-9))
defregion(3,zrange(0.5e-9,1.5e-9))

Sometimes one also needs to be a bit careful with rounding values, but in your specific case this should work.

Second, it is sufficient to set Msat and Aex to 0. For visualization purposes however, you will probably want to also set m to m=uniform(0,0,0) explicitly, and/or use the setgeom command. If you don't do this, it won't physically affect the simulation ( if a spin is defined as M_sat*m, then 0*(-1,0,0) is still (0,0,0) as far as the actual physics, even if m is (-1,0,0) ) but it will show nonzero spins when you plot m, which can be confusing.

Best,
Josh L.

RIYA MEHTA

unread,
Aug 18, 2026, 1:03:54 PMAug 18
to mumax2
Dear Josh,

Thank you very much for the help; it worked. Also, the Layer command worked for me.
I am a bit stuck with the periodic boundary condition. I want to have periodicity in the x and y directions only, so I used the PBC. I am wondering: without PBC, I was getting hysteresis; as soon as I put this PBC command, the simulation finished in less than a minute, and I am getting just a straight line.
I am not sure what's wrong here. Please find the code snippet attached.

setgridsize(256, 64, 6)
setcellsize(1e-9, 1e-9, 1e-9)

SetPBC(4, 4, 0)

// define two layers
defregion(1,Layer(0))
defregion(2,Layer(1).Add(Layer(2)).Add(Layer(3)).Add(Layer(4)))
defregion(3,Layer(5))
save(regions)


Msat.SetRegion(1, 11e5)
Msat.SetRegion(2,0)
Msat.SetRegion(3, 11e5)

Aex.SetRegion(1, 13e-12)
Aex.SetRegion(2, 0)
Aex.SetRegion(3, 13e-12)


Looking forward to your help with this.

Thank You.
Regards,
Riya

Josh Lauzier

unread,
Aug 19, 2026, 1:53:51 AMAug 19
to mumax2
Hi,

The solvers can get stuck if your sample is exactly symmetric. For a finite sample, the edges will sometimes be enough to break some solvers out of being stuck (usually relax/run will work, minimize will still be stuck), but when you apply PBC, there is no longer any place for differences to nucleate. You can read more about it in previous discussions for more details.

This can be solved by breaking the symmetry (add a slight canting to the applied field, or a bit of noise to the magnetization, etc, will usually do it).

Cheers,
Josh L.

RIYA MEHTA

unread,
Aug 19, 2026, 4:07:08 AMAug 19
to mum...@googlegroups.com
Dear Josh,

Thank you for your reply. I tried including a bit canting in y direction:
Still simulation finished in seconds, not sure what is missing.
setgridsize(256, 64, 6)
setcellsize(1e-9, 1e-9, 1e-9)

SetPBC(4, 4, 0)
.
.
.
for B:=0.0; B<=Bmax; B+=Bstep{
    B_ext = vector(B, 0.01*B, 0)
    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

for B:=Bmax; B>=-Bmax; B-=Bstep{
    B_ext = vector(B, 0.01*B, 0)
    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

for B:=-Bmax; B<=Bmax; B+=Bstep{
    B_ext = vector(B, 0.01*B, 0)
    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

Looking forward to your assistance.
Regards,

--
You received this message because you are subscribed to a topic in the Google Groups "mumax2" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mumax2/MUQb2AqhDYo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mumax2+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mumax2/e72f479a-2473-45f1-b26d-1c817a06393en%40googlegroups.com.


Confidentiality Notice: This email and any attachments may contain confidential or privileged information. If you are not the intended recipient, please notify the sender by replying to this message, and then delete the email and any attachments permanently. Thank you.

RIYA MEHTA

unread,
Aug 20, 2026, 2:53:42 AMAug 20
to mumax2
Hii,

I also tried applying field at certain tilt like:
angleB:=0.005*pi/180
print(angleB)


for B:=0.0; B<=Bmax; B+=Bstep{
    B_ext = vector(B*cos(angleB), 0, B*sin(angleB))

    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

for B:=Bmax; B>=-Bmax; B-=Bstep{
    B_ext = vector(B*cos(angleB), 0, B*sin(angleB))

    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

for B:=-Bmax; B<=Bmax; B+=Bstep{
    B_ext = vector(B*cos(angleB), 0, B*sin(angleB))

    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

Still simulation finished in seconds, getting a straight line.
May someone please assist with this.

Regards


Антон Луценко

unread,
Aug 21, 2026, 6:31:14 AMAug 21
to mumax2
Hi, 

PBC constrains the simulation to be strictly periodic, creating a sort of "topological protection". 

One way to make more accurate hysteresis simulation is to add a small random field (acting as a thermal field) and run the simulation for a bit before each minimize(). This should help with nucleation. You can create or load the randomized field as a mask, so that you can add it to B_ext, run, and remove in the beginning of each iteration. 

Hope that helps ! 

RIYA MEHTA

unread,
Aug 21, 2026, 2:17:54 PMAug 21
to mumax2
Hello,

Thank you for the reply. 
In PBC, I have tried to add some thermal noise by giving a temperature (a little bit of canting in the applied field I already tried,  but could not resolve the issue). Hysteresis here is quite different from without PBC. I am not sure what is wrong with the code.  Could you please assist with this. Here is the code snippet:

setgridsize(256, 64, 6)
setcellsize(1e-9, 1e-9, 1e-9)


// define  layers
defregion(1,Layer(0))
defregion(2,Layer(1).Add(Layer(2)).Add(Layer(3)).Add(Layer(4)))
defregion(3,Layer(5))
save(regions)

SetPBC(1,2,0)


Msat.SetRegion(1, 11e5)
Msat.SetRegion(2,0)
Msat.SetRegion(3, 11e5)

Aex.SetRegion(1, 13e-12)
Aex.SetRegion(2, 0)
Aex.SetRegion(3, 13e-12)

alpha.SetRegion(1, 0.1)
alpha.SetRegion(2, 0)
alpha.SetRegion(3, 0.1)

Ku1.SetRegion(1, 0.5e4) 
Ku1.SetRegion(3, 0.66e4)

m.setregion(1,uniform(1,0,0))
m.setregion(2,uniform(0,0,0))
m.setregion(3,uniform(1,0,0))
OutputFormat = OVF2_TEXT
//m = randomMag()

relax()         // high-energy states best minimized by relax()

Bmax  := 0.05
Bstep :=  1.0e-3
MinimizerStop = 1e-9
TableAdd(B_ext)
Save(m)

Temp = 100

for B:=0.0; B<=Bmax; B+=Bstep{
    B_ext = vector(B, 0, 0)
    run(0.2e-12)
    relax()

    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

Temp = 100

for B:=Bmax; B>=-Bmax; B-=Bstep{
    B_ext = vector(B,  0, 0)
    run(0.2e-12)
    relax()

    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

Temp = 100

for B:=-Bmax; B<=Bmax; B+=Bstep{
    B_ext = vector(B, 0, 0)
    run(0.2e-12)
    relax()

    minimize()   // small changes best minimized by minimize()
    tablesave()
    Save(m)
}

Thankyou.
Regards,
Riya

without_PBC.png
with_PBC.png

Josh Lauzier

unread,
Aug 21, 2026, 5:09:51 PMAug 21
to mumax2
Hi,

Can you post the full script? It makes it much easier to diagnose

Cheers,
Josh L.

RIYA MEHTA

unread,
Aug 22, 2026, 12:10:44 AMAug 22
to mumax2
Dear Josh,

Please find attached the complete script, where I have applied thermal noise (by the temp command)  to break the symmetry. Without this thermal noise and PBC, I was getting proper hysteresis.

Looking forward to your assistance with this.
Thank You.
Regards,
Riya

thermal_noise.txt

Josh Lauzier

unread,
Aug 22, 2026, 1:21:17 AMAug 22
to mumax2
Hi,

In that script, one thing I notice missing is that you did not set the anisotropy axis for the anisotropies with anisU. Without that, those anisotropies are not actually doing anything. With no uniaxial anisotropy, and (very little, no edges) demag field, there isn't anything to cause hysteresis. The only thing left are exchange, and the external field. So I think your shape is not unexpected, for that configuration. It is flipping at 0 field, so it is not the solver getting stuck.

In general, the way to think about it is,  hysteresis is normally a competition between different effects, but you've gotten rid of the effects that would cause it to do anything other than just follow the applied field uniformly. The two effects you have are Zeeman with external field, and exhange: so the spins will just align perfectly with the applied field due to Zeeman, and exchange will want to keep it uniform. You can kind of think of it as if you had a single spin. Even with the anisotropy applied, you will probably get something very rectangular (or stair-like, in your case, since you have a soft/hard layer)- the anisotropy will shift where the spins flip, there will still be nothing causing the film to be non-uniform and gradually switch. Instead the layers will tend to switch all at once.

Best,
Josh L.
Reply all
Reply to author
Forward
0 new messages