Skip to content

Commit

Permalink
Merge branch 'master' into 72_test_spinw_genmagstr
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccafair committed Aug 17, 2022
2 parents e8afe01 + 66ac715 commit 4b57897
Show file tree
Hide file tree
Showing 33 changed files with 440 additions and 53 deletions.
2 changes: 1 addition & 1 deletion +sw_tests/+system_tests/systemtest_spinwave_KCu3As2O7.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function prepareForRun(testCase)
% To test incommensurate spin wave calculations and also the structure optimisation routine
J = -2; Jp = -1; Jab = 0.75; Ja = -J/.66 - Jab; Jip = 0.01;
hK = spinw;
hK.genlattice('lat_const',[10.2 5.94 7.81],'angled',[90 117.7 90],'spgr','C 2/m');
hK.genlattice('lat_const',[10.2 5.94 7.81],'angled',[90 117.7 90],'sym','C 2/m');
hK.addatom('r',[0 0 0],'S',1/2,'label','MCu2','color','b');
hK.addatom('r',[1/4 1/4 0],'S',1/2,'label','MCu2','color','k');
hK.gencoupling();
Expand Down
2 changes: 1 addition & 1 deletion +sw_tests/+system_tests/systemtest_spinwave_af33kagome.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
function prepareForRun(testCase)
% From Tutorial 8, a sqrt(3) x sqrt(3) kagome AFM to test incommensurate calculations
AF33kagome = spinw;
AF33kagome.genlattice('lat_const',[6 6 40],'angled',[90 90 120],'spgr','P -3');
AF33kagome.genlattice('lat_const',[6 6 40],'angled',[90 90 120],'sym','P -3');
AF33kagome.addatom('r',[1/2 0 0],'S', 1,'label','MCu1','color','r');
AF33kagome.gencoupling('maxDistance',7);
AF33kagome.addmatrix('label','J1','value',1.00,'color','g');
Expand Down
2 changes: 1 addition & 1 deletion +sw_tests/+system_tests/systemtest_spinwave_pcsmo.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function prepareForRun(testCase)
SM4 = 7/4; % Spin length for Mn4+
SM3 = 7/4; % Spin length for Mn3+
pcsmo = spinw;
pcsmo.genlattice('lat_const', lat.*[2 2 1], 'angled', alf, 'spgr', 'x,y+1/2,-z');
pcsmo.genlattice('lat_const', lat.*[2 2 1], 'angled', alf, 'sym', 'x,y+1/2,-z');
[~,ffn3] = sw_mff('MMn3');
[~,ffn4] = sw_mff('MMn4');
myaddatom3 = @(x,y,z) pcsmo.addatom('label', x, 'r', y, 'S', SM3, 'color', z, ...
Expand Down
2 changes: 1 addition & 1 deletion +sw_tests/+system_tests/systemtest_spinwave_yb2ti2o7.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function prepareForRun(testCase)
symStr = '-z, y+3/4, x+3/4; z+3/4, -y, x+3/4; z+3/4, y+3/4, -x; y+3/4, x+3/4, -z; x+3/4, -z, y+3/4; -z, x+3/4, y+3/4';
yto = spinw;
a = 10.0307;
yto.genlattice('lat_const',[a a a],'angled',[90 90 90],'spgr',symStr,'label','F d -3 m Z')
yto.genlattice('lat_const',[a a a],'angled',[90 90 90],'sym',symStr,'label','F d -3 m Z')
yto.addatom('label','Yb3+','r',[1/2 1/2 1/2],'S',1/2)
% We generate the list of bonds.
yto.gencoupling
Expand Down
4 changes: 2 additions & 2 deletions +sw_tests/+unit_tests/unittest_spinw_addaniso.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function test_addaniso_with_no_magnetic_atom(testCase)
end

function test_addaniso_all_symm_equiv_atoms(testCase)
testCase.swobj.genlattice('spgr','I 4'); % body-centred
testCase.swobj.genlattice('sym','I 4'); % body-centred
testCase.swobj.addaniso('A1')
expected_single_ion = testCase.default_single_ion;
expected_single_ion.aniso = int32([1, 1]);
Expand All @@ -58,7 +58,7 @@ function test_addaniso_specific_atoms_wrong_atomIdx(testCase)
end

function test_addaniso_with_atomIdx_error_when_high_symm(testCase)
testCase.swobj.genlattice('spgr','I 4'); % body-centred
testCase.swobj.genlattice('sym','I 4'); % body-centred
testCase.verifyError(...
@() testCase.swobj.addaniso('A1', 'atom_1', 1), ...
'spinw:addaniso:SymmetryProblem')
Expand Down
2 changes: 1 addition & 1 deletion +sw_tests/+unit_tests/unittest_spinw_addcoupling.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function test_add_coupling_to_individual_bond(testCase)
end

function test_add_ccoupling_lower_symm_with_subIdx(testCase)
testCase.swobj.genlattice('spgr', 'I 4')
testCase.swobj.genlattice('sym', 'I 4')
testCase.swobj.gencoupling('maxDistance',5) % generate bond list
testCase.verifyWarning(...
@() testCase.swobj.addcoupling('mat', 'J1', 'bond', 1, 'subIdx', 1), ...
Expand Down
4 changes: 2 additions & 2 deletions +sw_tests/+unit_tests/unittest_spinw_addg.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function test_addg_with_wrong_atom_label_not_write_g(testCase)
end

function test_addg_all_symm_equiv_atoms(testCase)
testCase.swobj.genlattice('spgr','I 4'); % body-centred
testCase.swobj.genlattice('sym','I 4'); % body-centred
testCase.swobj.addg('g1')
expected_single_ion = testCase.default_single_ion;
expected_single_ion.g = int32([1, 1]);
Expand All @@ -57,7 +57,7 @@ function test_addg_all_symm_equiv_atoms(testCase)
end

function test_addg_with_atomIdx_error_when_high_symm(testCase)
testCase.swobj.genlattice('spgr','I 4'); % body-centred
testCase.swobj.genlattice('sym','I 4'); % body-centred
testCase.verifyError(...
@() testCase.swobj.addg('g1', 'atom_1', 1), ...
'spinw:addg:SymmetryProblem')
Expand Down
63 changes: 63 additions & 0 deletions +sw_tests/+unit_tests/unittest_spinw_field.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
classdef unittest_spinw_field < sw_tests.unit_tests.unittest_super
properties
swobj
end
properties (TestParameter)
incorrect_input = {0, [1; 1], ones(1, 4)};
end
methods(TestMethodSetup)
function create_sw_model(testCase)
testCase.swobj = spinw();
end
end
methods (Test)
function test_incorrect_shape_field_raises_error(testCase, ...
incorrect_input)
testCase.verifyError(...
@() field(testCase.swobj, incorrect_input), ...
'spinw:magfield:ArraySize');
end
function test_default_field(testCase)
testCase.assertEqual(field(testCase.swobj), [0 0 0]);
end
function test_set_field(testCase)
field_val = [1 2 3];
field(testCase.swobj, field_val);
testCase.assertEqual(field(testCase.swobj), field_val);
end
function test_set_field_column_vector(testCase)
field_val = [1; 2; 3];
field(testCase.swobj, field_val);
testCase.assertEqual(field(testCase.swobj), field_val');
end
function test_set_field_multiple_times(testCase)
field(testCase.swobj, [1 2 3]);
new_field_val = [1.5 2.5 -3.5];
field(testCase.swobj, new_field_val);
testCase.assertEqual(field(testCase.swobj), new_field_val);
end
function test_returns_spinw_obj(testCase)
field_val = [1 2 3];
new_swobj = field(testCase.swobj, field_val);
% Test field is set
testCase.assertEqual(field(testCase.swobj), field_val)
% Also test handle to swobj is returned
assert (testCase.swobj == new_swobj);
end
end
methods (Test, TestTags = {'Symbolic'})
function test_set_field_sym_mode_sym_input(testCase)
testCase.swobj.symbolic(true);
field_val = sym([pi pi/2 pi/3]);
field(testCase.swobj, field_val);
testCase.assertEqual(field(testCase.swobj), field_val);
end
function test_set_field_sym_mode_non_sym_input(testCase)
testCase.swobj.symbolic(true);
field_val = [pi pi/2 pi/3];
field(testCase.swobj, field_val);
expected_field_val = field_val*sym('B');
testCase.assertEqual(field(testCase.swobj), expected_field_val);
end
end
end
8 changes: 4 additions & 4 deletions +sw_tests/+unit_tests/unittest_spinw_gencoupling.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function test_gencoupling_with_tolDist_for_symm_equiv_bonds(testCase)

function test_gencoupling_with_non_P0_spacegroup(testCase)
% set ortho spacegroup even though lattice is tetragonal
testCase.swobj.genlattice('spgr', 'P 2') % not overwrite abc
testCase.swobj.genlattice('sym', 'P 2') % not overwrite abc
% test forceNoSym = true (just uses bond length for idx)
testCase.swobj.gencoupling('maxDistance', 4, 'forceNoSym', true)
testCase.verify_val(testCase.default_coupling, ...
Expand Down Expand Up @@ -129,7 +129,7 @@ function test_gencoupling_overwrites_previous_call(testCase)
end

function test_gencoupling_with_maxSym_multiple_bonds(testCase)
testCase.swobj.genlattice('spgr', 'P 4') % not overwrite abc
testCase.swobj.genlattice('sym', 'P 4') % not overwrite abc
% set maxSym distance to only include bond idx = 1
testCase.swobj.gencoupling('maxDistance', 4.5 , 'maxSym', 4)
expected_coupling = testCase.default_coupling;
Expand All @@ -149,7 +149,7 @@ function test_gencoupling_with_maxSym_multiple_bonds(testCase)
end

function test_gencoupling_maxSym_less_than_any_bond_length(testCase)
testCase.swobj.genlattice('spgr', 'P 4') % not overwrite abc
testCase.swobj.genlattice('sym', 'P 4') % not overwrite abc
testCase.verifyWarning(...
@() testCase.swobj.gencoupling('maxDistance', 4, ...
'maxSym', 2), 'spinw:gencoupling:maxSym')
Expand All @@ -159,7 +159,7 @@ function test_gencoupling_maxSym_less_than_any_bond_length(testCase)
end

function test_gencoupling_when_tol_violates_symmetry(testCase)
testCase.swobj.genlattice('lat_const',[3 3.5 5], 'spgr', 'P 4')
testCase.swobj.genlattice('lat_const',[3 3.5 5], 'sym', 'P 4')
% bond along a and b are sym. equiv. according to P 4
% but lengths differ by 0.5 Ang
testCase.verifyError(...
Expand Down
Loading

0 comments on commit 4b57897

Please sign in to comment.