You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Windows - Python 3.10 - PySpice v. 1.5 - default simulator (ngspice shared)
Dear community,
I'm pretty new in the use of this package, but I found it extremely useful!
I scceeded in running simulations of rather complicate circuits, but now I am trying to use it coupling my python code with external codes which should provide me the evolution of some electrical parameters (e.g. resistances) and I am struggling a lot.
In my plans the workflow would be the following:
run one time step of the circuit simulator in python (wich for my purpose is compiled in a .dll file which is called by the fortran main executable)
use the computed values of current as input to the other code, which, among other stuffs, computes the updated value of resistances to be sent back to the python circuit simulator
start again up to the end of both simulations.
I am able to assuere the comunication with the other code, by the way I'm still looking for a way to perform a simulation one time step at a time in PySpice. Indeed, my idea was to run a simulation which last for the lenght of a time step (I mean outer code time step), store the required results (e.g. Current in various branches) and the node voltages to be sent to the fortran code. Once did that, once started the new fortran time step, the stored node voltages are sent to PySpice which in principle should use them as "initial condition" to run another simulation of a leght of a fortran time step and so on and so forth...
To test the procedute I have used the test case reported in figure below in which the parallel of a constant resistance and a constant inductance are alimented by a ramping direct current.
The simulation has been performed running it entirely from Python obtaining proper results:
Then the strategy above has been adopted running the same simulation but calling it using the fortran-like logic but the simulation diverges without providing results. Can some of you spot what's going wrong here? I stress again the fact that I am pretty new in such a kind of electrical analysis so be patient if the answer is really easy, but I'm not able to see it!
#THIS IS THE TesterFunzioni.py
import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *
import PySpice.Spice.HighLevelElement as HLE
import matplotlib.pyplot as plt
import numpy as np
import math
iL, iR, vend = BS.Pydostep0(dt,t,v0)
# print('time = '+str(t+dt)+' [s]')
# print('iL = '+str(iL)+' [A]')
# print('iR = '+str(iR)+' [A]')
# print('v = '+str(vend[0])+' [V]')
iLarr[i] = iL
iRarr[i] = iR
iL0 = iL
iTot[i] = iL + iR
v0 = vend
Environment (OS, Python version, PySpice version, simulator)
Windows - Python 3.10 - PySpice v. 1.5 - default simulator (ngspice shared)
Dear community,
I'm pretty new in the use of this package, but I found it extremely useful!
I scceeded in running simulations of rather complicate circuits, but now I am trying to use it coupling my python code with external codes which should provide me the evolution of some electrical parameters (e.g. resistances) and I am struggling a lot.
In my plans the workflow would be the following:
I am able to assuere the comunication with the other code, by the way I'm still looking for a way to perform a simulation one time step at a time in PySpice. Indeed, my idea was to run a simulation which last for the lenght of a time step (I mean outer code time step), store the required results (e.g. Current in various branches) and the node voltages to be sent to the fortran code. Once did that, once started the new fortran time step, the stored node voltages are sent to PySpice which in principle should use them as "initial condition" to run another simulation of a leght of a fortran time step and so on and so forth...
To test the procedute I have used the test case reported in figure below in which the parallel of a constant resistance and a constant inductance are alimented by a ramping direct current.
The simulation has been performed running it entirely from Python obtaining proper results:
Then the strategy above has been adopted running the same simulation but calling it using the fortran-like logic but the simulation diverges without providing results. Can some of you spot what's going wrong here? I stress again the fact that I am pretty new in such a kind of electrical analysis so be patient if the answer is really easy, but I'm not able to see it!
#THIS IS THE TesterFunzioni.py
import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *
import PySpice.Spice.HighLevelElement as HLE
import matplotlib.pyplot as plt
import numpy as np
import math
def Pydostep0(dt,t0,v0):
#THIS IS THE USE OF THE FUNCTION
import TesterFunzioni as BS
import numpy as np
import matplotlib.pyplot as plt
dt = 0.1
tend = 1.1
tempo = np.arange(0,tend+dt,dt)
v0 = np.zeros(1)
iL0 = 0.0
iLarr = np.zeros_like(tempo)
iRarr = np.zeros_like(tempo)
iTot = np.zeros_like(tempo)
for i,t in enumerate(tempo):
fig, ax = plt.subplots()
ax.grid()
ax.set(xlabel = 'Time [s]', ylabel = 'I [A]')
ax.plot(tempo+dt,iLarr,'b-',linewidth = 4, label = 'L')
ax.plot(tempo+dt,iRarr,'r-',linewidth = 4, label = 'R')
ax.plot(tempo+dt,iTot,'k--',linewidth = 1.5)
ax.legend(loc = 'best')
plt.show()
I altready thanks a lot whoever will help me with this issue!
Yours
Marco
The text was updated successfully, but these errors were encountered: