798 lines
42 KiB
Python
798 lines
42 KiB
Python
import pickle
|
|
import os
|
|
import sys
|
|
import glob
|
|
import gc
|
|
|
|
# Limit the thread count for parallel solvers to prevent WSL from resource starvation/disconnecting
|
|
os.environ["OMP_NUM_THREADS"] = "6"
|
|
os.environ["MKL_NUM_THREADS"] = "6"
|
|
os.environ["TBB_NUM_THREADS"] = "6"
|
|
os.environ["OPENBLAS_NUM_THREADS"] = "6"
|
|
# Disable MKL internal memory manager to prevent memory accumulation (OOM) across solve calls
|
|
os.environ["MKL_DISABLE_FAST_MM"] = "1"
|
|
|
|
# Auto-detect and load Intel MKL before devsim is imported
|
|
mkl_libs = glob.glob(os.path.join(os.path.dirname(sys.executable), "../lib/libmkl_rt.so.*"))
|
|
if mkl_libs:
|
|
os.environ["DEVSIM_MATH_LIBS"] = mkl_libs[0]
|
|
|
|
import devsim
|
|
import numpy as np
|
|
|
|
DEV_DIR = os.environ.get("DEV_DIR", "devices/Triac_rp")
|
|
sys.path.insert(0, os.path.abspath(DEV_DIR))
|
|
|
|
OUT_DIR = os.path.join(os.environ.get("OUT_DIR", os.path.join(DEV_DIR, "output_this_run")), "")
|
|
os.makedirs(OUT_DIR, exist_ok=True)
|
|
import matplotlib.pyplot as plt
|
|
import time
|
|
|
|
# Enable Intel MKL PARDISO multi-threaded sparse solver
|
|
devsim.set_parameter(name="solver_type", value="pardiso")
|
|
|
|
from device_config import *
|
|
from physics.model_create import *
|
|
from physics.new_physics import *
|
|
|
|
device = "device_2d"
|
|
|
|
# 1. Load the mesh
|
|
mesh_file = os.path.join(DEV_DIR, "device_2d.msh")
|
|
print(f"Loading mesh: {mesh_file}...")
|
|
devsim.create_gmsh_mesh(mesh=device, file=mesh_file)
|
|
devsim.add_gmsh_region(mesh=device, gmsh_name="Silicon", region="Silicon", material="Silicon")
|
|
devsim.add_gmsh_region(mesh=device, gmsh_name="Oxide", region="Oxide", material="Oxide")
|
|
devsim.add_gmsh_region(mesh=device, gmsh_name="Molding", region="Molding", material="Molding")
|
|
|
|
# Add contacts and interfaces
|
|
if "LDMOS" in DEV_DIR:
|
|
# Silicon contacts
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="contR_Si", name="contR_Si", region="Silicon", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="contL_Si", name="contL_Si", region="Silicon", material="metal")
|
|
|
|
# Oxide contacts
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="gate_Ox", name="gate_Ox", region="Oxide", material="metal")
|
|
|
|
# Molding contacts
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="gate_Mold", name="gate_Mold", region="Molding", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="contR_Mold", name="contR_Mold", region="Molding", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="contL_Mold", name="contL_Mold", region="Molding", material="metal")
|
|
|
|
# Add interfaces (no Si_Mold for LDMOS)
|
|
devsim.add_gmsh_interface(mesh=device, gmsh_name="Si_Ox_Interface", name="Si_Ox", region0="Silicon", region1="Oxide")
|
|
devsim.add_gmsh_interface(mesh=device, gmsh_name="Ox_Mold_Interface", name="Ox_Mold", region0="Oxide", region1="Molding")
|
|
else:
|
|
# Add contacts for Silicon region
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT1_Si", name="MT1_Si", region="Silicon", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT2_Si", name="MT2_Si", region="Silicon", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT1_P12_Si", name="MT1_P12_Si", region="Silicon", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT2_P12_Si", name="MT2_P12_Si", region="Silicon", material="metal")
|
|
|
|
# Add contacts for Oxide region
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT1_Ox", name="MT1_Ox", region="Oxide", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT2_Ox", name="MT2_Ox", region="Oxide", material="metal")
|
|
|
|
# Add contacts for Molding region
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT1_Mold", name="MT1_Mold", region="Molding", material="metal")
|
|
devsim.add_gmsh_contact(mesh=device, gmsh_name="MT2_Mold", name="MT2_Mold", region="Molding", material="metal")
|
|
|
|
# Add interfaces
|
|
devsim.add_gmsh_interface(mesh=device, gmsh_name="Si_Ox_Interface", name="Si_Ox", region0="Silicon", region1="Oxide")
|
|
devsim.add_gmsh_interface(mesh=device, gmsh_name="Ox_Mold_Interface", name="Ox_Mold", region0="Oxide", region1="Molding")
|
|
devsim.add_gmsh_interface(mesh=device, gmsh_name="Si_Mold_Interface", name="Si_Mold", region0="Silicon", region1="Molding")
|
|
|
|
devsim.finalize_mesh(mesh=device)
|
|
devsim.create_device(mesh=device, device=device)
|
|
|
|
# 2. Set up doping in Silicon region
|
|
use_pcad = os.environ.get("USE_PCAD", "false").lower() == "true"
|
|
if use_pcad:
|
|
try:
|
|
from device_pcad_config import apply_pcad_doping_2d
|
|
apply_pcad_doping_2d(device, region="Silicon")
|
|
print("Applied PCAD doping configuration.")
|
|
except (ImportError, ModuleNotFoundError):
|
|
print("Warning: device_pcad_config not found. Falling back to analytical doping.")
|
|
use_pcad = False
|
|
|
|
if not use_pcad:
|
|
devsim.node_model(device=device, region="Silicon", name="nD_sub", equation=f"{N_SUB}")
|
|
|
|
def get_erfc_expr(peak, x1, x2, hdiff, vdiff):
|
|
return f"{peak} * erfc(y / {vdiff}) * 0.5 * (erf((x - ({x1})) / {hdiff}) - erf((x - ({x2})) / {hdiff}))"
|
|
|
|
p11_left_expr = get_erfc_expr(P11_PEAK, -P11_X2, -P11_X1, P_WELL_HDDIFF, P_WELL_VDDIFF)
|
|
p11_right_expr = get_erfc_expr(P11_PEAK, P11_X1, P11_X2, P_WELL_HDDIFF, P_WELL_VDDIFF)
|
|
devsim.node_model(device=device, region="Silicon", name="nA_p11_l", equation=p11_left_expr)
|
|
devsim.node_model(device=device, region="Silicon", name="nA_p11_r", equation=p11_right_expr)
|
|
|
|
p12_left_expr = get_erfc_expr(P12_PEAK, -P12_X2, -P12_X1, P_WELL_HDDIFF, P_WELL_VDDIFF)
|
|
p12_right_expr = get_erfc_expr(P12_PEAK, P12_X1, P12_X2, P_WELL_HDDIFF, P_WELL_VDDIFF)
|
|
devsim.node_model(device=device, region="Silicon", name="nA_p12_l", equation=p12_left_expr)
|
|
devsim.node_model(device=device, region="Silicon", name="nA_p12_r", equation=p12_right_expr)
|
|
|
|
p13_left_expr = get_erfc_expr(P13_PEAK, -P13_X2, -P13_X1, P_WELL_HDDIFF, P_WELL_VDDIFF)
|
|
p13_right_expr = get_erfc_expr(P13_PEAK, P13_X1, P13_X2, P_WELL_HDDIFF, P_WELL_VDDIFF)
|
|
devsim.node_model(device=device, region="Silicon", name="nA_p13_l", equation=p13_left_expr)
|
|
devsim.node_model(device=device, region="Silicon", name="nA_p13_r", equation=p13_right_expr)
|
|
|
|
nplus_left_expr = get_erfc_expr(NPLUS_PEAK, -NPLUS_X2, -NPLUS_X1, NPLUS_HDDIFF, NPLUS_VDDIFF)
|
|
nplus_right_expr = get_erfc_expr(NPLUS_PEAK, NPLUS_X1, NPLUS_X2, NPLUS_HDDIFF, NPLUS_VDDIFF)
|
|
devsim.node_model(device=device, region="Silicon", name="nD_nplus_l", equation=nplus_left_expr)
|
|
devsim.node_model(device=device, region="Silicon", name="nD_nplus_r", equation=nplus_right_expr)
|
|
|
|
mring_l_expr = get_erfc_expr(NPLUS_PEAK, -W_DEVICE, -MRING_X1, NPLUS_HDDIFF, NPLUS_VDDIFF)
|
|
mring_r_expr = get_erfc_expr(NPLUS_PEAK, MRING_X1, W_DEVICE, NPLUS_HDDIFF, NPLUS_VDDIFF)
|
|
devsim.node_model(device=device, region="Silicon", name="nD_mring_l", equation=mring_l_expr)
|
|
devsim.node_model(device=device, region="Silicon", name="nD_mring_r", equation=mring_r_expr)
|
|
|
|
devsim.node_model(device=device, region="Silicon", name="Donors",
|
|
equation="nD_sub + nD_nplus_l + nD_nplus_r + nD_mring_l + nD_mring_r")
|
|
devsim.node_model(device=device, region="Silicon", name="Acceptors",
|
|
equation="1e10 + nA_p11_l + nA_p11_r + nA_p12_l + nA_p12_r + nA_p13_l + nA_p13_r")
|
|
devsim.node_model(device=device, region="Silicon", name="NetDoping", equation="Donors - Acceptors")
|
|
devsim.node_model(device=device, region="Silicon", name="LogNetDoping", equation="asinh(NetDoping / 2.0) / log(10.0)")
|
|
|
|
# 3. Initialize electrostatic potential simulation (Poisson only)
|
|
CreateSolution(device, "Silicon", "Potential")
|
|
temp_val = os.environ.get("TEMP", "300")
|
|
devsim.set_parameter(device=device, name="T", value=temp_val)
|
|
CreateSiliconPotentialOnly(device, "Silicon")
|
|
|
|
# Oxide potential equations
|
|
def CreateOxidePotentialOnly(device, region):
|
|
if not InNodeModelList(device, region, "Potential"):
|
|
CreateSolution(device, region, "Potential")
|
|
devsim.set_parameter(device=device, region=region, name="Permittivity", value=3.9 * 8.85e-14)
|
|
efield = "(Potential@n0 - Potential@n1)*EdgeInverseLength"
|
|
CreateEdgeModel(device, region, "EField", efield)
|
|
CreateEdgeModelDerivatives(device, region, "EField", efield, "Potential")
|
|
dfield = "Permittivity*EField"
|
|
CreateEdgeModel(device, region, "PotentialEdgeFlux", dfield)
|
|
CreateEdgeModelDerivatives(device, region, "PotentialEdgeFlux", dfield, "Potential")
|
|
devsim.equation(device=device, region=region, name="PotentialEquation", variable_name="Potential",
|
|
edge_model="PotentialEdgeFlux", variable_update="default", min_error=1e-3)
|
|
|
|
CreateOxidePotentialOnly(device, "Oxide")
|
|
|
|
# Molding potential equations
|
|
def CreateMoldingPotentialOnly(device, region):
|
|
if not InNodeModelList(device, region, "Potential"):
|
|
CreateSolution(device, region, "Potential")
|
|
devsim.set_parameter(device=device, region=region, name="Permittivity", value=4.0 * 8.85e-14)
|
|
efield = "(Potential@n0 - Potential@n1)*EdgeInverseLength"
|
|
CreateEdgeModel(device, region, "EField", efield)
|
|
CreateEdgeModelDerivatives(device, region, "EField", efield, "Potential")
|
|
dfield = "Permittivity*EField"
|
|
CreateEdgeModel(device, region, "PotentialEdgeFlux", dfield)
|
|
CreateEdgeModelDerivatives(device, region, "PotentialEdgeFlux", dfield, "Potential")
|
|
devsim.equation(device=device, region=region, name="PotentialEquation", variable_name="Potential",
|
|
edge_model="PotentialEdgeFlux", variable_update="default", min_error=1e-3)
|
|
|
|
CreateMoldingPotentialOnly(device, "Molding")
|
|
|
|
# Interfaces continuous potential
|
|
def CreateContinuousPotentialInterface(device, interface):
|
|
model_name = CreateContinuousInterfaceModel(device, interface, "Potential")
|
|
devsim.interface_equation(device=device, interface=interface, name="PotentialEquation",
|
|
interface_model=model_name, type="continuous")
|
|
|
|
if "LDMOS" in DEV_DIR:
|
|
CreateContinuousPotentialInterface(device, "Si_Ox")
|
|
CreateContinuousPotentialInterface(device, "Ox_Mold")
|
|
else:
|
|
CreateContinuousPotentialInterface(device, "Si_Ox")
|
|
CreateContinuousPotentialInterface(device, "Ox_Mold")
|
|
CreateContinuousPotentialInterface(device, "Si_Mold")
|
|
|
|
# Potential contacts setup
|
|
if "LDMOS" in DEV_DIR:
|
|
silicon_contacts = ["contL_Si", "contR_Si"]
|
|
oxide_contacts = ["gate_Ox"]
|
|
molding_contacts = ["gate_Mold", "contL_Mold", "contR_Mold"]
|
|
else:
|
|
silicon_contacts = ["MT1_Si", "MT2_Si", "MT1_P12_Si", "MT2_P12_Si"]
|
|
oxide_contacts = ["MT1_Ox", "MT2_Ox"]
|
|
molding_contacts = ["MT1_Mold", "MT2_Mold"]
|
|
|
|
for c in silicon_contacts:
|
|
devsim.set_parameter(device=device, name=GetContactBiasName(c), value=0.0)
|
|
CreateSiliconPotentialOnlyContact(device, "Silicon", c)
|
|
|
|
def CreateOxidePotentialOnlyContact(device, region, contact):
|
|
contact_bias = GetContactBiasName(contact)
|
|
contact_model = f"Potential - {contact_bias}"
|
|
contact_model_name = f"{contact}_bc"
|
|
CreateContactNodeModel(device, contact, contact_model_name, contact_model)
|
|
CreateContactNodeModelDerivative(device, contact, contact_model_name, contact_model, "Potential")
|
|
devsim.contact_equation(device=device, contact=contact, name="PotentialEquation",
|
|
node_model=contact_model_name, edge_charge_model="PotentialEdgeFlux")
|
|
|
|
for c in oxide_contacts:
|
|
devsim.set_parameter(device=device, name=GetContactBiasName(c), value=0.0)
|
|
CreateOxidePotentialOnlyContact(device, "Oxide", c)
|
|
|
|
def CreateMoldingPotentialOnlyContact(device, region, contact):
|
|
contact_bias = GetContactBiasName(contact)
|
|
contact_model = f"Potential - {contact_bias}"
|
|
contact_model_name = f"{contact}_bc"
|
|
CreateContactNodeModel(device, contact, contact_model_name, contact_model)
|
|
CreateContactNodeModelDerivative(device, contact, contact_model_name, contact_model, "Potential")
|
|
devsim.contact_equation(device=device, contact=contact, name="PotentialEquation",
|
|
node_model=contact_model_name, edge_charge_model="PotentialEdgeFlux")
|
|
|
|
for c in molding_contacts:
|
|
devsim.set_parameter(device=device, name=GetContactBiasName(c), value=0.0)
|
|
CreateMoldingPotentialOnlyContact(device, "Molding", c)
|
|
|
|
# Solve initial zero-bias Poisson
|
|
print("Solving initial Poisson at thermal equilibrium...")
|
|
devsim.solve(type="dc", absolute_error=1.0, relative_error=1e-10, maximum_iterations=50)
|
|
print("Initial Poisson converged.")
|
|
|
|
# 4. Set up carrier solutions for Silicon Drift-Diffusion
|
|
# Compute initial guess for Electrons and Holes based on Potential
|
|
CreateSolution(device, "Silicon", "Electrons")
|
|
CreateSolution(device, "Silicon", "Holes")
|
|
|
|
devsim.set_node_values(device=device, region="Silicon", name="Electrons", init_from="IntrinsicElectrons")
|
|
devsim.set_node_values(device=device, region="Silicon", name="Holes", init_from="IntrinsicHoles")
|
|
|
|
# Redefine IntrinsicElectrons, IntrinsicHoles, and related models to avoid potential exponential overflow at high bias.
|
|
print("Redefining equilibrium models to prevent high-bias exponential overflow...")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicElectrons", equation="Electrons")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicElectrons:Potential", equation="0")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicElectrons:Electrons", equation="1")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicElectrons:Holes", equation="0")
|
|
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicHoles", equation="Holes")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicHoles:Potential", equation="0")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicHoles:Electrons", equation="0")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicHoles:Holes", equation="1")
|
|
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicCharge", equation="Holes - Electrons + NetDoping")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicCharge:Potential", equation="0")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicCharge:Electrons", equation="-1")
|
|
devsim.node_model(device=device, region="Silicon", name="IntrinsicCharge:Holes", equation="1")
|
|
|
|
devsim.node_model(device=device, region="Silicon", name="PotentialIntrinsicCharge", equation="0")
|
|
devsim.node_model(device=device, region="Silicon", name="PotentialIntrinsicCharge:Potential", equation="0")
|
|
|
|
# Mobility and drift diffusion equations
|
|
opts = CreateAroraMobilityLF(device, "Silicon")
|
|
# Bypassing HFMobility to prevent zero-bias convergence oscillations
|
|
CreateSiliconDriftDiffusion(device, "Silicon", **opts)
|
|
devsim.node_model(device=device, region="Silicon", name="LogElectrons", equation="log(Electrons + 1e-10) / log(10.0)")
|
|
devsim.node_model(device=device, region="Silicon", name="LogHoles", equation="log(Holes + 1e-10) / log(10.0)")
|
|
|
|
# Re-setup Silicon contacts for Drift-Diffusion
|
|
for c in silicon_contacts:
|
|
CreateSiliconDriftDiffusionContact(device, "Silicon", c, opts['Jn'], opts['Jp'])
|
|
|
|
# Solve initial zero-bias Drift-Diffusion with standard tolerances (using default log_damp updates)
|
|
print("Solving initial Drift-Diffusion equations at zero bias...")
|
|
devsim.solve(type="dc", absolute_error=1e10, relative_error=1e30, charge_error=1e12, maximum_iterations=50)
|
|
print("Initial Drift-Diffusion converged successfully!")
|
|
|
|
# Switch continuity and potential equations for the bias sweep
|
|
print("Configuring continuity and potential equations for the bias sweep (min_error=1e5, positive update)...")
|
|
|
|
# Instantiate Avalanche and BTBT generation models
|
|
CreateAvalancheGeneration(device, "Silicon", opts['Jn'], opts['Jp'])
|
|
CreateBTBTGeneration(device, "Silicon")
|
|
|
|
is_avalanche_enabled = os.environ.get("AVALANCHE", "false").lower() == "true"
|
|
is_btbt_enabled = os.environ.get("BTBT", "false").lower() == "true"
|
|
|
|
devsim.equation(device=device, region="Silicon", name="ElectronContinuityEquation", variable_name="Electrons",
|
|
time_node_model="NCharge", edge_model=opts['Jn'], edge_volume_model="",
|
|
variable_update="positive", node_model="ElectronGeneration", min_error=1e5)
|
|
devsim.equation(device=device, region="Silicon", name="HoleContinuityEquation", variable_name="Holes",
|
|
time_node_model="PCharge", edge_model=opts['Jp'], edge_volume_model="",
|
|
variable_update="positive", node_model="HoleGeneration", min_error=1e5)
|
|
devsim.equation(device=device, region="Silicon", name="HoleContinuityEquation", variable_name="Holes",
|
|
time_node_model="PCharge", edge_model=opts['Jp'], edge_volume_model="",
|
|
variable_update="positive", node_model="HoleGeneration", min_error=1e5)
|
|
devsim.equation(device=device, region="Silicon", name="PotentialEquation", variable_name="Potential",
|
|
node_model="PotentialNodeCharge", edge_model="DField", variable_update="default", min_error=1e-3)
|
|
|
|
# Save zero-bias tecplot and VTK
|
|
devsim.write_devices(file=f"{OUT_DIR}sweep_preview_0V.tec", type="tecplot")
|
|
# devsim.write_devices(file="sweep_preview_0V", type="vtk")
|
|
|
|
# 5. Define Sweep Parameters
|
|
v_target = 100.0 if "LDMOS" in DEV_DIR else 1000.0
|
|
sweep_target_env = os.environ.get("SWEEP_TARGET")
|
|
if sweep_target_env:
|
|
if sweep_target_env.endswith(('V', 'v')):
|
|
sweep_target_env = sweep_target_env[:-1]
|
|
try:
|
|
v_target = float(sweep_target_env)
|
|
print(f"Target voltage set from environment: {v_target} V")
|
|
except ValueError:
|
|
pass
|
|
v_current = 0.0
|
|
step_size = 0.1 # Initial step size (V)
|
|
max_step = 50.0 # Maximum step size (V)
|
|
min_step = 1e-4 # Minimum step size (V)
|
|
compliance_current = 1e-3 # 1 mA compliance current
|
|
|
|
# Helper functions to save/restore state in case of convergence failure
|
|
def save_state(device):
|
|
state = {}
|
|
for region in ["Silicon", "Oxide", "Molding"]:
|
|
state[region] = {
|
|
"Potential": list(devsim.get_node_model_values(device=device, region=region, name="Potential"))
|
|
}
|
|
state["Silicon"]["Electrons"] = list(devsim.get_node_model_values(device=device, region="Silicon", name="Electrons"))
|
|
state["Silicon"]["Holes"] = list(devsim.get_node_model_values(device=device, region="Silicon", name="Holes"))
|
|
return state
|
|
|
|
def restore_state(device, state):
|
|
for region in ["Silicon", "Oxide", "Molding"]:
|
|
devsim.set_node_values(device=device, region=region, name="Potential", values=state[region]["Potential"])
|
|
devsim.set_node_values(device=device, region="Silicon", name="Electrons", values=state["Silicon"]["Electrons"])
|
|
devsim.set_node_values(device=device, region="Silicon", name="Holes", values=state["Silicon"]["Holes"])
|
|
|
|
# File logging setup & Resume Support
|
|
resume_seed = os.environ.get("RESUME_SEED")
|
|
is_resuming = False
|
|
if resume_seed and os.path.exists(resume_seed):
|
|
import pickle
|
|
print(f"Loading resume seed from {resume_seed}...")
|
|
with open(resume_seed, "rb") as f:
|
|
seed_data = pickle.load(f)
|
|
restore_state(device, seed_data["state"])
|
|
v_current = seed_data["voltage"]
|
|
step_size = seed_data["step_size"]
|
|
print(f"Resuming from V = {v_current} V, step_size = {step_size} V")
|
|
|
|
# Set initial contact biases to the resumed voltage
|
|
if "LDMOS" in DEV_DIR:
|
|
for c in ["contR_Si", "contR_Mold"]:
|
|
devsim.set_parameter(device=device, name=f"{c}_bias", value=v_current)
|
|
for c in ["gate_Ox", "gate_Mold", "contL_Si", "contL_Mold"]:
|
|
devsim.set_parameter(device=device, name=f"{c}_bias", value=0.0)
|
|
else:
|
|
for c in ["MT1_Si", "MT1_P12_Si", "MT1_Ox", "MT1_Mold"]:
|
|
devsim.set_parameter(device=device, name=f"{c}_bias", value=v_current)
|
|
|
|
# Read existing simulation_time.log to populate lists
|
|
voltage_list = []
|
|
current_list = []
|
|
log_path = f"{OUT_DIR}simulation_time.log"
|
|
if os.path.exists(log_path):
|
|
with open(log_path, "r") as f:
|
|
lines = f.readlines()
|
|
clean_lines = []
|
|
for line in lines:
|
|
if "Total Sweep Time" in line or not line.strip():
|
|
continue
|
|
clean_lines.append(line)
|
|
for line in clean_lines[1:]: # skip header
|
|
parts = line.strip().split("\t")
|
|
if len(parts) >= 4:
|
|
try:
|
|
v_val = float(parts[1])
|
|
i_val = float(parts[3])
|
|
if v_val <= v_current:
|
|
voltage_list.append(v_val)
|
|
current_list.append(i_val)
|
|
except ValueError:
|
|
pass
|
|
print(f"Loaded {len(voltage_list)} historical I-V points from log.")
|
|
# Rewrite clean file
|
|
with open(log_path, "w") as f:
|
|
f.writelines(clean_lines)
|
|
time_log = open(log_path, "a", buffering=1)
|
|
is_resuming = True
|
|
next_recon_v = (v_current // 50.0 + 1) * 50.0
|
|
else:
|
|
v_current = 0.0
|
|
step_size = 0.1 # Initial step size (V)
|
|
voltage_list = [0.0]
|
|
current_list = [0.0]
|
|
time_log = open(f"{OUT_DIR}simulation_time.log", "w", buffering=1)
|
|
time_log.write("Time\tVoltage(V)\tStep(V)\tCurrent(A)\tIterations\tTimeTaken(s)\n")
|
|
next_recon_v = 50.0
|
|
|
|
# Recon variables log initialization
|
|
recon_av_mode = "a" if is_resuming else "w"
|
|
with open(f"{OUT_DIR}recon_avalanche.log", recon_av_mode) as f:
|
|
if recon_av_mode == "w":
|
|
f.write("Voltage(V)\tAvalancheCurrent(A)\n")
|
|
|
|
# Save initial state
|
|
state = save_state(device)
|
|
start_sweep_time = time.time()
|
|
|
|
print("Beginning adaptive bias sweep...")
|
|
step_count = 0
|
|
iter_history = []
|
|
sn = 0
|
|
consecutive_fails = 0
|
|
# --- Adaptive step control thresholds ---
|
|
step_ctl_reduce = 12
|
|
step_ctl_enlarge = 8
|
|
|
|
# Targets for saving intermediate state checkpoints
|
|
save_targets = [5.0, 50.0, 500.0]
|
|
saved_targets = set()
|
|
|
|
# Pre-refinement seed save targets
|
|
seed_save_targets = [5.0, 25.0, 45.0, 95.0, 195.0, 395.0, 595.0, 795.0, 995.0, 1195.0]
|
|
saved_seeds = {t for t in seed_save_targets if v_current >= t}
|
|
|
|
while v_current < v_target:
|
|
v_next = min(v_current + step_size, v_target)
|
|
|
|
# Apply new bias values to the swept contact (contR for LDMOS, MT1 for Triac)
|
|
if "LDMOS" in DEV_DIR:
|
|
for c in ["contR_Si", "contR_Mold"]:
|
|
devsim.set_parameter(device=device, name=f"{c}_bias", value=v_next)
|
|
for c in ["gate_Ox", "gate_Mold", "contL_Si", "contL_Mold"]:
|
|
devsim.set_parameter(device=device, name=f"{c}_bias", value=0.0)
|
|
else:
|
|
for c in ["MT1_Si", "MT1_P12_Si", "MT1_Ox", "MT1_Mold"]:
|
|
devsim.set_parameter(device=device, name=f"{c}_bias", value=v_next)
|
|
|
|
step_start_time = time.time()
|
|
try:
|
|
# Stage 1: Pre-conditioning (Relaxed Tolerance to get a good initial guess)
|
|
iters1 = 10
|
|
try:
|
|
res1 = devsim.solve(type="dc", absolute_error=1e10, relative_error=1e-1, charge_error=1e12, maximum_iterations=10, info=True)
|
|
iters1 = len(res1.get("iterations", []))
|
|
except devsim.error:
|
|
pass # Ignore non-convergence in pre-conditioning
|
|
|
|
import psutil
|
|
mem_stage1 = psutil.Process(os.getpid()).memory_info().rss / (1024**3)
|
|
print(f"Stage 1 (Precondition) Memory Usage: {mem_stage1:.1f} GB")
|
|
|
|
# Stage 2: Precision Newton (Strict Tolerance) - slightly relaxed relative_error to 3e-3 to avoid limit cycle oscillations
|
|
res = devsim.solve(type="dc", absolute_error=1e10, relative_error=3e-3, charge_error=1e12, maximum_iterations=12, info=True)
|
|
iters2 = len(res.get("iterations", []))
|
|
|
|
mem_stage2 = psutil.Process(os.getpid()).memory_info().rss / (1024**3)
|
|
print(f"Stage 2 (Newton) Memory Usage: {mem_stage2:.1f} GB")
|
|
iters = f"{iters1}+{iters2}"
|
|
total_iters = iters1 + iters2
|
|
|
|
if not res.get("converged", False):
|
|
raise devsim.error("Convergence failure")
|
|
|
|
step_end_time = time.time()
|
|
time_taken = step_end_time - step_start_time
|
|
|
|
# Convergence succeeded! Compute terminal current
|
|
if "LDMOS" in DEV_DIR:
|
|
i_n_si = devsim.get_contact_current(device=device, contact="contR_Si", equation="ElectronContinuityEquation")
|
|
i_p_si = devsim.get_contact_current(device=device, contact="contR_Si", equation="HoleContinuityEquation")
|
|
total_curr = i_n_si + i_p_si
|
|
else:
|
|
i_n_si = devsim.get_contact_current(device=device, contact="MT1_Si", equation="ElectronContinuityEquation")
|
|
i_p_si = devsim.get_contact_current(device=device, contact="MT1_Si", equation="HoleContinuityEquation")
|
|
i_n_p12 = devsim.get_contact_current(device=device, contact="MT1_P12_Si", equation="ElectronContinuityEquation")
|
|
i_p_p12 = devsim.get_contact_current(device=device, contact="MT1_P12_Si", equation="HoleContinuityEquation")
|
|
total_curr = i_n_si + i_p_si + i_n_p12 + i_p_p12
|
|
|
|
# Update simulation status
|
|
v_current = v_next
|
|
state = save_state(device)
|
|
|
|
voltage_list.append(v_current)
|
|
current_list.append(total_curr)
|
|
|
|
print(f"Step {step_count}: Converged at V = {v_current:.4f} V, I = {total_curr:.4e} A. Step size: {step_size:.4f} V. Iterations: {iters}. Time: {time_taken:.2f} s")
|
|
|
|
# Log to file
|
|
time_log.write(f"{time.strftime('%X')}\t{v_current:.4f}\t{step_size:.4f}\t{total_curr:.4e}\t{iters}\t{time_taken:.2f}\t{mem_stage1:.1f}GB\t{mem_stage2:.1f}GB\n")
|
|
|
|
# Save checkpoints when crossing target voltages
|
|
for target in save_targets:
|
|
if v_current >= target and target not in saved_targets:
|
|
filename = f"sweep_preview_{int(target)}V.tec"
|
|
filename_vtk = f"sweep_preview_{int(target)}V"
|
|
print(f"Saving checkpoint at V = {v_current:.2f} V to {filename} and VTK...")
|
|
devsim.write_devices(file=f"{OUT_DIR}{filename}", type="tecplot")
|
|
# devsim.write_devices(file=filename_vtk, type="vtk")
|
|
saved_targets.add(target)
|
|
|
|
# Save pre-refinement seeds when crossing target voltages
|
|
for target in seed_save_targets:
|
|
if v_current >= target and target not in saved_seeds:
|
|
seed_filename = f"{OUT_DIR}seed_{int(target)}V.pkl"
|
|
state_to_save = save_state(device)
|
|
seed_data = {"voltage": v_current, "step_size": step_size, "state": state_to_save}
|
|
with open(seed_filename, "wb") as f:
|
|
pickle.dump(seed_data, f)
|
|
print(f"Saved pre-refinement seed checkpoint at V = {v_current:.2f} V to {seed_filename}")
|
|
saved_seeds.add(target)
|
|
|
|
# Compliance check
|
|
if abs(total_curr) >= compliance_current:
|
|
print(f"Compliance current of {compliance_current:.1e} A reached at V = {v_current:.4f} V. Stopping sweep.")
|
|
time_log.write(f"Compliance current reached at V = {v_current:.4f} V.\n")
|
|
break
|
|
|
|
|
|
# --- RECONNAISSANCE PROBE ---
|
|
if v_current >= next_recon_v:
|
|
state_data = save_state(device)
|
|
seed_data = {"voltage": v_current, "step_size": step_size, "state": state_data}
|
|
seed_filename = f"{OUT_DIR}seed_{int(next_recon_v)}V.pkl"
|
|
with open(seed_filename, "wb") as f:
|
|
pickle.dump(seed_data, f)
|
|
print(f"\n--- RECON PROBE at {v_current:.2f} V ---")
|
|
print(f"Saved seed to {seed_filename}")
|
|
|
|
if is_avalanche_enabled or is_btbt_enabled:
|
|
# Helper to run a recon probe
|
|
def run_recon_probe(probe_name, model_n, model_p, log_file):
|
|
print(f" Running Recon Probe ({probe_name})...")
|
|
# Temporarily set equations
|
|
devsim.equation(device=device, region="Silicon", name="ElectronContinuityEquation", variable_name="Electrons",
|
|
time_node_model="NCharge", edge_model=opts['Jn'], edge_volume_model=model_n,
|
|
variable_update="positive", node_model="ElectronGeneration", min_error=1e5)
|
|
devsim.equation(device=device, region="Silicon", name="HoleContinuityEquation", variable_name="Holes",
|
|
time_node_model="PCharge", edge_model=opts['Jp'], edge_volume_model=model_p,
|
|
variable_update="positive", node_model="HoleGeneration", min_error=1e5)
|
|
|
|
converged = False
|
|
total_curr = 0.0
|
|
try:
|
|
# Stage 1 pre-conditioning
|
|
try:
|
|
devsim.solve(type="dc", absolute_error=1e10, relative_error=1e-1, charge_error=1e12, maximum_iterations=10, info=True)
|
|
except devsim.error:
|
|
pass
|
|
|
|
import psutil
|
|
mem_recon_stage1 = psutil.Process(os.getpid()).memory_info().rss / (1024**3)
|
|
print(f"Recon Stage 1 Memory Usage: {mem_recon_stage1:.1f} GB")
|
|
|
|
# Switch to positive update for Stage 2 precision Newton solve
|
|
devsim.equation(device=device, region="Silicon", name="ElectronContinuityEquation", variable_name="Electrons",
|
|
time_node_model="NCharge", edge_model=opts['Jn'], edge_volume_model=model_n,
|
|
variable_update="positive", node_model="ElectronGeneration", min_error=1e5)
|
|
devsim.equation(device=device, region="Silicon", name="HoleContinuityEquation", variable_name="Holes",
|
|
time_node_model="PCharge", edge_model=opts['Jp'], edge_volume_model=model_p,
|
|
variable_update="positive", node_model="HoleGeneration", min_error=1e5)
|
|
|
|
# Stage 2 solve (Strict Tolerance)
|
|
res_av = devsim.solve(type="dc", absolute_error=1e10, relative_error=1e-3, charge_error=1e12, maximum_iterations=15, info=True)
|
|
|
|
mem_recon_stage2 = psutil.Process(os.getpid()).memory_info().rss / (1024**3)
|
|
print(f"Recon Stage 2 Memory Usage: {mem_recon_stage2:.1f} GB")
|
|
if res_av.get("converged", False):
|
|
if "LDMOS" in DEV_DIR:
|
|
ia_n_si = devsim.get_contact_current(device=device, contact="contR_Si", equation="ElectronContinuityEquation")
|
|
ia_p_si = devsim.get_contact_current(device=device, contact="contR_Si", equation="HoleContinuityEquation")
|
|
total_curr = ia_n_si + ia_p_si
|
|
else:
|
|
ia_n_si = devsim.get_contact_current(device=device, contact="MT1_Si", equation="ElectronContinuityEquation")
|
|
ia_p_si = devsim.get_contact_current(device=device, contact="MT1_Si", equation="HoleContinuityEquation")
|
|
ia_n_p12 = devsim.get_contact_current(device=device, contact="MT1_P12_Si", equation="ElectronContinuityEquation")
|
|
ia_p_p12 = devsim.get_contact_current(device=device, contact="MT1_P12_Si", equation="HoleContinuityEquation")
|
|
total_curr = ia_n_si + ia_p_si + ia_n_p12 + ia_p_p12
|
|
converged = True
|
|
except devsim.error:
|
|
pass
|
|
|
|
# Restore state immediately after solve attempts
|
|
restore_state(device, state_data)
|
|
|
|
with open(log_file, "a") as f:
|
|
if converged:
|
|
print(f" {probe_name} Current at {v_current:.2f} V: {total_curr:.4e} A")
|
|
f.write(f"{v_current:.2f}\t{total_curr:.4e}\n")
|
|
else:
|
|
print(f" {probe_name} failed to converge.")
|
|
f.write(f"{v_current:.2f}\tFAILED\n")
|
|
|
|
# 1. Avalanche Only
|
|
if is_avalanche_enabled:
|
|
run_recon_probe("Avalanche", "AvalancheGeneration", "AvalancheGeneration_p", f"{OUT_DIR}recon_avalanche.log")
|
|
# 2. BTBT Only
|
|
if is_btbt_enabled:
|
|
run_recon_probe("BTBT", "BTBTGeneration", "BTBTGeneration_p", f"{OUT_DIR}recon_btbt.log")
|
|
# 3. Avalanche + BTBT
|
|
if is_avalanche_enabled and is_btbt_enabled:
|
|
run_recon_probe("Av+BTBT", "AvalancheGeneration + BTBTGeneration", "AvalancheGeneration_p + BTBTGeneration_p", f"{OUT_DIR}recon_av_btbt.log")
|
|
|
|
# Revert equations to main sweep configuration (no generation)
|
|
devsim.equation(device=device, region="Silicon", name="ElectronContinuityEquation", variable_name="Electrons",
|
|
time_node_model="NCharge", edge_model=opts['Jn'], edge_volume_model="",
|
|
variable_update="positive", node_model="ElectronGeneration", min_error=1e5)
|
|
devsim.equation(device=device, region="Silicon", name="HoleContinuityEquation", variable_name="Holes",
|
|
time_node_model="PCharge", edge_model=opts['Jp'], edge_volume_model="",
|
|
variable_update="positive", node_model="HoleGeneration", min_error=1e5)
|
|
else:
|
|
print("Probes skipped (Both AVALANCHE and BTBT options are disabled).")
|
|
print("--- END RECON PROBE ---\n")
|
|
next_recon_v += 50.0
|
|
|
|
# Grow step size for next step adaptively based on Newton iterations (Rolling average)
|
|
consecutive_fails = 0
|
|
iter_history.append(total_iters)
|
|
if len(iter_history) > 3:
|
|
iter_history.pop(0)
|
|
avg_iters = sum(iter_history) / len(iter_history)
|
|
|
|
eff_iters = max(0.0, avg_iters - sn)
|
|
if avg_iters > step_ctl_reduce:
|
|
step_size = max(step_size * 0.6, min_step)
|
|
sn = 0
|
|
elif eff_iters < step_ctl_enlarge:
|
|
step_size = min(step_size * 1.2, max_step)
|
|
sn = 0
|
|
else:
|
|
sn += 1.25
|
|
|
|
step_count += 1
|
|
|
|
# Active garbage collection to prevent memory accumulation
|
|
gc.collect()
|
|
|
|
# Force Intel MKL to release thread buffers
|
|
try:
|
|
import ctypes
|
|
import glob
|
|
import sys
|
|
import os
|
|
mkl_libs = glob.glob(os.path.join(os.path.dirname(sys.executable), "../lib/libmkl_rt.so.*"))
|
|
if mkl_libs:
|
|
ctypes.CDLL(mkl_libs[0]).MKL_Free_Buffers()
|
|
# Force glibc to return freed memory to the OS (mitigate malloc fragmentation)
|
|
libc = ctypes.CDLL("libc.so.6")
|
|
libc.malloc_trim(0)
|
|
except Exception as e:
|
|
pass
|
|
|
|
except devsim.error as e:
|
|
# Convergence failure: restore last state and cut step size
|
|
step_end_time = time.time()
|
|
time_taken = step_end_time - step_start_time
|
|
consecutive_fails += 1
|
|
shrink_factor = 0.3 if consecutive_fails == 1 else 0.1
|
|
print(f"Convergence failure at V = {v_next:.4f} V. Restoring state and scaling step size by {shrink_factor} from {step_size:.4f} V (consecutive fails: {consecutive_fails}).")
|
|
time_log.write(f"{time.strftime('%X')}\t{v_next:.4f}\t{step_size:.4f}\tFAILED\t-\t{time_taken:.2f}\n")
|
|
|
|
restore_state(device, state)
|
|
step_size *= shrink_factor
|
|
iter_history = [step_ctl_reduce, step_ctl_reduce, step_ctl_reduce] # Option A virtual history to stay conservative
|
|
sn = 0 # Reset counter on failure
|
|
|
|
if step_size < min_step:
|
|
print("Step size has fallen below minimum limit. Aborting simulation.")
|
|
time_log.write(f"Aborted: step size fell below {min_step:.1e} V\n")
|
|
break
|
|
|
|
total_sweep_time = time.time() - start_sweep_time
|
|
print(f"Sweep completed in {total_sweep_time:.2f} s.")
|
|
time_log.write(f"Total Sweep Time: {total_sweep_time:.2f} s\n")
|
|
time_log.close()
|
|
|
|
# 6. Save final results and generate plots
|
|
# Save final tecplot and VTK at highest voltage
|
|
devsim.write_devices(file=f"{OUT_DIR}sweep_preview_final.tec", type="tecplot")
|
|
# devsim.write_devices(file="sweep_preview_final", type="vtk")
|
|
|
|
# Save I-V data to CSV
|
|
np.savetxt(f"{OUT_DIR}sweep_iv_2d.csv", np.column_stack((voltage_list, current_list)),
|
|
header="Voltage(V),Current(A)", delimiter=",")
|
|
|
|
# Helper to read recon logs
|
|
def load_recon_log(filepath):
|
|
voltages = []
|
|
currents = []
|
|
if os.path.exists(filepath):
|
|
with open(filepath, "r") as f:
|
|
for line in f:
|
|
if "Voltage" in line or not line.strip():
|
|
continue
|
|
parts = line.strip().split()
|
|
if len(parts) == 2 and parts[1] != "FAILED":
|
|
try:
|
|
v = float(parts[0])
|
|
i = float(parts[1])
|
|
voltages.append(v)
|
|
currents.append(abs(i))
|
|
except ValueError:
|
|
pass
|
|
return voltages, currents
|
|
|
|
# Plot and save I-V curve
|
|
plt.figure(figsize=(8, 6))
|
|
plt.plot(voltage_list, np.abs(current_list), 'o-', color='#1f77b4', markersize=4, label='Main Sweep (Drift-Diffusion)')
|
|
|
|
v_av, i_av = load_recon_log(f"{OUT_DIR}recon_avalanche.log")
|
|
if v_av:
|
|
plt.plot(v_av, i_av, 's--', color='#ff7f0e', markersize=2, label='Avalanche Only (Recon)')
|
|
|
|
v_bt, i_bt = load_recon_log(f"{OUT_DIR}recon_btbt.log")
|
|
if v_bt:
|
|
plt.plot(v_bt, i_bt, '^--', color='#2ca02c', markersize=2, label='BTBT Only (Recon)')
|
|
|
|
v_av_bt, i_av_bt = load_recon_log(f"{OUT_DIR}recon_av_btbt.log")
|
|
if v_av_bt:
|
|
plt.plot(v_av_bt, i_av_bt, 'd--', color='#d62728', markersize=2, label='Avalanche + BTBT (Recon)')
|
|
|
|
plt.yscale('log')
|
|
plt.grid(True, which="both", ls="--")
|
|
plt.xlabel("Bias Voltage (V)")
|
|
plt.ylabel("Terminal Current Magnitude (A)")
|
|
plt.title(f"TVS 2D Bidirectional Bias Sweep I-V Curve (Log Scale) (T={temp_val}K)")
|
|
plt.legend()
|
|
plt.tight_layout()
|
|
plt.savefig(f"{OUT_DIR}sweep_iv_2d.png", dpi=300)
|
|
plt.close()
|
|
|
|
# Generate potential & electric field plots at final converged bias
|
|
# Extract final node values
|
|
x_si = np.array(devsim.get_node_model_values(device=device, region="Silicon", name="x")) / um
|
|
y_si = np.array(devsim.get_node_model_values(device=device, region="Silicon", name="y")) / um
|
|
pot_si = np.array(devsim.get_node_model_values(device=device, region="Silicon", name="Potential"))
|
|
tri_si = np.array(devsim.get_element_node_list(device=device, region="Silicon"))
|
|
|
|
# Compute final Emag
|
|
for reg in ["Silicon", "Oxide", "Molding"]:
|
|
devsim.element_from_edge_model(edge_model="EField", device=device, region=reg)
|
|
devsim.element_model(device=device, region=reg, name="Emag", equation="(EField_x^2 + EField_y^2)^(0.5)")
|
|
|
|
emag_si = np.array(devsim.get_element_model_values(device=device, region="Silicon", name="Emag"))[::3]
|
|
|
|
x_ox = np.array(devsim.get_node_model_values(device=device, region="Oxide", name="x")) / um
|
|
y_ox = np.array(devsim.get_node_model_values(device=device, region="Oxide", name="y")) / um
|
|
pot_ox = np.array(devsim.get_node_model_values(device=device, region="Oxide", name="Potential"))
|
|
tri_ox = np.array(devsim.get_element_node_list(device=device, region="Oxide"))
|
|
emag_ox = np.array(devsim.get_element_model_values(device=device, region="Oxide", name="Emag"))[::3]
|
|
|
|
x_mold = np.array(devsim.get_node_model_values(device=device, region="Molding", name="x")) / um
|
|
y_mold = np.array(devsim.get_node_model_values(device=device, region="Molding", name="y")) / um
|
|
pot_mold = np.array(devsim.get_node_model_values(device=device, region="Molding", name="Potential"))
|
|
tri_mold = np.array(devsim.get_element_node_list(device=device, region="Molding"))
|
|
emag_mold = np.array(devsim.get_element_model_values(device=device, region="Molding", name="Emag"))[::3]
|
|
|
|
def draw_device_boundaries(ax):
|
|
ax.plot([-W_DEVICE/um, W_DEVICE/um], [-T_OX/um, -T_OX/um], color='black', linestyle='--', linewidth=0.8)
|
|
ax.plot([-W_DEVICE/um, W_DEVICE/um], [0, 0], color='black', linestyle='-', linewidth=0.8)
|
|
ax.plot([-W_DEVICE/um, -W_DEVICE/um], [0, H_SI/um], color='black', linestyle='-', linewidth=0.8)
|
|
ax.plot([W_DEVICE/um, W_DEVICE/um], [0, H_SI/um], color='black', linestyle='-', linewidth=0.8)
|
|
ax.plot([-W_SIM/um, W_SIM/um], [H_SI/um, H_SI/um], color='black', linestyle='-', linewidth=1.2)
|
|
|
|
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 14))
|
|
|
|
# Plot Potential
|
|
tcf1_si = ax1.tripcolor(x_si, y_si, tri_si, pot_si, cmap='RdYlBu_r', shading='gouraud')
|
|
tcf1_ox = ax1.tripcolor(x_ox, y_ox, tri_ox, pot_ox, cmap='RdYlBu_r', shading='gouraud')
|
|
tcf1_mold = ax1.tripcolor(x_mold, y_mold, tri_mold, pot_mold, cmap='RdYlBu_r', shading='gouraud')
|
|
fig.colorbar(tcf1_si, ax=ax1, label='Electrostatic Potential (V)')
|
|
draw_device_boundaries(ax1)
|
|
ax1.set_xlabel('X (μm)')
|
|
ax1.set_ylabel('Y (μm)')
|
|
ax1.set_title(f'2D Electrostatic Potential at V = {v_current:.2f} V')
|
|
ax1.set_xlim(-W_SIM / um, W_SIM / um)
|
|
ax1.set_ylim(H_SI/um + 15.0, -110.0)
|
|
|
|
# Plot EField Magnitude
|
|
tcf2_si = ax2.tripcolor(x_si, y_si, tri_si, facecolors=emag_si, cmap='inferno', shading='flat')
|
|
tcf2_ox = ax2.tripcolor(x_ox, y_ox, tri_ox, facecolors=emag_ox, cmap='inferno', shading='flat')
|
|
tcf2_mold = ax2.tripcolor(x_mold, y_mold, tri_mold, facecolors=emag_mold, cmap='inferno', shading='flat')
|
|
fig.colorbar(tcf2_si, ax=ax2, label='Electric Field Magnitude (V/cm)')
|
|
draw_device_boundaries(ax2)
|
|
ax2.set_xlabel('X (μm)')
|
|
ax2.set_ylabel('Y (μm)')
|
|
ax2.set_title(f'2D Electric Field Magnitude at V = {v_current:.2f} V')
|
|
ax2.set_xlim(-W_SIM / um, W_SIM / um)
|
|
ax2.set_ylim(H_SI/um + 15.0, -110.0)
|
|
|
|
plt.tight_layout()
|
|
plt.savefig(f"{OUT_DIR}sweep_potential_2d.png", dpi=300)
|
|
plt.close()
|
|
|
|
print(f"Sweep visualization plots saved: sweep_iv_2d.png and sweep_potential_2d.png.")
|
|
import os; os.system(f'{sys.executable} plot_speed.py {OUT_DIR}simulation_time.log {OUT_DIR}simulation_speed.png')
|