-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parabolic_reflector_optimised.py
127 lines (111 loc) · 5.02 KB
/
Parabolic_reflector_optimised.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
#
# Algorithm for cutting the petals for a parabolic reflector
# Optimised code: it does not use arrays saved in the memory and writes values directly to the csv output file
#
# Dmitriy Makhnovskiy, October 2024
#
import csv
import numpy as np
pi = np.pi # pi-constant 3.1415....
c = 2.99792458e8 # speed of light in m/s
# Design parameters
units = 'mm' # your length units: mm, cm, m (use small letters)
# For R and f use the same units: mm, cm, or m
R = 500.0 # dish radius
f = 500.0 # focus length
N = 10 # number of petals used for the parabolic reflector
M = 50 # number of points on the petal template for drawing its profile
eps = 1.0e-10 # calculation precision of the roots of the non-linear equation
# The minimum and maximum frequencies used for the communication, for example, those used for 4G LTE
f_min = 0.9 # minimum frequency in GHz
f_max = 2.6 # maximum frequency in GHz
k = 0.6 # reflector efficiency (0-1)
# Calculated parameters
f_min = f_min * 1.0e9 # frequency in Hz
f_max = f_max * 1.0e9 # frequency in Hz
lambda_max = c / f_min # maximal wavelength
lambda_min = c / f_max # minimal wavelength
if units == 'mm':
radius = R / 1000.0
elif units == 'cm':
radius = R / 100.0
else:
radius = R
# Antenna gain range [Gain_min, Gain_max] dB for the given reflector efficiency k
Gain_min = 10.0 * np.log10(k * (2.0 * pi * radius / lambda_max)**2)
Gain_max = 10.0 * np.log10(k * (2.0 * pi * radius / lambda_min)**2)
a = 1.0 / (4.0 * f) # parabola coefficient, z(x) = a*x^2
theta = 2.0 * pi / N # angular width of the petal
value = np.sqrt(1.0 + 4.0 * a**2 * R**2)
L = R * value / 2.0 + np.log(2.0 * a * R + value) * f # petal length
# Calculating the radius r from the length l along the parabola using the method of "dividing by half"
def rl(length):
left = 0.0
right = R
r = (left + right) / 2.0 # initial middle point
value = np.sqrt(1.0 + 4.0 * a ** 2 * r ** 2)
value = r * value / 2.0 + np.log(2.0 * a * r + value) * f - length
i = 1 # interation counter
# Shifting the boundaries
while np.abs(value) > eps and i < 100:
if value < 0.0:
left = r
elif value > 0.0:
right = r
r = (left + right) / 2.0 # new middle point
value = np.sqrt(1.0 + 4.0 * a ** 2 * r ** 2)
value = r * value / 2.0 + np.log(2.0 * a * r + value) * f - length
i = i + 1 # number of iterations
return r
Dmax = R * np.sqrt(1.0 + 4.0 * a**2 * R**2)
effmax = theta / (2.0 * np.sqrt(1.0 + 4.0 * a**2 * R**2))
qmax = Dmax * (1.0 - np.cos(effmax))
smax = L - qmax
wmax = Dmax * np.sin(effmax)
# Open the file for writing and immediately write the header
with open('Parabolic_profile_data.csv', 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
header = ['l', 'r', 'D', 'eff', 'q', 's', 'w']
writer.writerow(header)
writer.writerow([0.0, 0.0, 0.0, theta / 2.0, 0.0, 0.0, 0.0]) # first row
# Loop for calculations and writing data as they are computed
for i in range(1, M-1):
l = i * L / (M - 1)
r = rl(l)
D = r * np.sqrt(1.0 + 4.0 * a ** 2 * r ** 2)
eff = theta / (2.0 * np.sqrt(1.0 + 4.0 * a ** 2 * r ** 2))
q = D * (1.0 - np.cos(eff))
s = l - q
w = D * np.sin(eff)
# Write the current calculated values to the file
writer.writerow([l, r, D, eff, q, s, w])
writer.writerow([L, R, Dmax, effmax, qmax, smax, wmax]) # last row
# Saving the design parameters to a txt file
Dish_radius = 'Dish radius = ' + str(R) + ' ' + units + '\n'
Dish_height = 'Dish height = ' + str(a * R**2) + ' ' + units + '\n'
Focus_length = 'Focus length of the reflector= ' + str(f) + ' ' + units + '\n'
Maximum_length = 'Petal length = ' + str(L) + ' ' + units + '\n'
N_number = 'Number of petals = ' + str(N) + '\n'
Petal_radius = 'Petal radius of curvature = ' + str(Dmax) + ' ' + units + '\n'
Frequency_min = 'Minimum frequency = ' + str(f_min / 1.0e9) + ' GHz' + '\n'
Frequency_max = 'Maximum frequency = ' + str(f_max / 1.0e9) + ' GHz' + '\n'
Wavelength_min = 'Minimum wavelength = ' + str(lambda_min) + ' m' + '\n'
Wavelength_max = 'Maximum wavelength = ' + str(lambda_max) + ' m' + '\n'
Reflector_eff = 'Reflector efficiency = ' + str(k) + '\n'
Antenna_Gain_min = 'Minimum antenna gain = ' + str(Gain_min) + ' dB' + '\n'
Antenna_Gain_max = 'Maximum antenna gain = ' + str(Gain_max) + ' dB' + '\n'
design_parameters = open('Design_parameters.txt', 'w')
design_parameters.write(Dish_radius)
design_parameters.write(Dish_height)
design_parameters.write(Focus_length)
design_parameters.write(Maximum_length)
design_parameters.write(N_number)
design_parameters.write(Petal_radius)
design_parameters.write(Frequency_min)
design_parameters.write(Frequency_max)
design_parameters.write(Wavelength_min)
design_parameters.write(Wavelength_max)
design_parameters.write(Reflector_eff)
design_parameters.write(Antenna_Gain_min)
design_parameters.write(Antenna_Gain_max)
design_parameters.close()