SpinW / spinw

SpinW Matlab library for spin wave calculation
http://www.spinw.org
GNU General Public License v3.0
35 stars 15 forks source link

Copy eigenvalues from `D` to `omega` when hermit=false and no mex #182

Closed RichardWaiteSTFC closed 4 months ago

RichardWaiteSTFC commented 4 months ago

Testing Instructions

(1) Run this script (taken from Tutorial 19)

swpref.setpref('usemex', false);

FeCuChain = spinw;
FeCuChain.genlattice('lat_const',[3 8 4],'spgr','P 1')
FeCuChain.addatom('label','MCu2','r',[0 0 0])
FeCuChain.addatom('label','MFe2','r',[0 1/2 0])

FeCuChain.gencoupling
FeCuChain.addmatrix('label','J_{Cu-Cu}','value',1,'color','r')
FeCuChain.addmatrix('label','J_{Fe-Fe}','value',1,'color','b')
FeCuChain.addmatrix('label','J_{Cu-Fe}','value',-0.1,'color','orange')

FeCuChain.addcoupling('mat','J_{Cu-Cu}','bond',1)
FeCuChain.addcoupling('mat','J_{Fe-Fe}','bond',2)
FeCuChain.addcoupling('mat','J_{Cu-Fe}','bond',[4 5])
FeCuChain.genmagstr('mode','helical','S',[0 0;1 1;0 0],'k',[1/2 0 0])

spec = FeCuChain.spinwave({[0 0 0] [1 0 0] 21},'formfact',true,'hermit',false, ...
                          'fastmode', true);

f = figure('color','white');
ax = axes(f); box on; hold on;
plot(ax, spec.hkl(1,:), spec.omega,'marker', 'o')
xlabel(ax, "H (r.l.u.)")
ylabel(ax, "Energy (meV)")

It should produce this plot image

Previously all eigenvalues were 0

Fixes #181

github-actions[bot] commented 4 months ago

Test Results

    4 files  ± 0    104 suites   - 2   8m 0s :stopwatch: - 7m 23s   684 tests  - 19    666 :white_check_mark:  - 19  18 :zzz: ±0  0 :x: ±0  1 908 runs   - 38  1 872 :white_check_mark:  - 38  36 :zzz: ±0  0 :x: ±0 

Results for commit 2b986701. ± Comparison against base commit 74422b73.

This pull request removes 19 tests. ``` sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_general_hkl sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_hamiltonian sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_hamiltonian_squared sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_hamiltonian_white sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_spectra(test_spectra_function_name=sw_egrid) sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_spectra(test_spectra_function_name=sw_instrument) sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_spectra(test_spectra_function_name=sw_neutron) sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_spectra(test_spectra_function_name=sw_omegasum) sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_spectra(test_spectra_function_name=sw_plotspec) sw_tests.system_tests.systemtest_spinwave_symbolic_nips ‑ test_symbolic_spectra(test_spectra_function_name=sw_tofres) … ```

:recycle: This comment has been updated with latest results.

RichardWaiteSTFC commented 4 months ago

Um, could you also remove lines 1163-1165 please? (I think I made a typo there and this supersedes it). Also maybe you can cherry pick the CI changes (commit 472e474c from the other PR and then merge this PR?

The previous fix was causing tests to fail for hermit=true e.g.

================================================================================
  Error occurred in sw_tests.unit_tests.unittest_spinw_spinwave/test_fastmode(mex=char_old) and it did not run to completion.
      ---------
      Error ID:
      ---------
      'MATLAB:UndefinedFunction'
      --------------
      Error Details:
      --------------
      Unrecognized function or variable 'D'.

      Error in spinw/spinwave (line 1044)
              omega = D(1:nMagExt,:);

      Error in sw_tests.unit_tests.unittest_spinw_spinwave/test_fastmode (line 657)
                  spec1 = swobj.spinwave(hkl, 'fastmode', true);
  ================================================================================

So after this commit https://github.com/SpinW/spinw/pull/182/commits/5b5f4c2bf0b9d50b2c1fe823b32888be13d7e930 I think I need to keep lines 1163-1165 (also from code looks like this will also be needed is using memory management loop).