mumax / 3

GPU-accelerated micromagnetic simulator
Other
457 stars 151 forks source link

Combining saved magnetizations #160

Closed DeSanz closed 6 years ago

DeSanz commented 6 years ago

Hello,

I am looking for a way to set m to a combination of two saved magnetizations (e.g. the average between "m1.ovf" and "m2.ovf") but I do not find any ways to do it. Would anyone have any suggestions?

Thanks in advance,

Dedalo

JeroenMulkers commented 6 years ago

The script below illustrates that this can be done in the mumax3 scripting language (there might be an easier way). Personally, I prefer to do such things during preprocessing.

// run.mx3

nx := 16
ny := 16
nz := 1
setgridsize(nx,ny,nz)
setcellsize(1,1,1)

m = vortex(1,1)
save(m)
m = uniform(1,0,0)
save(m)
Flush()

m1 := loadfile("./run.out/m000000.ovf")
m2 := loadfile("./run.out/m000001.ovf")

iz:=0; iy:=0; ix:=0
for iz=0; iz<nz;iz++{
    for iy=0; iy<ny;iy++{
        for ix=0; ix<nx;ix++{
            m1x := m1.Get(0,ix,iy,iz)
            m1y := m1.Get(1,ix,iy,iz)
            m1z := m1.Get(2,ix,iy,iz)
            m2x := m2.Get(0,ix,iy,iz)
            m2y := m2.Get(1,ix,iy,iz)
            m2z := m2.Get(2,ix,iy,iz)
            mcell :=vector(m1x+m2x,m1y+m2y,m1z+m2z)
            m.SetCell(ix,iy,iz,mcell)
        }
    }
}
DeSanz commented 6 years ago

Thanks Jeroen for the suggestion, I'm sure it can be done faster but it does the trick.

(!) Edit for users who may be checking this in the future: To do this properly the magnetization vector needs to be kept normalized, otherwise the energy calculations get messed up.

The loop below keeps m normalized:

iz:=0; iy:=0; ix:=0
for iz=0; iz<nz;iz++{
    print("Progress: ",iz/nz*100)
    for iy=0; iy<ny;iy++{
        for ix=0; ix<nx;ix++{
            m1x := m1.Get(0,ix,iy,iz)
            m1y := m1.Get(1,ix,iy,iz)
            m1z := m1.Get(2,ix,iy,iz)
            m2x := m2.Get(0,ix,iy,iz)
            m2y := m2.Get(1,ix,iy,iz)
            m2z := m2.Get(2,ix,iy,iz)
            modV = sqrt((m1x+m2x)*(m1x+m2x)+(m1y+m2y)*(m1y+m2y)+(m1z+m2z)*(m1z+m2z))
            normalization = 1
            if modV > 0 {
        normalization = 1/modV
            }
            mcell := vector((m1x+m2x)*normalization,(m1y+m2y)*normalization,(m1z+m2z)*normalization)
            m.SetCell(ix,iy,iz,mcell)
        }
    }
}