Skip to content

Commit

Permalink
Configuration: Fix for antiparallel spins in Homogeneous_Rotation.
Browse files Browse the repository at this point in the history
If two images had antiparallel spins, eg +z and -z, the resulting interpolated spins were not of unit length. This was due to the definition of the rotation axis as s1xs2, resulting in the null vector. The new behaviour is that either ex or ey is chosen as rotation axis and a warning is logged.
  • Loading branch information
M. Sallermann authored and M. Sallermann committed Feb 11, 2021
1 parent b549587 commit 67d7a37
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/src/utility/Configuration_Chain.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <utility/Configuration_Chain.hpp>
#include <utility/Configurations.hpp>
#include <utility/Constants.hpp>
#include <utility/Logging.hpp>
#include <data/Spin_System.hpp>
#include <engine/Vectormath.hpp>

Expand Down Expand Up @@ -31,12 +32,24 @@ namespace Utility

scalar angle, rot_angle;
Vector3 rot_axis;
Vector3 ex = {1,0,0};
Vector3 ey = {0,1,0};

bool antiparallel = false;
for( int i = 0; i < c->images[0]->nos; ++i )
{
rot_angle = Engine::Vectormath::angle(spins_1[i], spins_2[i]);
rot_axis = spins_1[i].cross(spins_2[i]).normalized();

if(std::abs(rot_angle - Constants::Pi) < 1e-4) // If spins are antiparallel, we choose an arbitrary rotation axis
{
antiparallel = true;
if(std::abs(spins_1[i].dot(ex)) - 1 > 1e-4)
rot_axis = ex;
else
rot_axis = ey;
}

// If they are not strictly parallel we can rotate
if( rot_angle > 1e-8 )
{
Expand All @@ -55,6 +68,8 @@ namespace Utility
}
}
}
if(antiparallel)
Log(Log_Level::Warning, Log_Sender::All, "For the interpolation of antiparallel spins an arbitrary rotation axis has been chosen.");
}
}//end namespace Configuration_Chain
}//end namespace Utility

0 comments on commit 67d7a37

Please sign in to comment.