|
1 | 1 | function Eout = energy(obj, varargin) |
2 | 2 | % calculates the ground state energy |
3 | | -% |
| 3 | +% |
4 | 4 | % ### Syntax |
5 | | -% |
| 5 | +% |
6 | 6 | % `E = energy(obj,Name,Value)` |
7 | | -% |
| 7 | +% |
8 | 8 | % ### Description |
9 | | -% |
| 9 | +% |
10 | 10 | % `E = energy(obj,Name,Value)` calculates the classical ground state energy |
11 | 11 | % per spin. The calculation correctly takes into account the magnetic |
12 | 12 | % supercell. The function gives correct results on single-k magnetic |
13 | 13 | % structures even defined on magnetic supercells. For multi-k magnetic |
14 | 14 | % structures first a definition of a larger supercell is necessary where an |
15 | 15 | % effective $k=0$ representation is possible. |
16 | | -% |
| 16 | +% |
17 | 17 | % ### Examples |
18 | | -% |
| 18 | +% |
19 | 19 | % After optimising the magnetic structure (by minimizing the ground state |
20 | 20 | % energy), the energy per spin is calculated. This can be compared to |
21 | 21 | % different ground state structures to decide which is the right classical |
|
31 | 31 | % >>cryst.optmagsteep('nRun',10) |
32 | 32 | % >>cryst.energy>> |
33 | 33 | % ``` |
34 | | -% |
| 34 | +% |
35 | 35 | % ### Input Arguments |
36 | | -% |
| 36 | +% |
37 | 37 | % `obj` |
38 | 38 | % : [spinw] object. |
39 | | -% |
| 39 | +% |
40 | 40 | % ### Name-Value Pair Arguments |
41 | | -% |
| 41 | +% |
42 | 42 | % `'epsilon'` |
43 | | -% : The smallest value of incommensurability that is tolerated |
| 43 | +% : The smallest value of incommensurability that is tolerated |
44 | 44 | % without warning. Default is $10^{-5}$. |
45 | | -% |
| 45 | +% |
46 | 46 | % ### Output Arguments |
47 | | -% |
| 47 | +% |
48 | 48 | % `E` |
49 | 49 | % : Energy per moment (anisotropy + exchange + Zeeman energy). |
50 | 50 | % |
|
59 | 59 | % ion anisotropy one has to be carefull! In the triangular case one has to |
60 | 60 | % extend the unit cell to `nExt = [3 3 1]` (in the hexagonal setting), in |
61 | 61 | % this case the energy will be correct.}} |
62 | | -% |
| 62 | +% |
63 | 63 | % ### See Also |
64 | | -% |
| 64 | +% |
65 | 65 | % [spinw] \| [spinw.anneal] \| [spinw.newcell] |
66 | 66 | % |
67 | 67 |
|
|
103 | 103 | end |
104 | 104 |
|
105 | 105 | if nMagExt>0 |
106 | | - |
| 106 | + |
107 | 107 | dR = [SS.all(1:3,:) zeros(3,nMagExt)]; |
108 | 108 | atom1 = [SS.all(4,:) 1:nMagExt]; |
109 | 109 | atom2 = [SS.all(5,:) 1:nMagExt]; |
|
127 | 127 |
|
128 | 128 | Ml = repmat(permute(M1,[1 3 2]),[1 3 1]); |
129 | 129 | Mr = repmat(permute(M2,[3 1 2]),[3 1 1]); |
130 | | - |
131 | | - exchE = sum(sum(sum(Ml.*JJ.*Mr,3),2),1); |
| 130 | + |
| 131 | + Q = Ml.*JJ.*Mr; |
| 132 | + if isa(Ml,'sym') || isa(Ml,'sym') || isa(Ml,'sym') |
| 133 | + [n1, n2, n3] = size(Q); |
| 134 | + sum_3 = 0; |
| 135 | + for k = 1:n3 |
| 136 | + sum_3 = sum_3 + Q(:,:,k); |
| 137 | + end |
| 138 | + else |
| 139 | + sum_3 = sum(Q,3); |
| 140 | + end |
| 141 | + exchE = sum(sum(sum_3,2),1); |
| 142 | + |
132 | 143 | % TODO |
133 | 144 | % correct energy for twins |
134 | 145 | ZeemanE = -sum(SI.field*permute(mmat(SI.g,permute(M0,[1 3 2])),[1 3 2]),2)*obj.unit.muB; |
|
0 commit comments