test-heatsink.py

This initial, experimental program demonstrates some features of the "heatsink" module. It's a dead end, further work will be on "model-heatsink.py".

# -*- coding: utf-8 -*-
"""
Created on Thu Apr 15 09:53:23 2021

@author: rmontant
"""
import numpy as np
import matplotlib.pyplot as plt
#from mpl_toolkits.mplot3d import Axes3D   # needed for '3d" projection

import heatsink    # import my file that defines the Heatsink class

myhs = []
for n in range(5):
    myhs.append( heatsink.Heatsink())

for n, hs in enumerate(myhs):
    print('cube {:d}'.format(n), hs.cube.shape)
    print('     ', hs.coords.shape)



def draw_heatsink(axis, heatsink):
    # define a reddish color
    def rgb(frac, transparency=0.2):
        return (np.sqrt(frac), frac, frac, transparency)
    color  = np.array( \
        [rgb(0.75*(v/heatsink.height)) \
             for v in heatsink.coords[ : ,3]
        ] )
    axis.scatter( \
        heatsink.coords[ : , 0],
        heatsink.coords[ : , 1],
        heatsink.coords[ : , 2],
        color=color
    )

fig = plt.figure()
axis = fig.add_subplot(111, projection='3d')
draw_heatsink(axis, myhs[0])