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

Bug in fastmode spinwave calculation when mex disabled and hermit=false #181

Closed RichardWaiteSTFC closed 4 months ago

RichardWaiteSTFC commented 4 months ago

Here is the spinwave spectrum for a FM chain calculated along H with mex enabled

swpref.setpref('usemex', true);

nqbins = 5;
dE = 0.2;
ebin_edge = 0:dE:6;
FMchain = spinw;
FMchain.genlattice('lat_const',[3 8 8],'angled',[90 90 90],'spgr',0);
FMchain.addatom('r',[0 0 0],'S',1,'label','MCu1','color','blue');
FMchain.gencoupling('maxDistance',7)
FMchain.addmatrix('value', -eye(3),'label','Ja','color','green')
FMchain.addcoupling('mat','Ja','bond',1);
FMchain.genmagstr('mode','direct', 'k',[0 0 0],'n',[1 0 0],'S',[0; 1; 0]);
FMspec = FMchain.spinwave({[0 0 0] [1 0 0], nqbins},'hermit',false, ...
                          'fastmode', true, 'neutron_output', true); % , 'sortMode', true);
FMspec = sw_egrid(FMspec,'component','Sperp', 'Evect', ebin_edge, 'dE', dE);
% sw_plotspec(FMspec)

f = figure('color','white');
ax = axes(f); box on; hold on;
h = imagesc(ax, FMspec.hkl(1,:), 0.5*(ebin_edge(1:end-1) + ebin_edge(2:end)), FMspec.swConv);
set(h, 'AlphaData', FMspec.swConv > 1e-10); % set 0s transparent
plot(ax, FMspec.hkl(1,:), FMspec.omega(1,:),'marker', 'o', 'color', 'r')
xlabel(ax, "H (r.l.u.)")
ylabel(ax, "Energy (meV)")

image

If you disable mex it looks like it returns eigenvalues of 0

>> FMspec.omega(1,:)
ans =
     0     0     0     0     0

So only get intensity within dE of the elastic line image

Note using home-made plotting code as sw_fitspec errors - see https://github.com/SpinW/spinw/pull/180#issuecomment-2090860373

RichardWaiteSTFC commented 4 months ago

Looks like the eigenvalues are just not copied from D to omega matrix The equivalent of this line appears to be missing form the fastmode branch on L1019 https://github.com/SpinW/spinw/blob/74422b738ab383108880656e2a9c3968e990f7af/swfiles/%40spinw/spinwave.m#L1028