Skip to content

Add configurable simulation temperature for diodes and transistors#225

Closed
esaruoho wants to merge 1 commit intopfalstad:masterfrom
esaruoho:temperature-and-comments
Closed

Add configurable simulation temperature for diodes and transistors#225
esaruoho wants to merge 1 commit intopfalstad:masterfrom
esaruoho:temperature-and-comments

Conversation

@esaruoho
Copy link
Copy Markdown

@esaruoho esaruoho commented Mar 1, 2026

Summary

Adds a configurable simulation temperature parameter, replacing the hardcoded 27°C (300.15K) thermal voltage used by diodes and transistors.

  • Fix Temperature Parameter (Use-Case: Diode) #147: The thermal voltage vt = k*T/q (Boltzmann constant * temperature / elementary charge) was hardcoded to 0.025865V (27°C) in Diode.java, DiodeModel.java, and TransistorElm.java. This PR makes it dynamic:
    • CirSim.temperature (Kelvin) and CirSim.vt (thermal voltage) as central static fields
    • CirSim.setTemperature() recalculates vt and refreshes all diode models
    • All three files now reference CirSim.vt instead of local hardcoded constants
    • Diode.vzcoef (Zener coefficient) becomes a dynamic instance variable
    • New DiodeModel.updateAllModels() propagates temperature changes to all models
    • Temperature setting in Other Options dialog (°C input)

Changes across 5 files (54 insertions, 29 deletions). Default behavior unchanged (27°C).

Test plan

  • Open Other Options, verify "Simulation Temperature (°C)" field shows 27
  • Place a diode, check I-V curve at 27°C (should match current behavior exactly)
  • Change temperature to 85°C, verify diode forward voltage decreases (~2mV/°C)
  • Change temperature to -40°C, verify diode forward voltage increases
  • Place a BJT, verify temperature affects Vbe (~2mV/°C)
  • Reset temperature to 27°C, verify original behavior restored

🤖 Generated with Claude Code

Fixes pfalstad#147: The thermal voltage (vt = k*T/q) was hardcoded to 27°C
(300.15K) in Diode.java, DiodeModel.java, and TransistorElm.java.

- Add CirSim.temperature and CirSim.vt static fields with
  setTemperature() method that recalculates vt from Boltzmann/charge
- Replace hardcoded vt in Diode.java, DiodeModel.java, TransistorElm.java
  with CirSim.vt references
- Make Diode.vzcoef dynamic (computed in setup() from CirSim.vt)
- Add DiodeModel.updateAllModels() to refresh all models on temp change
- Add temperature control in Other Options dialog (°C input)
- Changing temperature triggers updateAllModels() + updateModels()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@esaruoho
Copy link
Copy Markdown
Author

esaruoho commented Mar 2, 2026

Superseded by #243 which targets v3-dev instead of master. Closing this PR.

@esaruoho esaruoho closed this Mar 2, 2026
@esaruoho esaruoho deleted the temperature-and-comments branch March 2, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Temperature Parameter (Use-Case: Diode)

1 participant