This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
Create unit tests for the refactored spinwave calculation function #9
Labels
internal
internal code changes
Complete when there are unit tests that covers 80% of the core calculation code.
There should be several tests which checks the code flow within the
spin_wave_calculator
class dependent on input.Object setup
For the tests, a very simple model should be used. I recommend using a linear spin chain with the spin magnitude set to 1 (e.g. like in tutorial 1:
This model has a particularly simple dispersion - a single mode with energy
omega = 2*(1-cos(2*pi*qh))
(see Kittel, chapter 12, eq 22, but note that Kittel defines the Hamiltonian in eq 12 as -2Jsum_ij(Si.Sj) whereas in SpinW the prefactor of 2 is not included; also note that we've set the exchange integral to be1
in theaddmatrix
command).A non-Hermitian model can be setup by changing the magnetic structure to be antiferromagnetic instead:
An incommensurate model can be setup by using the
fourier
mode
and changing thek
parameter:Note that this would also give a non-Hermitian Hamiltonian because we have a ferromagnetic exchange interaction which would prefer all the spins to be parallel and this structure does not have that.
Possible tests
General tests for twins and incommensurate cases
cell
arrays as output and number of cells match number of twins2*nMagExt
number of modes, an incommensurate structure should have three times this, so6*nMagExt
number of modes)More specific test for the twins case
For each twin, the user gives a 3x3 transformation matrix which is applied to the input
hkl
q-vectors. A test could do something like this:hkl
vector (pick any 3 values) ->orig_single
output spectrarotmat * hkl
vector ->transformed_single
output spectrahkl
but with the twins set ->twinned
output spectraomega
field of thetwinned
output spectra is a cell with two elements (one for each twin, the first being the identity)omega
field oftwinned
with theomega
oforig_single
.omega
field oftwinned
with theomega
oftransformed_single
.Test for the form factor option
The magnetic form factor is a
hkl
-vector dependent scaling factor on the output neutron intensity. The test here would be to:hkl
without the formfactor option set tofalse
->spec_no_ff
true
->spec_ff
spec_no_ff.swConv * ff
andspec_ff.swConv
.Note, the
swConv
property is only generated after runningsw_egrid(sw_neutron(spectra))
.Test that the correct calculation is run for the
hermit
optionThere are two different matrix diagonalisation algorithms in SpinW - one which explicit requires a positive definite matrix which is used when
hermit
is true (that is, the Hamiltonian matrix must not be hermitian but its eigenvalues must also be strictly positive); and a second algorithm which works for any matrix but can give imaginary eigenvalues (e.g. unphysical spin wave energies) when thehermit
option is set tofalse
.The test here is to define the input such that we are sure that Hamiltonian matrix would not be Hermitian and run the calculation with
hermit
set totrue
and check that it gives an error. Then run the test withhermit
set tofalse
and check that no error is thrown and thatomega
has imaginary values.The text was updated successfully, but these errors were encountered: