In order to use all golang features such as defining arbitrary functions, you need to import mumax3 as a package from within golang code.
While there are many similarities with mumax3 script, certain things must be done in a different way. For example, in .mx3 (note: .mx3 is case-insensitive)
m = uniform(1, .1, 0)
autosave(m, 100e-12)
But in .go (note: case-sensitive!), it would become
M.Set(Uniform(1, .1, 0))
AutoSave(&M, 100e-12)
You can copy that example file to serve as a starting template, remove the last two lines in the main function (which is only used for testing), and modify accordingly the lines starting from SetGridSize until Run.
------------------------------------------
As a side note, it is technically possible to do in mx3 script what you're trying achieve, though somewhat impractical:
Aex = 3.05e-13
Dbulk = 2.75e-4
Msat = 160e3
Ku1 = -0.8e4
AnisU = Vector(0, 0, 1)
alpha = 0.1
H := 18e-9
Nx := 2
Ny := 2
Nz := 64
CellSize := H/Nz
Cx := CellSize
Cy := CellSize
Cz := CellSize
SetGridSize(Nx, Ny, Nz)
SetCellSize(Cx, Cy, Cz)
SetPBC(10, 10, 0)
TableAdd(B_ext)
TableAutoSave(1e-15)
B_ext = Vector(Sin(2*pi*1e9*t) +
Sin(2*pi*2e9*t) +
Sin(2*pi*3e9*t) +
Sin(2*pi*4e9*t) +
Sin(2*pi*5e9*t) +
Sin(2*pi*6e9*t) +
Sin(2*pi*7e9*t) +
Sin(2*pi*8e9*t) +
Sin(2*pi*9e9*t) +
Sin(2*pi*10e9*t), 0, 0)
Run(1)
As you may have already tried and found out, the following doesn't work:
spectrum := Vector(Sin(2*pi*10e9*t), 0, 0) // Becomes constant Vector(0, 0, 0) if spectrum assigned at t=0
B_ext = spectrum // B_ext becomes zero all the time
because during assignment, the right hand value is evaluated, turned into a constant.
mx3 doesn't support function literals either, so neither can you do this:
spectrum := func () { return 2*pi*1e9*t }
Currently, these statements are allowed in script:
- Assignment/Definition
- if (and optionally, else)
- for
You can't use goto-like statements in for, such as break and continue.
You can instead use if/else to skip parts of code. - Block scoping using braces.
You can define or redefine a variable that will exist only inside the scope.
jkl := 1010
mno := "whee"
{
jkl := 1515 // jkl redefined as new variable
mno = "opoo" // modifies mno defined outside scope
pqr := 10e-9
print(jkl) // prints 1515
print(mno) // prints opoo
print(pqr) // prints 10e-9
}
print(jkl) // prints 1010
print(mno) // prints opoo
print(pqr) // this line causes error, code will not run unless commented out
Although lacking in flexibility, mx3 scripts has the benefit of being able to be queued up in
mumax3-server.