-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriverSustainabilityBenchmarkingWeek2.py
More file actions
66 lines (55 loc) · 2.27 KB
/
DriverSustainabilityBenchmarkingWeek2.py
File metadata and controls
66 lines (55 loc) · 2.27 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
import os
import time
import numpy as np
from driver28b import Driver28b # Assuming Driver28b is a module
from driver28c import Driver28c # Assuming Driver28c is a module
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
# TODO: PUT IN YOUR GROUP NO AND STUDENT IDs FOR THE GROUP HERE
groupNo = "16" # Replace 'X' with your group no.
groupStudentIDs = "s214960/s224409" # Replace 'Y/Z' with your student id's.
# PATHS
dirThisScript = os.path.dirname(os.path.abspath(__file__))
dirStoreResults = '/Users/apek/02623/Handinresults/'
# PARAMETERS FOR SUSTAINABILITY CALCULATION
CO2intensity = 0.285 # [kg CO2/kWh]
PowerEstimate = 60 # [kW]
# PARAMETERS FOR THE SELECTED EXERCISES (DO NOT CHANGE)
x0, y0 = 0, 0
L1, L2 = 1, 1
noelms1, noelms2 = 40, 50
lam1, lam2 = 1, 1
fun = lambda x, y: np.cos(np.pi * x) * np.cos(np.pi * y)
qt = lambda x, y: 2 * np.pi**2 * np.cos(np.pi * x) * np.cos(np.pi * y)
# EXECUTE CODE
# Call Group 30 solver
start_time = time.time()
VX, VY, EToV, U = Driver28b(x0, y0, L1, L2, noelms1, noelms2, lam1, lam2, fun, qt)
tend = time.time() - start_time
DOF1 = len(U.flatten())
x0, y0 = -1, -1
L1, L2 = 2, 2
start_time = time.time()
VX2, VY2, EToV2, U2 = Driver28c(x0, y0, L1, L2, noelms1, noelms2, lam1, lam2, fun, qt)
tend2 = time.time() - start_time
DOF2 = len(U2.flatten())
CPUtime1 = tend
CPUtime2 = tend2
CO2eq1 = CPUtime1 / 3600 * PowerEstimate / 1000 * CO2intensity
CO2eq2 = CPUtime2 / 3600 * PowerEstimate / 1000 * CO2intensity
# Visualization
fig, ax = plt.subplots(1, 2, figsize=(15, 6))
triang = Triangulation(VX, VY, EToV)
ax[0].tripcolor(triang, U, shading='flat')
ax[0].set_title(f'2.8b. Group: {groupStudentIDs}, Time: {tend:.4e}, DOF: {DOF1}, noelsm1={noelms1}, noelms2={noelms2}, CO2e={CO2eq1:.4e}')
triang2 = Triangulation(VX2, VY2, EToV2)
ax[1].tripcolor(triang2, U2, shading='flat')
ax[1].set_title(f'2.8c. Group: {groupStudentIDs}, Time: {tend2:.4e}, DOF: {DOF2}, noelsm1={noelms1}, noelms2={noelms2}, CO2e={CO2eq2:.4e}')
plt.show()
# STORE THE RESULTS
filename = f'Week2ResultsGroup{groupNo}.txt'
with open(os.path.join(dirStoreResults, filename), 'w') as file:
file.write(f'{groupNo}\n')
file.write(f'{groupStudentIDs}\n')
file.write(f'{CPUtime1:.4e} {DOF1} {CO2eq1:.4e}\n')
file.write(f'{CPUtime2:.4e} {DOF2} {CO2eq2:.4e}\n')