-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_cases_sobol.py
192 lines (160 loc) · 5.29 KB
/
set_cases_sobol.py
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import datetime
import json
import os
import pandas as pd
import dict_update
import sample_gen
import idf_creator_floor as whole_gen
import singlezone_diss
import runep_subprocess
import output_processing
import other_crack_fac
update = dict_update.update
# Globals
FOLDER = 'sobol2'
SIZE = 155648 # 77824
OUTPUT_NAME = 'sample_sobol2'
NUM_CLUSTERS = int(os.cpu_count()/2)
# NAME_STDRD = 'whole'
NAME_STDRD_2 = 'single'
INPUT = "seed.json" # INPUT_WHOLE
# INPUT_SZ = "seed_sz.json"
EXTENSION = 'epJSON'
REMOVE_ALL_BUT = [EXTENSION, 'csv', 'err']
EPW_NAME = '~/dissertacao/BRA_SP_Sao.Paulo-Congonhas.AP.837800_TMYx.2003-2017.epw'
MONTH_MEANS = '/media/marcelo/OS/LabEEE_1-2/idf-creator/month_means_8760.csv'
OUTPUT_PROCESSED = 'means_'+FOLDER
CONCRETE_EPS = True
SOBOL = True
CRACK = .8
PARAMETERS = {
'area':[20,100],
'ratio':[.4,2.5],
'zone_height':[2.3,3.2],
'azimuth':[0,359.9],
'floor_height':[0,50],
'absorptance':[.2,.8],
'wall_u':[.5,4.4],
'wall_ct':[.22,450],
'wwr':[.1,.6],
'glass':[.2,.87],
'shading':[0,80],
'people':[.05,.2],
# 'corner_window':[0,1],
'open_fac':[0.2,1],
'roof':[0,1],
'ground':[0,1],
'bldg_ratio': [.2,1],
# 'n_floor':[1,9],
'v_ar':[0,1],
'room_type':[0,1]
}
start_time = datetime.datetime.now()
# Dependents
col_names = list(PARAMETERS)
samples_x_cluster = SIZE/NUM_CLUSTERS
name_length = '{:0'+str(len(str(SIZE)))+'.0f}'
name_length_cluster = '{:0'+str(len(str(NUM_CLUSTERS)))+'.0f}'
def add_crack(file_name, crack_fac=.1):
with open(file_name, 'r') as file:
model = json.loads(file.read())
model["AirflowNetwork:MultiZone:Surface:Crack"] = {
"door_crack": {
"air_mass_flow_coefficient_at_reference_conditions": crack_fac,
"air_mass_flow_exponent": 0.667,
"idf_max_extensible_fields": 0,
"idf_max_fields": 4
}
}
with open(file_name, 'w') as file:
file.write(json.dumps(model))
def parameter_value(key, i):
value = PARAMETERS[key][0]+(PARAMETERS[key][1]-PARAMETERS[key][0])*i
return value
print('\nCREATING DIRECTORIES\n')
os.system('mkdir '+FOLDER)
for i in range(NUM_CLUSTERS):
os.system('mkdir '+FOLDER+'/cluster'+name_length_cluster.format(i))
# Generate sample
print('\nGENERATING SAMPLE\n')
sample = sample_gen.main(SIZE, col_names, OUTPUT_NAME, sobol=SOBOL)
# sample = pd.read_csv(OUTPUT_NAME+'.csv')
if SOBOL:
sample = (sample+1)/2
# Set cases
print('\nGENERATING MODELS\n')
df = pd.DataFrame(columns=col_names+['folder','file'])
line = 0
for i in range(len(sample)):
sample_line = list(sample.iloc[i])
model_values = dict((param,parameter_value(param, sample.loc[i, param])) for param in col_names)
if model_values['roof'] > .5:
roof = True
else:
roof = False
if model_values['ground'] > .5:
ground = True
else:
ground = False
if model_values['room_type'] < .2:
# ##room_type = '1_window'
zn = 1
corner_window = True
elif model_values['room_type'] < .4:
# ##room_type = '3_window'
zn = 0
corner_window = True
elif model_values['room_type'] < .6:
# ##room_type = '1_wall'
zn = 1
corner_window = False
elif model_values['room_type'] < .8:
# ##room_type = '3_wall'
zn = 0
corner_window = False
else:
# ##room_type = '0_window'
zn = 2
corner_window = False
zone_feat = whole_gen.zone_list(model_values)
cluster_n = int(line//samples_x_cluster)
case = name_length.format(line)
# print(case)
output = (FOLDER+'/cluster'+name_length_cluster.format(cluster_n)+'/'+NAME_STDRD_2+'_{}'.format(case)+'.epJSON')
df = df.append(pd.DataFrame([sample_line+['cluster'+name_length_cluster.format(cluster_n),NAME_STDRD_2+'_{}'.format(case)+'.epJSON'.format(case)]],columns=col_names+['folder','file']))
singlezone_diss.main(
zone_area = model_values['area'],
zone_ratio = model_values['ratio'],
zone_height = model_values['zone_height'],
absorptance = model_values['absorptance'],
shading = model_values['shading'],
azimuth = model_values['azimuth'],
bldg_ratio = model_values['bldg_ratio'],
wall_u = model_values['wall_u'],
wall_ct = model_values['wall_ct'],
zn=zn,
floor_height = model_values['floor_height'],
corner_window = corner_window,
ground=ground,
roof=roof,
people=model_values['people'],
glass_fs=model_values['glass'],
wwr=model_values['wwr'],
door=False,
cp_eq = True,
open_fac=model_values['open_fac'],
input_file=INPUT ,
output=output,
outdoors=False
)
add_crack(output, CRACK)
line += 1
os.chdir(FOLDER)
print('\nRUNNING SIMULATIONS\n')
list_epjson_names = runep_subprocess.gen_list_epjson_names(NUM_CLUSTERS, EXTENSION)
runep_subprocess.main(list_epjson_names, NUM_CLUSTERS, EXTENSION, REMOVE_ALL_BUT, epw_name=EPW_NAME)
print('\nPROCESSING OUTPUT\n')
output_processing.main(df, MONTH_MEANS, OUTPUT_PROCESSED)
end_time = datetime.datetime.now()
total_time = (end_time - start_time)
print("Total processing time: " + str(total_time))