-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
161 lines (126 loc) · 5.57 KB
/
main.py
File metadata and controls
161 lines (126 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import json
from PPMatLib import PPMatLib
from PPMatSolid import PPMatSolid
from PPMATPCM import PPMATPCM
import numpy as np
from utils import ConvertToPPTCM
from SCPPT import ScPPT
from FormModel import FormModel
from PRResults import PPResults
import time
def list_to_mat(data_list):
"""
Converts PowerSynth numerical lists to a list of floats.
PowerSynth sends over x, y, and z coordinate start and end locations of
features as a list of paired values as text. This function converts
them to a list of floats compatible with ParaPower formatting.
"""
data_mat = [float(data) for data in data_list[:2]]
return data_mat
def NameLookUp(ps_name):
"""
Converts PowerSynth material names to those used in ParaPower.
This function is a temporary solution only until the material library linking is completed.
"""
if not ps_name:
ps_name = 'SiC'
ps_mats = ['copper', 'Pb-Sn Solder Alloy', 'MarkeTech AlN 160', 'SiC', 'Aluminum', 'Al_N', 'Copper', 'Air']
pp_mats = ['Cu', 'SAC405', 'AlN', 'SiC', 'Al', 'AlN', 'Cu', 'AIR']
if ps_name.lower() in (mat.lower() for mat in ps_mats):
mat_map = dict(zip(ps_mats, pp_mats))
parapower_name = mat_map.get(ps_name, ps_name)
else:
parapower_name = ps_name
return parapower_name
def thermal_static(model):
InitTime = []
StepsToEstimate = 0
ComputeTime = []
S1 = ScPPT(MI = model)
S1.setup_impl()
Tprnt, T_in, MeltFrac, MeltFrac_in = S1.step_impl(ComputeTime)
if len(ComputeTime) > StepsToEstimate:
raise NotImplementedError("The number of steps to estimate is greater than the number of steps to compute.")
else:
Tprnt = np.concatenate((T_in[:,:,:,np.newaxis],Tprnt[:,:,:,np.newaxis]), axis = 3)
MeltFrac = np.concatenate((MeltFrac_in[:,:,:,np.newaxis],MeltFrac[:,:,:,np.newaxis]), axis = 3)
results = PPResults(1, "Thermal", "MeltFrac")
results.setState("Thermal", Tprnt)
results.setState("MeltFrac", MeltFrac)
return results
def get_global_max(results_object, result_type):
time = [0,0]
temporary_results = np.zeros((len(time)))
results_data = results_object.getState(result_type)
for i in range(len(time)):
results_data_slice = results_data[:,:,:,i]
if result_type.lower() == "thermal":
temporary_results[i] = np.max(results_data_slice)
return temporary_results
def get_max_by_feature(results_object, result_type):
FeatureDescr = results_object.Model["FeatureDescr"]
time = [0,0]
results_data = results_object.getState(result_type)
results = {}
for i in range(len(FeatureDescr)):
current_item = FeatureDescr[i]
feat_ind = np.where(results_object.Model["FeatureMatrix"].flatten(order="F") == i+1)
temporary_results = np.zeros((len(time)))
for j in range(len(time)):
results_data_slice = results_data[:,:,:,j]
temporary_results[j] = np.max(results_data_slice.flatten(order="F")[feat_ind])
results[current_item] = temporary_results
return results
def main(json_file, mode, type_, results_type):
with open(json_file, 'r') as file:
data = json.load(file)
data["Version"] = "V2.0"
mlib = PPMatLib()
materials = np.load("materials.npy", allow_pickle=True).item()
mat_index = [0, 1, 2, 3, 7, 8, 14]
for i in range(len(mat_index)):
# Testing: cycle through materials in old lib and add them as new materials in the new PPMatLib structure.
ind = mat_index[i]
name = materials["Material"][ind]
cte = materials["cte"][ind]
E = materials["E"][ind]
nu = materials["nu"][ind]
k = materials["k"][ind]
rho = materials["rho"][ind]
cp = materials["cp"][ind]
# Adjust thermal conductivity based on material name
if name.lower() == 'air':
k = 0.024
elif name.lower() == 'sac405':
k = 13.9
# Create new material object
new_matl = PPMatSolid(cte=cte, E=E, nu=nu, k=k, rho=rho, cp=cp)
new_matl.name = name
# Add the new material to the material library
mlib.AddMatl(new_matl)
new_matl = PPMATPCM(cte = 2, E = 1, nu = 4, k = 7, rho = 4, cp = 4)
new_matl.name = "Test Material"
mlib.AddMatl(new_matl)
data["MatLib"] = mlib
for i in range(len(data["Features"])):
# Convert PowerSynth Material Names into ParaPower Material Names
data["Features"][i]["Matl"] = NameLookUp(data["Features"][i]["Matl"])
data["Features"][i]["x"] = [value * 1e-6 for value in data["Features"][i]["x"]]
data["Features"][i]["y"] = [value * 1e-6 for value in data["Features"][i]["y"]]
data["Features"][i]["z"] = [value * 1e-6 for value in data["Features"][i]["z"]]
# Update the name of the BasePlate to be Substrate
data["Features"][0]["name"] = "substrate"
data_converted = ConvertToPPTCM(data)
PSMI = FormModel(data_converted)
if mode == "thermal":
if type_ == "static":
resobj = thermal_static(PSMI)
resobj.Model["FeatureDescr"] = PSMI["FeatureDescr"]
resobj.Model["FeatureMatrix"] = PSMI["FeatureMatrix"]
res = []
if mode == "thermal":
if results_type == "global":
ind_res = get_global_max(resobj, "Thermal")
elif results_type == "individual":
ind_res = get_max_by_feature(resobj, "Thermal")
return ind_res