44b41698e8
- gui1d: - Created interactive 1D Diode simulator dashboard (gui1d/app.py, solve_1d.py). - Redesigned doping process step editor, layout, and centered legend plots. - Implemented state caching for I-V sweeps and grid spacing optimization. - Doubled voltage step resolution: 0.05V step for V < 1V, and V/20 step for V >= 1V. - physics (avalanche bug fix): - Fixed charge sign in Hole Continuity Equation for avalanche generation. - Created AvalancheGeneration_p in physics/new_physics.py to correctly act as a hole source. - Resolved physical breakdown current polarity and negative current leakage at high reverse bias.
134 lines
6.8 KiB
Makefile
134 lines
6.8 KiB
Makefile
# =============================================================================
|
||
# Makefile for TVS/TRIAC DEVSIM Simulation Pipeline
|
||
# =============================================================================
|
||
|
||
# Limit threads for parallel solvers to avoid starving the WSL VM resources
|
||
export OMP_NUM_THREADS = 4
|
||
export MKL_NUM_THREADS = 4
|
||
export TBB_NUM_THREADS = 4
|
||
export OPENBLAS_NUM_THREADS = 4
|
||
|
||
# Default simulation control options
|
||
avalanche ?= false
|
||
refine ?= false
|
||
refine_v_step ?= 50.0
|
||
temp ?= 300.0
|
||
|
||
PYTHON := .venv/bin/python
|
||
|
||
.PHONY: help help-detail clean mesh static sweep resume resume-bg show-conv monitor backup-run
|
||
|
||
help:
|
||
@echo "============================================================================="
|
||
@echo "TVS/TRIAC Simulation Pipeline - Developer Operations & Maintenance"
|
||
@echo "============================================================================="
|
||
@echo "Core Workflow:"
|
||
@echo " 1. make mesh - Build base grid device_2d.msh under 0V built-in field"
|
||
@echo " 2. make static - Verify equilibrium Poisson/doping convergence at 0V"
|
||
@echo " 3. make sweep - Run high-voltage bias sweep (avalanche & refinement controls)"
|
||
@echo ""
|
||
@echo "High-Level Operations:"
|
||
@echo " make static - Solve equilibrium 0V Poisson state"
|
||
@echo " make sweep - Execute bias sweep simulation"
|
||
@echo " make resume - Resume from latest or specific checkpoint"
|
||
@echo " make resume-bg - Resume simulation in the background (nohup)"
|
||
@echo ""
|
||
@echo "Maintenance & Diagnostics:"
|
||
@echo " make mesh - (Re)generate adaptive base mesh"
|
||
@echo " make clean - Clear temporary files and simulation logs"
|
||
@echo " make monitor - Live-monitor convergence log of active sweep"
|
||
@echo " make show-conv - Print last few convergence step error details"
|
||
@echo ""
|
||
@echo "Output & Backup Rules:"
|
||
@echo " output_this_run/ - Current logs, checkpoints & visualization plots"
|
||
@echo " output_last_run/ - Previous run archive (triggered by new make mesh or sweep)"
|
||
@echo " * Note: Rebuilding mesh via make mesh auto-archives output_this_run to prevent"
|
||
@echo " loading old checkpoints on the updated grid structure."
|
||
@echo ""
|
||
@echo "For detail variables (e.g., avalanche=true, refine=false, checkpoint=xxx), run:"
|
||
@echo " make help-detail"
|
||
@echo "============================================================================="
|
||
|
||
help-detail:
|
||
@echo "============================================================================="
|
||
@echo "Detailed Command Parameters and Variables:"
|
||
@echo "============================================================================="
|
||
@echo "Command Variables:"
|
||
@echo " avalanche=true|false - Toggle impact ionization (avalanche) model"
|
||
@echo " Default: false (normal sweep without avalanche)"
|
||
@echo " refine=true|false - Toggle dynamic adaptive refinement during sweep"
|
||
@echo " Default: true (enable grid splitting at milestones)"
|
||
@echo " refine_v_step=<voltage> - Set voltage interval (V) to trigger dynamic refinement"
|
||
@echo " Default: 50.0 (e.g., every 50V). Less than 1.0 disables it."
|
||
@echo " temp=<temperature> - Set device simulation temperature in Kelvin"
|
||
@echo " Default: 300.0 (e.g., room temperature)"
|
||
@echo " checkpoint=<filepath> - Specify seed/recovery pickle file to resume from"
|
||
@echo " Default: automatically searches for latest checkpoints"
|
||
@echo ""
|
||
@echo "Usage Examples:"
|
||
@echo " make sweep avalanche=true"
|
||
@echo " make sweep temp=350.0"
|
||
@echo " make sweep refine=false"
|
||
@echo " make sweep refine_v_step=25.0"
|
||
@echo " make resume checkpoint=output_this_run/seed_500V.pkl temp=350.0"
|
||
@echo " make resume-bg avalanche=true refine_v_step=30.0 temp=350.0"
|
||
@echo "============================================================================="
|
||
|
||
# --- 網格自適應優化流程 ---
|
||
# 1. 刪除舊的 bgmesh,以確保 generate_mesh_2d.py 產生的是最乾淨之基礎網格
|
||
# 2. 執行基礎網格生成
|
||
# 3. 執行 run_refinement_2d.py 讀取基礎網格,求解電場並寫出新的 device_bgmesh.pos
|
||
# 4. 再次執行 generate_mesh_2d.py,此時會自動載入 bgmesh 並輸出最終優化網格 device_2d.msh
|
||
mesh: device_config.py generate_mesh_2d.py generate_analytical_bgmesh.py
|
||
@echo ">>> [Mesh] 開始進行自適應網格重構流程..."
|
||
rm -f device_bgmesh.pos
|
||
$(PYTHON) generate_mesh_2d.py
|
||
$(PYTHON) generate_analytical_bgmesh.py
|
||
$(PYTHON) generate_mesh_2d.py
|
||
@echo ">>> [Mesh] 自適應優化網格生成完畢!(Saved: device_2d.msh)"
|
||
|
||
# --- 熱平衡電位求解 ---
|
||
# 依賴於對應的網格與求解腳本
|
||
static: device_2d.msh solve_static_2d.py
|
||
@echo ">>> [Static] 求解零偏壓熱平衡狀態 (temp=$(temp))..."
|
||
TEMP=$(temp) $(PYTHON) solve_static_2d.py
|
||
|
||
# --- 高壓偏壓掃描 ---
|
||
# 依賴於對應的網格與掃描腳本
|
||
sweep: device_2d.msh solve_sweep_recon.py
|
||
@echo ">>> [Sweep] 開始高壓偏壓漂移-擴散模擬 (avalanche=$(avalanche), refine=$(refine), refine_v_step=$(refine_v_step), temp=$(temp))..."
|
||
AVALANCHE=$(avalanche) REFINE=$(refine) REFINE_V_STEP=$(refine_v_step) TEMP=$(temp) $(PYTHON) solve_sweep_recon.py > sweeping.log 2>&1
|
||
|
||
resume:
|
||
@echo ">>> [Resume] 從指定的 Checkpoint ($(checkpoint)) 或最新的自動備份接續掃描 (avalanche=$(avalanche), refine=$(refine), refine_v_step=$(refine_v_step), temp=$(temp))..."
|
||
AVALANCHE=$(avalanche) REFINE=$(refine) REFINE_V_STEP=$(refine_v_step) TEMP=$(temp) $(PYTHON) resume_run.py $(checkpoint) >> sweeping.log 2>&1
|
||
|
||
resume-bg:
|
||
@echo ">>> [Resume-BG] 在背景從指定的 Checkpoint ($(checkpoint)) 或最新的自動備份接續掃描 (avalanche=$(avalanche), refine=$(refine), refine_v_step=$(refine_v_step), temp=$(temp))..."
|
||
AVALANCHE=$(avalanche) REFINE=$(refine) REFINE_V_STEP=$(refine_v_step) TEMP=$(temp) nohup $(PYTHON) resume_run.py $(checkpoint) >> sweeping.log 2>&1 &
|
||
|
||
# --- 萃取與監控收斂曲線 ---
|
||
show-conv:
|
||
@if [ -f sweeping.log ]; then \
|
||
awk '/Iteration:/ {printf "Iteration %s:", $$2} /Device:/ {print $$4}' sweeping.log | tail -n 10; \
|
||
else \
|
||
echo "sweeping.log does not exist."; \
|
||
fi
|
||
|
||
monitor:
|
||
@if [ -f sweeping.log ]; then \
|
||
tail -f sweeping.log | awk '/Iteration:/ {printf "Iteration %s:", $$2; fflush()} /Device:/ {print $$4; fflush()}'; \
|
||
else \
|
||
echo "sweeping.log does not exist."; \
|
||
fi
|
||
|
||
# --- 網格依賴規則 ---
|
||
# 當沒有 device_2d.msh 或 device_config.py 有更動時,自動觸發 mesh 流程
|
||
device_2d.msh: device_config.py generate_mesh_2d.py generate_analytical_bgmesh.py
|
||
$(MAKE) mesh
|
||
|
||
clean:
|
||
@echo ">>> 清除暫存與網格檔案..."
|
||
rm -f *.msh *.pos *.tec *.png *.csv *.vtm *.vtu *.visit
|
||
rm -rf __pycache__ physics/__pycache__
|