Skip to content

Commit

Permalink
Add scaling factor for smoothing to enable shut off. Screen output no…
Browse files Browse the repository at this point in the history
…w also in log file
  • Loading branch information
wingena committed Apr 26, 2024
1 parent e14124d commit baa4c1d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions source/plasma3DClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def __init__(self):
self.NCPUs = 100
self.teProfileData = None
self.neProfileData = None
self.scaleSmooth = 1.0


def allowed_class_vars(self):
Expand Down Expand Up @@ -594,17 +595,18 @@ def allowed_class_vars(self):
:model: string in [layer, conductive, convective] to select heat flux model
:NCPUs: integer, number of CPUs to use in MAFOT, default is 10
same as in plasma3D class
:scaleSmooth: float, factor to scale the range of the heat flux moving average filter
"""
self.allowed_vars = ['Lcmin', 'lcfs', 'lqCN', 'S', 'P', 'radFrac', 'qBG',
'teProfileData', 'neProfileData', 'kappa', 'model','NCPUs']
'teProfileData', 'neProfileData', 'kappa', 'model','NCPUs','scaleSmooth']


def setTypes(self):
"""
Set variable types for the stuff that isnt a string from the input file
"""
integers = ['NCPUs']
floats = ['Lcmin', 'lcfs', 'lqCN', 'S', 'P', 'radFrac', 'qBG', 'kappa']
floats = ['Lcmin', 'lcfs', 'lqCN', 'S', 'P', 'radFrac', 'qBG', 'kappa', 'scaleSmooth']
bools = []
setAllTypes(self, integers, floats, bools)

Expand Down Expand Up @@ -708,6 +710,7 @@ def print_settings(self):
print('radFrac = ' + str(self.radFrac))
print('qBG = ' + str(self.qBG))
print('kappa = ' + str(self.kappa))
print('scaleSmooth = ' + str(self.scaleSmooth))
print('#=============================================================')
print('# 3D Plasma Variables')
print('#=============================================================')
Expand All @@ -726,6 +729,7 @@ def print_settings(self):
log.info('radFrac = ' + str(self.radFrac))
log.info('qBG = ' + str(self.qBG))
log.info('kappa = ' + str(self.kappa))
log.info('scaleSmooth = ' + str(self.scaleSmooth))
log.info('#=============================================================')
log.info('# 3D Plasma Variables')
log.info('#=============================================================')
Expand Down Expand Up @@ -1206,9 +1210,8 @@ def smoothq(self, allNeighbours, centers, shadowed_mask, q = None):
smooth heat flux with neighbouring triangles within distance delta
this uses all triangles in a mesh, shadowed and unshadowed, but only smoothes the unshadowed ones
"""
delta = 0.5*self.fluxExpansion * self.S *1e-3 # in meters
delta = 0.5*self.fluxExpansion * self.S *1e-3 * self.scaleSmooth # in meters
deltasq = delta**2
print('Smoothing heat flux with moving average filter within radius: ' + str(np.round(delta*1e3,2)) + ' mm')
numberOfNeighbours = []

N_facets = len(centers)
Expand All @@ -1217,7 +1220,14 @@ def smoothq(self, allNeighbours, centers, shadowed_mask, q = None):
q = np.zeros(N_facets)
use = np.where(shadowed_mask == 0)[0]
q[use] = self.q # self.q lives on the 'use' subset


if self.scaleSmooth <= 0: # skip the smoothing and return the input unchanged
print('No smoothing of heat flux')
log.info('No smoothing of heat flux')
return q

print('Smoothing heat flux with moving average filter within radius: ' + str(np.round(delta*1e3,2)) + ' mm')
log.info('Smoothing heat flux with moving average filter within radius: ' + str(np.round(delta*1e3,2)) + ' mm')
for idx in range(N_facets):
if shadowed_mask[idx] > 0: continue # skip shadowed triangles
stack = set([idx])
Expand All @@ -1228,6 +1238,7 @@ def smoothq(self, allNeighbours, centers, shadowed_mask, q = None):

numberOfNeighbours = np.array(numberOfNeighbours)
print('Number of triangles used for smoothing: ' + str(int(numberOfNeighbours.mean()+0.5)) + ' ± ' + str(int(numberOfNeighbours.std()+0.5)))
log.info('Number of triangles used for smoothing: ' + str(int(numberOfNeighbours.mean()+0.5)) + ' ± ' + str(int(numberOfNeighbours.std()+0.5)))

return qav

Expand Down

0 comments on commit baa4c1d

Please sign in to comment.