Skip to content

Feature: Custom Quantities#384

Open
jplauzie wants to merge 9 commits intomumax:3.11.2from
jplauzie:Custom_Quantities
Open

Feature: Custom Quantities#384
jplauzie wants to merge 9 commits intomumax:3.11.2from
jplauzie:Custom_Quantities

Conversation

@jplauzie
Copy link

@jplauzie jplauzie commented Mar 18, 2026

This branch adds the ability for the user to promote arbitrary slices (which can be made using NewScalarMask and NewVectorMask) into a custom Quantity. The implementation is backported from @XuebingZhao 's umagnus fork. Currently, custom fields can only be made from existing Quantities, Const or Constvector , limiting the amount of spatially varying Quantities that are possible.

  • The main use case is that it allows users to create spatially varying field terms that are not limited to 256 regions, but of course there are many other options. Does not use any Cuda, so probably slower than Jakelove's Feature/spatial_quantity #289 implementation for spatial Quantities, but also probably more flexible overall.
  • Works with both Scalar and Vector slices. Adding functionality to handle tensors isn't included and would be a bit of extra work, but users can fairly easily build a rank2 tensor out of Vectors.
  • Works with normal Quantity operators (Add, Mul, etc), as well as with Run/Relax/Minimize etc.
  • Included is a test file custom_quantities.mx3. I compared it to mumax's built-in uniaxial anisotropy, it matches exactly within numerical precision.
  • In a previous PR, I mentioned potentially doing custom Excitations. After spending some more time on it, I believe it should actually be possible to do time varying Quantities as well, but it will take some more time to fully work it out and verify, so that will come at some later time in a different PR.

JonathanMaes and others added 6 commits March 12, 2026 15:12
This Branch adds the ability for the user to define promote arbitrary slices (both scalar masks and vector masks) into a Custom Quantity.

Implementation follows xfong's implementation in the https://github.com/seeder-research/umagnus fork.
Previous was old version (no functional changes, just comments)
mx3 file went to wrong folder on new PR.
@JonathanMaes JonathanMaes changed the base branch from master to 3.11.2 March 18, 2026 15:27


mask := newScalarMask(Nx, Ny, Nz)
for i:=0; i<Nx; i++{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps having a CUDA kernel that generates a slice containing all the cell indices (similar to the functions from #289) could be useful for large simulations. In the example here, one could then use .Comp(0), promote that to a quantity, and then operate on that quantity to efficiently build the mask.

But there were some unresolved comments on #289, so it's probably best to limit this PR to the slice-to-Quantity conversion and keep this idea for a potential future PR.

Copy link
Author

@jplauzie jplauzie Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this would be very useful at some point, especially because using .set() and .get() can end up being somewhat slow due to the extra overhead, for large simulations. Set isn't too bad by itself, but if a user wants to do something like Region.getcell to compare to a value, then .set() it gets really bogged down

@JonathanMaes JonathanMaes added this to the 3.12 milestone Mar 19, 2026
@JonathanMaes
Copy link
Contributor

I also think this feature is sufficiently useful to rename the file ext_customquantities.go to customquantity.go.

Fixes following comments:

Relaxes changed to short Runs. Relax was not needed, just a convenience during testing, and Run() finishes the test faster.

Renamed to customquantity.go

Description clarified that slices can be created using NewScalarMask and NewVectorMask, and that the slices should match the grid size.

Remove  a superfluous multiplication by 1 that was left over from initial testing
Remind users that custom Quantities are not limited to 256 regions
added Loadfile to description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants