-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
345 lines (304 loc) · 14.9 KB
/
index.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EV Vehicle Range Simulator</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; line-height: 1.6; }
h1, h2 { color: #333; }
.physics-section {
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 5px;
padding: 20px;
margin-bottom: 20px;
}
.equation {
background-color: #e9e9e9;
padding: 10px;
border-radius: 5px;
margin: 10px 0;
font-family: "Courier New", monospace;
}
.slider-container {
margin-bottom: 20px;
display: flex;
flex-direction: column;
}
.slider-container label {
margin-bottom: 5px;
}
.slider-container input[type="range"] {
-webkit-appearance: none;
width: 100%;
height: 15px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
transition: opacity .2s;
}
.slider-container input[type="range"]:hover {
opacity: 1;
}
.slider-container input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.slider-container input[type="range"]::-moz-range-thumb {
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
canvas { margin-top: 20px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
</style>
</head>
<body>
<h1>EV Vehicle Range Simulator</h1>
<h2>Why this simulator?</h2>
<p>Electric vehicles (EVs) are often marketed with an "EPA range," which typically refers to the vehicle's range at 55 mph. However, in practice, an EV's range decreases significantly as speed increases, primarily due to aerodynamic drag. This means that at typical highway speeds (around 75 mph), users will experience a noticeably shorter range than the advertised EPA figure.</p>
<p>This discrepancy led to the concept of an 'honest mile' for EVs, which represents a mile of range at energy use of 75 mph speed. For example, a Tesla Model X with an EPA range of 330 miles would have only about 245 'honest miles' of range. This alternative measure provides a more realistic expectation for drivers: they can expect "245 miles or more" rather than "330 miles or less" under typical highway conditions, more akin to gasoline car driver experience.</p>
<p>Another goal of this simulator was to explore what kind of EV would be needed to travel from San Francisco to Los Angeles (383 miles) at highway speeds (75 mph) on a single charge.
Initially I thought that trying to optimize for vehicle weight and
aerodynamics is the best way to achieve this. The simulation revealed that
the most practical way is to have Tesla Model X equipped with a 170 kWh battery
- adding 70kWh is would make it capable of accomplishing this feat.</p>
<p>This simulator allows you to experiment with various vehicle parameters and see how they affect range and energy consumption at different speeds, helping to understand the real-world performance of electric vehicles.</p>
<p>The simulator comes preloaded with data corresponding to Tesla Model
X (to the best of my abilities).</p>
<div class="slider-container">
<label for="cx">Drag Coefficient (Cx): <span id="cxValue">0.24</span></label>
<input type="range" id="cx" min="0.1" max="0.5" step="0.01" value="0.24">
</div>
<div class="slider-container">
<label for="frontalArea">Frontal Area (m²): <span id="frontalAreaValue">2.96</span></label>
<input type="range" id="frontalArea" min="1" max="5" step="0.1" value="2.96">
</div>
<div class="slider-container">
<label for="efficiency">Drivetrain Efficiency (%): <span id="efficiencyValue">94</span></label>
<input type="range" id="efficiency" min="80" max="100" step="1" value="94">
</div>
<div class="slider-container">
<label for="crr">Rolling Resistance Coefficient: <span id="crrValue">0.015</span></label>
<input type="range" id="crr" min="0.001" max="0.02" step="0.001" value="0.015">
</div>
<div class="slider-container">
<label for="baseMass">Base Mass (kg): <span id="baseMassValue">1800</span></label>
<input type="range" id="baseMass" min="1000" max="4000" step="50" value="1800">
</div>
<div class="slider-container">
<label for="batteryCapacity">Battery Capacity (kWh): <span id="batteryCapacityValue">100</span></label>
<input type="range" id="batteryCapacity" min="10" max="500" step="1" value="100">
</div>
<div>
<label for="batteryWeightRatio">Battery Weight Ratio (kg/kWh): </label>
<input type="number" id="batteryWeightRatio" min="1" max="20" step="0.1" value="7">
<input type="checkbox" id="autoAdjustMass" checked>
<label for="autoAdjustMass">Auto-adjust mass</label>
<br> <span id="totalMass">Total Mass: 1800 kg</span>
</div>
<table id="keySpeedsTable"></table>
<canvas id="energyConsumptionChart"></canvas>
<canvas id="rangeChart"></canvas>
<div class="physics-section">
<h2>Understanding the physics</h2>
<p>This dashboard uses basic physics principles to calculate an electric vehicle's energy consumption. Here are the key equations:</p>
<h3>1. Air Drag Force</h3>
<p>This is the force of air resistance on the vehicle:</p>
<div class="equation">
F_drag = 0.5 * Cx * A * ρ * v²
</div>
<p>Where:</p>
<ul>
<li>Cx: Drag coefficient</li>
<li>A: Frontal area (m²)</li>
<li>ρ (rho): Air density (typically 1.225 kg/m³)</li>
<li>v: Velocity (m/s)</li>
</ul>
<h3>2. Rolling Resistance Force</h3>
<p>This is the force resisting the motion when the vehicle rolls on a surface:</p>
<div class="equation">
F_rolling = Crr * m * g
</div>
<p>Where:</p>
<ul>
<li>Crr: Coefficient of rolling resistance</li>
<li>m: Mass of the vehicle (kg)</li>
<li>g: Acceleration due to gravity (9.81 m/s²)</li>
</ul>
<h3>3. Total Force</h3>
<p>The total force the vehicle must overcome is the sum of air drag and rolling resistance:</p>
<div class="equation">
F_total = F_drag + F_rolling
</div>
<h3>4. Power Required</h3>
<p>The power required to overcome these forces:</p>
<div class="equation">
P = F_total * v
</div>
<h3>5. Energy Consumption</h3>
<p>Energy consumption per unit distance, accounting for drivetrain efficiency:</p>
<div class="equation">
E = P / (v * η)
</div>
<p>Where η (eta) is the drivetrain efficiency.</p>
<h3>6. Range</h3>
<p>The theoretical range of the vehicle:</p>
<div class="equation">
Range = Battery Capacity / E
</div>
</div>
<script>
// Global variables
let cx = 0.24, frontalArea = 2.96, crr = 0.015, baseMass = 1800, efficiency = 94;
let batteryCapacity = 100, batteryWeightRatio = 7, autoAdjustMass = true, totalMass = 1800;
// Initialize charts
const energyConsumptionChart = new Chart(document.getElementById('energyConsumptionChart').getContext('2d'), {
type: 'line',
data: {
datasets: [
{ label: 'Total Energy Consumption', borderColor: 'rgb(255, 99, 132)', yAxisID: 'y' },
{ label: 'Air Drag', borderColor: 'rgb(54, 162, 235)', yAxisID: 'y' },
{ label: 'Rolling Resistance', borderColor: 'rgb(75, 192, 192)', yAxisID: 'y' },
{ label: 'Range', borderColor: 'rgb(255, 159, 64)', yAxisID: 'y1' }
]
},
options: {
scales: {
x: { title: { display: true, text: 'Speed (mph)' } },
y: { title: { display: true, text: 'Energy Consumption (Wh/mile)' } },
y1: { position: 'right', title: { display: true, text: 'Range (miles)' } }
}
}
});
const rangeChart = new Chart(document.getElementById('rangeChart').getContext('2d'), {
type: 'line',
data: {
datasets: [
{ label: 'Range at 35 mph (City)', borderColor: 'rgb(255, 99, 132)' },
{ label: 'Range at 55 mph (EPA)', borderColor: 'rgb(54, 162, 235)' },
{ label: 'Range at 75 mph (Highway)', borderColor: 'rgb(75, 192, 192)' }
]
},
options: {
scales: {
x: { title: { display: true, text: 'Battery Capacity (kWh)' } },
y: { title: { display: true, text: 'Range (miles)' } }
}
}
});
function updateTotalMass() {
if (autoAdjustMass) {
totalMass = baseMass + batteryCapacity * batteryWeightRatio;
} else {
totalMass = baseMass;
}
document.getElementById('totalMass').textContent = `Total Mass: ${totalMass.toFixed(0)} kg`;
}
// Helper functions
function calculateEnergy(speed, mass, capacity) {
const airDensity = 1.225; // kg/m³
const gravityAcceleration = 9.81; // m/s²
const speedMps = speed * 0.44704; // Convert mph to m/s
const airDragForce = 0.5 * cx * frontalArea * airDensity * Math.pow(speedMps, 2);
const rollingResistanceForce = crr * mass * gravityAcceleration;
const totalForce = airDragForce + rollingResistanceForce;
const powerRequired = totalForce * speedMps;
const powerRequiredWithEfficiency = powerRequired / (efficiency / 100);
const energyConsumption = powerRequiredWithEfficiency / speed; // In Wh/mile
const range = (capacity * 1000) / energyConsumption; // Convert kWh to Wh and calculate range in miles
return {
speed,
total: energyConsumption,
airDrag: (airDragForce * speedMps / (efficiency / 100)) / speed,
rollingResistance: (rollingResistanceForce * speedMps / (efficiency / 100)) / speed,
range: range
};
}
function updateCharts() {
updateTotalMass();
const energyData = Array.from({ length: 100 }, (_, i) => calculateEnergy(i + 1, totalMass, batteryCapacity));
energyConsumptionChart.data.labels = energyData.map(d => d.speed);
energyConsumptionChart.data.datasets[0].data = energyData.map(d => d.total);
energyConsumptionChart.data.datasets[1].data = energyData.map(d => d.airDrag);
energyConsumptionChart.data.datasets[2].data = energyData.map(d => d.rollingResistance);
energyConsumptionChart.data.datasets[3].data = energyData.map(d => d.range);
energyConsumptionChart.update();
const rangeData = Array.from({ length: 49 }, (_, i) => (i + 1) * 10);
rangeChart.data.labels = rangeData;
rangeChart.data.datasets[0].data = rangeData.map(capacity => {
const mass = autoAdjustMass ? baseMass + capacity * batteryWeightRatio : totalMass;
return calculateEnergy(35, mass, capacity).range;
});
rangeChart.data.datasets[1].data = rangeData.map(capacity => {
const mass = autoAdjustMass ? baseMass + capacity * batteryWeightRatio : totalMass;
return calculateEnergy(55, mass, capacity).range;
});
rangeChart.data.datasets[2].data = rangeData.map(capacity => {
const mass = autoAdjustMass ? baseMass + capacity * batteryWeightRatio : totalMass;
return calculateEnergy(75, mass, capacity).range;
});
rangeChart.update();
updateKeySpeedsTable();
}
function updateKeySpeedsTable() {
const keySpeedsData = [
{ ...calculateEnergy(35, totalMass, batteryCapacity), label: "City" },
{ ...calculateEnergy(55, totalMass, batteryCapacity), label: "EPA" },
{ ...calculateEnergy(75, totalMass, batteryCapacity), label: "Highway" }
];
const table = document.getElementById('keySpeedsTable');
table.innerHTML = `
<tr>
<th>Speed (mph)</th>
<th>Type</th>
<th>Energy Consumption (Wh/mile)</th>
<th>Range (miles)</th>
</tr>
${keySpeedsData.map(data => `
<tr>
<td>${data.speed}</td>
<td>${data.label}</td>
<td>${data.total.toFixed(2)}</td>
<td>${data.range.toFixed(2)}</td>
</tr>
`).join('')}
`;
}
document.querySelectorAll('input[type="range"], input[type="number"], input[type="checkbox"]').forEach(input => {
input.addEventListener('input', function() {
const value = this.type === 'checkbox' ? this.checked : parseFloat(this.value);
switch(this.id) {
case 'cx': cx = value; break;
case 'frontalArea': frontalArea = value; break;
case 'crr': crr = value; break;
case 'baseMass': baseMass = value; break;
case 'efficiency': efficiency = value; break;
case 'batteryCapacity': batteryCapacity = value; break;
case 'batteryWeightRatio': batteryWeightRatio = value; break;
case 'autoAdjustMass': autoAdjustMass = value; break;
}
if (this.type !== 'checkbox' && this.type !== 'number') {
document.getElementById(this.id + 'Value').textContent = value.toFixed(this.id === 'crr' ? 3 : 2);
}
updateCharts();
});
});
// Initial update
updateCharts();
</script>
</body>
<footer><a href="https://github.com/vprelovac/ev-sim">Source</a></footer>
</html>