Closed DeadTomGC closed 3 years ago
Hi @DeadTomGC , I'm afraid it's more complex than that. Variables in this situation must map to an unknown variable in the solver because the behavioral source needs to compute derivatives to it and then fill the modified nodal analysis matrix accordingly. In some cases you might get convergence in a simulation even if you do it like that (so you can try to use your own compiled version), but it is not something we should add in the public library.
[EDIT] The only exception where we can do this, is an independent current source because that current does not depend on any other variable in the solver. It is really independent. The current through a resistor depends on the node voltages it is connected to, so that is not independent and cannot be used in behavioral expressions.
My suggestion (if you need the current through a resistor) is that you add a voltage source in series with the resistor and to use the current through that instead. A voltage source creates branched behaviors (IBranchedBehavior<>
), which means that it actively adds a new branch current as an unknown variable to the solver that represents the current through the voltage source.
Also a small sidenote: if you want to contribute please make pull requests to the development branch instead of the master branch (I really should add some contribution guidelines in the README).
Once again, thanks for tips! Will factor that in.
One note is that it does sorta work for my use case.. I'm sure this COULD lead to really weird behavior, but in practice, shouldn't it only make it so that the current used in the calculation is one timestep old?
If you take a current from one timestep old, then it serves as an independent current contribution, which will always be ok for convergence. You will still have issues for time-less simulations though: if you can't converge for the operating point of a transient analysis you would still be stuck. :-)
That makes sense, and in my use case, behavioral sources are either pure inputs or pure outputs, so I haven't had an issue with convergence in transient analysis.
I'm using this in a project. Hopefully this is the right way to do it.