Qucs / gnucsator

This package provides a gnucap based qucsator implementation.
GNU General Public License v3.0
13 stars 4 forks source link

DC voltage sweep #14

Closed ddrake closed 3 years ago

ddrake commented 3 years ago

This is in reference to the second bulleted item in https://github.com/Qucs/gnucsator/issues/11, which I think had too broad a scope.

If we have a netlist similar to 'tests/dc_sweep.0.net', but which does a single sweep of DC voltage like this:

Vdc:V1 A gnd U="V1"
.SW:SW1 Sim="DC1" Type="lin" Param="V1" Start="10m" Stop="50m" Points="5"
.DC:DC1 Temp="26.85" reltol="0.001" abstol="1 pA" vntol="1 uV" saveOPs="no" MaxIter="150" saveAll="no" convHelper="none" Solver="CroutLU"
R:R1 gnd A R="500"

The simulation fails, and no output is generated because (I think) in the method find_sweep(CARD* c) in 's_dc.cc', line 202 the dynamic_cast<ELEMENT*>(c) fails for the CARD c with dev_type Vdc and long_label V1. This results in the exception message "dc/op: can't sweep V1". The dynamic cast succeeds in analogous cases of dev_type R and Idc. Comparing the traces of this netlist with the those of the dc_sweep tests, it seems that the parsing of the Vdc CARD in 'lang_qucs.cc' is being done consistently.

I've used gnucap directly to simulate this Vdc sweep, so it's clear that it's supported. I've tried digging into the gnucap code to try to understand better why the dynamic_cast fails in this case but succeeds in the other cases. I think ELEMENT derives from COMPONENT which derives from CARD, but I'm stuck trying to troubleshoot this dynamic_cast.

If you have any thoughts on this, I'd be grateful!

felix-salfelder commented 3 years ago

On Sat, Oct 02, 2021 at 02:55:57PM -0700, Dow Drake wrote:

If we have a netlist similar to 'tests/dc_sweep.0.net', but which does a single sweep of DC voltage like this:

Vdc:V1 A gnd U="V1"
.SW:SW1 Sim="DC1" Type="lin" Param="V1" Start="10m" Stop="50m" Points="5"
.DC:DC1 Temp="26.85" reltol="0.001" abstol="1 pA" vntol="1 uV" saveOPs="no" MaxIter="150" saveAll="no" convHelper="none" Solver="CroutLU"
R:R1 gnd A R="500"

The simulation fails, and no output is generated because (I think) in the method find_sweep(CARD* c) in 's_dc.cc', line 202 the dynamic_cast<ELEMENT*>(c) fails for the CARD c with dev_type Vdc and long_label V1.

The issue is, in Qucsator, a Vdc instance is not an ELEMENT but a CARD with a subckt. I put in find_sweep to find the actual ELEMENT to sweep. At this stage I chose that the name must be "dev". I forgot to rename all ELEMENT wrapper subdevices to "dev". Please try that.

I was hoping for a better solution... a qucsator-compatible solution would sweep parameters, not ELEMENTs.

ddrake commented 3 years ago

Thanks -- that makes sense! I ran into a couple issues, though. Before making any changes, I ran make check. The following tests failed for me:

When I changed module Vdc in 'include/sources.v' from vsource #(.dc(U)) v(p n) to vsource #(.dc(U)) dev(p n), the DC sweep of Vdc worked correctly. However, this update caused two other tests to fail:

Similar changes to module C and module L in 'include/lumped.v' made it possible to sweep the values of capacitors and inductors and did not cause any tests to fail.

felix-salfelder commented 3 years ago

On Sun, Oct 03, 2021 at 01:03:57PM -0700, Dow Drake wrote:

Thanks -- that makes sense! I ran into a couple issues, though. Before making any changes, I ran make check. The following tests failed for me:

  • bpf.net (missing -- maybe not committed)
  • TTL_NAND.net (No rule to make target TTL_NAND.net.v.diff -- I don't understand this, the file is there)
  • Iprobe.1.net (major diffs with ref)
  • list.1.net (major diffs with ref)

my hasty commits... perhaps time for CI. :|

  • wilkinson.net (minor diffs with ref -- precision)

not here. ignore?

felix-salfelder commented 3 years ago

On Sun, Oct 03, 2021 at 01:03:57PM -0700, Dow Drake wrote:

  • wrap.gc.net (diffs with ref -- .print dc v(nodes) v(foo*.v) gives no match so v(foo1.v) and v(foo2.v) are not printed)

done

  • lang_qucs.1.net (diffs with ref -- the number of timesteps for a transient simulation of Vdc was reduced from 4 to 3)

odd. I still see 4.

Similar changes to module C and module L in 'include/lumped.v' made it possible to sweep the values of capacitors and inductors and did not cause any tests to fail.

done

thanks

ddrake commented 3 years ago

Great -- thanks! All tests are passing for me now except wilkinson. In particular, the issue with the number of timesteps in lang_qucs.1.net is fixed. I've tested a few different sweeps -- they are all working now. I'll try testing a few more configurations, but you're welcome to close this now if you like.

not here. ignore?

We could ignore it unless it's easy to relax the tolerance a bit. I'm attaching the diff

wilkinson.net.gc.diff.txt .

felix-salfelder commented 3 years ago

We could ignore it unless it's easy to relax the tolerance a bit. I'm attaching the diff deferred

thanks!