Expression containing simulation results

53 views
Skip to first unread message

Vadim Kuznetsov

unread,
Feb 19, 2015, 10:38:39 AM2/19/15
to xyce-...@googlegroups.com


Has Xyce and equivalent for Ngspice expression assigned via let statement? I need give name for my user variable, that is calculated afrer simulation and contains simulation results? Or I can only pass such expression into .print directly?

Here is example Ngspice netlist:

V1 in 0 DC SIN(0 0.6 7.5e+06 0 0) AC 0.6
L1 in _net0  1e-05
C1 _net0 out  4e-11
R1 0 out  30
.AC LIN 200 1e+06 1e+07
.control
set filetype=ascii
run
let K=ac.V(out)/ac.V(in) * I need equivalent for this construction
write out.txt  K
exit
.endc
.END

xyce-users

unread,
Feb 19, 2015, 11:33:26 AM2/19/15
to xyce-...@googlegroups.com


On Thursday, February 19, 2015 at 8:38:39 AM UTC-7, Vadim Kuznetsov wrote:


Has Xyce and equivalent for Ngspice expression assigned via let statement? I need give name for my user variable, that is calculated afrer simulation and contains simulation results? Or I can only pass such expression into .print directly?

Vadim:

No, Xyce does not have the equivalent of this "let" statement that allows you to create an output variable name that is a shortcut for an expression.  Other than the ".measure" function, the only output capability we have is the .print line. And unfortunately, the Xyce expression library is not yet extended to support complex arithmetic.  So the only way to get expressions output at all time points or all frequency values is to put them on the .print line.  Since the expression library does not yet support complex arithmetic, doing what you want is a little messy as you have to work out the real and imaginary parts of the result directly from the real and imaginary parts of the variables:

 

*Xyce output of AC computations
V1
in 0 DC SIN(0 0.6 7.5e+06 0 0) AC 0.6

L1
in _net0  1e-05
C1 _net0
out  4e-11
R1
0 out  30
.AC LIN 200 1e+06 1e+07
.print ac format=raw {(VR(out)*VR(in)+VI(out)*VI(in))/VM(in)**2} {(VI(out)*VR(in)-VR(out)*VI(in))/VM(in)**2}
.END


This won't even give you exactly what you want, as the real and imaginary parts of K will be in separate variables in the rawfile.  But it does get the values in there.

It is unfortunate that it is this difficult.  The Xyce expression library was developed long before Xyce had AC analysis or Harmonic Balance, and extending the expression library in its current design is very difficult.  We have a path forward for replacing the expression package with something more maintainable and extensible, but it  will not be in the upcoming 6.3 release.  Until then, the expression package can only produce real numbers, and all variables in expressions must be real.

It is possible to define user functions for complex division to simplify the .print line somewhat, but not much:

*test of complex division output with user functions
* real and imaginary part of K=vo/vi
.func kr(vir,vii, vor,voi) {(vor*vir+voi*vii)/(vir*vir+vii*vii)}
.func ki(vir,vii, vor,voi) {(voi*vir-vor*vii)/(vir*vir+vii*vii)}


V1
in 0 DC SIN(0 0.6 7.5e+06 0 0) AC 0.6
L1
in _net0  1e-05
C1 _net0
out  4e-11
R1
0 out  30
.AC LIN 200 1e+06 1e+07
.print ac format=raw {KR(VR(in),VI(in),VR(out),VI(out))} {KI(VR(in),VI(in),VR(out),VI(out))}
.END


I'm sorry that this is the answer.

Reply all
Reply to author
Forward
0 new messages