Help Needed with Transient Simulation for BJT Example

Hello DEVSIM Community,

I am working on performing a transient simulation for the BJT example provided in the DEVSIM BJT Example Repository. My goal is to simulate transient behavior where the collector voltage Vc​ is incrementally increased over time.

Below is the code I am using:

import devsim
import bjt_common

def transient_simulation():
    # Uncomment the following lines for extended mode
    # devsim.set_parameter(name="extended_solver", value=True) 
    # devsim.set_parameter(name="extended_model", value=True) 
    # devsim.set_parameter(name="extended_equation", value=True)

    bjt_common.run()
    
    # Initial DC solution
    devsim.solve(type="transient_dc", absolute_error=1e6, relative_error=1e-1, maximum_iterations=40)
    devsim.circuit_alter(name="Vb", value=0.6)
    devsim.solve(type="dc", absolute_error=1e6, relative_error=1e-1, maximum_iterations=40)
    devsim.solve(type="transient_dc", absolute_error=1e6, relative_error=1e-1, maximum_iterations=40)

    # Transient simulation settings
    time_step = 1e-9  # Time step
    total_time = 1e-7  # Total simulation time
    current_time = 0.0
    target_vc = 1.0  # Final Vc value
    vc_step = target_vc / (total_time / time_step)

    while current_time < total_time:
        new_vc = current_time / time_step * vc_step  # Increment Vc
        devsim.circuit_alter(name="Vc", value=new_vc)
        
        devsim.solve(type="transient_bdf1",
                     absolute_error=1e6,
                     relative_error=1e-1,
                     maximum_iterations=100,
                     tdelta=time_step,
                     charge_error=1)
        
        current_time += time_step

if __name__ == "__main__":
    transient_simulation()

Issue: The script executes, but I am encountering different behaviors depending on the mode I use:

  • In normal mode, the simulation fails due to overflow or convergence failure.
  • In extended mode (with extended_solver, extended_model, and extended_equation parameters enabled), the simulation runs but stops progressing at a certain point without explicitly reporting a convergence failure.

Observations:

  • I am using the mesh and setup from the DEVSIM BJT Example Repository.
  • The transient simulation starts but fails to complete as expected.
  • Adding a collector resistor did not help improve convergence or stability.
  • The way I increment Vc​ over time might be contributing to instability.

Questions:

  1. Are there specific solver settings or parameters to improve the stability and convergence for this transient simulation?
  2. Is my method of incrementing Vc​ in the loop correct, or does it need adjustment?
  3. Are there additional strategies or configurations I should consider to enhance solver robustness?

I have attached the log file with further details for reference. Thank you for your time and assistance!

Best regards,
AC

Log File Output

Adding 14773 nodes
Adding 43698 edges with 0 duplicates removed
Adding 28926 triangles with 0 duplicate removed
Contact base in region bjt with 63 nodes
Contact collector in region bjt with 345 nodes
Contact emitter in region bjt with 63 nodes
Replacing Node Model Acceptors in region bjt of material Silicon
Replacing Node Model DEG in region bjt of material Silicon
Replacing Edge Model DField in region bjt of material Silicon
Replacing Edge Model DField:Potential@n0 in region bjt of material Silicon
Replacing Edge Model DField:Potential@n1 in region bjt of material Silicon
Replacing Node Model Donors in region bjt of material Silicon
Replacing Node Model EC in region bjt of material Silicon
Replacing Node Model EC:Potential in region bjt of material Silicon
Replacing Node Model EFN in region bjt of material Silicon
Replacing Node Model EFN:Electrons in region bjt of material Silicon
Replacing Node Model EFN:Potential in region bjt of material Silicon
Replacing Node Model EFP in region bjt of material Silicon
Replacing Node Model EFP:Holes in region bjt of material Silicon
Replacing Node Model EFP:Potential in region bjt of material Silicon
Replacing Edge Model EField in region bjt of material Silicon
Replacing Edge Model EField:Potential@n0 in region bjt of material Silicon
Replacing Edge Model EField:Potential@n1 in region bjt of material Silicon
Replacing Triangle Edge Model EField_x in region bjt of material Silicon
Replacing Triangle Edge Model EField_y in region bjt of material Silicon
Replacing Node Model EG in region bjt of material Silicon
Replacing Node Model EI in region bjt of material Silicon
Replacing Node Model EI:Potential in region bjt of material Silicon
Replacing Node Model EV in region bjt of material Silicon
Replacing Node Model EV:Potential in region bjt of material Silicon
Replacing Node Model ElectronGeneration in region bjt of material Silicon
Replacing Node Model ElectronGeneration:Electrons in region bjt of material Silicon
Replacing Node Model ElectronGeneration:Holes in region bjt of material Silicon
Replacing Edge Model Electrons@n0 in region bjt of material Silicon
Replacing Edge Model Electrons@n1 in region bjt of material Silicon
Replacing Triangle Edge Model Emag in region bjt of material Silicon
Replacing Edge Model Epar_n in region bjt of material Silicon
Replacing Edge Model Epar_n:Potential@n0 in region bjt of material Silicon
Replacing Edge Model Epar_n:Potential@n1 in region bjt of material Silicon
Replacing Edge Model Epar_p in region bjt of material Silicon
Replacing Edge Model Epar_p:Potential@n0 in region bjt of material Silicon
Replacing Edge Model Epar_p:Potential@n1 in region bjt of material Silicon
Replacing Node Model HoleGeneration in region bjt of material Silicon
Replacing Node Model HoleGeneration:Electrons in region bjt of material Silicon
Replacing Node Model HoleGeneration:Holes in region bjt of material Silicon
Replacing Edge Model Holes@n0 in region bjt of material Silicon
Replacing Edge Model Holes@n1 in region bjt of material Silicon
Replacing Node Model IntrinsicCharge in region bjt of material Silicon
Replacing Node Model IntrinsicCharge:Potential in region bjt of material Silicon
Replacing Node Model IntrinsicElectrons in region bjt of material Silicon
Replacing Node Model IntrinsicElectrons:Potential in region bjt of material Silicon
Replacing Node Model IntrinsicHoles in region bjt of material Silicon
Replacing Node Model IntrinsicHoles:Potential in region bjt of material Silicon
Replacing Edge Model Jn in region bjt of material Silicon
Replacing Edge Model Jn:Electrons@n0 in region bjt of material Silicon
Replacing Edge Model Jn:Electrons@n1 in region bjt of material Silicon
Replacing Edge Model Jn:Holes@n0 in region bjt of material Silicon
Replacing Edge Model Jn:Holes@n1 in region bjt of material Silicon
Replacing Edge Model Jn:Potential@n0 in region bjt of material Silicon
Replacing Edge Model Jn:Potential@n1 in region bjt of material Silicon
Replacing Edge Model Jn_arora_lf in region bjt of material Silicon
Replacing Edge Model Jn_arora_lf:Electrons@n0 in region bjt of material Silicon
Replacing Edge Model Jn_arora_lf:Electrons@n1 in region bjt of material Silicon
Replacing Edge Model Jn_arora_lf:Holes@n0 in region bjt of material Silicon
Replacing Edge Model Jn_arora_lf:Holes@n1 in region bjt of material Silicon
Replacing Edge Model Jn_arora_lf:Potential@n0 in region bjt of material Silicon
Replacing Edge Model Jn_arora_lf:Potential@n1 in region bjt of material Silicon
Replacing Triangle Edge Model Jn_x in region bjt of material Silicon
Replacing Triangle Edge Model Jn_y in region bjt of material Silicon
Replacing Triangle Edge Model Jnmag in region bjt of material Silicon
Replacing Edge Model Jp in region bjt of material Silicon
Replacing Edge Model Jp:Electrons@n0 in region bjt of material Silicon
Replacing Edge Model Jp:Electrons@n1 in region bjt of material Silicon
Replacing Edge Model Jp:Holes@n0 in region bjt of material Silicon
Replacing Edge Model Jp:Holes@n1 in region bjt of material Silicon
Replacing Edge Model Jp:Potential@n0 in region bjt of material Silicon
Replacing Edge Model Jp:Potential@n1 in region bjt of material Silicon
Replacing Edge Model Jp_arora_lf in region bjt of material Silicon
Replacing Edge Model Jp_arora_lf:Electrons@n0 in region bjt of material Silicon
Replacing Edge Model Jp_arora_lf:Electrons@n1 in region bjt of material Silicon
Replacing Edge Model Jp_arora_lf:Holes@n0 in region bjt of material Silicon
Replacing Edge Model Jp_arora_lf:Holes@n1 in region bjt of material Silicon
Replacing Edge Model Jp_arora_lf:Potential@n0 in region bjt of material Silicon
Replacing Edge Model Jp_arora_lf:Potential@n1 in region bjt of material Silicon
Replacing Triangle Edge Model Jp_x in region bjt of material Silicon
Replacing Triangle Edge Model Jp_y in region bjt of material Silicon
Replacing Triangle Edge Model Jpmag in region bjt of material Silicon
Replacing Node Model LogNetDoping in region bjt of material Silicon
Replacing Node Model NC in region bjt of material Silicon
Replacing Node Model NCharge in region bjt of material Silicon
Replacing Node Model NCharge:Electrons in region bjt of material Silicon
Replacing Node Model NIE in region bjt of material Silicon
Replacing Node Model NTOT in region bjt of material Silicon
Replacing Node Model NV in region bjt of material Silicon
Replacing Node Model NetDoping in region bjt of material Silicon
Replacing Node Model PCharge in region bjt of material Silicon
Replacing Node Model PCharge:Holes in region bjt of material Silicon
Replacing Edge Model Potential@n0 in region bjt of material Silicon
Replacing Edge Model Potential@n1 in region bjt of material Silicon
Replacing Node Model PotentialIntrinsicCharge in region bjt of material Silicon
Replacing Node Model PotentialIntrinsicCharge:Potential in region bjt of material Silicon
Replacing Node Model PotentialNodeCharge in region bjt of material Silicon
Replacing Node Model PotentialNodeCharge:Electrons in region bjt of material Silicon
Replacing Node Model PotentialNodeCharge:Holes in region bjt of material Silicon
Replacing Node Model Tn in region bjt of material Silicon
Replacing Node Model USRH in region bjt of material Silicon
Replacing Node Model USRH:Electrons in region bjt of material Silicon
Replacing Node Model USRH:Holes in region bjt of material Silicon
Replacing Node Model V_t in region bjt of material Silicon
Replacing Edge Model V_t_edge in region bjt of material Silicon
Replacing Node Model basenodeelectrons in region bjt of material Silicon
Replacing Node Model basenodeelectrons:Electrons in region bjt of material Silicon
Replacing Node Model basenodeholes in region bjt of material Silicon
Replacing Node Model basenodeholes:Holes in region bjt of material Silicon
Replacing Node Model basenodemodel in region bjt of material Silicon
Replacing Node Model basenodemodel:Potential in region bjt of material Silicon
Replacing Edge Model beta_n in region bjt of material Silicon
Replacing Edge Model beta_p in region bjt of material Silicon
Replacing Node Model collectornodeelectrons in region bjt of material Silicon
Replacing Node Model collectornodeelectrons:Electrons in region bjt of material Silicon
Replacing Node Model collectornodeholes in region bjt of material Silicon
Replacing Node Model collectornodeholes:Holes in region bjt of material Silicon
Replacing Node Model collectornodemodel in region bjt of material Silicon
Replacing Node Model collectornodemodel:Potential in region bjt of material Silicon
Replacing Node Model contactcharge_node in region bjt of material Silicon
Replacing Node Model emitternodeelectrons in region bjt of material Silicon
Replacing Node Model emitternodeelectrons:Electrons in region bjt of material Silicon
Replacing Node Model emitternodeholes in region bjt of material Silicon
Replacing Node Model emitternodeholes:Holes in region bjt of material Silicon
Replacing Node Model emitternodemodel in region bjt of material Silicon
Replacing Node Model emitternodemodel:Potential in region bjt of material Silicon
Replacing Edge Model mu_arora_n_lf in region bjt of material Silicon
Replacing Node Model mu_arora_n_node in region bjt of material Silicon
Replacing Edge Model mu_arora_p_lf in region bjt of material Silicon
Replacing Node Model mu_arora_p_node in region bjt of material Silicon
Replacing Edge Model mu_n in region bjt of material Silicon
Replacing Edge Model mu_n:Electrons@n0 in region bjt of material Silicon
Replacing Edge Model mu_n:Electrons@n1 in region bjt of material Silicon
Replacing Edge Model mu_n:Holes@n0 in region bjt of material Silicon
Replacing Edge Model mu_n:Holes@n1 in region bjt of material Silicon
Replacing Edge Model mu_n:Potential@n0 in region bjt of material Silicon
Replacing Edge Model mu_n:Potential@n1 in region bjt of material Silicon
Replacing Edge Model mu_p in region bjt of material Silicon
Replacing Edge Model mu_p:Electrons@n0 in region bjt of material Silicon
Replacing Edge Model mu_p:Electrons@n1 in region bjt of material Silicon
Replacing Edge Model mu_p:Holes@n0 in region bjt of material Silicon
Replacing Edge Model mu_p:Holes@n1 in region bjt of material Silicon
Replacing Edge Model mu_p:Potential@n0 in region bjt of material Silicon
Replacing Edge Model mu_p:Potential@n1 in region bjt of material Silicon
Replacing Edge Model vsat_n in region bjt of material Silicon
Replacing Edge Model vsat_p in region bjt of material Silicon
Replacing Node Model basenodemodel in region bjt of material Silicon
Replacing Node Model basenodemodel:Potential in region bjt of material Silicon
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: base, Equation: PotentialEquation
Replacing Node Model basenodeelectrons in region bjt of material Silicon
Replacing Node Model basenodeelectrons:Electrons in region bjt of material Silicon
Replacing Node Model basenodeholes in region bjt of material Silicon
Replacing Node Model basenodeholes:Holes in region bjt of material Silicon
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: base, Equation: ElectronContinuityEquation
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: base, Equation: HoleContinuityEquation
Replacing Node Model emitternodemodel in region bjt of material Silicon
Replacing Node Model emitternodemodel:Potential in region bjt of material Silicon
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: emitter, Equation: PotentialEquation
Replacing Node Model emitternodeelectrons in region bjt of material Silicon
Replacing Node Model emitternodeelectrons:Electrons in region bjt of material Silicon
Replacing Node Model emitternodeholes in region bjt of material Silicon
Replacing Node Model emitternodeholes:Holes in region bjt of material Silicon
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: emitter, Equation: ElectronContinuityEquation
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: emitter, Equation: HoleContinuityEquation
Replacing Node Model collectornodemodel in region bjt of material Silicon
Replacing Node Model collectornodemodel:Potential in region bjt of material Silicon
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: collector, Equation: PotentialEquation
Replacing Node Model collectornodeelectrons in region bjt of material Silicon
Replacing Node Model collectornodeelectrons:Electrons in region bjt of material Silicon
Replacing Node Model collectornodeholes in region bjt of material Silicon
Replacing Node Model collectornodeholes:Holes in region bjt of material Silicon
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: collector, Equation: ElectronContinuityEquation
Warning: Replacing Contact Equation with Contact Equation of the same name.
Contact: collector, Equation: HoleContinuityEquation
creating solution dcop with 6 nodes
number of equations 44325
creating solution dcop_prev with 6 nodes
Iteration: 0
Device: “bjt” RelError: 2.79806e-01 AbsError: 1.13014e+07
Region: “bjt” RelError: 2.79806e-01 AbsError: 1.13014e+07
Equation: “ElectronContinuityEquation” RelError: 1.24746e-02 AbsError: 8.73575e+06
Equation: “HoleContinuityEquation” RelError: 2.67332e-01 AbsError: 2.56566e+06
Equation: “PotentialEquation” RelError: 2.43219e-08 AbsError: 5.39830e-12
Circuit: RelError: 2.83219e-06 AbsError: 2.84249e-16
Iteration: 1
Device: “bjt” RelError: 6.41556e-02 AbsError: 8.28313e+03
Region: “bjt” RelError: 6.41556e-02 AbsError: 8.28313e+03
Equation: “ElectronContinuityEquation” RelError: 5.46127e-02 AbsError: 8.17775e+03
Equation: “HoleContinuityEquation” RelError: 9.54290e-03 AbsError: 1.05385e+02
Equation: “PotentialEquation” RelError: 1.84650e-12 AbsError: 2.28823e-16
Circuit: RelError: 2.84794e-06 AbsError: 2.88152e-16
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 4.93139e-02 AbsError: 8.27283e+03
Region: “bjt” RelError: 4.93139e-02 AbsError: 8.27283e+03
Equation: “ElectronContinuityEquation” RelError: 4.92892e-02 AbsError: 8.17775e+03
Equation: “HoleContinuityEquation” RelError: 2.47177e-05 AbsError: 9.50865e+01
Equation: “PotentialEquation” RelError: 4.34556e-12 AbsError: 1.38444e-16
Circuit: RelError: 2.33512e-08 AbsError: 3.05173e-18
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 1.04642e+01 AbsError: 7.61305e+17
Region: “bjt” RelError: 1.04642e+01 AbsError: 7.61305e+17
Equation: “ElectronContinuityEquation” RelError: 9.58639e-01 AbsError: 4.38268e+17
Equation: “HoleContinuityEquation” RelError: 9.64430e-01 AbsError: 3.23037e+17
Equation: “PotentialEquation” RelError: 8.54112e+00 AbsError: 6.00000e-01
Circuit: RelError: 1.00000e+00 AbsError: 6.00000e-01
Iteration: 1
Device: “bjt” RelError: 2.73680e+00 AbsError: 6.37560e+17
Region: “bjt” RelError: 2.73680e+00 AbsError: 6.37560e+17
Equation: “ElectronContinuityEquation” RelError: 1.00000e+00 AbsError: 3.19413e+17
Equation: “HoleContinuityEquation” RelError: 1.00000e+00 AbsError: 3.18147e+17
Equation: “PotentialEquation” RelError: 7.36795e-01 AbsError: 1.32042e-01
Circuit: RelError: 1.00000e+00 AbsError: 3.66509e-04
Iteration: 2
Device: “bjt” RelError: 2.13024e+00 AbsError: 1.93793e+17
Region: “bjt” RelError: 2.13024e+00 AbsError: 1.93793e+17
Equation: “ElectronContinuityEquation” RelError: 9.94521e-01 AbsError: 9.28883e+16
Equation: “HoleContinuityEquation” RelError: 9.95892e-01 AbsError: 1.00904e+17
Equation: “PotentialEquation” RelError: 1.39829e-01 AbsError: 5.00367e-02
Circuit: RelError: 4.59849e+00 AbsError: 4.95548e-04
Iteration: 3
Device: “bjt” RelError: 1.38090e+00 AbsError: 7.28651e+15
Region: “bjt” RelError: 1.38090e+00 AbsError: 7.28651e+15
Equation: “ElectronContinuityEquation” RelError: 4.95951e-01 AbsError: 3.14751e+15
Equation: “HoleContinuityEquation” RelError: 8.48025e-01 AbsError: 4.13900e+15
Equation: “PotentialEquation” RelError: 3.69213e-02 AbsError: 1.26512e-02
Circuit: RelError: 1.23915e+01 AbsError: 1.25466e-04
Iteration: 4
Device: “bjt” RelError: 1.41460e-01 AbsError: 2.07027e+14
Region: “bjt” RelError: 1.41460e-01 AbsError: 2.07027e+14
Equation: “ElectronContinuityEquation” RelError: 7.35700e-02 AbsError: 1.44573e+14
Equation: “HoleContinuityEquation” RelError: 6.48800e-02 AbsError: 6.24539e+13
Equation: “PotentialEquation” RelError: 3.01010e-03 AbsError: 1.04471e-03
Circuit: RelError: 7.93485e+02 AbsError: 1.95994e-05
Iteration: 5
Device: “bjt” RelError: 1.55914e-03 AbsError: 2.12314e+12
Region: “bjt” RelError: 1.55914e-03 AbsError: 2.12314e+12
Equation: “ElectronContinuityEquation” RelError: 7.27669e-04 AbsError: 1.50960e+12
Equation: “HoleContinuityEquation” RelError: 8.08492e-04 AbsError: 6.13541e+11
Equation: “PotentialEquation” RelError: 2.29807e-05 AbsError: 7.93527e-06
Circuit: RelError: 1.15915e+00 AbsError: 1.70627e-07
Iteration: 6
Device: “bjt” RelError: 1.90023e-04 AbsError: 2.07918e+10
Region: “bjt” RelError: 1.90023e-04 AbsError: 2.07918e+10
Equation: “ElectronContinuityEquation” RelError: 1.87659e-04 AbsError: 1.10948e+10
Equation: “HoleContinuityEquation” RelError: 2.28603e-06 AbsError: 9.69698e+09
Equation: “PotentialEquation” RelError: 7.73106e-08 AbsError: 2.15189e-08
Circuit: RelError: 9.39505e-05 AbsError: 2.23722e-09
Iteration: 7
Device: “bjt” RelError: 1.95439e-08 AbsError: 3.93944e+07
Region: “bjt” RelError: 1.95439e-08 AbsError: 3.93944e+07
Equation: “ElectronContinuityEquation” RelError: 1.73213e-08 AbsError: 3.01255e+07
Equation: “HoleContinuityEquation” RelError: 2.14447e-09 AbsError: 9.26888e+06
Equation: “PotentialEquation” RelError: 7.81739e-11 AbsError: 2.43572e-11
Circuit: RelError: 1.36799e-07 AbsError: 7.93968e-14
Iteration: 8
Device: “bjt” RelError: 7.62995e-11 AbsError: 2.32146e+04
Region: “bjt” RelError: 7.62995e-11 AbsError: 2.32146e+04
Equation: “ElectronContinuityEquation” RelError: 5.74589e-11 AbsError: 2.02093e+04
Equation: “HoleContinuityEquation” RelError: 1.87928e-11 AbsError: 3.00526e+03
Equation: “PotentialEquation” RelError: 4.78202e-14 AbsError: 1.35556e-14
Circuit: RelError: 9.42600e-11 AbsError: 1.25978e-17
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 1.41734e-11 AbsError: 8.25129e+03
Region: “bjt” RelError: 1.41734e-11 AbsError: 8.25129e+03
Equation: “ElectronContinuityEquation” RelError: 7.61290e-12 AbsError: 8.17103e+03
Equation: “HoleContinuityEquation” RelError: 6.56013e-12 AbsError: 8.02604e+01
Equation: “PotentialEquation” RelError: 4.15251e-16 AbsError: 7.65172e-17
Circuit: RelError: 3.48785e-11 AbsError: 5.14189e-18
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 3.05222e-11 AbsError: 8.31617e+03
Region: “bjt” RelError: 3.05222e-11 AbsError: 8.31617e+03
Equation: “ElectronContinuityEquation” RelError: 8.84944e-12 AbsError: 8.17103e+03
Equation: “HoleContinuityEquation” RelError: 2.16717e-11 AbsError: 1.45136e+02
Equation: “PotentialEquation” RelError: 1.12779e-15 AbsError: 1.53100e-16
Circuit: RelError: 1.73927e-08 AbsError: 1.76881e-15
Charge Relative Error 1.63468e-02
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 1.72092e-11 AbsError: 9.56686e+03
Region: “bjt” RelError: 1.72092e-11 AbsError: 9.56686e+03
Equation: “ElectronContinuityEquation” RelError: 8.10094e-12 AbsError: 8.17103e+03
Equation: “HoleContinuityEquation” RelError: 9.09306e-12 AbsError: 1.39583e+03
Equation: “PotentialEquation” RelError: 1.52031e-14 AbsError: 2.03374e-15
Circuit: RelError: 3.64276e-09 AbsError: 5.79067e-16
Charge Relative Error 1.63350e-02
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 2.68240e-10 AbsError: 1.18980e+05
Region: “bjt” RelError: 2.68240e-10 AbsError: 1.18980e+05
Equation: “ElectronContinuityEquation” RelError: 5.26740e-12 AbsError: 6.44312e+04
Equation: “HoleContinuityEquation” RelError: 2.62367e-10 AbsError: 5.45484e+04
Equation: “PotentialEquation” RelError: 6.05485e-13 AbsError: 8.10606e-14
Circuit: RelError: 1.28537e-07 AbsError: 1.81937e-14
Charge Relative Error 1.63336e-02
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 1.19562e-08 AbsError: 5.32026e+06
Region: “bjt” RelError: 1.19562e-08 AbsError: 5.32026e+06
Equation: “ElectronContinuityEquation” RelError: 1.78224e-10 AbsError: 2.87982e+06
Equation: “HoleContinuityEquation” RelError: 1.17509e-08 AbsError: 2.44044e+06
Equation: “PotentialEquation” RelError: 2.70383e-11 AbsError: 3.61992e-12
Circuit: RelError: 5.72876e-06 AbsError: 8.25063e-13
Iteration: 1
Device: “bjt” RelError: 4.77850e-11 AbsError: 8.38070e+03
Region: “bjt” RelError: 4.77850e-11 AbsError: 8.38070e+03
Equation: “ElectronContinuityEquation” RelError: 2.65621e-11 AbsError: 8.18802e+03
Equation: “HoleContinuityEquation” RelError: 2.12214e-11 AbsError: 1.92677e+02
Equation: “PotentialEquation” RelError: 1.53896e-15 AbsError: 2.05789e-16
Circuit: RelError: 2.62286e-08 AbsError: 2.41003e-15
Charge Relative Error 1.62717e-02
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 5.26411e-07 AbsError: 2.34613e+08
Region: “bjt” RelError: 5.26411e-07 AbsError: 2.34613e+08
Equation: “ElectronContinuityEquation” RelError: 7.87554e-09 AbsError: 1.27022e+08
Equation: “HoleContinuityEquation” RelError: 5.17343e-07 AbsError: 1.07591e+08
Equation: “PotentialEquation” RelError: 1.19261e-09 AbsError: 1.59666e-10
Circuit: RelError: 2.52674e-04 AbsError: 3.63479e-11
Iteration: 1
Device: “bjt” RelError: 6.48790e-11 AbsError: 8.30848e+03
Region: “bjt” RelError: 6.48790e-11 AbsError: 8.30848e+03
Equation: “ElectronContinuityEquation” RelError: 3.27627e-11 AbsError: 8.18600e+03
Equation: “HoleContinuityEquation” RelError: 3.21154e-11 AbsError: 1.22486e+02
Equation: “PotentialEquation” RelError: 8.51962e-16 AbsError: 1.19510e-16
Circuit: RelError: 1.14065e-07 AbsError: 1.35255e-14
Charge Relative Error 1.03878e-02
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 2.33788e-05 AbsError: 1.04140e+10
Region: “bjt” RelError: 2.33788e-05 AbsError: 1.04140e+10
Equation: “ElectronContinuityEquation” RelError: 3.49575e-07 AbsError: 5.63772e+09
Equation: “HoleContinuityEquation” RelError: 2.29763e-05 AbsError: 4.77629e+09
Equation: “PotentialEquation” RelError: 5.29320e-08 AbsError: 7.08653e-09
Circuit: RelError: 1.10922e-02 AbsError: 1.61360e-09
Iteration: 1
Device: “bjt” RelError: 4.30693e-09 AbsError: 2.85163e+05
Region: “bjt” RelError: 4.30693e-09 AbsError: 2.85163e+05
Equation: “ElectronContinuityEquation” RelError: 1.20274e-11 AbsError: 1.55496e+05
Equation: “HoleContinuityEquation” RelError: 4.29344e-09 AbsError: 1.29667e+05
Equation: “PotentialEquation” RelError: 1.46048e-12 AbsError: 1.95510e-13
Circuit: RelError: 2.12032e-07 AbsError: 6.32542e-14
Charge Relative Error 4.12999e-03
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 3.07237e+03 AbsError: 4.67169e+16
Region: “bjt” RelError: 3.07237e+03 AbsError: 4.67169e+16
Equation: “ElectronContinuityEquation” RelError: 2.05051e+03 AbsError: 2.52709e+16
Equation: “HoleContinuityEquation” RelError: 1.02155e+03 AbsError: 2.14459e+16
Equation: “PotentialEquation” RelError: 3.09367e-01 AbsError: 3.17885e-02
Circuit: RelError: 1.05240e+00 AbsError: 7.23519e-03
Iteration: 1
Device: “bjt” RelError: 4.88095e+03 AbsError: 2.34092e+16
Region: “bjt” RelError: 4.88095e+03 AbsError: 2.34092e+16
Equation: “ElectronContinuityEquation” RelError: 1.66681e+02 AbsError: 1.27705e+16
Equation: “HoleContinuityEquation” RelError: 4.71410e+03 AbsError: 1.06387e+16
Equation: “PotentialEquation” RelError: 1.71631e-01 AbsError: 3.73252e-02
Circuit: RelError: 1.11064e+00 AbsError: 6.10344e-02
Iteration: 2
Device: “bjt” RelError: 9.43829e+02 AbsError: 1.69650e+16
Region: “bjt” RelError: 9.43829e+02 AbsError: 1.69650e+16
Equation: “ElectronContinuityEquation” RelError: 4.03964e+00 AbsError: 7.55082e+15
Equation: “HoleContinuityEquation” RelError: 9.39643e+02 AbsError: 9.41418e+15
Equation: “PotentialEquation” RelError: 1.46287e-01 AbsError: 4.37047e-02
Circuit: RelError: 6.57858e-01 AbsError: 2.28269e-02
Iteration: 3
Device: “bjt” RelError: 2.76754e+02 AbsError: 1.65791e+16
Region: “bjt” RelError: 2.76754e+02 AbsError: 1.65791e+16
Equation: “ElectronContinuityEquation” RelError: 4.96005e+00 AbsError: 7.52971e+15
Equation: “HoleContinuityEquation” RelError: 2.71674e+02 AbsError: 9.04938e+15
Equation: “PotentialEquation” RelError: 1.19791e-01 AbsError: 3.77931e-02
Circuit: RelError: 2.70849e-01 AbsError: 8.40170e-03
Iteration: 4
Device: “bjt” RelError: 9.31479e+02 AbsError: 1.10955e+16
Region: “bjt” RelError: 9.31479e+02 AbsError: 1.10955e+16
Equation: “ElectronContinuityEquation” RelError: 1.90627e+00 AbsError: 5.20046e+15
Equation: “HoleContinuityEquation” RelError: 9.29505e+02 AbsError: 5.89504e+15
Equation: “PotentialEquation” RelError: 6.71850e-02 AbsError: 2.47877e-02
Circuit: RelError: 8.13139e-03 AbsError: 9.73656e-05
Iteration: 5
Device: “bjt” RelError: 8.48824e+03 AbsError: 2.64936e+16
Region: “bjt” RelError: 8.48824e+03 AbsError: 2.64936e+16
Equation: “ElectronContinuityEquation” RelError: 1.10308e+00 AbsError: 1.22364e+16
Equation: “HoleContinuityEquation” RelError: 8.48697e+03 AbsError: 1.42572e+16
Equation: “PotentialEquation” RelError: 1.67272e-01 AbsError: 6.69905e-02
Circuit: RelError: 3.30267e-01 AbsError: 1.23252e-02
Iteration: 6
Device: “bjt” RelError: 8.21682e+03 AbsError: 6.93979e+17
Region: “bjt” RelError: 8.21682e+03 AbsError: 6.93979e+17
Equation: “ElectronContinuityEquation” RelError: 7.78065e+00 AbsError: 2.76293e+17
Equation: “HoleContinuityEquation” RelError: 8.20464e+03 AbsError: 4.17686e+17
Equation: “PotentialEquation” RelError: 4.40276e+00 AbsError: 1.82916e+00
Circuit: RelError: 2.74308e+00 AbsError: 1.24827e-02
Iteration: 7
Device: “bjt” RelError: 9.86477e+04 AbsError: 1.40023e+18
Region: “bjt” RelError: 9.86477e+04 AbsError: 1.40023e+18
Equation: “ElectronContinuityEquation” RelError: 6.00597e+04 AbsError: 5.85128e+17
Equation: “HoleContinuityEquation” RelError: 3.08589e+03 AbsError: 8.15103e+17
Equation: “PotentialEquation” RelError: 3.55022e+04 AbsError: 3.29294e+00
Circuit: RelError: 1.40239e+00 AbsError: 9.90147e-02
Iteration: 8
Device: “bjt” RelError: 8.17687e+04 AbsError: 2.17717e+18
Region: “bjt” RelError: 8.17687e+04 AbsError: 2.17717e+18
Equation: “ElectronContinuityEquation” RelError: 5.57840e+03 AbsError: 9.52540e+17
Equation: “HoleContinuityEquation” RelError: 2.96513e+03 AbsError: 1.22463e+18
Equation: “PotentialEquation” RelError: 7.32252e+04 AbsError: 5.63977e+00
Circuit: RelError: 1.69114e+00 AbsError: 3.60203e-01
Iteration: 9
Device: “bjt” RelError: 7.63745e+03 AbsError: 6.19079e+20
Region: “bjt” RelError: 7.63745e+03 AbsError: 6.19079e+20
Equation: “ElectronContinuityEquation” RelError: 7.26125e+03 AbsError: 2.82408e+20
Equation: “HoleContinuityEquation” RelError: 8.34334e+01 AbsError: 3.36671e+20
Equation: “PotentialEquation” RelError: 2.92767e+02 AbsError: 5.30890e+02
Circuit: RelError: 1.00130e+00 AbsError: 2.10281e+02
while evaluating node model IntrinsicElectrons on Device: bjt on Region: bjt
There was a Overflow floating point exception while evaluating exp((Potential * pow(V_t,(-1))))
while evaluating node model IntrinsicElectrons on Device: bjt on Region: bjt
There was a Overflow floating point exception while evaluating exp((Potential * pow(V_t,(-1))))
while evaluating model IntrinsicElectrons: expression (NIE * exp((Potential * pow(V_t,(-1))))) evaluates to invalid

Hi @AC_hm

I think there is a bug, but I am not sure where it is. It may be somewhere in the time-dependent models for the bjt example. Changing “transient_bdf1” to “dc” in the loop causes every thing to run, but unfortunately it is not time dependent. This example is very old, and may take a while to debug.

This script works by using the models packaged in devsim, instead of the bjt example. It also loads the mesh from gmsh and applies the doping profile. Loading from the format made it confusing because it was loading the previous physics along with the structure data.

Please let me know if this is useful to you:

from devsim import (
    circuit_alter,
    circuit_element,
    equation,
    get_contact_list,
    get_equation_command,
    set_node_values,
    set_parameter,
    solve,
    )
from devsim.python_packages.model_create import CreateSolution
from devsim.python_packages.simple_physics import (
    CreateSiliconDriftDiffusion,
    CreateSiliconDriftDiffusionAtContact,
    CreateSiliconPotentialOnly,
    CreateSiliconPotentialOnlyContact,
    GetContactBiasName,
    SetSiliconParameters,
    )
import read_gmsh
import netdoping

device="bjt"
region="bjt"

# read in gmsh mesh
# we are avoiding the devsim mesh format, since it loads new physics models
# which may hae a bug
read_gmsh.run("bjt.msh", device, region, "Silicon", ("base", "collector", "emitter"))

# set net doping
netdoping.run(device, region)


####
#### Initial DC solution
####
# here we are avoiding new physical models and using the ones from devsim
CreateSolution(device, region, "Potential")
# start with temperature as a model and not a parameter
set_parameter(device=device, name="T", value=300)
SetSiliconParameters(device, region, 300)
#set_parameter(device=device, name="taun", value=1e-10)
#set_parameter(device=device, name="taup", value=1e-10)



CreateSiliconPotentialOnly(device, region)

fixed_contacts = []
circuit_contacts = ['base', 'collector', 'emitter']

for c in fixed_contacts:
    CreateSiliconPotentialOnlyContact(device, region, c)
    set_parameter(device=device, region=region, name=GetContactBiasName(c), value=0.0)
for c in circuit_contacts:
    circuit_element(name="V%s" % c[0], n1=GetContactBiasName(c), n2="0", value=0.0)
    CreateSiliconPotentialOnlyContact(device, region, c, is_circuit=True)

solve(type="dc", absolute_error=1.0, relative_error=1e-9, maximum_iterations=40)

###
### Drift diffusion and circuit
###
CreateSolution(device, region, "Electrons")
CreateSolution(device, region, "Holes")
set_node_values(device=device, region=region, name="Electrons", init_from="IntrinsicElectrons")
set_node_values(device=device, region=region, name="Holes",     init_from="IntrinsicHoles")

CreateSiliconDriftDiffusion(device, region)

#eqcmd = get_equation_command(device="bjt", region="bjt", name="PotentialEquation")
#eqcmd['variable_update'] = 'default'
#equation(**eqcmd)


for c in fixed_contacts:
    CreateSiliconDriftDiffusionAtContact(device, region, c, is_circuit=False)
for c in circuit_contacts:
    #set_parameter(device=device, region=region, name=GetContactBiasName(c), value=0.0)
    CreateSiliconDriftDiffusionAtContact(device, region, c, is_circuit=True)
    # use first initial of each contact name

circuit_alter(name="Vb", value=0.6)

solve(type="dc", absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)
solve(type="transient_dc", absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)

# Transient simulation settings
time_step = 1e-11  # Time step
total_time = 1e-9  # Total simulation time
current_time = 0.0
target_vc = 1.0  # Final Vc value
vc_step = target_vc / (total_time / time_step)
new_vc = 0.0
while current_time < total_time:
    current_time += time_step
    new_vc += vc_step
    circuit_alter(name="Vc", value=new_vc)
    
    try:
        solve(type="transient_bdf1",
                     absolute_error=1e6,
                     relative_error=1e-5,
                     maximum_iterations=40,
                     tdelta=time_step,
                     charge_error=1e3)
    except:
        print((new_vc,time_step))
        raise

Hi @Juan ,

Thank you for providing the script that utilizes DEVSIM’s built-in models and loads the mesh from Gmsh. This approach is indeed helpful, as it ensures a clean setup by avoiding the inadvertent loading of previous physics along with the structural data.

Regarding the transient simulation, I have observed discrepancies in the current calculations compared to the DC analysis. Specifically, the base current in the transient simulation is significantly larger and negative, and Kirchhoff’s Current Law (KCL) is not satisfied within the specified tolerance. This contrasts with the DC simulation, where KCL is satisfied.

Transient Simulation Results:

  • Base Voltage: 0.6 V
  • Collector Voltage: 2.0 V
  • Emitter Voltage: ~0 V
  • Base Current: -4.177e-03 A
  • Collector Current: 6.076e-04 A
  • Emitter Current: 3.569e-03 A
  • KCL Status: Not satisfied

DC Simulation Results:

  • Base Voltage: 0.6 V
  • Collector Voltage: 2.0 V
  • Emitter Voltage: ~0 V
  • Base Current: 1.594e-07 A
  • Collector Current: 1.580e-04 A
  • Emitter Current: -1.582e-04 A
  • KCL Status: Satisfied

I have ensured that the mesh is correctly loaded from Gmsh and that the doping profile is appropriately applied. The script utilizes DEVSIM’s built-in models, and I have verified that the initial conditions and biasing are consistent between simulations.

  1. Current Calculation Methodology: Is there a difference in how DEVSIM calculates currents in transient versus DC simulations that might explain these discrepancies?

  2. Current densities: In a 2D DEVSIM simulation, is it necessary to adjust the calculated current densities by multiplying them with the respective contact widths to obtain the total current, or does DEVSIM inherently account for the contact width when computing the total current?

  3. is there a solution for transient simulation like the “dcop” or a better way to do it ?

def print_circuit_solution():
    """Prints the circuit node values for DC operating point."""
    for node in devsim.get_circuit_node_list():
        r = devsim.get_circuit_node_value(solution="dcop", node=node)
        print(f"{node}\t{r:1.15e}")

The widths of these contacts are as follows:

Contact Width (cm)
Emitter 5 × 10⁻⁴
Base 5 × 10⁻⁴
Collector 3 × 10⁻³

I have attached the log files and scripts for both simulations for your reference. Your insights into resolving these issues would be greatly appreciated.

Best regards,
AC

Transient_simulation

from devsim import (
circuit_alter,
circuit_element,
get_contact_current,
get_circuit_node_value,
set_node_values,
set_parameter,
solve,
)
from devsim.python_packages.model_create import CreateSolution
from devsim.python_packages.simple_physics import (
CreateSiliconDriftDiffusion,
CreateSiliconDriftDiffusionAtContact,
CreateSiliconPotentialOnly,
CreateSiliconPotentialOnlyContact,
GetContactBiasName,
SetSiliconParameters,
)
import read_gmsh
import netdoping

device = “bjt”
region = “bjt”

Read in Gmsh mesh

read_gmsh.run(“bjt.msh”, device, region, “Silicon”, (“base”, “collector”, “emitter”))

Set net doping

netdoping.run(device, region)

Initial DC solution setup

CreateSolution(device, region, “Potential”)
set_parameter(device=device, name=“T”, value=300)
SetSiliconParameters(device, region, 300)

CreateSiliconPotentialOnly(device, region)

fixed_contacts =
circuit_contacts = [‘base’, ‘collector’, ‘emitter’]

Setup for contacts

for c in fixed_contacts:
CreateSiliconPotentialOnlyContact(device, region, c)
set_parameter(device=device, region=region, name=GetContactBiasName(c), value=0.0)

for c in circuit_contacts:
circuit_element(name=f"V{c[0]}", n1=GetContactBiasName(c), n2=“0”, value=0.0)
CreateSiliconPotentialOnlyContact(device, region, c, is_circuit=True)

solve(type=“dc”, absolute_error=1.0, relative_error=1e-9, maximum_iterations=40)

Drift-diffusion and circuit setup

CreateSolution(device, region, “Electrons”)
CreateSolution(device, region, “Holes”)
set_node_values(device=device, region=region, name=“Electrons”, init_from=“IntrinsicElectrons”)
set_node_values(device=device, region=region, name=“Holes”, init_from=“IntrinsicHoles”)

CreateSiliconDriftDiffusion(device, region)

for c in fixed_contacts:
CreateSiliconDriftDiffusionAtContact(device, region, c, is_circuit=False)

for c in circuit_contacts:
CreateSiliconDriftDiffusionAtContact(device, region, c, is_circuit=True)

Function to print contact currents

def print_contact_currents(device, contacts):
for contact in contacts:
electron_current = get_contact_current(device=device, contact=contact, equation=“ElectronContinuityEquation”)
hole_current = get_contact_current(device=device, contact=contact, equation=“HoleContinuityEquation”)
total_current = electron_current + hole_current
print(f"Total current at {contact} contact: {total_current} A")

def print_contact_voltages_dc(device, contacts):
for contact in contacts:
circuit_node = GetContactBiasName(contact)
if circuit_node:
voltage = get_circuit_node_value(solution=‘dcop’, node=circuit_node)
print(f"Voltage at {contact} contact (DC): {voltage} V")
else:
print(f"Error: No circuit node found for contact {contact}")

Function for Printing Contact Voltages during Transient Simulations:

def print_contact_voltages_transient(device, contacts):
for contact in contacts:
circuit_node = GetContactBiasName(contact)
if circuit_node:
voltage = get_circuit_node_value(solution=‘dcop’, node=circuit_node)
print(f"Voltage at {contact} contact (Transient): {voltage} V")
else:
print(f"Error: No circuit node found for contact {contact}")

Function to verify Kirchhoff’s Current Law (KCL) using relative error

def verify_kcl(device, contacts, relative_error_threshold=1e-5):
currents =
for contact in contacts:
electron_current = get_contact_current(device=device, contact=contact, equation=“ElectronContinuityEquation”)
hole_current = get_contact_current(device=device, contact=contact, equation=“HoleContinuityEquation”)
total_current = electron_current + hole_current
currents.append(total_current)

ic, ie, ib = currents
numerator = abs(ic + ie + ib)
denominator = abs(ic) + abs(ie) + abs(ib)
relative_error = numerator / denominator

print(f"Sum of currents (numerator): {numerator} A")
print(f"Total absolute currents (denominator): {denominator} A")
print(f"Relative error: {relative_error}")

if relative_error < relative_error_threshold:
    print("KCL is satisfied within the specified tolerance.")
    return True
else:
    print("KCL is NOT satisfied within the specified tolerance.")
    return False

Apply biases and solve

circuit_alter(name=“Vb”, value=0.6)
solve(type=“dc”, absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)

circuit_alter(name=“Vc”, value=1.0)
solve(type=“dc”, absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)
solve(type=“transient_dc”, absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)

Print contact currents

print_contact_voltages_dc(device, circuit_contacts)
print_contact_currents(device, circuit_contacts)

Verify Kirchhoff’s Current Law

kcl_satisfied = verify_kcl(device, circuit_contacts)
if not kcl_satisfied:
print(“Investigate discrepancies in current calculations.”)

Transient simulation settings

time_step = 1e-11 # Time step
total_time = 1e-9 # Total simulation time
current_time = 0.0
target_vc = 2.0 # Final Vc value
vc_step = target_vc / (total_time / time_step)
new_vc = 1.0

while current_time < total_time:
current_time += time_step
new_vc += vc_step
if new_vc > target_vc: # Prevent exceeding the target voltage
new_vc = target_vc

circuit_alter(name="Vc", value=new_vc)

try:
    solve(type="transient_bdf1",
          absolute_error=1e6,
          relative_error=1e-5,
          maximum_iterations=40,
          tdelta=time_step,
          charge_error=1e3)
    print_contact_voltages_transient(device, circuit_contacts)
    print_contact_currents(device, circuit_contacts)
    kcl_satisfied = verify_kcl(device, circuit_contacts)
except Exception as e:
    print(f"Error at Vc={new_vc}, time_step={time_step}: {e}")
    raise
DC_simulation

from devsim import (
circuit_alter,
circuit_element,
get_contact_current,
set_node_values,
set_parameter,
solve,
get_circuit_node_value,

)
from devsim.python_packages.model_create import CreateSolution
from devsim.python_packages.simple_physics import (
CreateSiliconDriftDiffusion,
CreateSiliconDriftDiffusionAtContact,
CreateSiliconPotentialOnly,
CreateSiliconPotentialOnlyContact,
GetContactBiasName,
SetSiliconParameters,
)
import read_gmsh
import netdoping

device = “bjt”
region = “bjt”

Read in Gmsh mesh

read_gmsh.run(“bjt.msh”, device, region, “Silicon”, (“base”, “collector”, “emitter”))

Set net doping

netdoping.run(device, region)

Initial DC solution setup

CreateSolution(device, region, “Potential”)
set_parameter(device=device, name=“T”, value=300)
SetSiliconParameters(device, region, 300)

CreateSiliconPotentialOnly(device, region)

fixed_contacts =
circuit_contacts = [‘base’, ‘collector’, ‘emitter’]

Setup for contacts

for c in fixed_contacts:
CreateSiliconPotentialOnlyContact(device, region, c)
set_parameter(device=device, region=region, name=GetContactBiasName(c), value=0.0)

for c in circuit_contacts:
circuit_element(name=f"V{c[0]}", n1=GetContactBiasName(c), n2=“0”, value=0.0)
CreateSiliconPotentialOnlyContact(device, region, c, is_circuit=True)

solve(type=“dc”, absolute_error=1.0, relative_error=1e-9, maximum_iterations=40)

Drift-diffusion and circuit setup

CreateSolution(device, region, “Electrons”)
CreateSolution(device, region, “Holes”)
set_node_values(device=device, region=region, name=“Electrons”, init_from=“IntrinsicElectrons”)
set_node_values(device=device, region=region, name=“Holes”, init_from=“IntrinsicHoles”)

CreateSiliconDriftDiffusion(device, region)

for c in fixed_contacts:
CreateSiliconDriftDiffusionAtContact(device, region, c, is_circuit=False)

for c in circuit_contacts:
CreateSiliconDriftDiffusionAtContact(device, region, c, is_circuit=True)

Function to print contact currents

def print_contact_currents(device, contacts):
for contact in contacts:
electron_current = get_contact_current(device=device, contact=contact, equation=“ElectronContinuityEquation”)
hole_current = get_contact_current(device=device, contact=contact, equation=“HoleContinuityEquation”)
total_current = electron_current + hole_current
print(f"Total current at {contact} contact: {total_current} A")

def print_contact_voltages_dc(device, contacts):
for contact in contacts:
circuit_node = GetContactBiasName(contact)
if circuit_node:
voltage = get_circuit_node_value(solution=‘dcop’, node=circuit_node)
print(f"Voltage at {contact} contact (DC): {voltage} V")
else:
print(f"Error: No circuit node found for contact {contact}")

Function to verify Kirchhoff’s Current Law (KCL) using relative error

def verify_kcl(device, contacts, relative_error_threshold=1e-10):
currents =
for contact in contacts:
electron_current = get_contact_current(device=device, contact=contact, equation=“ElectronContinuityEquation”)
hole_current = get_contact_current(device=device, contact=contact, equation=“HoleContinuityEquation”)
total_current = electron_current + hole_current
currents.append(total_current)

ic, ie, ib = currents
numerator = abs(ic + ie + ib)
denominator = abs(ic) + abs(ie) + abs(ib)
relative_error = numerator / denominator

print(f"Sum of currents (numerator): {numerator} A")
print(f"Total absolute currents (denominator): {denominator} A")
print(f"Relative error: {relative_error}")

if relative_error < relative_error_threshold:
    print("KCL is satisfied within the specified tolerance.")
    return True
else:
    print("KCL is NOT satisfied within the specified tolerance.")
    return False

Apply biases and solve

circuit_alter(name=“Vb”, value=0.6)
solve(type=“dc”, absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)

circuit_alter(name=“Vc”, value=1.0)
solve(type=“dc”, absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)

Print contact currents

print_contact_currents(device, circuit_contacts)

Verify Kirchhoff’s Current Law

kcl_satisfied = verify_kcl(device, circuit_contacts)
if not kcl_satisfied:
print(“Investigate discrepancies in current calculations.”)

Additional solves

circuit_alter(name=“Vc”, value=2.0)
solve(type=“dc”, absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)
solve(type=“transient_dc”, absolute_error=1e6, relative_error=1e-10, maximum_iterations=40)

Print final contact currents

print_contact_voltages_dc(device, circuit_contacts)
print_contact_currents(device, circuit_contacts)
kcl_satisfied = verify_kcl(device, circuit_contacts)

LogFile_Transient

Iteration: 0
Device: “bjt” RelError: 5.69178e-02 AbsError: 5.16664e+14
Region: “bjt” RelError: 5.69178e-02 AbsError: 5.16664e+14
Equation: “ElectronContinuityEquation” RelError: 2.83395e-02 AbsError: 2.77942e+14
Equation: “HoleContinuityEquation” RelError: 2.60882e-02 AbsError: 2.38722e+14
Equation: “PotentialEquation” RelError: 2.49014e-03 AbsError: 3.43039e-04
Circuit: RelError: 4.21915e-02 AbsError: 3.66993e-04
Iteration: 1
Device: “bjt” RelError: 2.69822e-04 AbsError: 3.36630e+11
Region: “bjt” RelError: 2.69822e-04 AbsError: 3.36630e+11
Equation: “ElectronContinuityEquation” RelError: 7.96143e-05 AbsError: 1.66795e+11
Equation: “HoleContinuityEquation” RelError: 1.89682e-04 AbsError: 1.69835e+11
Equation: “PotentialEquation” RelError: 5.25627e-07 AbsError: 7.25311e-08
Circuit: RelError: 7.96281e-05 AbsError: 1.27676e-07
Iteration: 2
Device: “bjt” RelError: 1.84350e-09 AbsError: 1.11674e+05
Region: “bjt” RelError: 1.84350e-09 AbsError: 1.11674e+05
Equation: “ElectronContinuityEquation” RelError: 1.07660e-10 AbsError: 4.10965e+04
Equation: “HoleContinuityEquation” RelError: 1.73576e-09 AbsError: 7.05771e+04
Equation: “PotentialEquation” RelError: 8.43567e-14 AbsError: 2.08496e-14
Circuit: RelError: 3.07594e-09 AbsError: 2.00836e-12
Charge Relative Error 9.60282e-03
Voltage at base contact (Transient): 0.6 V
Voltage at collector contact (Transient): 2.0 V
Voltage at emitter contact (Transient): -2.8597602890957234e-33 V
Total current at base contact: -0.004523244987649031 A
Total current at collector contact: 0.0006450019873405258 A
Total current at emitter contact: 0.0038775338339720232 A
Sum of currents (numerator): 7.091663364821275e-07 A
Total absolute currents (denominator): 0.009045780808961582 A
Relative error: 7.83974707611268e-05
KCL is NOT satisfied within the specified tolerance.
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 5.57415e-02 AbsError: 4.96560e+14
Region: “bjt” RelError: 5.57415e-02 AbsError: 4.96560e+14
Equation: “ElectronContinuityEquation” RelError: 2.75304e-02 AbsError: 2.67149e+14
Equation: “HoleContinuityEquation” RelError: 2.58114e-02 AbsError: 2.29411e+14
Equation: “PotentialEquation” RelError: 2.39969e-03 AbsError: 3.29788e-04
Circuit: RelError: 4.22790e-02 AbsError: 3.52810e-04
Iteration: 1
Device: “bjt” RelError: 2.48687e-04 AbsError: 3.10835e+11
Region: “bjt” RelError: 2.48687e-04 AbsError: 3.10835e+11
Equation: “ElectronContinuityEquation” RelError: 7.35661e-05 AbsError: 1.54016e+11
Equation: “HoleContinuityEquation” RelError: 1.74635e-04 AbsError: 1.56818e+11
Equation: “PotentialEquation” RelError: 4.85983e-07 AbsError: 6.69001e-08
Circuit: RelError: 7.56371e-05 AbsError: 1.17727e-07
Iteration: 2
Device: “bjt” RelError: 1.56979e-09 AbsError: 9.50880e+04
Region: “bjt” RelError: 1.56979e-09 AbsError: 9.50880e+04
Equation: “ElectronContinuityEquation” RelError: 9.17493e-11 AbsError: 3.49181e+04
Equation: “HoleContinuityEquation” RelError: 1.47797e-09 AbsError: 6.01700e+04
Equation: “PotentialEquation” RelError: 7.13341e-14 AbsError: 1.78783e-14
Circuit: RelError: 1.37934e-09 AbsError: 1.99484e-12
Charge Relative Error 8.32832e-03
Voltage at base contact (Transient): 0.6 V
Voltage at collector contact (Transient): 2.0 V
Voltage at emitter contact (Transient): -3.0591541061011293e-32 V
Total current at base contact: -0.004346801087934734 A
Total current at collector contact: 0.0006259327487453262 A
Total current at emitter contact: 0.0037201866089124004 A
Sum of currents (numerator): 6.817302770074744e-07 A
Total absolute currents (denominator): 0.00869292044559246 A
Relative error: 7.842361853813233e-05
KCL is NOT satisfied within the specified tolerance.
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 5.45489e-02 AbsError: 4.77228e+14
Region: “bjt” RelError: 5.45489e-02 AbsError: 4.77228e+14
Equation: “ElectronContinuityEquation” RelError: 2.67221e-02 AbsError: 2.56770e+14
Equation: “HoleContinuityEquation” RelError: 2.55146e-02 AbsError: 2.20458e+14
Equation: “PotentialEquation” RelError: 2.31226e-03 AbsError: 3.17038e-04
Circuit: RelError: 4.23690e-02 AbsError: 3.39165e-04
Iteration: 1
Device: “bjt” RelError: 2.28996e-04 AbsError: 2.87006e+11
Region: “bjt” RelError: 2.28996e-04 AbsError: 2.87006e+11
Equation: “ElectronContinuityEquation” RelError: 6.79739e-05 AbsError: 1.42212e+11
Equation: “HoleContinuityEquation” RelError: 1.60573e-04 AbsError: 1.44794e+11
Equation: “PotentialEquation” RelError: 4.49301e-07 AbsError: 6.17077e-08
Circuit: RelError: 7.18248e-05 AbsError: 1.08556e-07
Iteration: 2
Device: “bjt” RelError: 3.01938e-09 AbsError: 8.10935e+04
Region: “bjt” RelError: 3.01938e-09 AbsError: 8.10935e+04
Equation: “ElectronContinuityEquation” RelError: 7.84776e-11 AbsError: 2.97338e+04
Equation: “HoleContinuityEquation” RelError: 2.94084e-09 AbsError: 5.13597e+04
Equation: “PotentialEquation” RelError: 6.04886e-14 AbsError: 1.51782e-14
Circuit: RelError: 8.49244e-10 AbsError: 5.40534e-13
Charge Relative Error 9.14359e-03
Voltage at base contact (Transient): 0.6 V
Voltage at collector contact (Transient): 2.0 V
Voltage at emitter contact (Transient): 8.20389997066352e-33 V
Total current at base contact: -0.004177181640944649 A
Total current at collector contact: 0.0006076078739598118 A
Total current at emitter contact: 0.003568918398199972 A
Sum of currents (numerator): 6.553687848655058e-07 A
Total absolute currents (denominator): 0.008353707913104434 A
Relative error: 7.845244191952546e-05
KCL is NOT satisfied within the specified tolerance.

LogFile_DC

Iteration: 13
Device: “bjt” RelError: 2.80335e+04 AbsError: 1.87212e+14
Region: “bjt” RelError: 2.80335e+04 AbsError: 1.87212e+14
Equation: “ElectronContinuityEquation” RelError: 2.05169e+00 AbsError: 1.35653e+14
Equation: “HoleContinuityEquation” RelError: 2.80314e+04 AbsError: 5.15582e+13
Equation: “PotentialEquation” RelError: 1.21145e-02 AbsError: 2.82814e-02
Circuit: RelError: 1.28352e-02 AbsError: 1.22428e-08
Iteration: 14
Device: “bjt” RelError: 1.31168e+03 AbsError: 9.44289e+13
Region: “bjt” RelError: 1.31168e+03 AbsError: 9.44289e+13
Equation: “ElectronContinuityEquation” RelError: 1.00000e+00 AbsError: 7.24969e+13
Equation: “HoleContinuityEquation” RelError: 1.31067e+03 AbsError: 2.19321e+13
Equation: “PotentialEquation” RelError: 9.77010e-03 AbsError: 2.30334e-02
Circuit: RelError: 1.09794e-03 AbsError: 2.85018e-09
Iteration: 15
Device: “bjt” RelError: 1.67054e+03 AbsError: 8.69035e+13
Region: “bjt” RelError: 1.67054e+03 AbsError: 8.69035e+13
Equation: “ElectronContinuityEquation” RelError: 2.40664e-01 AbsError: 6.52564e+13
Equation: “HoleContinuityEquation” RelError: 1.67030e+03 AbsError: 2.16471e+13
Equation: “PotentialEquation” RelError: 3.62118e-04 AbsError: 8.25373e-04
Circuit: RelError: 1.47921e-03 AbsError: 2.64726e-09
Iteration: 16
Device: “bjt” RelError: 2.95501e-01 AbsError: 4.92981e+11
Region: “bjt” RelError: 2.95501e-01 AbsError: 4.92981e+11
Equation: “ElectronContinuityEquation” RelError: 1.17988e-03 AbsError: 4.18893e+11
Equation: “HoleContinuityEquation” RelError: 2.94319e-01 AbsError: 7.40879e+10
Equation: “PotentialEquation” RelError: 1.89134e-06 AbsError: 4.31092e-06
Circuit: RelError: 2.40703e-08 AbsError: 2.15010e-12
Iteration: 17
Device: “bjt” RelError: 6.81948e-07 AbsError: 1.64152e+07
Region: “bjt” RelError: 6.81948e-07 AbsError: 1.64152e+07
Equation: “ElectronContinuityEquation” RelError: 3.13281e-08 AbsError: 1.46390e+07
Equation: “HoleContinuityEquation” RelError: 6.50561e-07 AbsError: 1.77625e+06
Equation: “PotentialEquation” RelError: 5.92172e-11 AbsError: 1.34974e-10
Circuit: RelError: 2.75873e-12 AbsError: 2.04696e-17
Iteration: 18
Device: “bjt” RelError: 1.54549e-15 AbsError: 1.88462e-02
Region: “bjt” RelError: 1.54549e-15 AbsError: 1.88462e-02
Equation: “ElectronContinuityEquation” RelError: 1.26283e-15 AbsError: 1.72272e-02
Equation: “HoleContinuityEquation” RelError: 2.82596e-16 AbsError: 1.61901e-03
Equation: “PotentialEquation” RelError: 6.43335e-20 AbsError: 1.46635e-19
Circuit: RelError: 4.89100e-18 AbsError: 1.11173e-21
number of equations 44325
Iteration: 0
Device: “bjt” RelError: 2.73929e-25 AbsError: 7.24246e-15
Region: “bjt” RelError: 2.73929e-25 AbsError: 7.24246e-15
Equation: “ElectronContinuityEquation” RelError: 2.72571e-25 AbsError: 7.10234e-15
Equation: “HoleContinuityEquation” RelError: 1.35821e-27 AbsError: 1.40123e-16
Equation: “PotentialEquation” RelError: 7.52529e-34 AbsError: 1.53433e-33
Circuit: RelError: 4.89100e-18 AbsError: 1.11173e-21
Voltage at base contact (DC): 0.6 V
Voltage at collector contact (DC): 2.0 V
Voltage at emitter contact (DC): 9.9743548256647e-42 V
Total current at base contact: 1.5943467399288255e-07 A
Total current at collector contact: 0.00015805397985680026 A
Total current at emitter contact: -0.00015821341453079314 A
Sum of currents (numerator): 0.0 A
Total absolute currents (denominator): 0.0003164268290615863 A
Relative error: 0.0
KCL is satisfied within the specified tolerance.

I appreciate your patience. I will be able to take a look in the next few days

Hello @AC_hm

I have been on vacation, but I am now looking at your scripts. It will take me some more time to get you an answer concerning your simulation. I think there may be some charge models that are in the bjt example equations, which are not correct and I will update you after I see if removing them makes a difference.

At the end of each step, the current and charge are stored on the contact.
Using get_contact_current does not account for any transient charge. For an ohmic contact to a semiconductor, it should be sufficient. For a MOS capacitor, you can use get_contact_charge to get the charge on the insulator.

To get the net current, including the time derivative of charge, you should use a circuit node. If your voltage source is Vb, then the current through it will be Vb.I, and will account for the net current resulting from electron current and charge from the contact. At the end of each transient step, it will be stored on dcop, which is the same storage as the dc solution.

The flux into the circuit is from the current and charge and goes into this option of the contact_equation command.

    circuit_node : str, optional
       Name of the circuit we integrate the flux into

The models for charge and current integrated into the circuit node are:

    edge_charge_model : str, optional
       Name of the edge model used to determine the charge at this contact
    edge_current_model : str, optional
       Name of the edge model used to determine the current flowing out of this contact
    element_charge_model : str, optional
       Name of the element edge model used to determine the charge at this contact
    element_current_model : str, optional
       Name of the element edge model used to determine the current flowing out of this contact
    node_charge_model : str, optional
       Name of the node model used to determine the charge at this contact
    node_current_model : str, optional
       Name of the node model used to determine the current flowing out of this 

For an ohmic contact, I would expect that only edge_current_model would need to be defined. You can use get_contact_equation_command to verify this. I suspect for historical reasons, the BJT example may be defining edge_charge_model and node_charge_model which I now believe is incorrect. I will check this and see about removing it using:

eqcmd = get_contact_equation_command(.....)
eqcmd['edge_charge_model'] = ''
eqcmd['node_charge_model'] = ''
contact_equation(**eqcmd)

DEVSIM accounts for the contact width by integrating the edge current going into the contact by its EdgeCouple model.

I = \sum_i \sum_j J_{i,j} \text{EdgeCouple}_{i,j}

where J_{i,j} is the edge current between a node on the contact and another node inside the bulk of the device.

dcop is the correct solution to use for both transient and dc simulation.