C-V characteristic of MOSFET

Hi! Are there any examples of C-V characteristics of a mosfet (C-Vgs)? I tried to transfer the code from the diode example (ssac_diode), but apparently got confused( and it doesn’t work.

vgs=[]
cgs=[]
ids=[]

v=0.0
while v < 4.1:
    circuit_alter(name="V1", value=v)
    set_parameter(device=device, name=GetContactBiasName('gate'), value=v)
    solve(type="dc", absolute_error=1.0e30, relative_error=1e-5, maximum_iterations=50)
    #solve(type="dc", absolute_error=1e30, relative_error=1e-10, maximum_iterations=100)
    #PrintCurrents(device, "drain")

    contact_bias_name = GetContactBiasName('drain')
    electron_current= get_contact_current(device=device, contact='drain', equation="ElectronContinuityEquation")
    hole_current= get_contact_current(device=device, contact='drain', equation="HoleContinuityEquation")
    total_current= electron_current + hole_current

    solve(type="ac", frequency=1.0)
    cap=get_circuit_node_value(node="V1.I", solution="ssac_imag")/ (-2*math.pi)
    print("capacitance {0} {1}".format(v, cap))

    vgs.append(v)
    cgs.append(c)
    ids.append(total_current)

    v += 0.1

If you are putting circuit nodes on a device terminal, avoid using set_parameter, because that parameter name can override the circuit node value when evaluating the contact equations. Instead, create a circuit node with the same name. If you want to measure the current through a terminal, you can measure it through a voltage source.

For example, please see here for a BJT see https://github.com/devsim/devsim_bjt_example/blob/main/simdir/bjt_common.py#L83:

def run():
    device="bjt"
    region="bjt"
    load_devices(file="bjt_dd_0.msh")
    bjt_params.run(device, region)
    netdoping.set_params(device, region)
    SetSiliconParameters(device, region)

    for c in ("base", "emitter", "collector"):
        #set_parameter(device=device, region=region, name=GetContactBiasName(c), value=0.0)
        CreateSiliconDriftDiffusionContact(device, region, c, "Jn", "Jp", True)
        # use first initial of each contact name
        circuit_element(name="V%s" % c[0], n1=GetContactBiasName(c), n2="0", value=0.0)

Please see the bjt example for more examples for reading the current from the voltage sources.