I have this circuit driving a pulsed laser. I want to compute the energy dumped into the laser and the energy stored in the power supply capacitors. The ballpark is 120 amps into a 20 volt laser for a few hundred microseconds.
What I did was create a "B" behavioral current source whose equation is I = V(LASER) * I(LASER) which represents power, and dump that into a 1 farad cap. The voltage on the cap is then energy in joules, and I can probe/plot that just like any other node. This works [1].
Then, for the cap energy, I made a behavioral voltage source
V = 0.5 * 1m * V(VCC)**2
where the 1m is because it's a 1000 uF cap. That gives me a probe-able node scaled 1 volt per joule. That works, but if I change the cap value I have to edit the equation. The nicer version is
V = 0.5 * C1 * V(VCC)**2
but Spice barfs on the C1 bit. Is there a way to put the cap value into the equation?
Too bad there's no integration operator available in the equations.
[1] except that it initializes to -250 megavolts. Putting a 1 ohm resistor across the cap fixes that.