Skip to content

Commit

Permalink
Test sw_egrid (#130)
Browse files Browse the repository at this point in the history
* Add initial test file

* Add Sxx etc tests

* Add polarisation tests

* Add Evect tests

* Add temperature test

* Add fName test

* Add twin tests

* Add test for cell array of components

* Add test for imagChk parameter

* Fix bug where epsilon was overwritten

* Fix bug in sw_egrid test for imagChk

* Fix bug causing out-by-one binning of eigvals onto energy grid

Code refactor and renaming variables to make clearer bin edges and centress

* Add test for irregular bins (now gives same result)

* Add test for autoEmin

* Add test for modeIdx

* Fix incomm/comm consistency systems test (WIP)

* Do not include strucutre factor at zero eigenvalue

Tends to blow up at zero energy and soemtimes due to floating point precision zero eignevalues are actually included in energy bins with edge at zero energy

* Update system test data post removing 0 eigenvalues from struct. fact

* Fix size mismatch bug if modeIDx supplied post neglect zero eigvals

* Increase tolerance on eigvals = 0 (for which DSF to be neglected)

* Add threshold parameter to remove zero-energy modes

* Increase tolerance on ghost mdoe identification AFM kagome

* Add unit test for ZeroModeThreshold

* Update test data post zero mode check

* Update system test data for biquad, KCu3As2O7 and afm kagome

* Use tol on magnitude of all eigvals to ignore (not just zero modes)

Added test for new parameter (zeroEnergyTol, previously ZeromodeThreshold) and fixed other tests by removing all intensity from bins with edge at zero

* Deprecate epsilon parameter

* Remove epsilon from autoEmin check

Change in behaviour - now adds max imag component of energy eig vals (ioMax) to the first energy bin edge if within ioMax of 0 (and half this to the bin center)

* Update system test reference data

* Increase zeroEnergyTol in incom vs supercell test

* Fix bug in half polarise calc reshaping intP

Thanks @mducle for spotting and fixing this

* Update fname test

* Move autoEmin check to occur only if imgChk true

Don't have to uodate test as imgChk is true by default

* Add parameter to zero DSF above a given limit (maxDSF)

---------

Co-authored-by: Richard Waite <richard.waite@stfc.ac.uk>
  • Loading branch information
rebeccafair and RichardWaiteSTFC authored Jul 6, 2023
1 parent 92551aa commit 49880bc
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
reference_data_file = [];
tol = 1e-5;
end
methods
function om = remove_ghosts(testCase, spec)
om = spec.omega(find(abs(spec.Sperp) > testCase.tol));
om = sort(unique(round(om / testCase.tol) * testCase.tol));
methods (Static)
function om = remove_ghosts(spec, tol)
om = spec.omega(find(abs(spec.Sperp) > tol));
om = sort(unique(round(om / tol) * tol));
end

end
methods
function assert_super_and_incom_consistency(testCase, swobj, ...
spec_super, spec_incom)
spec_super, spec_incom, ...
ghost_tol)
if nargin < 5
ghost_tol = testCase.tol;
end
% test cross-section in q,En bins
testCase.verify_test_data(spec_incom.swConv, ...
spec_super.swConv)
Expand All @@ -22,8 +27,8 @@ function assert_super_and_incom_consistency(testCase, swobj, ...
6*n_matom);
testCase.assertEqual(size(spec_super.Sperp, 1), ...
2*prod(nExt)*n_matom);
testCase.assertEqual(testCase.remove_ghosts(spec_super),...
testCase.remove_ghosts(spec_incom));
testCase.assertEqual(testCase.remove_ghosts(spec_super, ghost_tol), ...
testCase.remove_ghosts(spec_incom, ghost_tol));
end
end

Expand All @@ -35,31 +40,33 @@ function test_AFM_kagome(testCase)
'angled',[90 90 120], 'sym','P -3')
AF33kagome.addatom('r',[1/2 0 0],'S', 1, 'label','MCu1')
AF33kagome.gencoupling('maxDistance',7);
AF33kagome.addmatrix('label','J1','value',1.00)
AF33kagome.addmatrix('label','J1','value',1)
AF33kagome.addcoupling('mat','J1','bond',1);
% sqrt3 x sqrt(3) magnetic structure
k = [-1/3 -1/3 0];
n = [0, 0, 1];
S = [0 0 -1; 1 1 -1; 0 0 0];
% binning for spinwave spectrum
qarg = {[-1/2 0 0] [0 0 0] [1/2 1/2 0] 3};
evec = 0:0.5:2;
qarg = {[-1/2 0 0] [0 0 0] [1/2 1/2 0] 50};
evec = 0:0.1:1.5;

% use structural unit cell with incommensurate k
AF33kagome.genmagstr('mode','helical','unit','lu', 'k', k,...
'n',n, 'S', S, 'nExt',[1 1 1]);
testCase.disable_warnings('spinw:spinwave:NonPosDefHamiltonian');
spec_incom = AF33kagome.spinwave(qarg, 'hermit', true);
spec_incom = sw_egrid(spec_incom, 'component','Sperp', 'Evect',evec);
spec_incom = sw_egrid(spec_incom, 'component','Sperp', 'Evect', evec, ...
'zeroEnergyTol', 1e-2);
% use supercell k=0 structure
AF33kagome.genmagstr('mode','helical','unit','lu', 'k', k,...
'n',n, 'S', S, 'nExt', [3,3,1]);

spec_super = AF33kagome.spinwave(qarg, 'hermit', true);
spec_super = sw_egrid(spec_super, 'component','Sperp', 'Evect',evec);
spec_super = sw_egrid(spec_super, 'component','Sperp', 'Evect', evec);

testCase.assert_super_and_incom_consistency(AF33kagome, ...
spec_super, ...
spec_incom);
spec_incom, 5e-2);
end

function test_two_matom_per_unit_cell(testCase)
Expand All @@ -81,8 +88,8 @@ function test_two_matom_per_unit_cell(testCase)
k = [1/2, 0, 0];
S = [0 0;1 1;0 0];
% binning for spinwave spectrum
qarg = {[0 0 0] [1/2 0 0] 5};
evec = 0:1.5:5;
qarg = {[0 0 0] [0, 0.5, 0] 5};
evec = 0:0.5:5;

% use structural unit cell with incommensurate k
testCase.disable_warnings('spinw:spinwave:NonPosDefHamiltonian', ...
Expand Down
Loading

0 comments on commit 49880bc

Please sign in to comment.