78 lines
3.6 KiB
Makefile
78 lines
3.6 KiB
Makefile
# =============================================================================
|
||
# Makefile for TVS/TRIAC DEVSIM Simulation Pipeline
|
||
# =============================================================================
|
||
|
||
PYTHON := .venv/bin/python
|
||
|
||
.PHONY: help clean refine static sweep show-conv monitor
|
||
|
||
help:
|
||
@echo "TVS/TRIAC Simulation Pipeline Command List:"
|
||
@echo " make refine - 依據 device_config.py 中的 doping 與幾何,自動重跑: "
|
||
@echo " 1. 產生無背景場的基礎網格"
|
||
@echo " 2. 執行零偏壓 Poisson 模擬生成電場背景網格場 (device_bgmesh.pos)"
|
||
@echo " 3. 重新呼叫 Gmsh 生成自適應優化網格 (device_2d.msh)"
|
||
@echo " make static - 載入目前已優化之網格,執行熱平衡 Poisson 模擬並更新 potential 圖面"
|
||
@echo " make sweep - 載入目前已優化之網格,進行漂移-擴散 (Drift-Diffusion) 高壓掃描"
|
||
@echo " make clean - 清除所有產生的網格與暫存檔"
|
||
@echo " make show-conv - 萃取並顯示當前/歷史的相對誤差收斂趨勢 (awk 格式)"
|
||
@echo " make monitor - 即時監控背景正在跑的 sweep 收斂狀況"
|
||
|
||
# --- 網格自適應優化流程 ---
|
||
# 1. 刪除舊的 bgmesh,以確保 generate_mesh_2d.py 產生的是最乾淨的無背景場基礎網格
|
||
# 2. 執行基礎網格生成
|
||
# 3. 執行 run_refinement_2d.py 讀取基礎網格,求解電場並寫出新的 device_bgmesh.pos
|
||
# 4. 再次執行 generate_mesh_2d.py,此時會自動載入 bgmesh 並輸出最終優化網格 device_2d.msh
|
||
refine: device_config.py generate_mesh_2d.py generate_analytical_bgmesh.py
|
||
@echo ">>> [Refine] 開始進行自適應網格重構流程..."
|
||
rm -f device_bgmesh.pos
|
||
$(PYTHON) generate_mesh_2d.py
|
||
$(PYTHON) generate_analytical_bgmesh.py
|
||
$(PYTHON) generate_mesh_2d.py
|
||
@echo ">>> [Refine] 自適應優化網格生成完畢!(Saved: device_2d.msh)"
|
||
|
||
# --- 熱平衡電位求解 ---
|
||
# 依賴於對應的網格與求解腳本
|
||
static: device_2d.msh solve_static_2d.py
|
||
@echo ">>> [Static] 求解零偏壓熱平衡狀態..."
|
||
$(PYTHON) solve_static_2d.py
|
||
|
||
# --- 高壓偏壓掃描 ---
|
||
# 依賴於對應的網格與掃描腳本
|
||
# 注意:若 solve_sweep_2d.py 還不存在,可以手動新增
|
||
sweep: device_2d.msh solve_sweep_2d.py
|
||
@echo ">>> [Sweep] 備份上一次的日誌與輸出檔案..."
|
||
@rm -f sweeping.last_log simulation_time.last_log
|
||
@-[ -f sweeping.log ] && mv sweeping.log sweeping.last_log || true
|
||
@-[ -f simulation_time.log ] && mv simulation_time.log simulation_time.last_log || true
|
||
@mkdir -p last_run_outputs
|
||
@rm -f last_run_outputs/*
|
||
@-mv sweep_preview_* sweep_iv_2d.csv sweep_iv_2d.png sweep_potential_2d.png last_run_outputs/ 2>/dev/null || true
|
||
@echo ">>> [Sweep] 開始高壓偏壓漂移-擴散模擬..."
|
||
$(PYTHON) solve_sweep_2d.py > 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 有更動時,自動觸發 refine 流程
|
||
device_2d.msh: device_config.py generate_mesh_2d.py run_refinement_2d.py
|
||
$(MAKE) refine
|
||
|
||
clean:
|
||
@echo ">>> 清除暫存與網格檔案..."
|
||
rm -f *.msh *.pos *.tec *.png *.csv *.vtm *.vtu *.visit
|
||
rm -rf __pycache__ physics/__pycache__
|