heatsink.py module, as modified in class

The new "set_hotspot()" method of the HeatSink class had one small flaw: the rmax value was supposed to be multiplied by the scale parameter. Without this it is much to big, and smears the hotspots over the entire heatsink. Just another "oopsy", the correction is shown here.

# -*- coding: utf-8 -*-
"""
Created on Thu Apr 15 09:35:33 2021

@author: rmontant
"""
import numpy as np

def pdf(dx):
    return ( np.exp(-(dx**2)/2) / np.sqrt(2*np.pi) )
#--------

class HeatSink:
    surround = -1e100
    initial_temperature = 20

    def __init__(self, nfins=4, finwidth=4, gapwidth=6, baseheight=5):
        self.nfins = nfins
        self.finwidth = finwidth
        self.gapwidth = gapwidth
        self.baseheight = baseheight
        self.ngaps = self.nfins - 1

        self.width = nfins * finwidth + self.ngaps * gapwidth
        self.length = self.width
        self.height = int( 1.2 * self.width ) # 1.2 seems like a good number

        self.cube = np.empty(
            (self.width + 2, self.length + 2, self.height + 2) )

        self.form_base()
        self.form_fins()
        self.build_pointarray()
        #for p in self.coords:
        #    w, l, h, v = p
        #    self.cube[int(w),int(l),int(h)] = h / self.height

    #--------

    def form_base(self):
        self.cube[1:self.width-1, 1:self.length-1, 1:self.baseheight+1] \
            = self.initial_temperature

    def form_fins(self):
        for f in range(self.nfins):
            fstart = 1 + f * (self.gapwidth + self.finwidth)
            fend = fstart + self.finwidth
            self.cube[ \
                fstart:fend, 1:self.length-1 , self.baseheight+1:self.height-1 \
            ] = self.initial_temperature
    #--------

    def build_pointarray(self):
        coords = []
        for x in range(self.width):
            for y in range(self.length):
                for z in range(self.height):
                    if self.cube[x,y,z] > self.surround:
                        coords.append( (x,y,z, self.cube[x,y,z]) )
        self.coords = np.array( coords )

    def set_hotspot(self, w, l, t, scale):
        rmax = ((self.width**2 + self.length**2)**0.5) * scale
        for x in range(1, self.width-1):
            for y in range(1, self.length-1):
                r = ( (w-x)**2 + (l-y)**2 )**0.5
                s = pdf(r/rmax) / pdf(0)

                self.cube[x,y,0] = s * t \
                    + (1-s) * self.cube[x,y,0]
#--------