Issues initializing DEVSIM

I am running an example of 1D Capacitor in Devsim,and some error occur when i press the “Run File” button for the second time,but it is always ok for the first time. The same situation can happen when it comes to other examples in Devsim. I would like to know why and how could i solve this “Problem”.
Below is the error infomation:
runfile(‘D:/06 Devsim/Cap1d_ch_debug.py’, wdir=‘D:/06 Devsim’)
problems with creating default derivatives. declare(dBdx(x)); define(B(x),dBdx(x)); declare(sgn(x)); declare(step(x)); define(abs(x), sgn(x)); declare(derfdx(x)); declare(derfcdx(x)); define(erf(x), derfdx(x)); define(erfc(x), derfcdx(x));declare(derf_invdx(x)); declare(derfc_invdx(x)); define(erf_inv(x), derf_invdx(x)); define(erfc_inv(x), derfc_invdx(x));declare(dFermidx(x)); declare(dInvFermidx(x)); define(Fermi(x), dFermidx(x)); define(InvFermi(x), dInvFermidx(x)); define(vec_sum(x),1);declare(vec_max(x));declare(vec_min(x));declare(dot2d(ax,ay,bx,by));define(dot2d(ax, ay, bx, by), bx, by, ax, ay);define(max(x, y), x >= y, x < y);define(min(x, y), x <= y, x > y);define(kahan3(a, b, c), 1, 1, 1);define(kahan4(a, b, c, d), 1, 1, 1, 1);define(asinh(x), ((1 + (x^2))^(-1/2)));define(acosh(x), (((x^2) - 1)^(-1/2)));define(atanh(x), ((1 - (x^2))^(-1)));declare(cosh(x));define(sinh(x), cosh(x));define(cosh(x), sinh(x));declare(tanh(x));define(tanh(x), 1 - pow(tanh(x), 2));declare(dgfidx(x,y));define(gfi(x,y), dgfidx(x,y), 0);declare(digfidx(x,y));define(igfi(x,y), digfidx(x,y), 0);
dBdx has already been declared with 1 argument(s)
sgn has already been declared with 1 argument(s)
step has already been declared with 1 argument(s)
derfdx has already been declared with 1 argument(s)
derfcdx has already been declared with 1 argument(s)
derf_invdx has already been declared with 1 argument(s)
derfc_invdx has already been declared with 1 argument(s)
dFermidx has already been declared with 1 argument(s)
dInvFermidx has already been declared with 1 argument(s)
vec_max has already been declared with 1 argument(s)
vec_min has already been declared with 1 argument(s)
dot2d has already been declared with 4 argument(s)
cosh has already been declared with 1 argument(s)
tanh has already been declared with 1 argument(s)
dgfidx has already been declared with 2 argument(s)
digfidx has already been declared with 2 argument(s)
Traceback (most recent call last):

File “D:\06 Devsim\Cap1d_ch_debug.py”, line 9, in
import devsim as dv

File “c:\users\caihng\devsim_win64_v2.1.0\devsim_win64_v2.1.0\lib\devsim_init_.py”, line 8, in
from .devsim_py3 import *

RuntimeError: Issues initializing DEVSIM.

The code for this example is also listed here:

-- coding: utf-8 --

“”"
Created on Mon Jun 13 20:01:26 2022

@author: Caiheng
“”"

#from devsim import *
import devsim as dv
device=“MyDevice”
region=“MyRegion”

Create a 1D mesh

dv.create_1d_mesh (mesh=“mesh1”)
dv.add_1d_mesh_line (mesh=“mesh1”, pos=0.0, ps=0.1, tag=“contact1”)
dv.add_1d_mesh_line (mesh=“mesh1”, pos=1.0, ps=0.1, tag=“contact2”)
dv.add_1d_contact (mesh=“mesh1”, name=“contact1”, tag=“contact1”,
material=“metal”)
dv.add_1d_contact (mesh=“mesh1”, name=“contact2”, tag=“contact2”,
material=“metal”)
dv.add_1d_region (mesh=“mesh1”, material=“Si”, region=region,
tag1=“contact1”, tag2=“contact2”)
dv.finalize_mesh (mesh=“mesh1”)
dv.create_device (mesh=“mesh1”, device=device)

Set parameters on the region

dv.set_parameter(device=device, region=region,
name=“Permittivity”, value=3.9*8.85e-14)

Create the Potential solution variable

dv.node_solution(device=device, region=region, name=“Potential”)

Creates the Potential@n0 and Potential@n1 edge model

dv.edge_from_node_model(device=device, region=region, node_model=“Potential”)

Electric field on each edge, as well as its derivatives with respect to

the potential at each node

dv.edge_model(device=device, region=region, name=“ElectricField”,
equation="(Potential@n0 - Potential@n1)*EdgeInverseLength")

dv.edge_model(device=device, region=region, name=“ElectricField:Potential@n0”,
equation=“EdgeInverseLength”)

dv.edge_model(device=device, region=region, name=“ElectricField:Potential@n1”,
equation="-EdgeInverseLength")

Model the D Field

dv.edge_model(device=device, region=region, name=“DField”,
equation=“Permittivity*ElectricField”)

dv.edge_model(device=device, region=region, name=“DField:Potential@n0”,
equation=“diff(Permittivity*ElectricField, Potential@n0)”)

dv.edge_model(device=device, region=region, name=“DField:Potential@n1”,
equation="-DField:Potential@n0")

Create the bulk equation

dv.equation(device=device, region=region, name=“PotentialEquation”,
variable_name=“Potential”, edge_model=“DField”,
variable_update=“default”)

Contact models and equations

for c in (“contact1”, “contact2”):
dv.contact_node_model(device=device, contact=c, name="%s_bc" % c,
equation=“Potential - %s_bias” % c)

dv.contact_node_model(device=device, contact=c, name="%s_bc:Potential" % c,
equation=“1”)

dv.contact_equation(device=device, contact=c, name=“PotentialEquation”,
node_model="%s_bc" % c, edge_charge_model=“DField”)

Set the contact

dv.set_parameter(device=device, region=region, name=“contact1_bias”, value=1.0e-0)
dv.set_parameter(device=device, region=region, name=“contact2_bias”, value=0.0)

Solve

dv.solve(type=“dc”, absolute_error=1.0, relative_error=1e-10, maximum_iterations=30)

Print the charge on the contacts

for c in (“contact1”, “contact2”):
print(“contact: %s charge: %1.5e”
% (c, dv.get_contact_charge(device=device, contact=c, equation=“PotentialEquation”)))

Hi @caihng

Thanks for using the software. I am not familiar with the runfile command or the “Run File” button. Are you using a GUI front end to your Python interpreter?

This is an interesting problem, as it appears the devsim module is being initialized a second time with all of the preexisting C++ data structures for the first run still present.

Are there any settings in your system that control how Python scripts are invoked? Ideally, the devsim module should only be loaded once.

Hi @caihng
I’ve had that issue before. I’m using Spyder to run my files, from Anaconda.Navigator.
A simple way I got rid of the issue is to restart the kernel before you run a program again. I don’t know about other software, but with Spyder, if you check the variable explorer you’ll see that after the first time you run, the variables are still stored the second time you try to run, hence the errors.
In Spyder you can use the shortcut "Ctrl + . " after clicking the console to restart the kernel, but I don’t know about other software.

Thanks. It seems that we are having the same problem. Restart the kernel before running a program again can really help in Spyder. I am wondering if this situation is a bug in Devsim module that can be solved ?

Thanks, I am using Spyder in Anaconda.

I have never worked with Spyder, or any other interactive Python environment. Please file an issue here:
https://github.com/devsim/devsim/issues
as this may require an extensive investigation.

Thank you @katzir for helping with the issue.