Skip to content

Commit

Permalink
Hamiltonian_Heisenberg:
Browse files Browse the repository at this point in the history
- Exchange/DMI: cu_idx_from_pair was erroneously given the cell index as first argument (it should be the spin index)
- Zeeman: The index computation was missing a factor of n_cell_atoms

Vectormath:
- cu_idx_from_pair was different from idx_from_pair and missing a division by N (aka n_cell_atoms)
  • Loading branch information
M. Sallermann authored and M. Sallermann committed May 20, 2021
1 parent a010ea0 commit 382cac3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions core/include/engine/Vectormath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ namespace Engine
// Translations (cell) of spin i
int nic = ispin / (N*Na*Nb);
int nib = (ispin - nic*N*Na*Nb) / (N*Na);
int nia = ispin - nic*N*Na*Nb - nib*N*Na;
int nia = (ispin - nic*N*Na*Nb - nib*N*Na) / N;

// Translations (cell) of spin j (possibly outside of non-periodical domain)
int pm = 1;
Expand Down Expand Up @@ -336,8 +336,7 @@ namespace Engine
// Calculate the index of spin j according to it's translations
int jspin = pair.j + (nja)*N + (njb)*N*Na + (njc)*N*Na*Nb;

// Invalid index if atom type of spin j is not correct
if ( pair.j != jspin%N || !cu_check_atom_type(atom_types[jspin]) )
if ( !cu_check_atom_type(atom_types[jspin]) )
return -1;

// Return a valid index
Expand Down
12 changes: 6 additions & 6 deletions core/src/engine/Hamiltonian_Heisenberg.cu
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ namespace Engine
{
for (int ibasis=0; ibasis<n_cell_atoms; ++ibasis)
{
int ispin = icell + ibasis;
int ispin = n_cell_atoms * icell + ibasis;
if ( cu_check_atom_type(atom_types[ispin]) )
Energy[ispin] -= mu_s[ispin] * external_field_magnitude * external_field_normal.dot(spins[ispin]);
}
Expand Down Expand Up @@ -305,7 +305,7 @@ namespace Engine
for(auto ipair = 0; ipair < n_pairs; ++ipair)
{
int ispin = pairs[ipair].i + icell*n_cell_atoms;
int jspin = cu_idx_from_pair(icell, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
int jspin = cu_idx_from_pair(ispin, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
if (jspin >= 0)
{
Energy[ispin] -= 0.5 * magnitudes[ipair] * spins[ispin].dot(spins[jspin]);
Expand Down Expand Up @@ -335,7 +335,7 @@ namespace Engine
for(auto ipair = 0; ipair < n_pairs; ++ipair)
{
int ispin = pairs[ipair].i + icell*n_cell_atoms;
int jspin = cu_idx_from_pair(icell, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
int jspin = cu_idx_from_pair(ispin, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
if (jspin >= 0)
{
Energy[ispin] -= 0.5 * magnitudes[ipair] * normals[ipair].dot(spins[ispin].cross(spins[jspin]));
Expand Down Expand Up @@ -708,7 +708,7 @@ namespace Engine
{
for (int ibasis=0; ibasis<n_cell_atoms; ++ibasis)
{
int ispin = icell + ibasis;
int ispin = n_cell_atoms * icell + ibasis;
if ( cu_check_atom_type(atom_types[ispin]) )
gradient[ispin] -= mu_s[ispin] * external_field_magnitude*external_field_normal;
}
Expand Down Expand Up @@ -760,7 +760,7 @@ namespace Engine
for(auto ipair = 0; ipair < n_pairs; ++ipair)
{
int ispin = pairs[ipair].i + icell*n_cell_atoms;
int jspin = cu_idx_from_pair(icell, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
int jspin = cu_idx_from_pair(ispin, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
if (jspin >= 0)
{
gradient[ispin] -= magnitudes[ipair]*spins[jspin];
Expand Down Expand Up @@ -790,7 +790,7 @@ namespace Engine
for(auto ipair = 0; ipair < n_pairs; ++ipair)
{
int ispin = pairs[ipair].i + icell*n_cell_atoms;
int jspin = cu_idx_from_pair(icell, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
int jspin = cu_idx_from_pair(ispin, bc, nc, n_cell_atoms, atom_types, pairs[ipair]);
if (jspin >= 0)
{
gradient[ispin] -= magnitudes[ipair]*spins[jspin].cross(normals[ipair]);
Expand Down

0 comments on commit 382cac3

Please sign in to comment.