From 21372d11356c9be858bca9e22ce8b29e62d85e01 Mon Sep 17 00:00:00 2001
From: Nicolas Essing <n.essing@fz-juelich.de>
Date: Thu, 21 Oct 2021 15:05:01 +0200
Subject: [PATCH] Renamed angle_fixed to angle_fix_mode

This is more instructive as the interger is not a simple
switch anymore.
---
 source/KKRnano/source/CalculationData_mod.F90 |  2 +-
 .../source/NonCollinearMagnetism_mod.F90      | 12 ++---
 .../KKRnano/source/ProcessKKRresults_mod.F90  | 46 +++++++++----------
 .../NonCollinearMagnetismData_mod.F90         | 17 +++----
 source/KKRnano/source/wrappers_mod.F90        |  6 +--
 5 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/source/KKRnano/source/CalculationData_mod.F90 b/source/KKRnano/source/CalculationData_mod.F90
index abd9c75a9..51b0fe716 100644
--- a/source/KKRnano/source/CalculationData_mod.F90
+++ b/source/KKRnano/source/CalculationData_mod.F90
@@ -364,7 +364,7 @@ module CalculationData_mod
 !   in case of a NOCO calculation - read file 'nonco_angle.dat'
     if (dims%korbit == 1) then
        if(dims%nspind .NE. 2) die_here('NSPIND=2 in global.conf is mandatory for SOC calculations')
-       call loadascii(self%noco_data%theta_noco, self%noco_data%phi_noco, self%noco_data%angle_fixed, dims%naez)
+       call loadascii(self%noco_data%theta_noco, self%noco_data%phi_noco, self%noco_data%angle_fix_mode, dims%naez)
        !call store(noco, 'bin.noco.0')
     else
        if(dims%korbit .NE. 0) die_here('When not using NOCO: KORBIT in global.conf should be zero')    
diff --git a/source/KKRnano/source/NonCollinearMagnetism_mod.F90 b/source/KKRnano/source/NonCollinearMagnetism_mod.F90
index b227d1344..cf586ae2e 100644
--- a/source/KKRnano/source/NonCollinearMagnetism_mod.F90
+++ b/source/KKRnano/source/NonCollinearMagnetism_mod.F90
@@ -333,7 +333,7 @@ SUBROUTINE rhovalnew(ldorhoef,ielast,nsra,nspin,lmax,ez,wez,zat,  &
         socscale,cleb,icleb,iend,ifunm,lmsp,ncheb,  &
         npan_tot,npan_log,npan_eq,rmesh,irws,  &
         rpan_intervall,ipan_intervall,  &
-        rnew,vinsnew,thetasnew,theta,phi,angle_fixed, &
+        rnew,vinsnew,thetasnew,theta,phi,angle_fix_mode, &
         moment_x,moment_y,moment_z, &
         ipot,  &
         den_out,espv,rho2ns,r2nef,gmatn, muorb,  &
@@ -373,7 +373,7 @@ DOUBLE PRECISION, INTENT(IN)             :: vinsnew(:,:,:)
 DOUBLE PRECISION, INTENT(IN)             :: thetasnew(:,:)
 DOUBLE PRECISION, INTENT(INOUT)          :: theta
 DOUBLE PRECISION, INTENT(INOUT)          :: phi
-INTEGER (kind=1), INTENT(IN)             :: angle_fixed
+INTEGER (kind=1), INTENT(IN)             :: angle_fix_mode
 DOUBLE PRECISION, INTENT(OUT)            :: moment_x
 DOUBLE PRECISION, INTENT(OUT)            :: moment_y
 DOUBLE PRECISION, INTENT(OUT)            :: moment_z
@@ -826,7 +826,7 @@ END DO
 if (ltorque) then
   call calc_torque(bfield, vins, rho2nsc, theta, phi, lmax, rpan_intervall, ipan_intervall, &
                    npan_tot, ncheb, imt1, iend, icleb, cleb, ifunm, thetasnew, &
-                   lbfield_constr, lbfield_mt, itscf0, itscf1, iteration_number, angle_fixed)
+                   lbfield_constr, lbfield_mt, itscf0, itscf1, iteration_number, angle_fix_mode)
 end if
 
 allocate(rhotemp(irmdnew,lmpotd))
@@ -866,7 +866,7 @@ deallocate(rhotemp)
 deallocate(rhonewtemp)
 ! calculate new THETA and PHI for non-colinear
 !IF (.NOT.test('FIXMOM  ')) THEN
-if (angle_fixed == 0) then ! angle not fixed
+if (angle_fix_mode == 0) then ! angle not fixed
   rho2ns_temp(1,1)=rho2int(1)
   rho2ns_temp(2,2)=rho2int(2)
   rho2ns_temp(1,2)=rho2int(3)
@@ -917,7 +917,7 @@ if (angle_fixed == 0) then ! angle not fixed
 !  WRITE(12,*) thetanew,phinew
 
 ! Use old angles for rotation
-!if (angle_fixed == 1) then
+!if (angle_fix_mode == 1) then
 !  thetanew = theta
 !  phinew   = phi
 !endif 
@@ -973,7 +973,7 @@ DO lm1=0,lmaxd1
 END DO
 
 ! UPDATE ANGLES
-if (angle_fixed == 0) then
+if (angle_fix_mode == 0) then
 phi   = phinew
 theta = thetanew        
 endif
diff --git a/source/KKRnano/source/ProcessKKRresults_mod.F90 b/source/KKRnano/source/ProcessKKRresults_mod.F90
index 7f82afb63..ac3e854de 100644
--- a/source/KKRnano/source/ProcessKKRresults_mod.F90
+++ b/source/KKRnano/source/ProcessKKRresults_mod.F90
@@ -520,7 +520,7 @@ module ProcessKKRresults_mod
                           calc%gaunts, emesh, ldau_data, params%Volterra, &
                           dims%korbit, calc%noco_data%theta_noco(atom_id), calc%noco_data%phi_noco(atom_id), &
                           calc%noco_data%theta_noco_old(atom_id), calc%noco_data%phi_noco_old(atom_id), &
-                          calc%noco_data%angle_fixed(atom_id), calc%noco_data%moment_x(atom_id), &
+                          calc%noco_data%angle_fix_mode(atom_id), calc%noco_data%moment_x(atom_id), &
                           calc%noco_data%moment_y(atom_id), calc%noco_data%moment_z(atom_id), &
                           densities%muorb, densities%iemxd, params, calc%bfields(ila), &
                           get_muffin_tin_index(atomdata%chebmesh_ptr), iter)
@@ -603,7 +603,7 @@ module ProcessKKRresults_mod
                               atomdata%core%QC_corecharge, densities%MUORB, &
                               calc%noco_data%phi_noco(atom_id), calc%noco_data%theta_noco(atom_id), &
                               calc%noco_data%phi_noco_old(atom_id), calc%noco_data%theta_noco_old(atom_id), &
-                              calc%noco_data%angle_fixed(atom_id), &
+                              calc%noco_data%angle_fix_mode(atom_id), &
                               calc%noco_data%moment_x(atom_id),calc%noco_data%moment_y(atom_id), &
                               calc%noco_data%moment_z(atom_id))
       enddo
@@ -1070,8 +1070,8 @@ module ProcessKKRresults_mod
     integer :: lrecres1
 
     !lrecres1 = 8*43 + 16*(lmaxd+2)
-    !lrecres1 = 8*43 + 16*(lmaxd+2) + 8*(lmaxd+3)*3 + 8*2 + 1*1 ! NOCO with nonco angles and angle_fixed
-    lrecres1 = 8*43 + 16*(lmaxd+2) + 8*(lmaxd+3)*3 + 8*4 + 1*1 + 8*3 ! NOCO with old and new nonco angles, angle_fixed and moments
+    !lrecres1 = 8*43 + 16*(lmaxd+2) + 8*(lmaxd+3)*3 + 8*2 + 1*1 ! NOCO with nonco angles and angle_fix_mode
+    lrecres1 = 8*43 + 16*(lmaxd+2) + 8*(lmaxd+3)*3 + 8*4 + 1*1 + 8*3 ! NOCO with old and new nonco angles, angle_fix_mode and moments
     if (npol == 0) lrecres1 = lrecres1 + 32*(lmaxd+2)*iemxd
 
     fu = 71
@@ -1082,7 +1082,7 @@ module ProcessKKRresults_mod
   !> Write some stuff to the 'results1' file
   subroutine writeResults1File(fu, catom, charge, den, ecore, i1, npol, qc, &
                                muorb, phi_soc, theta_soc, phi_soc_old, &
-                               theta_soc_old, angle_fixed, &
+                               theta_soc_old, angle_fix_mode, &
                                moment_x, moment_y, moment_z)
                            
     integer, intent(in) :: fu !< file unit
@@ -1091,21 +1091,21 @@ module ProcessKKRresults_mod
     double precision, intent(in) :: ecore(20,2)
     integer, intent(in) :: i1, npol
     double precision, intent(in) :: qc
-    double precision, intent(in) :: muorb(:,:)    ! NOCO
-    double precision, intent(in) :: phi_soc       ! NOCO
-    double precision, intent(in) :: theta_soc     ! NOCO
-    double precision, intent(in) :: phi_soc_old   ! NOCO
-    double precision, intent(in) :: theta_soc_old ! NOCO
-    integer (kind=1), intent(in) :: angle_fixed   ! NOCO
-    double precision, intent(in) :: moment_x      ! NOCO
-    double precision, intent(in) :: moment_y      ! NOCO
-    double precision, intent(in) :: moment_z      ! NOCO
+    double precision, intent(in) :: muorb(:,:)     ! NOCO
+    double precision, intent(in) :: phi_soc        ! NOCO
+    double precision, intent(in) :: theta_soc      ! NOCO
+    double precision, intent(in) :: phi_soc_old    ! NOCO
+    double precision, intent(in) :: theta_soc_old  ! NOCO
+    integer (kind=1), intent(in) :: angle_fix_mode ! NOCO
+    double precision, intent(in) :: moment_x       ! NOCO
+    double precision, intent(in) :: moment_y       ! NOCO
+    double precision, intent(in) :: moment_z       ! NOCO
 
     if (npol == 0) then
-      write(unit=fu, rec=i1) qc,catom,charge,ecore,muorb,phi_soc,theta_soc,phi_soc_old,theta_soc_old,angle_fixed, &
+      write(unit=fu, rec=i1) qc,catom,charge,ecore,muorb,phi_soc,theta_soc,phi_soc_old,theta_soc_old,angle_fix_mode, &
               moment_x,moment_y,moment_z,den  ! write density of states (den) only when certain options set
     else
-      write(unit=fu, rec=i1) qc,catom,charge,ecore,muorb,phi_soc,theta_soc,phi_soc_old,theta_soc_old,angle_fixed, &
+      write(unit=fu, rec=i1) qc,catom,charge,ecore,muorb,phi_soc,theta_soc,phi_soc_old,theta_soc_old,angle_fix_mode, &
               moment_x,moment_y,moment_z
     endif
   endsubroutine ! write
@@ -1536,7 +1536,7 @@ module ProcessKKRresults_mod
     double precision theta_noco !NOCO
     double precision phi_noco_old !NOCO
     double precision theta_noco_old !NOCO
-    integer (kind=1) angle_fixed !NOCO
+    integer (kind=1) angle_fix_mode !NOCO
     double precision moment_x !NOCO
     double precision moment_y !NOCO
     double precision moment_z !NOCO
@@ -1571,8 +1571,8 @@ module ProcessKKRresults_mod
     max_delta_atom = 1     !NOCO
 
     !lrecres1 = 8*43 + 16*(lmax+2) ! w/o NOCO
-    !lrecres1 = 8*43 + 16*(lmax+2) + 8*(lmax+3)*3 + 8*2 + 1*1 ! NOCO with noco angles and angle_fixed option
-    lrecres1 = 8*43 + 16*(lmax+2) + 8*(lmax+3)*3 + 8*4 + 1*1 + 8*3 ! NOCO with old and new noco angles, angle_fixed option and moments
+    !lrecres1 = 8*43 + 16*(lmax+2) + 8*(lmax+3)*3 + 8*2 + 1*1 ! NOCO with noco angles and angle_fix_mode
+    lrecres1 = 8*43 + 16*(lmax+2) + 8*(lmax+3)*3 + 8*4 + 1*1 + 8*3 ! NOCO with old and new noco angles, angle_fix_mode and moments
     
     if (npol == 0) lrecres1 = lrecres1 + 32*(lmax+2)*iemxd ! dos calc.
 
@@ -1588,10 +1588,10 @@ module ProcessKKRresults_mod
         sum_moment_z = 0.0d0
       do i1 = 1, natoms
         if (npol == 0) then 
-          read(71, rec=i1) qc,catom,charge,ecore,muorb,phi_noco,theta_noco,phi_noco_old,theta_noco_old,angle_fixed, &
+          read(71, rec=i1) qc,catom,charge,ecore,muorb,phi_noco,theta_noco,phi_noco_old,theta_noco_old,angle_fix_mode, &
                   moment_x,moment_y,moment_z,den
         else
-          read(71, rec=i1) qc,catom,charge,ecore,muorb,phi_noco,theta_noco,phi_noco_old,theta_noco_old,angle_fixed, &
+          read(71, rec=i1) qc,catom,charge,ecore,muorb,phi_noco,theta_noco,phi_noco_old,theta_noco_old,angle_fix_mode, &
                   moment_x,moment_y,moment_z
         endif
        
@@ -1616,7 +1616,7 @@ module ProcessKKRresults_mod
           ! save to 'nonco_angle_out.dat' in converted units (degrees)
           write(13,*) theta_noco/(2.0D0*PI)*360.0D0, &
                       phi_noco/(2.0D0*PI)*360.0D0, &
-                      angle_fixed
+                      angle_fix_mode
 
           ! save extended information to 'nonco_moment_out.txt', e.g. for
           ! visualization
@@ -1626,7 +1626,7 @@ module ProcessKKRresults_mod
                       sqrt(moment_x**2+moment_y**2+moment_z**2), &
                       theta_noco/(2.0D0*PI)*360.0D0, &
                       phi_noco/(2.0D0*PI)*360.0D0, &
-                      angle_fixed
+                      angle_fix_mode
         sum_moment_x = sum_moment_x + moment_x
         sum_moment_y = sum_moment_y + moment_y
         sum_moment_z = sum_moment_z + moment_z
diff --git a/source/KKRnano/source/datastructures/NonCollinearMagnetismData_mod.F90 b/source/KKRnano/source/datastructures/NonCollinearMagnetismData_mod.F90
index b645ba41a..102594c4f 100644
--- a/source/KKRnano/source/datastructures/NonCollinearMagnetismData_mod.F90
+++ b/source/KKRnano/source/datastructures/NonCollinearMagnetismData_mod.F90
@@ -20,7 +20,8 @@ module NonCollinearMagnetismData_mod
     double precision, allocatable :: phi_noco(:)         !< non-collinear magnetism angle, WARNING: not synchronized between MPI threads
     double precision, allocatable :: theta_noco_old(:)   !< non-collinear magnetism angle from iteration before, WARNING: not synchronized between MPI threads
     double precision, allocatable :: phi_noco_old(:)     !< non-collinear magnetism angle from iteration before, WARNING: not synchronized between MPI threads
-    integer (kind=1), allocatable :: angle_fixed(:)      !< keep angles fixed (1) or not (0), WARNING: not synchronized between MPI threads
+    integer (kind=1), allocatable :: angle_fix_mode(:)   !< keep angles fixed (1,2,3) or not (0), using constraint magnetic fields (2,3) with a
+                                                         !< selfconsistency cycle (2) or to cancel the torque (3) WARNING: not synchronized between MPI threads
     double precision, allocatable :: moment_x(:)         !< non-collinear magnetism moment in x-direction, WARNING: not synchronized between MPI threads
     double precision, allocatable :: moment_y(:)         !< non-collinear magnetism moment in x-direction, WARNING: not synchronized between MPI threads
     double precision, allocatable :: moment_z(:)         !< non-collinear magnetism moment in x-direction, WARNING: not synchronized between MPI threads
@@ -63,7 +64,7 @@ module NonCollinearMagnetismData_mod
     ALLOCATECHECK(self%phi_noco(naez))
     ALLOCATECHECK(self%theta_noco_old(naez))
     ALLOCATECHECK(self%phi_noco_old(naez))
-    ALLOCATECHECK(self%angle_fixed(naez))
+    ALLOCATECHECK(self%angle_fix_mode(naez))
     ALLOCATECHECK(self%moment_x(naez))
     ALLOCATECHECK(self%moment_y(naez))
     ALLOCATECHECK(self%moment_z(naez))
@@ -83,7 +84,7 @@ module NonCollinearMagnetismData_mod
     DEALLOCATECHECK(self%phi_noco)
     DEALLOCATECHECK(self%theta_noco_old)
     DEALLOCATECHECK(self%phi_noco_old)
-    DEALLOCATECHECK(self%angle_fixed)
+    DEALLOCATECHECK(self%angle_fix_mode)
     DEALLOCATECHECK(self%moment_x)
     DEALLOCATECHECK(self%moment_y)
     DEALLOCATECHECK(self%moment_z)
@@ -103,7 +104,7 @@ module NonCollinearMagnetismData_mod
               self%phi_noco, &
               self%theta_noco_old, &
               self%phi_noco_old, &
-              self%angle_fixed, &
+              self%angle_fix_mode, &
               self%moment_x, &
               self%moment_y, &
               self%moment_z
@@ -126,7 +127,7 @@ module NonCollinearMagnetismData_mod
               self%phi_noco, &
               self%theta_noco_old, &
               self%phi_noco_old, &
-              self%angle_fixed, &
+              self%angle_fix_mode, &
               self%moment_x, &
               self%moment_y, &
               self%moment_z
@@ -136,11 +137,11 @@ module NonCollinearMagnetismData_mod
 
   !-----------------------------------------------------------------------------
   !>    Reads nonco_angle.dat file.
-  subroutine readNOCODataascii(theta, phi, angle_fixed, naez)
+  subroutine readNOCODataascii(theta, phi, angle_fix_mode, naez)
    
     double precision,  intent(out) :: theta (naez)
     double precision,  intent(out) :: phi (naez)
-    integer (kind=1),  intent(out) :: angle_fixed (naez) ! (1): keep angle fixed, (0): relax angle
+    integer (kind=1),  intent(out) :: angle_fix_mode (naez) ! (1): keep angle fixed, (0): relax angle
     integer, intent(in)            :: naez
   
     logical :: lread, lcheckangles
@@ -156,7 +157,7 @@ module NonCollinearMagnetismData_mod
     if (lread) then
             open(UNIT=10,FILE='nonco_angle.dat',FORM='FORMATTED')
             do I1 = 1,naez
-               read(10,*) theta(I1),phi(I1),angle_fixed(I1)
+               read(10,*) theta(I1),phi(I1),angle_fix_mode(I1)
               ! if((abs(theta(I1)).lt.(pi+eps)   .and. abs(theta(I1)).gt.eps) .or. &
               ! (abs(phi(I1)).lt.(2*pi+eps) .and. abs(phi(I1)).gt.eps)) then
               !   LCHECKANGLES = .true.
diff --git a/source/KKRnano/source/wrappers_mod.F90 b/source/KKRnano/source/wrappers_mod.F90
index cd698824c..88f360b1b 100644
--- a/source/KKRnano/source/wrappers_mod.F90
+++ b/source/KKRnano/source/wrappers_mod.F90
@@ -28,7 +28,7 @@ module wrappers_mod
   subroutine RHOVAL_wrapper(atomdata, ldorhoef, icst, nsra, rho2ns, r2nef, den, &
                             espv, gmatn, gaunts, emesh, ldau_data, method, &
                             korbit, theta_noco, phi_noco, theta_noco_old, &                          
-                            phi_noco_old, angle_fixed, &
+                            phi_noco_old, angle_fix_mode, &
                             moment_x, moment_y, moment_z, &
                             muorb, iemxd, params, bfield, imt, iteration_number) ! NOCO/SOC
     use BasisAtom_mod, only: BasisAtom
@@ -58,7 +58,7 @@ module wrappers_mod
     integer, intent(in)             :: korbit          ! NOCO
     double precision, intent(out)   :: theta_noco      ! NOCO
     double precision, intent(out)   :: phi_noco        ! NOCO
-    integer (kind=1), intent(in)    :: angle_fixed     ! NOCO
+    integer (kind=1), intent(in)    :: angle_fix_mode  ! NOCO
     double precision, intent(out)   :: theta_noco_old  ! NOCO
     double precision, intent(out)   :: phi_noco_old    ! NOCO
     double precision, intent(out)   :: moment_x        ! NOCO
@@ -94,7 +94,7 @@ module wrappers_mod
                       chebmesh%npan_tot,params%npan_log,params%npan_eq,mesh%r,mesh%irws,  &
                       chebmesh%rpan_intervall,chebmesh%ipan_intervall,  &
                       chebmesh%rnew,atomdata%potential%vinscheb,chebmesh%thetasnew, &
-                      theta_noco,phi_noco,angle_fixed,moment_x,moment_y,moment_z,&
+                      theta_noco,phi_noco,angle_fix_mode,moment_x,moment_y,moment_z,&
                       1,  &  ! ipot=1
                       den,espv,rho2ns,r2nef, gmatn(:,:,:,1), muorb,  & ! just one spin component of gmatn needed
                       atomdata%potential%lpot,lmaxd,mesh%irmd,chebmesh%irmd_new,iemxd, params%soc,params%enable_quad_prec, &
-- 
GitLab