I charge a capacitance in parallel with two nodes very quickly, but in a simulation-friendly manner, to an initial voltage.

Construct with three nodes, which are assigned local variables n1, n2, and nv0 in my setup. The last one is an input voltage that tells my circuitry what the initial voltage is.:

         +----------------------------------------------------------+
         | +------------------------------------------------------+ |
         | |                                                      | |
         | |   +------+                                 +-----+   | |
   n1 ---|-+--x|-     |         +----+                  |     |>--+ |
         |     |  B:V |-- n3 ---| R1 |-------+--- n4 --x|  G  |     |
   n2 ---+----x|+     |         +----+       |          |     |<----+
               |      |                    +----+       +-----+
   nv0 -------x|+     |                    | C1 |
               +------+                    +----+
                                             |
                                          n5 |  +----+
                                             +--| R2 |--0
                                                +----+

The LPF of R1+C1 keeps the error voltage at the input n4 to G from transitioning too fast. The minimum transition time is 1/5 Nts*ts or 2*ts, whichever is larger. This imparts a bit of "I" into the PID loop, along with the "P". (There never will be any implementation of a "D" term.)

Instance Variable C The capacitance value. Can be an AV object, but only one with a known value.
Instance Variable ti The time alloted for initial charging at the beginning of the TRAN simulation for the capacitor to approach completion of its transition to the initial value. (Read-only.)
Class Variable Nts Minimum number of simulation timesteps for initial charging interval.
Class Variable I_max Maximum initial charging current. (Going very far beyond this risks numerical problems, non-convergence.)
Class Variable P Proportional (and only) term of PID driving the charging current.
Method setup Included circuit definition.
Method _calc_C1R2

Calculates values of R1, C1, and R2 in the RC LPF that implements the "P" and "I" terms of the PID loop with transition time tt. (No "D" term is implemented.):

Inherited from NodeStuff (via Include):

Instance Variable shunts A dict of current sensing V elements with the pairs of nodes they connect.
Class Variable debug A Bag that gets set True for all instances to log info about each setup call.
Class Method autoName Undocumented
Method setupResults Undocumented
Method fill Undocumented
Method nodeCheck Call with the circuit building tool f and a sequence of nodes provided to this Include or Subcircuit.
Method rawNetlist Get lines of a raw netlist from a search hierarchy of possible sources.
Method shunt Call to insert a current-measuring shunt and add an entry to my Elements baton's dict of shunts.
Method raw See Elements.raw.
Method iNode See Elements.iNode.
Method ground See Elements.ground.
Method sca See Elements.sca.
Method sca6 See Elements.sca6.
Class Method _libDir Undocumented
Method _strippedLines Undocumented
Method _call_setup Calls my setup method (almost always your override of that method, actually) and processes any return value.

Inherited from NodeStuff (via Include):

Instance Variable shunts A dict of current sensing V elements with the pairs of nodes they connect.
Class Variable debug A Bag that gets set True for all instances to log info about each setup call.
Class Method autoName Undocumented
Method setupResults Undocumented
Method fill Undocumented
Method nodeCheck Call with the circuit building tool f and a sequence of nodes provided to this Include or Subcircuit.
Method rawNetlist Get lines of a raw netlist from a search hierarchy of possible sources.
Method shunt Call to insert a current-measuring shunt and add an entry to my Elements baton's dict of shunts.
Method raw See Elements.raw.
Method iNode See Elements.iNode.
Method ground See Elements.ground.
Method sca See Elements.sca.
Method sca6 See Elements.sca6.
Class Method _libDir Undocumented
Method _strippedLines Undocumented
Method _call_setup Calls my setup method (almost always your override of that method, actually) and processes any return value.
C =
The capacitance value. Can be an AV object, but only one with a known value.
ti =
The time alloted for initial charging at the beginning of the TRAN simulation for the capacitor to approach completion of its transition to the initial value. (Read-only.)
Nts =
Minimum number of simulation timesteps for initial charging interval.
I_max =
Maximum initial charging current. (Going very far beyond this risks numerical problems, non-convergence.)
P =
Proportional (and only) term of PID driving the charging current.
def _calc_C1R2(self, tt):

Calculates values of R1, C1, and R2 in the RC LPF that implements the "P" and "I" terms of the PID loop with transition time tt. (No "D" term is implemented.):

   The P term is G*R2/(R1+R2).
   The I term is G.
   Thus, I*R2/(R1+R2) = P
   So R1+R2 = I*R2/P
   and thus R1 = R2*(I/P - 1).
   R1 is set to 1.0. So, finally, R2 = 1.0 / (I/P - 1).

Note that I > P. You can't implement a PI loop with P > I using this simple RC circuit.

def setup(self, f, n1, n2, nv0):

Included circuit definition.

Override this to define your own method for constructing part of a netlist, using the Elements object provided as f. Why use f? Because it's short and a conveniently typed letter on the keyboard.

As with Subcircuit.setup, your override method can return a dict of attribute names and values to set in my instance.

API Documentation for pingspice, generated by pydoctor at 2021-09-18 08:41:11.