Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit e3bed3e

Browse files
committed
Clean up code
Remove spinwave_single.m (initial functional implementation) Put back warnings and other informational info
1 parent 3675ad5 commit e3bed3e

File tree

2 files changed

+26
-512
lines changed

2 files changed

+26
-512
lines changed

swfiles/+sw_classes/spin_wave_calculator.m

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
zed % The u vector in eq (9) of Toth & Lake
1515
SI % A struct with single-ion (SI) properties
1616
RR % A 3 x nMagExt matrix with positions of the spins/atoms
17+
orthWarn = false % Flag if orthogonal warning is triggered
18+
posdefWarn = false % Flag if positive-definite warning triggered
1719
end
1820

1921
methods(Access=public)
@@ -34,16 +36,21 @@
3436
Vsave_twin = cell(1,nTwins);
3537
Sabp_twin = cell(1,nTwins);
3638
omegap_twin = cell(1,nTwins);
39+
if self.magnetic_structure.incomm
40+
k_incomm_vec = [-self.magnetic_structure.km', zeros(3,1), self.magnetic_structure.km'];
41+
calc_type = 'INCOMMENSURATE';
42+
else
43+
k_incomm_vec = zeros(3,1);
44+
calc_type = 'COMMENSURATE';
45+
end
46+
fprintf0(self.parameters.fid,['Calculating %s spin wave spectra '...
47+
'(nMagExt = %d, nHkl = %d, nTwin = %d)...\n'], calc_type, ...
48+
self.magnetic_structure.nMagExt, self.qvectors.nHkl, nTwins);
3749
% Gets the transformation matrices for the hkl for each twin
3850
[~, rotQ] = self.spinWaveObject.twinq([0;0;0]);
3951
for iTwin = 1:nTwins
4052
rotC = self.spinWaveObject.twin.rotc(:,:,iTwin);
4153
% Incommensurate loop
42-
if self.magnetic_structure.incomm
43-
k_incomm_vec = [-self.magnetic_structure.km', zeros(3,1), self.magnetic_structure.km'];
44-
else
45-
k_incomm_vec = zeros(3,1);
46-
end
4754
sz_incomm = size(k_incomm_vec,2);
4855
Hsave = cell(1, sz_incomm);
4956
Vsave = cell(1, sz_incomm);
@@ -116,6 +123,14 @@
116123
end
117124
end
118125
end
126+
if self.posdefWarn && ~self.parameters.fitmode
127+
warning('spinw:spinwave:NonPosDefHamiltonian',['To make the Hamiltonian '...
128+
'positive definite, a small omega_tol value was added to its diagonal!'])
129+
end
130+
% issue eigorth warning
131+
if self.orthWarn
132+
warning('spinw:spinwave:NoOrth','Eigenvectors of defective eigenvalues cannot be orthogonalised at some q-point!');
133+
end
119134
% If number of formula units are given per cell normalize to formula unit
120135
if self.spinWaveObject.unit.nformula > 0
121136
Sab = Sab / double(self.spinWaveObject.unit.nformula);
@@ -295,12 +310,10 @@ function prepareHamiltonian(self)
295310
bqAtom2 = SS.all(5, bq);
296311
bqJJ = SS.all(6, bq);
297312
self.bq_hamiltonian = sw_classes.biquadratic_hamiltonian(bqJJ, bqdR, bqAtom1, bqAtom2, self.zed, self.eta, S_mag);
313+
% Remove the biquadratic interactions for subsequent calculations
298314
SS.all = SS.all(1:14,SS.all(15,:)==0);
299315
end
300316

301-
%fprintf0(fid,['Calculating COMMENSURATE spin wave spectra '...
302-
% '(nMagExt = %d, nHkl = %d, nTwin = %d)...\n'],nMagExt, nHkl0, nTwin);
303-
304317
dR = [SS.all(1:3,:) zeros(3,nMagExt)];
305318
atom1 = [SS.all(4,:) 1:nMagExt];
306319
atom2 = [SS.all(5,:) 1:nMagExt];
@@ -363,7 +376,7 @@ function prepareHamiltonian(self)
363376
if self.parameters.hermit
364377
% All the matrix calculations are according to Colpa's paper
365378
% J.H.P. Colpa, Physica 93A (1978) 327-353
366-
[V, omega] = spinwave_hermit(ham, self.parameters, nMagExt);
379+
[V, omega, self.posdefWarn] = spinwave_hermit(ham, self.parameters, nMagExt);
367380

368381
else
369382
% All the matrix calculations are according to White's paper
@@ -377,9 +390,9 @@ function prepareHamiltonian(self)
377390

378391
gham = mmat(gComm,ham);
379392

380-
[V, omega, orthWarn] = eigorth(gham, self.parameters.omega_tol, self.parameters.useMex);
393+
[V, omega, orthWarn1] = eigorth(gham, self.parameters.omega_tol, self.parameters.useMex);
381394

382-
%orthWarn0 = orthWarn || orthWarn0;
395+
self.orthWarn = orthWarn1 || self.orthWarn;
383396

384397
for ii = 1:size(omega, 2)
385398
% multiplication with g removed to get negative and positive
@@ -420,7 +433,6 @@ function prepareHamiltonian(self)
420433
% calculate magnetic structure factor using the hklExt0 Q-values
421434
% since the S(Q+/-k,omega) correlation functions also belong to the
422435
% F(Q)^2 form factor
423-
424436
if self.parameters.formfact
425437
% include the form factor in the z^alpha, z^beta matrices
426438
zeda = zeda.*repmat(permute(self.parameters.FF,[3 4 5 1 2]),[3 3 2*nMagExt 2 1]);
@@ -448,7 +460,8 @@ function prepareHamiltonian(self)
448460
end
449461

450462

451-
function [V, omega] = spinwave_hermit(ham, param, nMagExt)
463+
function [V, omega, warn1] = spinwave_hermit(ham, param, nMagExt)
464+
warn1 = false;
452465
nHklMEM = size(ham, 3);
453466

454467
% diagonal of the boson commutator matrix

0 commit comments

Comments
 (0)