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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Gradio Interactive Demo for Thermal Cooling Performance Analysis
|
| 3 |
+
================================================================
|
| 4 |
+
|
| 5 |
+
This interactive demo allows users to explore the thermal performance
|
| 6 |
+
of the iconic jacket-and-denim ensemble under various conditions.
|
| 7 |
+
|
| 8 |
+
Run this script to launch a web interface where users can:
|
| 9 |
+
- Adjust environmental conditions
|
| 10 |
+
- Modify material properties
|
| 11 |
+
- Experiment with fit parameters
|
| 12 |
+
- Visualize thermal performance results
|
| 13 |
+
|
| 14 |
+
Requirements:
|
| 15 |
+
pip install gradio plotly thermal_model
|
| 16 |
+
|
| 17 |
+
Usage:
|
| 18 |
+
python app.py
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import gradio as gr
|
| 22 |
+
import plotly.graph_objects as go
|
| 23 |
+
import plotly.express as px
|
| 24 |
+
import pandas as pd
|
| 25 |
+
import numpy as np
|
| 26 |
+
from thermal_model import ThermalModel
|
| 27 |
+
import json
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class ThermalDemoApp:
|
| 31 |
+
"""Gradio application for interactive thermal analysis."""
|
| 32 |
+
|
| 33 |
+
def __init__(self):
|
| 34 |
+
self.model = ThermalModel()
|
| 35 |
+
self.setup_interface()
|
| 36 |
+
|
| 37 |
+
def analyze_thermal_performance(
|
| 38 |
+
self,
|
| 39 |
+
# Environmental parameters
|
| 40 |
+
T_ambient, T_skin, A_total,
|
| 41 |
+
# Body region parameters
|
| 42 |
+
A_frac_upper,
|
| 43 |
+
# Upper body fit parameters
|
| 44 |
+
f_open, f_loose,
|
| 45 |
+
# Material properties
|
| 46 |
+
k_leather, k_denim, k_cotton,
|
| 47 |
+
# Air gap thicknesses
|
| 48 |
+
d_air_gap_upper, d_air_gap_lower,
|
| 49 |
+
# Convection coefficients
|
| 50 |
+
h_open, h_loose, h_tight, h_lower
|
| 51 |
+
):
|
| 52 |
+
"""
|
| 53 |
+
Perform thermal analysis with user-specified parameters.
|
| 54 |
+
|
| 55 |
+
Returns formatted results and visualization.
|
| 56 |
+
"""
|
| 57 |
+
try:
|
| 58 |
+
# Run the thermal analysis
|
| 59 |
+
results = self.model.calculate_cooling_performance(
|
| 60 |
+
T_skin=T_skin,
|
| 61 |
+
T_ambient=T_ambient,
|
| 62 |
+
A_total=A_total,
|
| 63 |
+
A_frac_upper=A_frac_upper,
|
| 64 |
+
k_leather=k_leather,
|
| 65 |
+
k_cotton=k_cotton,
|
| 66 |
+
k_denim=k_denim,
|
| 67 |
+
d_air_gap_upper=d_air_gap_upper,
|
| 68 |
+
d_air_gap_lower=d_air_gap_lower,
|
| 69 |
+
f_open=f_open,
|
| 70 |
+
f_loose=f_loose,
|
| 71 |
+
h_open=h_open,
|
| 72 |
+
h_loose=h_loose,
|
| 73 |
+
h_tight=h_tight,
|
| 74 |
+
h_lower=h_lower
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
# Generate summary
|
| 78 |
+
summary = self.model.get_performance_summary(results)
|
| 79 |
+
|
| 80 |
+
# Create formatted output
|
| 81 |
+
output_text = self._format_results(results, summary)
|
| 82 |
+
|
| 83 |
+
# Create visualizations
|
| 84 |
+
performance_chart = self._create_performance_chart(results)
|
| 85 |
+
resistance_chart = self._create_resistance_breakdown(results)
|
| 86 |
+
|
| 87 |
+
return output_text, performance_chart, resistance_chart
|
| 88 |
+
|
| 89 |
+
except Exception as e:
|
| 90 |
+
error_msg = f"❌ **Error in calculation:** {str(e)}\n\nPlease check your input parameters."
|
| 91 |
+
empty_fig = go.Figure()
|
| 92 |
+
empty_fig.add_annotation(text="Error in calculation",
|
| 93 |
+
x=0.5, y=0.5, showarrow=False)
|
| 94 |
+
return error_msg, empty_fig, empty_fig
|
| 95 |
+
|
| 96 |
+
def _format_results(self, results, summary):
|
| 97 |
+
"""Format results for display in the Gradio interface."""
|
| 98 |
+
output = []
|
| 99 |
+
|
| 100 |
+
# Header
|
| 101 |
+
output.append("# 🔥 Thermal Analysis Results")
|
| 102 |
+
output.append("")
|
| 103 |
+
|
| 104 |
+
# Key metrics
|
| 105 |
+
output.append("## 📊 Key Performance Metrics")
|
| 106 |
+
output.append(f"- **Total Heat Dissipation:** {results.total_heat_dissipation:.1f} W")
|
| 107 |
+
output.append(f"- **Thermal Efficiency:** {results.thermal_efficiency:.1f}% of 100W target")
|
| 108 |
+
output.append(f"- **Performance Status:** {results.performance_status}")
|
| 109 |
+
output.append("")
|
| 110 |
+
|
| 111 |
+
# Detailed breakdown
|
| 112 |
+
output.append("## 🔧 Detailed Analysis")
|
| 113 |
+
output.append(f"- **Upper Body Contribution:** {results.heat_dissipation_upper:.1f} W")
|
| 114 |
+
output.append(f"- **Lower Body Contribution:** {results.heat_dissipation_lower:.1f} W")
|
| 115 |
+
output.append(f"- **Upper Body Resistance:** {results.R_upper_equivalent:.3f} m²·K/W")
|
| 116 |
+
output.append(f"- **Lower Body Resistance:** {results.R_lower_total:.3f} m²·K/W")
|
| 117 |
+
output.append("")
|
| 118 |
+
|
| 119 |
+
# Engineering assessment
|
| 120 |
+
output.append("## 🎯 Engineering Assessment")
|
| 121 |
+
output.append(summary["Engineering Assessment"])
|
| 122 |
+
|
| 123 |
+
return "\n".join(output)
|
| 124 |
+
|
| 125 |
+
def _create_performance_chart(self, results):
|
| 126 |
+
"""Create a performance visualization chart."""
|
| 127 |
+
# Data for the chart
|
| 128 |
+
categories = ['Upper Body', 'Lower Body', 'Total System']
|
| 129 |
+
heat_dissipation = [
|
| 130 |
+
results.heat_dissipation_upper,
|
| 131 |
+
results.heat_dissipation_lower,
|
| 132 |
+
results.total_heat_dissipation
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
# Create bar chart
|
| 136 |
+
fig = go.Figure()
|
| 137 |
+
|
| 138 |
+
# Add bars
|
| 139 |
+
fig.add_trace(go.Bar(
|
| 140 |
+
x=categories[:2],
|
| 141 |
+
y=heat_dissipation[:2],
|
| 142 |
+
name='Heat Dissipation',
|
| 143 |
+
marker_color=['#FF6B6B', '#4ECDC4'],
|
| 144 |
+
text=[f'{val:.1f}W' for val in heat_dissipation[:2]],
|
| 145 |
+
textposition='auto'
|
| 146 |
+
))
|
| 147 |
+
|
| 148 |
+
# Add target line
|
| 149 |
+
fig.add_hline(y=100, line_dash="dash", line_color="red",
|
| 150 |
+
annotation_text="100W TDP Target")
|
| 151 |
+
|
| 152 |
+
# Add total as separate trace
|
| 153 |
+
fig.add_trace(go.Bar(
|
| 154 |
+
x=[categories[2]],
|
| 155 |
+
y=[heat_dissipation[2]],
|
| 156 |
+
name='Total Performance',
|
| 157 |
+
marker_color='#45B7D1',
|
| 158 |
+
text=f'{heat_dissipation[2]:.1f}W',
|
| 159 |
+
textposition='auto'
|
| 160 |
+
))
|
| 161 |
+
|
| 162 |
+
fig.update_layout(
|
| 163 |
+
title='Thermal Performance Breakdown',
|
| 164 |
+
xaxis_title='System Component',
|
| 165 |
+
yaxis_title='Heat Dissipation (W)',
|
| 166 |
+
showlegend=False,
|
| 167 |
+
height=400,
|
| 168 |
+
template='plotly_white'
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
return fig
|
| 172 |
+
|
| 173 |
+
def _create_resistance_breakdown(self, results):
|
| 174 |
+
"""Create thermal resistance breakdown visualization."""
|
| 175 |
+
# Data for resistance comparison
|
| 176 |
+
resistances = {
|
| 177 |
+
'Upper Body': results.R_upper_equivalent,
|
| 178 |
+
'Lower Body': results.R_lower_total
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
# Create pie chart
|
| 182 |
+
fig = go.Figure(data=[go.Pie(
|
| 183 |
+
labels=list(resistances.keys()),
|
| 184 |
+
values=list(resistances.values()),
|
| 185 |
+
hole=0.3,
|
| 186 |
+
marker_colors=['#FF6B6B', '#4ECDC4']
|
| 187 |
+
)])
|
| 188 |
+
|
| 189 |
+
fig.update_layout(
|
| 190 |
+
title='Thermal Resistance Distribution',
|
| 191 |
+
height=400,
|
| 192 |
+
template='plotly_white'
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
return fig
|
| 196 |
+
|
| 197 |
+
def parameter_sweep_analysis(self, param_name, param_range):
|
| 198 |
+
"""Perform parameter sweep analysis for sensitivity study."""
|
| 199 |
+
base_params = {
|
| 200 |
+
'T_ambient': 26.0,
|
| 201 |
+
'T_skin': 33.5,
|
| 202 |
+
'A_total': 1.8,
|
| 203 |
+
'A_frac_upper': 0.6,
|
| 204 |
+
'f_open': 0.35,
|
| 205 |
+
'f_loose': 0.50
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
results_list = []
|
| 209 |
+
param_values = np.linspace(param_range[0], param_range[1], 20)
|
| 210 |
+
|
| 211 |
+
for value in param_values:
|
| 212 |
+
params = base_params.copy()
|
| 213 |
+
params[param_name] = value
|
| 214 |
+
|
| 215 |
+
try:
|
| 216 |
+
result = self.model.calculate_cooling_performance(**params)
|
| 217 |
+
results_list.append({
|
| 218 |
+
param_name: value,
|
| 219 |
+
'Heat_Dissipation': result.total_heat_dissipation,
|
| 220 |
+
'Thermal_Efficiency': result.thermal_efficiency
|
| 221 |
+
})
|
| 222 |
+
except:
|
| 223 |
+
continue
|
| 224 |
+
|
| 225 |
+
return pd.DataFrame(results_list)
|
| 226 |
+
|
| 227 |
+
def setup_interface(self):
|
| 228 |
+
"""Set up the Gradio interface."""
|
| 229 |
+
|
| 230 |
+
# Custom CSS for styling
|
| 231 |
+
css = """
|
| 232 |
+
.gradio-container {
|
| 233 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 234 |
+
}
|
| 235 |
+
.title {
|
| 236 |
+
text-align: center;
|
| 237 |
+
color: #2C3E50;
|
| 238 |
+
margin-bottom: 20px;
|
| 239 |
+
}
|
| 240 |
+
.description {
|
| 241 |
+
text-align: center;
|
| 242 |
+
color: #7F8C8D;
|
| 243 |
+
margin-bottom: 30px;
|
| 244 |
+
}
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
with gr.Blocks(css=css, title="Jensen-TDP: Thermal Analysis Demo") as self.demo:
|
| 248 |
+
|
| 249 |
+
# Header
|
| 250 |
+
gr.Markdown("""
|
| 251 |
+
# 🔥 Jensen-TDP: Thermal Cooling Performance Analyzer
|
| 252 |
+
|
| 253 |
+
**Interactive demo for analyzing the passive cooling performance of an iconic jacket-and-denim ensemble**
|
| 254 |
+
|
| 255 |
+
Based on the research paper: *"Thermal Overload: A Holistic Analysis of the Jacket-and-Denim Heatsink Paradigm"*
|
| 256 |
+
|
| 257 |
+
---
|
| 258 |
+
""")
|
| 259 |
+
|
| 260 |
+
with gr.Row():
|
| 261 |
+
with gr.Column(scale=1):
|
| 262 |
+
gr.Markdown("## 🌡️ Environmental Conditions")
|
| 263 |
+
|
| 264 |
+
T_ambient = gr.Slider(
|
| 265 |
+
minimum=15, maximum=35, value=26.0, step=0.5,
|
| 266 |
+
label="Ambient Temperature (°C)",
|
| 267 |
+
info="Environmental temperature"
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
T_skin = gr.Slider(
|
| 271 |
+
minimum=30, maximum=37, value=33.5, step=0.1,
|
| 272 |
+
label="Skin Temperature (°C)",
|
| 273 |
+
info="Body surface temperature"
|
| 274 |
+
)
|
| 275 |
+
|
| 276 |
+
A_total = gr.Slider(
|
| 277 |
+
minimum=1.2, maximum=2.5, value=1.8, step=0.1,
|
| 278 |
+
label="Total Body Surface Area (m²)",
|
| 279 |
+
info="Total heat transfer area"
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
gr.Markdown("## 👕 Upper Body Configuration")
|
| 283 |
+
|
| 284 |
+
A_frac_upper = gr.Slider(
|
| 285 |
+
minimum=0.5, maximum=0.7, value=0.6, step=0.01,
|
| 286 |
+
label="Upper Body Area Fraction",
|
| 287 |
+
info="Fraction of total area (upper body)"
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
f_open = gr.Slider(
|
| 291 |
+
minimum=0.1, maximum=0.6, value=0.35, step=0.05,
|
| 292 |
+
label="Open Front Zone Fraction",
|
| 293 |
+
info="Jacket front opening (chimney effect)"
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
f_loose = gr.Slider(
|
| 297 |
+
minimum=0.2, maximum=0.7, value=0.50, step=0.05,
|
| 298 |
+
label="Loose Fit Zone Fraction",
|
| 299 |
+
info="Side areas with air gap"
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
with gr.Column(scale=1):
|
| 303 |
+
gr.Markdown("## 🧥 Material Properties")
|
| 304 |
+
|
| 305 |
+
k_leather = gr.Slider(
|
| 306 |
+
minimum=0.08, maximum=0.25, value=0.15, step=0.01,
|
| 307 |
+
label="Leather Thermal Conductivity (W/m·K)",
|
| 308 |
+
info="Calfskin leather properties"
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
k_denim = gr.Slider(
|
| 312 |
+
minimum=0.04, maximum=0.12, value=0.06, step=0.01,
|
| 313 |
+
label="Denim Thermal Conductivity (W/m·K)",
|
| 314 |
+
info="Cotton denim fabric"
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
k_cotton = gr.Slider(
|
| 318 |
+
minimum=0.03, maximum=0.08, value=0.05, step=0.005,
|
| 319 |
+
label="Cotton T-shirt Conductivity (W/m·K)",
|
| 320 |
+
info="Base layer fabric"
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
+
gr.Markdown("## 💨 Air Gap & Convection")
|
| 324 |
+
|
| 325 |
+
d_air_gap_upper = gr.Slider(
|
| 326 |
+
minimum=0.002, maximum=0.020, value=0.01, step=0.002,
|
| 327 |
+
label="Upper Air Gap Thickness (m)",
|
| 328 |
+
info="Jacket interior air space"
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
d_air_gap_lower = gr.Slider(
|
| 332 |
+
minimum=0.001, maximum=0.010, value=0.005, step=0.001,
|
| 333 |
+
label="Lower Air Gap Thickness (m)",
|
| 334 |
+
info="Pants interior air space"
|
| 335 |
+
)
|
| 336 |
+
|
| 337 |
+
h_open = gr.Slider(
|
| 338 |
+
minimum=8, maximum=25, value=15.0, step=1.0,
|
| 339 |
+
label="Open Zone Convection (W/m²·K)",
|
| 340 |
+
info="Chimney effect strength"
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
h_lower = gr.Slider(
|
| 344 |
+
minimum=2, maximum=10, value=5.0, step=0.5,
|
| 345 |
+
label="Lower Body Convection (W/m²·K)",
|
| 346 |
+
info="Pants external convection"
|
| 347 |
+
)
|
| 348 |
+
|
| 349 |
+
h_loose = gr.Slider(
|
| 350 |
+
minimum=3, maximum=12, value=6.0, step=0.5,
|
| 351 |
+
label="Loose Zone Convection (W/m²·K)",
|
| 352 |
+
info="Jacket side areas"
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
h_tight = gr.Slider(
|
| 356 |
+
minimum=2, maximum=8, value=3.5, step=0.5,
|
| 357 |
+
label="Tight Zone Convection (W/m²·K)",
|
| 358 |
+
info="Close-fitting areas"
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
# Analysis button
|
| 362 |
+
analyze_btn = gr.Button("🔬 Run Thermal Analysis", variant="primary", size="lg")
|
| 363 |
+
|
| 364 |
+
# Results section
|
| 365 |
+
with gr.Row():
|
| 366 |
+
with gr.Column(scale=1):
|
| 367 |
+
results_output = gr.Markdown()
|
| 368 |
+
|
| 369 |
+
with gr.Column(scale=1):
|
| 370 |
+
performance_plot = gr.Plot()
|
| 371 |
+
resistance_plot = gr.Plot()
|
| 372 |
+
|
| 373 |
+
# Preset scenarios
|
| 374 |
+
gr.Markdown("## 🎛️ Preset Scenarios")
|
| 375 |
+
|
| 376 |
+
with gr.Row():
|
| 377 |
+
scenario_btns = [
|
| 378 |
+
gr.Button("❄️ Cold Office (20°C)", size="sm"),
|
| 379 |
+
gr.Button("🌡️ Standard Room (26°C)", size="sm"),
|
| 380 |
+
gr.Button("🔥 Warm Environment (30°C)", size="sm"),
|
| 381 |
+
gr.Button("🏃 Active/Exercise Mode", size="sm")
|
| 382 |
+
]
|
| 383 |
+
|
| 384 |
+
# Event handlers
|
| 385 |
+
analyze_btn.click(
|
| 386 |
+
fn=self.analyze_thermal_performance,
|
| 387 |
+
inputs=[
|
| 388 |
+
T_ambient, T_skin, A_total, A_frac_upper,
|
| 389 |
+
f_open, f_loose,
|
| 390 |
+
k_leather, k_denim, k_cotton,
|
| 391 |
+
d_air_gap_upper, d_air_gap_lower,
|
| 392 |
+
h_open, h_loose, h_tight, h_lower
|
| 393 |
+
],
|
| 394 |
+
outputs=[results_output, performance_plot, resistance_plot]
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
# Preset scenario handlers
|
| 398 |
+
scenario_btns[0].click( # Cold office
|
| 399 |
+
lambda: self._apply_preset("cold"),
|
| 400 |
+
outputs=[T_ambient, h_open, h_lower]
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
scenario_btns[1].click( # Standard room
|
| 404 |
+
lambda: self._apply_preset("standard"),
|
| 405 |
+
outputs=[T_ambient, h_open, h_lower]
|
| 406 |
+
)
|
| 407 |
+
|
| 408 |
+
scenario_btns[2].click( # Warm environment
|
| 409 |
+
lambda: self._apply_preset("warm"),
|
| 410 |
+
outputs=[T_ambient, h_open, h_lower]
|
| 411 |
+
)
|
| 412 |
+
|
| 413 |
+
scenario_btns[3].click( # Active mode
|
| 414 |
+
lambda: self._apply_preset("active"),
|
| 415 |
+
outputs=[T_skin, h_open, h_loose, h_lower]
|
| 416 |
+
)
|
| 417 |
+
|
| 418 |
+
# Footer
|
| 419 |
+
gr.Markdown("""
|
| 420 |
+
---
|
| 421 |
+
|
| 422 |
+
**About this model:** This analysis treats clothing as a thermal management system,
|
| 423 |
+
modeling heat transfer through multiple parallel and series resistance networks.
|
| 424 |
+
The model accounts for material conduction, air gaps, and natural convection effects.
|
| 425 |
+
|
| 426 |
+
**Disclaimer:** This is a simplified engineering model for educational and
|
| 427 |
+
entertainment purposes. Real thermal behavior involves many additional factors.
|
| 428 |
+
|
| 429 |
+
🔗 [GitHub Repository](https://github.com/NewJerseyStyle/Jensen-TDP) |
|
| 430 |
+
📄 [Read the Paper](https://www.arxiv.org/)
|
| 431 |
+
""")
|
| 432 |
+
|
| 433 |
+
def _apply_preset(self, scenario):
|
| 434 |
+
"""Apply preset parameter configurations."""
|
| 435 |
+
presets = {
|
| 436 |
+
"cold": (20.0, 18.0, 4.0), # T_ambient, h_open, h_lower
|
| 437 |
+
"standard": (26.0, 15.0, 5.0), # Default values
|
| 438 |
+
"warm": (30.0, 12.0, 6.0), # Reduced convection
|
| 439 |
+
"active": (None, None, None) # Special case handled below
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
if scenario == "active":
|
| 443 |
+
return 35.0, 20.0, 8.0, 7.0 # T_skin, h_open, h_loose, h_lower
|
| 444 |
+
else:
|
| 445 |
+
return presets[scenario]
|
| 446 |
+
|
| 447 |
+
def launch(self, **kwargs):
|
| 448 |
+
"""Launch the Gradio interface."""
|
| 449 |
+
return self.demo.launch(**kwargs)
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def create_parameter_sensitivity_analysis():
|
| 453 |
+
"""Create a parameter sensitivity analysis visualization."""
|
| 454 |
+
model = ThermalModel()
|
| 455 |
+
|
| 456 |
+
# Test different ambient temperatures
|
| 457 |
+
temps = np.arange(15, 35, 1)
|
| 458 |
+
cooling_performance = []
|
| 459 |
+
|
| 460 |
+
for temp in temps:
|
| 461 |
+
try:
|
| 462 |
+
result = model.calculate_cooling_performance(T_ambient=temp)
|
| 463 |
+
cooling_performance.append(result.total_heat_dissipation)
|
| 464 |
+
except:
|
| 465 |
+
cooling_performance.append(0)
|
| 466 |
+
|
| 467 |
+
# Create sensitivity plot
|
| 468 |
+
fig = go.Figure()
|
| 469 |
+
|
| 470 |
+
fig.add_trace(go.Scatter(
|
| 471 |
+
x=temps,
|
| 472 |
+
y=cooling_performance,
|
| 473 |
+
mode='lines+markers',
|
| 474 |
+
name='Cooling Performance',
|
| 475 |
+
line=dict(color='#45B7D1', width=3),
|
| 476 |
+
marker=dict(size=6)
|
| 477 |
+
))
|
| 478 |
+
|
| 479 |
+
fig.add_hline(y=100, line_dash="dash", line_color="red",
|
| 480 |
+
annotation_text="100W TDP Target")
|
| 481 |
+
|
| 482 |
+
fig.update_layout(
|
| 483 |
+
title='Cooling Performance vs Ambient Temperature',
|
| 484 |
+
xaxis_title='Ambient Temperature (°C)',
|
| 485 |
+
yaxis_title='Heat Dissipation Capacity (W)',
|
| 486 |
+
template='plotly_white',
|
| 487 |
+
height=400
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
return fig
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def main():
|
| 494 |
+
"""Main function to launch the demo application."""
|
| 495 |
+
print("🚀 Launching Jensen-TDP Thermal Analysis Demo...")
|
| 496 |
+
print("📊 Initializing thermal model and interface...")
|
| 497 |
+
|
| 498 |
+
app = ThermalDemoApp()
|
| 499 |
+
|
| 500 |
+
print("✅ Ready! Opening browser interface...")
|
| 501 |
+
|
| 502 |
+
# Launch with public sharing option
|
| 503 |
+
app.launch(
|
| 504 |
+
share=False, # Set to True for public sharing
|
| 505 |
+
server_name="0.0.0.0",
|
| 506 |
+
server_port=7860,
|
| 507 |
+
show_error=True
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
if __name__ == "__main__":
|
| 512 |
+
main()
|