model-heatsink.py

This program is the beginning of the heatsink model. It includes a function to draw contours of a slice of the heatsink. However, the parameters for the function are slightly off. This will be corrected in class Thursday.

# -*- coding: utf-8 -*-
"""
Created on Tue Apr 20 10:06:10 2021

@author: rmontant
"""
import sys
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import Normalize
from mpl_toolkits.mplot3d import Axes3D

import heatsink

def draw_contour(axis, surface, tmin=None, tmax=None):
    if not tmin:
        tmin = np.min(surface)
    if not tmax:
        tmax = np.max(surface)
    normal = Normalize(tmin, tmax)
    pcolormap = axis.pcolormesh(surface, cmap=cm.hot, norm=normal)
#--------

def main(argv=[__name__]):
    htsnk = heatsink.HeatSink(nfins=7, gapwidth=9)

    nhotspots = 3
    for i in range(nhotspots):
        temperature = 100 + 10 * np.random.random()
        w = np.random.randint(1, htsnk.width-1)
        l = np.random.randint(1, htsnk.length-1)
        scale = 0.07 + 0.06 * np.random.random()
        print('hotspot {:d} is {:.3} at ({:d}, {:d})' \
              .format(i, scale, w, l))
        htsnk.set_hotspot(w, l, temperature, scale)

    fig = plt.figure(figsize=(8,3))
    axisL = fig.add_subplot(1, 2, 1)
    #axisL.contour(htsnk.cube[:,:,0])
    draw_contour(axisL, htsnk.cube[:,:,0], tmin=90)

    axisR = fig.add_subplot(1,2, 2)
    draw_contour(axisR, htsnk.cube[:,:,htsnk.height//2], tmin=20)

    plt.show()
#--------

if __name__ == '__main__':
    sys.exit(main(sys.argv))
#--------