/*
	Test custom field implementation.
	Like uniaxialanisotropy.mx3, but with custom anisotropy implementation.
*/

setgridsize(64, 64, 1)
setcellsize(4e-9, 4e-9, 2e-9)

Aex   = 13e-12
alpha = 1
M     = uniform(1, 1, 0)

// Custom anisotropy, easy, in-plane
Msat  = 1100e3
K := 0.5e6
u := Normalized(ConstVector(1000, 0, 0))

prefactor := Const( (2 * K) / (Msat.Average()))
MyAnis := Mul(prefactor, Mul( Dot(u, m), u))
AddFieldTerm(MyAnis)
AddEdensTerm(Mul(Const(-0.5),Dot(MyAnis,M_full)))

B_ext = vector(0, 0.00, 0)
relax()
expect("my", m.average()[1], 0.000, 1e-3)
expect("E_custom", E_custom, -6.553505382400001e-17, 1e-22)

B_ext = vector(0, 0.01, 0)
relax()
expect("my", m.average()[1], 0.011, 1e-3)
print(E_custom)
expect("E_custom", E_custom, -6.552704614400001e-17, 1e-22)

B_ext = vector(0, 0.03, 0)
relax()
expect("my", m.average()[1], 0.033, 1e-3)
print(E_custom)
expect("E_custom", E_custom, -6.546302566400002e-17, 1e-22)

B_ext = vector(0, 0.10, 0)
relax()
expect("my", m.average()[1], 0.110, 1e-3)
print(E_custom)
expect("E_custom", E_custom, -6.473485516800002e-17, 1e-22)

B_ext = vector(0, 0.30, 0)
relax()
expect("my", m.average()[1], 0.331, 1e-3)
print(E_custom)
expect("E_custom", E_custom, -5.833683353600001e-17, 1e-22)

