Extracting magnetization value at each point of a sample

49 views
Skip to first unread message

Shyamali

unread,
Nov 14, 2025, 12:21:43 PMNov 14
to mumax2
Hello,

I have a doubt whether it is possible to find out magnetization value (mx, my, mz) at each point (x, y, z) of a sample by reading the ovf file. If so, what can be the best possible way to do it?
Looking forward to hearing from you.

Thanks in advance,
Mani

Mohammad Ahmad

unread,
Nov 14, 2025, 12:43:26 PMNov 14
to mum...@googlegroups.com
Hi Mani,

I'm not sure if this is what you're looking for but the ovf files can be converted to numpy. And then the individual values read using a python script.

This can be done using:
mumax3-convert -numpy output/*.ovf

If you want to do some processing in your mumax script then this method might not work for you.

Best,
Mohammad


--
You received this message because you are subscribed to the Google Groups "mumax2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mumax2+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/mumax2/e362575d-2ff6-464f-8297-ce378b1c8df4n%40googlegroups.com.

Josh Lauzier

unread,
Nov 15, 2025, 1:09:17 AMNov 15
to mumax2
Hi,

Yes, in your script, if you use the command "save(m)", it will store the magnetization values of each cell. By default, OVF files are encoded in binary, so you will need to find a way to convert them when doing your post-processing of choice (this can be done in something like Python, etc). You can also use mumax3-convert to convert existing OVF files to some other convenient format. As the previous comment mentioned, numpy files, but you can also convert it to plaintext.

If you dislike working with binary, you can use the command "OutputFormat = OVF2_TEXT" before you run the save command in your mx3 script. The OVF file will then be saved in plain text. You might find this easier to work with, however the filesize will be larger.

As far as working with OVF files, any sort of programming language should do (Python, matlab, etc). Essentially it is just like reading from a text file into a matrix/array. For Python specifically, you might find the mumax tutorial useful, linked here. In the post-processing notebook there are some examples of working with OVF files in Python by importing the OVF file, converting them to numpy arrays, and then working with the numpy arrays.

Best,
Josh L.

Shyamali

unread,
Nov 16, 2025, 3:59:59 AMNov 16
to mumax2
Hi,

Thank you so much for your reply. The command "OutputFormat = OVF2_TEXT" works fine for me. But the output file getting generated is printing only the mx, my and mz values but not the corresponding values of x, y, and z. Is there any way to print the output in such a way that I can get an exact idea of what is the magnetization value (mx, my, mz) corresponding to a particular point (x, y, z).
Looking foraward to hearing from you.

Regards,
Mani

Josh Lauzier

unread,
Nov 16, 2025, 4:51:34 AMNov 16
to mumax2
Hi,

There is not a direct way. The x,y,z values are implicit, based on the formatting of the file. Since the simulation box is always a cuboid, the formatting is very consistent. For instance, the first cell, corresponding to 0,0,0 will be in the bottom (y-direction), left (x-direction), top (z-direction) cell , and in the file it will be the first line. What I would recommend is doing is generating a few simple example files to get used to the format. The OVF format is pretty straightforward, it just list the cells in order. Once you see some actual examples, it will be clear.

One silly example OVF files would be to save something like B_ext, but set B_ext in each cell to be the position value. (You can't do this with m since it's restricted to be [-1,1] for each component). For instance, something like:

Nx := 64
Ny := 32
Nz := 4
c := 5e-9
setgridsize(Nx, Ny, Nz)
setcellsize(c, c, c)
m = uniform(0, 0, 1)

mask := newVectorMask(Nx, Ny, Nz)
for i:=0; i<Nx; i++{
for j:=0; j<Ny; j++{
for k:=0; k<Nz; k++{
r := index2coord(i, j, k)
x := r.X()
y := r.Y()
z := r.Z()
mask.setVector(i, j, k, vector(i,j,k))
}
}
}
B_ext.add(mask, 1)
OutputFormat = OVF2_TEXT

save(B_ext)

This is just a test file, so that B_x=x, B_y=y=y, B_z=z, so you can follow the formatting. When you open the file, you will see that it indexes from (0,0,0) to (1,0,0) etc... up to eventually 63,0,0, which is followed by 0,1,0.. etc, until the final line is (63,31,3). If you want physical positions in nm instead of cell indices, you can instead save x,y,z in the script by setting

mask.setVector(i, j, k, vector(x,y,z)) 

instead. x,y,z position values are measured from the center of the simulation (and then to the center of each cell). So cell 0,0,0, which was bottom (y-direction), left (x-direction), top (z-direction) cell, will be x=- 64*5e-9/2-2.5e-9=-1.575e-7 nm (64 cells, divided by 2 to center, and 5 nm per cell, shifted by 2.5nm to get the center of the cell), y= 32*5e-9/2 -2.5e-9 , z=-4*5e-9 -2.5e-9 , etc.

Best,
Josh L.

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

unread,
Nov 17, 2025, 3:37:21 PMNov 17
to mumax2
Hi Mani,

You can import the OVF file into Python directly using unpack() or unpack_into_xarray() from this file:
https://github.com/AbsoluteVacuum/mumax-utilities/blob/main/python/mx3import.py
If you use unpack_into_xarray(), you would be able to access the coordinates of the cell together with the cell's data.

Naintara .

unread,
Nov 18, 2025, 11:05:44 PMNov 18
to mum...@googlegroups.com
Hey, if you want to extract the magnetization at an exact X–Y range, then first you need to define the X and Y ranges. After that, intersect them and use setgeom. Once you set the geometry, assign a name to that geometry and define the region using:

DefRegion(int, Shape)

After defining the region, you can use the command:

TableAdd(CropRegion(m, int))

This will allow you to extract the magnetization for that specific X–Y range.



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.
Reply all
Reply to author
Forward
0 new messages