Skip to content

Commit 09b84c0

Browse files
authored
Merge pull request #7 from DeIonizedPlasma/tMaker_vcoils
TokaMaker: Add normalization to non-uniform coils
2 parents c0a93b8 + a4b491b commit 09b84c0

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/python/OpenFUSIONToolkit/TokaMaker/_core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'''
1212
import collections
1313
import ctypes
14+
from os import walk
1415
import numpy
1516
from ._interface import *
1617

@@ -1867,7 +1868,7 @@ def save_mug(self,filename):
18671868
if error_string.value != b'':
18681869
raise Exception(error_string.value)
18691870

1870-
def set_coil_current_dist(self,coil_name,curr_dist):
1871+
def set_coil_current_dist(self,coil_name,curr_dist,normalize=False):
18711872
'''! Overwrite coil with non-uniform current distribution.
18721873
18731874
@param coil_name Name of coil to modify
@@ -1881,7 +1882,7 @@ def set_coil_current_dist(self,coil_name,curr_dist):
18811882
self.dist_coils[iCoil] = curr_dist
18821883
curr_dist = numpy.ascontiguousarray(curr_dist, dtype=numpy.float64)
18831884
error_string = self._oft_env.get_c_errorbuff()
1884-
tokamaker_set_coil_current_dist(self._tMaker_ptr,c_int(iCoil+1),curr_dist,error_string)
1885+
tokamaker_set_coil_current_dist(self._tMaker_ptr,c_int(iCoil+1),curr_dist,c_bool(normalize),error_string)
18851886
if error_string.value != b'':
18861887
raise Exception(error_string.value)
18871888

src/python/OpenFUSIONToolkit/TokaMaker/_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class tokamaker_settings_struct(c_struct):
243243

244244
# tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,error_str)
245245
tokamaker_set_coil_current_dist = ctypes_subroutine(oftpy_lib.tokamaker_set_coil_current_dist,
246-
[c_void_p, c_int, ctypes_numpy_array(numpy.float64,1), c_char_p])
246+
[c_void_p, c_int, ctypes_numpy_array(numpy.float64,1), c_bool, c_char_p])
247247
## @endcond
248248

249249

src/python/wrappers/tokamaker_f.F90

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,10 +1545,11 @@ END SUBROUTINE tokamaker_save_mug
15451545
!---------------------------------------------------------------------------
15461546
!> Overwrites default coil flux contribution to non-uniform current distribution
15471547
!------------------------------------------------------------------------------
1548-
SUBROUTINE tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,error_str) BIND(C,NAME="tokamaker_set_coil_current_dist")
1548+
SUBROUTINE tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,normalize,error_str) BIND(C,NAME="tokamaker_set_coil_current_dist")
15491549
TYPE(c_ptr), VALUE, INTENT(in) :: tMaker_ptr !< TokaMaker instance
15501550
INTEGER(c_int), VALUE, INTENT(in) :: iCoil
15511551
TYPE(c_ptr), VALUE, INTENT(in) :: curr_dist
1552+
LOGICAL(c_bool), VALUE, INTENT(in) :: normalize
15521553
CHARACTER(KIND=c_char), INTENT(out) :: error_str(OFT_ERROR_SLEN) !< Error string (empty if no error)
15531554
REAL(8), POINTER, DIMENSION(:) :: vals_tmp
15541555
INTEGER(4) :: i
@@ -1562,6 +1563,9 @@ SUBROUTINE tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,error_str)
15621563
call tMaker_obj%gs%psi%new(tmp_vec)
15631564

15641565
CALL gs_coil_source_distributed(tMaker_obj%gs,iCoil,tmp_vec,vals_tmp)
1566+
IF (normalize) THEN
1567+
CALL tmp_vec%scale(1.0/tmp_vec%sum())
1568+
END IF
15651569

15661570
CALL tMaker_obj%gs%zerob_bc%apply(tmp_vec)
15671571
CALL gs_vacuum_solve(tMaker_obj%gs,tMaker_obj%gs%psi_coil(iCoil)%f,tmp_vec)

0 commit comments

Comments
 (0)