-
Notifications
You must be signed in to change notification settings - Fork 0
/
Parabolic_reflector.html
226 lines (194 loc) · 9.97 KB
/
Parabolic_reflector.html
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Parabolic Reflector Profile</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
label, input, select {
margin: 5px 0;
display: block;
}
button {
margin: 10px 0;
}
#output {
margin-top: 20px;
background-color: #f0f0f0;
padding: 10px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<h1>Parabolic Reflector Profile with CSV and Text File Generation</h1>
<label for="R">Dish Radius (R):</label>
<input type="number" id="R" placeholder="Enter R">
<label for="f">Focus Length (f):</label>
<input type="number" id="f" placeholder="Enter f">
<label for="N">Number of Petals (N):</label>
<input type="number" id="N" placeholder="Enter N">
<label for="M">Number of Points on Petal (M):</label>
<input type="number" id="M" placeholder="Enter M">
<label for="f_min">Minimum Frequency (f_min in GHz):</label>
<input type="number" id="f_min" placeholder="Enter f_min">
<label for="f_max">Maximum Frequency (f_max in GHz):</label>
<input type="number" id="f_max" placeholder="Enter f_max">
<label for="k">Reflector Efficiency (k):</label>
<input type="number" id="k" step="0.01" placeholder="Enter efficiency (k)" value="0.6">
<!-- Select units -->
<label for="units">Select Units:</label>
<select id="units">
<option value="mm">Millimeters (mm)</option>
<option value="cm">Centimeters (cm)</option>
<option value="m">Meters (m)</option>
</select>
<!-- Input for calculation precision (eps) -->
<label for="eps">Calculation Precision (eps):</label>
<input type="number" id="eps" placeholder="Enter eps" step="1e-12" value="1.0e-10">
<button id="generateBtn">Generate and Download Files</button>
<!-- Div for displaying output -->
<div id="output">The results will appear here...</div>
<script>
document.getElementById('generateBtn').addEventListener('click', function () {
try {
console.clear();
console.log("Button clicked, starting process...");
// Clear old output
document.getElementById('output').innerHTML = "Processing...";
// Get input values
const R = parseFloat(document.getElementById('R').value);
const f = parseFloat(document.getElementById('f').value);
const N = parseInt(document.getElementById('N').value);
const M = parseInt(document.getElementById('M').value);
const f_min = parseFloat(document.getElementById('f_min').value) * 1e9; // GHz to Hz
const f_max = parseFloat(document.getElementById('f_max').value) * 1e9; // GHz to Hz
const k = parseFloat(document.getElementById('k').value);
const units = document.getElementById('units').value;
const eps = parseFloat(document.getElementById('eps').value); // Precision for calculation
console.log("Input values received...");
// Validate input
if (isNaN(R) || isNaN(f) || isNaN(N) || isNaN(M) || isNaN(f_min) || isNaN(f_max) || isNaN(k) || isNaN(eps)) {
alert("Please enter valid values for all fields.");
return;
}
// Basic calculations (following Python code closely)
const pi = Math.PI;
const c = 2.99792458e8; // Speed of light in m/s
const lambda_max = c / f_min;
const lambda_min = c / f_max;
let radius;
if (units === 'mm') {
radius = R / 1000.0;
} else if (units === 'cm') {
radius = R / 100.0;
} else {
radius = R;
}
const Gain_min = 10.0 * Math.log10(k * (2.0 * pi * radius / lambda_max) ** 2);
const Gain_max = 10.0 * Math.log10(k * (2.0 * pi * radius / lambda_min) ** 2);
// Parabolic coefficient calculation
const a = 1.0 / (4.0 * f);
const theta = 2.0 * pi / N;
const value = Math.sqrt(1.0 + 4.0 * a ** 2 * R ** 2);
const L = (R * value / 2.0) + Math.log(2.0 * a * R + value) * f;
// Calculating radius r using method of "dividing by half"
function rl(length) {
let left = 0.0;
let right = R;
let r = (left + right) / 2.0;
let value = Math.sqrt(1.0 + 4.0 * a ** 2 * r ** 2);
value = r * value / 2.0 + Math.log(2.0 * a * r + value) * f - length;
let i = 1;
while (Math.abs(value) > eps && i < 100) {
if (value < 0.0) {
left = r;
} else if (value > 0.0) {
right = r;
}
r = (left + right) / 2.0;
value = Math.sqrt(1.0 + 4.0 * a ** 2 * r ** 2);
value = r * value / 2.0 + Math.log(2.0 * a * r + value) * f - length;
i++;
}
return r;
}
// Initialize arrays
const l = new Array(M).fill(0);
const r = new Array(M).fill(0);
const D = new Array(M).fill(0);
const eff = new Array(M).fill(0);
const q = new Array(M).fill(0);
const s = new Array(M).fill(0);
const w = new Array(M).fill(0);
l[M - 1] = L;
r[M - 1] = R;
D[M - 1] = R * Math.sqrt(1.0 + 4.0 * a ** 2 * R ** 2);
eff[0] = theta / 2.0;
eff[M - 1] = theta / (2.0 * Math.sqrt(1.0 + 4.0 * a ** 2 * R ** 2));
q[M - 1] = D[M - 1] * (1.0 - Math.cos(eff[M - 1]));
s[M - 1] = l[M - 1] - q[M - 1];
w[M - 1] = D[M - 1] * Math.sin(eff[M - 1]);
// Perform the calculations for each point
for (let i = 1; i < M - 1; i++) {
const length = i * L / (M - 1);
l[i] = length;
r[i] = rl(length);
D[i] = r[i] * Math.sqrt(1.0 + 4.0 * a ** 2 * r[i] ** 2);
eff[i] = theta / (2.0 * Math.sqrt(1.0 + 4.0 * a ** 2 * r[i] ** 2));
q[i] = D[i] * (1.0 - Math.cos(eff[i]));
s[i] = l[i] - q[i];
w[i] = D[i] * Math.sin(eff[i]);
}
// Generate CSV content
let csvContent = "l,r,D,eff,q,s,w\n";
for (let i = 0; i < M; i++) {
csvContent += `${l[i].toFixed(4)},${r[i].toFixed(4)},${D[i].toFixed(4)},${eff[i].toFixed(4)},${q[i].toFixed(4)},${s[i].toFixed(4)},${w[i].toFixed(4)}\n`;
}
// Create and download CSV file
const blobCsv = new Blob([csvContent], { type: "text/csv" });
const linkCsv = document.createElement("a");
linkCsv.href = URL.createObjectURL(blobCsv);
linkCsv.download = "Parabolic_profile_data.csv";
document.body.appendChild(linkCsv);
linkCsv.click();
document.body.removeChild(linkCsv);
console.log("CSV file generated.");
// Generate text file with design parameters
let designParameters = '';
designParameters += `Dish radius = ${R} ${units}\n`;
designParameters += `Dish height = ${(a * R ** 2).toFixed(4)} ${units}\n`;
designParameters += `Focus length of the reflector = ${f} ${units}\n`;
designParameters += `Petal length = ${L.toFixed(4)} ${units}\n`;
designParameters += `Number of petals = ${N}\n`;
designParameters += `Petal radius of curvature = ${D[M - 1].toFixed(4)} ${units}\n`;
designParameters += `Minimum frequency = ${(f_min / 1.0e9).toFixed(4)} GHz\n`;
designParameters += `Maximum frequency = ${(f_max / 1.0e9).toFixed(4)} GHz\n`;
designParameters += `Minimum wavelength = ${lambda_min.toFixed(4)} m\n`;
designParameters += `Maximum wavelength = ${lambda_max.toFixed(4)} m\n`;
designParameters += `Reflector efficiency = ${k}\n`;
designParameters += `Minimum antenna gain = ${Gain_min.toFixed(4)} dB\n`;
designParameters += `Maximum antenna gain = ${Gain_max.toFixed(4)} dB\n`;
// Create and download text file
const blobTxt = new Blob([designParameters], { type: "text/plain" });
const linkTxt = document.createElement("a");
linkTxt.href = URL.createObjectURL(blobTxt);
linkTxt.download = "Design_parameters.txt";
document.body.appendChild(linkTxt);
linkTxt.click();
document.body.removeChild(linkTxt);
console.log("Text file with design parameters generated.");
// Output result
document.getElementById('output').innerHTML = "<h3>CSV and Text files generated and downloaded.</h3>";
} catch (error) {
console.error("Error encountered:", error);
alert("An error occurred. Check the console for more information.");
}
});
</script>
</body>
</html>