Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/python/OpenFUSIONToolkit/TokaMaker/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'''
import collections
import ctypes
from os import walk
import numpy
from ._interface import *

Expand Down Expand Up @@ -1808,7 +1809,7 @@ def save_mug(self,filename):
if error_string.value != b'':
raise Exception(error_string.value)

def set_coil_current_dist(self,coil_name,curr_dist):
def set_coil_current_dist(self,coil_name,curr_dist,normalize=False):
'''! Overwrite coil with non-uniform current distribution.

@param coil_name Name of coil to modify
Expand All @@ -1822,7 +1823,7 @@ def set_coil_current_dist(self,coil_name,curr_dist):
self.dist_coils[iCoil] = curr_dist
curr_dist = numpy.ascontiguousarray(curr_dist, dtype=numpy.float64)
error_string = self._oft_env.get_c_errorbuff()
tokamaker_set_coil_current_dist(self._tMaker_ptr,c_int(iCoil+1),curr_dist,error_string)
tokamaker_set_coil_current_dist(self._tMaker_ptr,c_int(iCoil+1),curr_dist,c_bool(normalize),error_string)
if error_string.value != b'':
raise Exception(error_string.value)

Expand Down
2 changes: 1 addition & 1 deletion src/python/OpenFUSIONToolkit/TokaMaker/_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class tokamaker_settings_struct(c_struct):

# tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,error_str)
tokamaker_set_coil_current_dist = ctypes_subroutine(oftpy_lib.tokamaker_set_coil_current_dist,
[c_void_p, c_int, ctypes_numpy_array(numpy.float64,1), c_char_p])
[c_void_p, c_int, ctypes_numpy_array(numpy.float64,1), c_bool, c_char_p])
## @endcond


Expand Down
6 changes: 5 additions & 1 deletion src/python/wrappers/tokamaker_f.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,11 @@ END SUBROUTINE tokamaker_save_mug
!---------------------------------------------------------------------------
!> Overwrites default coil flux contribution to non-uniform current distribution
!------------------------------------------------------------------------------
SUBROUTINE tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,error_str) BIND(C,NAME="tokamaker_set_coil_current_dist")
SUBROUTINE tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,normalize,error_str) BIND(C,NAME="tokamaker_set_coil_current_dist")
TYPE(c_ptr), VALUE, INTENT(in) :: tMaker_ptr !< TokaMaker instance
INTEGER(c_int), VALUE, INTENT(in) :: iCoil
TYPE(c_ptr), VALUE, INTENT(in) :: curr_dist
LOGICAL(c_bool), VALUE, INTENT(in) :: normalize
CHARACTER(KIND=c_char), INTENT(out) :: error_str(OFT_ERROR_SLEN) !< Error string (empty if no error)
REAL(8), POINTER, DIMENSION(:) :: vals_tmp
INTEGER(4) :: i
Expand All @@ -1470,6 +1471,9 @@ SUBROUTINE tokamaker_set_coil_current_dist(tMaker_ptr,iCoil,curr_dist,error_str)
call tMaker_obj%gs%psi%new(tmp_vec)

CALL gs_coil_source_distributed(tMaker_obj%gs,iCoil,tmp_vec,vals_tmp)
IF (normalize) THEN
CALL tmp_vec%scale(1.0/tmp_vec%sum())
END IF

CALL tMaker_obj%gs%zerob_bc%apply(tmp_vec)
CALL gs_vacuum_solve(tMaker_obj%gs,tMaker_obj%gs%psi_coil(iCoil)%f,tmp_vec)
Expand Down
Loading