Skip to content
Snippets Groups Projects
Commit a8cbb566 authored by Nicolas Essing's avatar Nicolas Essing
Browse files

Fix torque based constraints for negative moments.

The constraint magnetic field that is calculated based on the torque
is now muliplied by the sign of the magnetic moment in the local
frame of reference.
The torque has to be understood as an energy related to a change in
the direction of the local frame of reference. This can differ from
the direction of the magnetic moment by a sign. For the constraint
fields, the energy related to a change of the direction of the moment
is needed, so this sign has to be put at this point.
(This is probably somewhat confusing, I'll add a better explanation
and probably some sketch to the documentation of these features.)
parent 12acdadb
No related branches found
No related tags found
No related merge requests found
......@@ -164,7 +164,7 @@ contains
double precision, dimension(3) :: dir, mag_mom_dir
double precision, dimension(3) :: old_b_constr
double precision :: mag_mom_len
double precision :: mag_mom_len, mag_mom_sign
! If the current iteration is not in the window the magnetic fields should be
! applied, return without changing the potential
......@@ -177,13 +177,16 @@ contains
dir(2) = sin(theta) * sin(phi)
dir(3) = cos(theta)
! Calculate direction and absolute value of the magnetic moment
! Calculate direction and absolute value of the magnetic moment and the
! sign the magnetic moment has in the local frame of reference
mag_mom_len = sqrt(dot_product(bfield%mag_mom(:), bfield%mag_mom(:)))
mag_mom_dir = bfield%mag_mom(:) / mag_mom_len
mag_mom_sign = sign(1., dot_product(mag_mom_dir, dir))
if (constr_mode == 3) then
bfield%bfield_constr(:) = bfield%bfield_constr(:) - &
(bfield%mag_torque(:) / mag_mom_len) * constr_bfield_mixing
( mag_mom_sign * (bfield%mag_torque(:) / mag_mom_len) * &
constr_bfield_mixing )
else if (constr_mode == 2) then
old_b_constr = bfield%bfield_constr(:)
bfield%bfield_constr(:) = old_b_constr - dot_product(old_b_constr,dir)*dir - &
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment