Hi,
Previously in mumax3, specifically for a radially symmetric one, you would need to do it as you are already, with Circles. You can do it in a for loop. Something like:
imax:=5
for i:=0; i<=imax; i=i+1{
defregion(i, Circle(2*i*(120e-9-i*20e-9)))
Ku1.SetRegion(1, exp(-pow((i*20e-9)/100e-9, 2)) )
}
This isn't truly an arbitrary function, but specifically for a radially specific problem, you can parametrize the radius and use Circles. There are two caveats: You are still limited to regions, as Anton mentioned. In particular, there can only be 256 regions, even if you load from a file.Two, when you have overlapping regions like this, keep in mind that the latest assignment will overwrite the previous ones (this was correct in your original script where you started with bigger circles down to smaller, just mentioning in case it was accidental).
However, with the latest release 3.12, I am happy to say that it is now possible to do arbitrary functions of f(x,y,z) via the new CustomQuantity() feature, as long as the effect you want can be represented by a Custom Field. CustomQuantity() allows a user to upgrade a slice with arbitrary values to a Quantity that can be used with CustomQuantity. The slice used with CustomQuantity() should match the mesh size. The process goes something like:
1) Slices can already be built using analytical functions (for an example, look to the " Spinning hard disk" example on the
examples page where they construct a slice with a Gaussian profile) or via Loadfile().
You would construct a slice of K values for each cell using NewScalarMask() or NewVectorMask() the same way as the hard disk example.
2) Then, instead of using B_ext.add() as in the hard disk example to make an external field, you would call CustomQuantity on the slice to upgrade it to a Quantity.
3) Once it is a Quantity, you can apply it as a CustomField using AddFieldTerm() (same with energy densities and AddEdensterm() ). For an example of Custom Fields, look to the "custom effective field terms" on the API page. It shows how to construct a uniaxial anisotropy via custom fields. The only difference for you will be instead of Const(2*K/Ms), since your K is no longer constant you will have Mul( Const(2/Ms), Kvals), where Kvals is your CustomQuantity.
The process is a bit involved, so I've attached an example file. You may need to tweak it slightly slightly but it should give the idea. If you have less than 256 regions, either method should be equivalent. The advantage of CustomQuantity() is that it's not limited to 256 regions, and not limited to the built-in Shapes. However, Custom Fields will in general be a bit slower and use a bit more memory during the actual simulation run compared to the native anisotropy implementation. Also, your fields/energies will show up under B_custom/Edens_Custom instead of the B_anis.
As Anton mentioned, I would double check your output, your existing script works as intended. Here is regions from the GUI. And Ku1:

Cheers,
Josh L.