# Devsim numerical accuracy issue

Hi Devsim team,

I tried to run the examples/diode/ssac_diode.py.

I added couple of lines to print the diode capacitance versus voltage (see at the bottom). no change to other lines.

The C-V curve is very noisy as shown below.

How to improve the accuracy? I tried smaller values of absolute_eror and relative_error, it leads to either no improvement or divergence.

Kejun

``````xx=[]

yy=[]

v=0.0

while v < 0.51:

circuit_alter(name="V1", value=v)

solve(type="dc", absolute_error=1e3, relative_error=1e-12, maximum_iterations=1000)

#TODO: get out circuit information

# PrintCurrents(device, "top")

PrintCurrents(device, "bot")

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))

v += 0.01

xx.append(v)

yy.append(cap)

for x in get_circuit_node_list():

for y in get_circuit_solution_list():

z = get_circuit_node_value(node=x, solution=y)

print(("{0}\t{1}\t{2}".format(x, y, z)))

import matplotlib

import matplotlib.pyplot

matplotlib.pyplot.plot(xx, yy)
``````

This is what I am getting running in windows on the original ssac_diode example:

``````xx=[]
yy=[]
v=0.0
while v < 0.51:
circuit_alter(name="V1", value=v)
solve(type="dc", absolute_error=1e10, relative_error=1e-10, maximum_iterations=30)
#TODO: get out circuit information
#  PrintCurrents(device, "top")
PrintCurrents(device, "bot")
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))
xx.append(v)
yy.append(cap)
v += 0.1

for x in get_circuit_node_list():
for y in get_circuit_solution_list():
z = get_circuit_node_value(node=x, solution=y)
print(("{0}\t{1}\t{2}".format(x, y, z)))

import matplotlib
import matplotlib.pyplot
matplotlib.pyplot.plot(xx, yy)
matplotlib.pyplot.show()

``````

Please report your operating system and version of python you are using. Also it would be helpful to print this value from devsim:

``````>>>
print(devsim.get_parameter(name="info"))
{'copyright': 'Copyright © 2009-2023 DEVSIM LLC', 'explicit_math_load': True, 'extended_precision': True, 'license': 'Apache License, Version 2.0', 'mkl_version': 'Intel(R) oneAPI Math Kernel Library Version 2021.4-Product Build 20210904 for Intel(R) 64 architecture applications', 'superlu_version': '5.3.0', 'version': '2.3.8', 'website': 'https://devsim.org'}
``````

Please make sure you have the Intel MKL installed. If it is not installed, it reverts to using SuperLU as the direct solver. Setting the voltage step to `0.01` in the previous script, I can reproduce the type of behavior you are seeing:

In Anaconda:

``````conda install mkl
``````

or in a Python virtual environment.

``````pip install mkl
``````

Juan,
Indeed. The problem has been resolved with mkl. Thank you very much.

Thanks @sharkjune for bringing up this issue. SuperLU is the default for Apple M1 (arm64), as the Intel MKL is not available. This warrants additional investigation.