al davis a écrit :
On Wednesday 03 May 2006 12:07, Cyril Giraudon wrote:
Hello,
I actually try to write a tclspice like tool in python
(pyrex, numpy modules).
How about doing it for gnucap?
Lots of people have written front-ends and wrappers for Spice. Gnucap
really needs something like that, and to provide the functionality of
"nutmeg".
Hello,
My idea is to write an object oriented python module, and I need a
python module for my work.
For instance I'd like to write :
import circuitModule as cm
cl[]
cl['c1'] = cm.Circuit('aFile.cir')
cl['c2'] = cm.Circuit('anOtherFie.cir')
for c in cl:
c.run()
d = cm.Circuit('aThirdFile.cir')
e = d.run().toArray('V(1)')
# e is an array numpy.
The issue is not writing a pure spice frontend but rather a pythonic
spice tool (module).
We can see the simulator has to handle several circuits at a time.
2 solution :
- The simulation can natively handle several circuits
- The simulation is already object oriented and one can instanciate more
than one circuit : each circuit owns its namespace (matrices, results
vectors)
I don't want to hack the simulator code (not too much), it's to hard to
maintain.
I've tried to study and understand gnucap sources. Gnucap was the first
simulator I thougth about : Pure C++ program, 8000 lines of code (I
think), compiles very well.
Gnucap is written in C++ so I wished each circuit was a class instance
with its proprieties and methods (own resolution matrices, ...) But it
is not the way gnucap is coded, gnucap is not oriented "library". There
are a lot of global variables that could be local to a simulation. So
the only thing Gnucap permits is wrapping its interpreter and gives the
capability to use gnucap inside the python interpreter (it's already a
good thing).
Then I believe Gnucap doesn't save the nodes values when a simulation
runs, Gnucap writes currents, tensions in a file or in the console but
doesn't save them into the memory in order to retrieve them. So
converting vectors into numpy arrays is not easy.
Spice is not written with an object oriented language but offers an
"object oriented approach" : A struct instance for a circuit. All struct
instances references in ft_circuits... Nodes current and tension are
stocked during the simulation. The conversion into numpy array needed
only a 30 lines functions reusing native spice function.
So the job is not technically easy with Gnucap. Spice is a better
candidate for that purpose. I think.
The module call directly spicelib or frontend functions.
I 'd like to give an object oriented approach to the module,
so I need to clean the memory when a circuit is not used any
more (garbage collector).
I use the com_removecirc() function for that purpose but the
circuit is still
in ft_circuits list and a "run" causes a segmentation fault.
Is there a function removing entirely a circuit from the
memory (database and circuits list) ?
Spice: no (to all). Spice is designed to load a circuit once, then
make only non-structural changes. For a serious topology change, you
need to start over.
Gnucap: yes (to all). It is designed so you can make arbitrary
changes to the circuit. It can even make some topology changes
dynamically as the simulation runs.
Yes Gnucap can clean its memory, but Gnucap handle only one circuit at a
time. Resolution matrices are deleted then re-allocated so it's not
possible the swap between circuit without a lot of work.
More over, it seems that the model name in a .cir file can't
contain ('/', '+', '-').
What are the rules for models name ?
I think it is letters, numbers, and underscore. Mostly not case
sensitive. Actually, the rule is that it is not case sensitive, but
there are occasional surprises, like the FAT file system. Model names
are supposed to start with a letter, but there are occasions where
this is not enforced.
In fact, I've asked this question because I've tried to use PSpice diode
model in ngspice, and ngspice failed reading the lib, ngspice stuck on
name model like "ABC12345/-67". It was with a win XP machine and ngspice
rework 17 compiled with mingw.
Libraries are perhaps rewritten (by PSpice) before being read by the
simulator ? Or the simulator is radicaly different ?
Cyril.