Region Specific Custom Fields?

32 views
Skip to first unread message

ΙΩΑΝΝΗΣ ΠΑΝΑΓΙΩΤΟΠΟΥΛΟΣ

unread,
Jan 28, 2026, 3:51:45 AMJan 28
to mumax2
Can custom Field and Energy terms (AddFieldTerm/AddEdensTerm) be made to vary from region to region?

It would be a great help if you had a solution.

Thank you in advance
I. Panagiotopoulos

Josh Lauzier

unread,
Jan 28, 2026, 6:58:26 AMJan 28
to mumax2
Hi,

You can achieve this using the Masked() command. There isn't a direct regions method, but Masked takes a Quantity and a Shape, so you will need to create a Shape that matches your regions. For example, here is a slightly modified example, following the 'Custom effective field terms' API example, but with a different anisotropy vector in each region:

cs := 1e-9
setcellsize(cs,cs,cs)
setgridsize(64,64,2)

firstshape := layer(0)
secondshape := layer(1)
defregion(0, firstshape )
defregion(1, secondshape )

Ms := 1100e3
K  := 0.5e6
u1  := ConstVector(1, 0, 0)
anisField1 := Mul( Const(2*K/Ms)  , Mul( Dot(u1, m), u1))
anisEdens1:= Mul( Const(-0.5*Ms) , Dot( anisField1, m))

anisFieldmasked1 := Masked(anisField1, firstshape )
anisEdensmasked1 := Masked(anisEdens1, firstshape )

u2  := ConstVector(-1, 0, 0)
anisField2 := Mul( Const(2*K/Ms)  , Mul( Dot(u2, m), u2))
anisEdens2:= Mul( Const(-0.5*Ms) , Dot( anisField2, m))

anisFieldmasked2 := Masked(anisField2, secondshape  )
anisEdensmasked2 := Masked(anisEdens2, secondshape )

AddFieldTerm(anisField1)
AddEdensTerm(anisEdens1)
AddFieldTerm(anisField2)
AddEdensTerm(anisEdens2) 

Best,
Josh L.

ΙΩΑΝΝΗΣ ΠΑΝΑΓΙΩΤΟΠΟΥΛΟΣ

unread,
Jan 28, 2026, 1:37:16 PMJan 28
to mumax2
Thank you for you prompt and useful reply. I think I will make it work. Ideally, I would need the opposite shape1 := region(1)  :-) in which case I could combine it  with voronoi tesselation.

Best Regards
Ioannis
 

Josh Lauzier

unread,
Feb 9, 2026, 7:08:22 AM (3 days ago) Feb 9
to mumax2
Unfortunately, voronoi tessellation is the one use case that it doesn't work well with, as the tessellation does not utilize Shapes. It is an oversight, I think. The only way I know within mumax (without modifying the source code) is something like:

for regionsvar:=0;  regionsvar <maxRegion;  regionsvar ++{
a:= Rect(0,0)
for i:=0; i<Nx; i++{
for j:=0; j<Ny; j++{
for k:=0; k<Nz; k++{
if(regions.Getcell(i,j,k)==regionsvar) {
a=a.add(Cell(i,j,k))
}
}
}
// put custom field masking terms here
}

However, this is extremely inefficient, and quickly becomes unusable even for very small numbers of cells. The problem is the getcell() command has to pull the regions data off the GPU for each iteration of the nested loops. There are supposed to be methods that would allow for this (like regions.HostArray() ), but they return the wrong data type to be useful. They return as uint8's instead of float64's.

What is the exact form of the custom field? There may be another kludge, depending on the form. Also, are you able to recompile mumax from source? It would be relatively easy to make a little custom function that has the shape1 := region(1)  functionality you would want, but it would require recompiling . If it would be useful, I can post a modified .go file with a function, and it would just need you to recompile following the normal compilation procedure.

Best regards,
Josh L.

ΙΩΑΝΝΗΣ ΠΑΝΑΓΙΩΤΟΠΟΥΛΟΣ

unread,
Feb 9, 2026, 11:40:01 AM (3 days ago) Feb 9
to mum...@googlegroups.com
Thank you for your interesting reply! I made tests with square regions, it does not change the physics that much.

--
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/a3db3bd3-ecca-4321-b238-54a4e4bcad4dn%40googlegroups.com.


--
Panagiotopoulos Ioannis, Professor
Department of Materials Science and Engineering 
University of Ioannina, 45110 Ioannina, Greece 
http://users.uoi.gr/ipanagio/indexENG.html
Reply all
Reply to author
Forward
0 new messages