mumax / 3

GPU-accelerated micromagnetic simulator
Other
450 stars 150 forks source link

Saving sliced quantities does not work when called inside a for loop #192

Closed AngusLaurenson closed 6 years ago

AngusLaurenson commented 6 years ago

Sliced output works when in the main body but not when in a loop. There is no error message and the simulation runs to completion. However the .ovf files expected to be saved during execution of the for loop are absent from the output folder.

The script

//output directory: example-layers.out/
SetGridsize(128, 32, 32)
SetCellsize(500e-9/128, 125e-9/32, 125e-9/32)
Msat = 800e3
Aex = 13e-12
alpha = 0.02
m.loadfile("m000000.ovf")
save(m)
save(CropZ(m, 16, 17))
save(CropLayer(m_full, 16))
save(m.Comp(2))
B_ext = vector(-24.6E-3, 4.3E-3, 0)
for n := 0; n <= 10; n++ {
    run(1e-10)
    save(CropZ(m, 16, 17))
    save(CropLayer(m_full, 16))
    save(m.Comp(2))
}

ls of .out folder

gui      m000000.ovf                 m_z000000.ovf          references.bib
log.txt  m_full_zrange16_000000.ovf  m_zrange16_000000.ovf  table.txt
JeroenMulkers commented 6 years ago

I think that the output files are overwritten in every iteration of the for loop. You can avoid this by defining a crop quantity only once, which you can then save in each iteration.

Something like:

crp := CropZ(m, 16, 17)
save(crp)
for n := 0; n <= 10; n++ {
    run(1e-10)
    save(crp)
}

Although this might save your problem, I would suggest a more robust approach in which you name the output files yourselves:

crp := CropZ(m, 16, 17)
saveas(crp,"crop_init.ovf")
for n :=0 ; n<10; n++ {
    run(1e-12)
    filename = sprintf("crop%.3d.ovf",n) // use the iteration index to number the files
    saveas(crp, filename)
}
PAKAM12 commented 2 years ago

hello, I'am new in goland and mumax3. I want to know, for this above answer, how can we save this file by changing the name for in each iteration? like: saveas(crp, filename(n)). so that we can save can have names in output: filename0, filename1, filename2, ...., filename10

Thanks , waiting fir help.