from IPython.display import Image
Image(filename =r'time_constant_2_fig_1.png', width=210)
# run this cell to view the circuit file.
%pycat time_constant_2_orig.in
We now replace the strings \$VC0 and \\$C with the values of our choice by running the python script given below. It takes an existing circuit file time_constant_2_orig.in and produces a new circuit file time_constant_2.in, after replacing \$VC0 and \\$C with the values of our choice.
import gseim_calc as calc
s_VC0 = '2.5' # initial value of VC, to be changed by user
s_C = '25n' # to be changed by user
l = [
('$VC0', s_VC0),
('$C', s_C),
]
calc.replace_strings_1("time_constant_2_orig.in", "time_constant_2.in", l)
print('time_constant_2.in is ready for execution')
time_constant_2.in is ready for execution
Execute the following cell to run GSEIM on time_constant_2.in.
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("time_constant_2.in")
os.system('run_gseim time_constant_2.in')
Circuit: filename = time_constant_2.in main: i_solve = 0 main: calling solve_startup main: i_solve = 1 main: calling solve_trns Transient simulation starts... i=0 i=1000 GSEIM: Program completed.
0
The circuit file (time_constant_2.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on time_constant_2.in) creates the data file time_constant_2.dat in the same directory. We can now use the python code below to compute and display the quantities of interest.
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("time_constant_2.in")
i_slv = 1
i_out = 0
filename = slv.l_filename_all[i_slv][i_out]
print('filename:', filename)
u = np.loadtxt(filename)
t = u[:, 0]
t_end = t[-1]
IR1 = 2.0e-3
IR = slv.get_array_double(i_slv, i_out, 'IR', u)
VB = slv.get_array_double(i_slv, i_out, 'VB', u)
l_cross_1, l_cross_2 = calc.cross_over_points_1(t, IR, 0.0, t_end, IR1)
print('time points at which IR crosses', "%5.2f"%(IR1*1.0e3), "mA", "positive slope")
for t1 in l_cross_1:
print(" ", "%5.2f"%(t1*1e6), "micro-sec")
print('time points at which IR crosses', "%5.2f"%(IR1*1.0e3), "mA", "negative slope")
for t1 in l_cross_2:
print(" ", "%5.2f"%(t1*1e6), "micro-sec")
color1='blue'
color2='green'
color3='red'
fig, ax = plt.subplots(2, sharex=False)
plt.subplots_adjust(wspace=0, hspace=0.0)
set_size(5.5, 4.5, ax[0])
for i in range(2):
ax[i].set_xlim(left=0.0, right=t_end*1e6)
ax[i].grid(color='#CCCCCC', linestyle='solid', linewidth=0.5)
ax[0].set_ylim(bottom=0.0, top=10.0)
ax[0].set_ylabel(r'$V_C$ (Volts)', fontsize=12)
ax[1].set_ylabel(r'$i$ (mA)', fontsize=12)
ax[0].tick_params(labelbottom=False)
ax[0].plot(t*1e6, VB, color=color1, linewidth=1.0, label="$V_C$")
ax[1].plot(t*1e6, IR*1e3, color=color2, linewidth=1.0, label="$i$")
ax[1].axhline(y = IR1*1e3, color = color3, linestyle = '--', linewidth=0.8, dashes=(5,5))
ax[1].set_xlabel('time (micro-sec)', fontsize=11)
#plt.tight_layout()
plt.show()
filename: time_constant_2.dat time points at which IR crosses 2.00 mA positive slope time points at which IR crosses 2.00 mA negative slope 34.36 micro-sec
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.