From ae4a07aa12e568bd7d4945b775a7dfb864c9117f Mon Sep 17 00:00:00 2001
From: Nicolas Essing <n.essing@fz-juelich.de>
Date: Tue, 5 Oct 2021 09:25:07 +0200
Subject: [PATCH] Introduced the input parameters to control the constraint
 bfields.

The parameters are taken from Sascha Brinkers presentation and should
match what is implemented in KKRhost.
The names are kept as close as possible to the inputcard keywords in
KKRhost, thus they might differ from what they are called in the
KKRhost code.

Added the parameters to datastructures/InputParamsNew.txt and
generated a new datastructures/InputParams_mod.F90 using
the generate.sh skript.
---
 .../source/datastructures/InputParamsNew.txt  |  20 ++++
 .../source/datastructures/InputParams_mod.F90 | 100 ++++++++++++++++++
 2 files changed, 120 insertions(+)

diff --git a/source/KKRnano/source/datastructures/InputParamsNew.txt b/source/KKRnano/source/datastructures/InputParamsNew.txt
index 6726ca822..4f4edb2ce 100644
--- a/source/KKRnano/source/datastructures/InputParamsNew.txt
+++ b/source/KKRnano/source/datastructures/InputParamsNew.txt
@@ -124,3 +124,23 @@ d r_log 0.1D0
 d a_log 0.025D0
 ### unknown
 l enable_quad_prec .FALSE.
+### [bfields] external magnetic field, non-collinear magnetic field (called lbfield in KKRhost code)
+l noncobfield .FALSE.
+### [bfields] constraining fields, non-collinear magnetic field (called lbfield_constr in KKRhost code)
+l constr_field .FALSE.
+### [bfields] apply same field to all atoms (True) or individual fields to each atom (called lbfield_all in KKRhost code)
+l same_bfield .FALSE.
+### [bfields] apply only transversal bfield (called lbfield_trans in KKRhost code)
+l trans_bfield .FALSE.
+### [bfields] apply magnetic field only in the muffin-tin (called lbfield_mt in KKRhost code)
+l mt_bfield .FALSE.
+### [bfields] calculate magnetic torque (called ltorque in KKRhost code)
+l torque .FALSE.
+### [bfields] spin (0), orbital (1), spin+orbial (2) fields (called ibfield in KKRhost code)
+i ibfield 0
+### [bfields] type of contraint (0 = torque, 1 = magnetic moment) (called ibfield_constr in KKRhost code)
+i iconstr 0
+### [bfields] start magnetic field at iteration itscf0 (called ibfield_itscf0 in KKRhost code)
+i itbfield0 0
+### [bfields] stop applying magnetic field after iteration itscf1 (called ibfield_itscf1 in KKRhost code)
+i itbfield1 10000
diff --git a/source/KKRnano/source/datastructures/InputParams_mod.F90 b/source/KKRnano/source/datastructures/InputParams_mod.F90
index dfbfc4602..73ebc527a 100644
--- a/source/KKRnano/source/datastructures/InputParams_mod.F90
+++ b/source/KKRnano/source/datastructures/InputParams_mod.F90
@@ -78,6 +78,16 @@ module InputParams_mod
     double precision :: r_log
     double precision :: a_log
     logical :: enable_quad_prec
+    logical :: noncobfield
+    logical :: constr_field
+    logical :: same_bfield
+    logical :: trans_bfield
+    logical :: mt_bfield
+    logical :: torque
+    integer :: ibfield
+    integer :: iconstr
+    integer :: itbfield0
+    integer :: itbfield1
   endtype ! InputParams
 
 
@@ -638,6 +648,96 @@ integer function getValues(filename, self) result(ierror)
     destroy_and_return
   endif
 
+  ierror = getValue(cr, "noncobfield", self%noncobfield , def=.FALSE.)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for noncobfield. Set noncobfield to .FALSE."
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for noncobfield."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "constr_field", self%constr_field , def=.FALSE.)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for constr_field. Set constr_field to .FALSE."
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for constr_field."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "same_bfield", self%same_bfield , def=.FALSE.)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for same_bfield. Set same_bfield to .FALSE."
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for same_bfield."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "trans_bfield", self%trans_bfield , def=.FALSE.)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for trans_bfield. Set trans_bfield to .FALSE."
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for trans_bfield."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "mt_bfield", self%mt_bfield , def=.FALSE.)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for mt_bfield. Set mt_bfield to .FALSE."
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for mt_bfield."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "torque", self%torque , def=.FALSE.)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for torque. Set torque to .FALSE."
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for torque."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "ibfield", self%ibfield , def=0)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for ibfield. Set ibfield to 0"
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for ibfield."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "iconstr", self%iconstr , def=0)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for iconstr. Set iconstr to 0"
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for iconstr."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "itbfield0", self%itbfield0 , def=0)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for itbfield0. Set itbfield0 to 0"
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for itbfield0."
+    destroy_and_return
+  endif
+
+  ierror = getValue(cr, "itbfield1", self%itbfield1 , def=10000)
+  if (ierror == use_default) then
+    write(*,*) "WARNING: Bad/no value given for itbfield1. Set itbfield1 to 10000"
+    ierror = 0 ! ok, no error
+  elseif (ierror /= 0) then
+    write(*,*) "Bad/no value given for itbfield1."
+    destroy_and_return
+  endif
+
   write(*,*) "Finished reading information from input.conf"
   destroy_and_return
 #undef destroy_and_return
-- 
GitLab