-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
207 lines (170 loc) · 9.16 KB
/
run.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import argparse
import sys
import os
import getopt
import subprocess
from archaea.geometry.point3d import Point3d
from specklepy.api import operations
from specklepy.transports.server import ServerTransport
from specklepy.objects.geometry import Mesh, Base
from archaea_simulation.speckle.account import get_auth_speckle_client
from archaea_simulation.speckle.vtk_to_speckle import vtk_to_speckle
from archaea_simulation.simulation_objects.domain import Domain
from archaea_simulation.cfd.utils.path import get_cfd_export_path, get_bes_export_path
from archaea_simulation.simulation_objects.courtyard_building import CourtyardBuilding
def run(argv):
parser = argparse.ArgumentParser(description="Welcome to Archaea Simulation CLI program for CFD and BES calculations!")
# Define arguments
parser.add_argument("-n", "--name", default="test", help="Project name (default: test)")
parser.add_argument("-x", "--exec", action="store_true", help="Execute simulations (default: False)")
parser.add_argument("-ws", "--wind-speed", default=10.0, type=float, help="Wind speed (default: 10)")
parser.add_argument("-wd", "--wind-direction", default=0, type=float, help="Wind direction (default: 0)")
parser.add_argument("-dw", "--domain-width", default=25.0, type=float, help="Domain width (default: 25.0)")
parser.add_argument("-dd", "--domain-depth", default=25.0, type=float, help="Domain depth (default: 25.0)")
parser.add_argument("-dh", "--domain-height", default=10.0, type=float, help="Domain height (default: 10.0)")
parser.add_argument("-nos", "--number-of-storeys", default=1, type=int, help="Number of storeys (default: 1)")
parser.add_argument("-nor", "--number-of-rooms", default=3, type=int, help="Number of rooms (default: 3)")
parser.add_argument("-cw", "--courtyard-width", default=10.0, type=float, help="Courtyard width (default: 10.0)")
parser.add_argument("-rw", "--room-width", default=4.0, type=float, help="Room width (default: 4.0)")
parser.add_argument("-rd", "--room-depth", default=4.0, type=float, help="Room depth (default: 4.0)")
parser.add_argument("-rh", "--room-height", default=3.0, type=float, help="Room height (default: 3.0)")
parser.add_argument("-rwt", "--room-wall-thickness", default=0.1, type=float, help="Room wall thickness (default: 0.1)")
parser.add_argument("-rwe", "--room-window-existence", default=1, type=int, help="Room window existence (default: 1)")
parser.add_argument("-rww", "--room-window-width", default=0.6, type=float, help="Room window width (default: 0.6)")
parser.add_argument("-rwh", "--room-window-height", default=1.2, type=float, help="Room window height (default: 1.2)")
parser.add_argument("-rde", "--room-door-existence", default=1, type=int, help="Room door existence (default: 1)")
parser.add_argument("-rdw", "--room-door-width", default=0.8, type=float, help="Room door width (default: 0.8)")
parser.add_argument("-rdh", "--room-door-height", default=2.0, type=float, help="Room door height (default: 2.0)")
parser.add_argument("-ddy", "--design-day-year-file", required=True, type=str, help=".ddy file for EnergyPlus simulation")
parser.add_argument("-epw", "--energy-plus-weather-file", required=True, type=str, help=".epw file for EnergyPlus simulation")
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
# Parse arguments
args = parser.parse_args()
# Use parsed arguments
arg_name = args.name
arg_exec = args.exec
arg_wind_speed = args.wind_speed
arg_wind_direction = args.wind_direction
arg_domain_width = args.domain_width
arg_domain_depth = args.domain_depth
arg_domain_height = args.domain_height
arg_number_of_storeys = args.number_of_storeys
arg_number_of_rooms = args.number_of_rooms
arg_courtyard_width = args.courtyard_width
arg_room_width = args.room_width
arg_room_depth = args.room_depth
arg_room_height = args.room_height
arg_room_wall_thickness = args.room_wall_thickness
arg_room_window_existence = args.room_window_existence
arg_room_window_width = args.room_window_width
arg_room_window_height = args.room_window_height
arg_room_door_existence = args.room_door_existence
arg_room_door_width = args.room_door_width
arg_room_door_height = args.room_door_height
arg_ddy_path = args.design_day_year_file
arg_epw_path = args.energy_plus_weather_file
center = Point3d(0, 0, 0)
courtyard_building = CourtyardBuilding(
center,
arg_number_of_storeys,
arg_number_of_rooms,
arg_courtyard_width,
arg_room_width,
arg_room_depth,
arg_room_height,
arg_room_wall_thickness,
bool(arg_room_window_existence),
arg_room_window_width,
arg_room_window_height,
bool(arg_room_door_existence),
arg_room_door_width,
arg_room_door_height
)
# Get authorized speckle client
client = get_auth_speckle_client()
results = client.stream.search("Archaea Tests")
if not results:
new_stream_id = client.stream.create(name="Archaea Tests")
results = client.stream.search("Archaea Tests")
stream = results[0]
transport = ServerTransport(stream_id=stream.id, client=client)
branches = client.branch.list(stream.id)
is_openfoam_branch_exist = any(branch.name == "OpenFOAM" for branch in branches)
if not is_openfoam_branch_exist:
branch_id = client.branch.create(stream.id, "OpenFOAM", "Created by Archaea.")
branch = client.branch.get(stream.id, "OpenFOAM")
domain = Domain(center,
float(arg_domain_width), # x
float(arg_domain_depth), # y
float(arg_domain_height), # z
context_meshes = courtyard_building.context,
wind_direction = float(arg_wind_direction),
wind_speed = float(arg_wind_speed)
)
for zone in courtyard_building.zones:
domain.add_zone(zone)
base = Base(detachable={'Domain', 'Buildings', 'Results'})
domain_ground_mesh = Mesh()
domain_ground_mesh.units = 'm'
domain_ground_mesh.name = 'Ground'
archaea_domain_mesh = domain.export_domain_ground_single_mesh()
domain_ground_mesh.vertices = [item for sublist in archaea_domain_mesh.vertices for item in sublist]
domain_ground_mesh.faces = [item for sublist in archaea_domain_mesh.polygons for item in [len(sublist)] + sublist]
zones_mesh = Mesh()
zones_mesh.units = 'm'
zones_mesh.name = 'Buildings'
archaea_zone_mesh = domain.export_zones_to_single_mesh()
zones_mesh.vertices = [item for sublist in archaea_zone_mesh.vertices for item in sublist]
zones_mesh.faces = [item for sublist in archaea_zone_mesh.polygons for item in [len(sublist)] + sublist]
context_mesh = Mesh()
context_mesh.units = 'm'
context_mesh.name = 'Context'
archaea_context_mesh = domain.export_context_to_single_mesh()
context_mesh.vertices = [item for sublist in archaea_context_mesh.vertices for item in sublist]
context_mesh.faces = [item for sublist in archaea_context_mesh.polygons for item in [len(sublist)] + sublist]
base.Domain = [domain_ground_mesh]
base.Buildings = [zones_mesh]
base.Context = [context_mesh]
cfd_case_folder = get_cfd_export_path(arg_name)
bes_case_folder = get_bes_export_path(arg_name)
if not os.path.exists(cfd_case_folder):
os.makedirs(cfd_case_folder)
domain.create_cfd_case(cfd_case_folder)
idf_file_path = domain.create_bes_case(bes_case_folder, arg_name, arg_ddy_path, arg_epw_path)
if arg_exec:
print("##################################")
print("### BUILDING ENERGY SIMULATION ###")
print("##################################\n")
out_path = os.path.join(bes_case_folder, "run")
cmd_bes_osw = [
"/usr/local/openstudio-3.6.1/EnergyPlus/energyplus",
"-w", arg_epw_path,
"-d", out_path,
"-i", "/usr/local/openstudio-3.6.1/EnergyPlus/Energy+.idd",
"-x", idf_file_path
]
completed_process_bes = subprocess.run(cmd_bes_osw, shell=False)
print(completed_process_bes.stdout)
print("\n####################################")
print("### COMPUTATIONAL FLUID DYNAMICS ###")
print("####################################\n")
cmd_cfd = os.path.join(cfd_case_folder, './Allrun')
completed_process_cfd = subprocess.run(cmd_cfd, shell=False)
print(completed_process_cfd.stdout)
vtk_file = os.path.join(cfd_case_folder, 'postProcessing', 'cutPlaneSurface', '400', 'U_cutPlane.vtk')
legend_point = Point3d(domain.center.x + (domain.x / 2) + 5, domain.center.y - (domain.y / 2), 0)
result_meshes = vtk_to_speckle(vtk_file, legend_point)
base.Results = result_meshes
obj_id = operations.send(base, [transport])
# now create a commit on that branch with your updated data!
commit_id = client.commit.create(
stream.id,
obj_id,
branch.name,
message="Sent from Archaea.",
source_application='Archaea'
)
if __name__ == "__main__":
run(sys.argv)