Time constants
In the circuit shown in the figure, $V_C=1\,$V at $t=0$. Find $C$ such that $V_C=4.5\,$V at $t=20\,\mu$s. Plot $V_C(t)$ and $i(t)$.In [1]:
from IPython.display import Image
Image(filename =r'time_constant_1_fig_1.png', width=210)
Out[1]:
In [2]:
# run this cell to view the circuit file.
%pycat time_constant_1_orig.in
We now replace the string \$C with the value of our choice by running the python script given below. It takes an existing circuit file time_constant_1_orig.in and produces a new circuit file time_constant_1.in, after replacing \$C with the value of our choice.
In [3]:
import gseim_calc as calc
s_C = '100n' # to be changed by user
l = [
('$C', s_C),
]
calc.replace_strings_1("time_constant_1_orig.in", "time_constant_1.in", l)
print('time_constant_1.in is ready for execution')
time_constant_1.in is ready for execution
Execute the following cell to run GSEIM on time_constant_1.in.
In [4]:
import os
import dos_unix
# uncomment for windows:
#dos_unix.d2u("time_constant_1.in")
os.system('run_gseim time_constant_1.in')
Circuit: filename = time_constant_1.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.
Out[4]:
0
The circuit file (time_constant_1.in) is created in the same directory as that used for launching Jupyter notebook. The last step (i.e., running GSEIM on time_constant_1.in) creates the data file time_constant_1.dat in the same directory. We can now use the python code below to compute and display the quantities of interest.
In [5]:
import numpy as np
import matplotlib.pyplot as plt
import gseim_calc as calc
from setsize import set_size
slv = calc.slv("time_constant_1.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]
VC1 = 4.5
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, VB, 0.0, t_end, VC1)
print('time points at which VC crosses', "%5.2f"%VC1)
for t1 in l_cross_1:
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[0].axhline(y = VC1, 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_1.dat time points at which VC crosses 4.50 49.25 micro-sec
This notebook was contributed by Prof. M. B. Patil, IIT Bombay. He may be contacted at mbpatil@ee.iitb.ac.in.
In [ ]: