Capacitance - nasa/gunns GitHub Wiki

Derivation of the Capacitance Effect on the System

Capacitance is a property of a location where quantity can be collected with any density. Capacitance C is defined as the change in quantity Q needed to increase the node’s potential p by unit:

C = dQ/dp

Flux w is the change in quantity per unit time, so:

w = dQ/dt,
C = w · dt/dp,
w = C · dp/dt,

which also happens to be the governing equation of electrical capacitance, where generic flux w is electrical current I and generic potential p is voltage v:

I = C · dv/dt

The flux across a capacitor at time t is related to the potential difference across the capacitor and the capacitance constant as:

w(t) = C · dp(t)/dt
w(t) · dt = C · dp(t)

Integrating from the previous time t-1 to t:

t-1t w(t) · dt = t-1t C · dp(t).

For this integral, we assume that w(t) is constant over the step from t-1 to t_. This is called Backward Eulermethod discretization, which we tend to use for all GUNNS links. It is very stable, at the cost of some accuracy. In addition to being more stable, it also makes the math simpler than for more accurate integration methods like trapezoidal, etc. Evaluating the integral:

w(t) · dt = C · [ dp(t) – dp(t-1) ]
w(t) = C · dp(t)/dt – C · dp(t-1)/dt.

Nodal analysis is based on Kirchoff’s Current Law, which states that due to conservation principles (energy or mass depending on the aspect), the sum of all fluxes on a node is zero. Nodes are just points in space, and have no capacity to store quantity in themselves – therefore any quantity entering the node must be matched by an equal quantity leaving the node along another path. Likewise the capacitor does not accumulate quantity in itself – rather an increase of quantity accumulated on one side is matched by a loss of quantity on the other side, with the potential difference dp created (stored as potential energy) by the imbalance of quantity on each side. So the flux w is still effectively flux “through” the capacitor, even though different electrons or fluid molecules are entering & leaving each side. The animation below helps to visualize this:

The red barrier between the left & right sides is like a stretchy membrane. As fluid is displaced to the left it stretches the membrane. The membrane wants to push the fluid out to the right and pull fluid in from the left to move itself to its neutral position. This creates a higher pressure on the right-hand side fluid than the left-hand side fluid. All capacitors can be thought of as having an analogous effect even though their physical mechanisms causing the delta-potential are different.

This also shows that capacitance is not a property of a node, but of an effect between two nodes. Since effects between nodes are the job of GUNNS links, capacitance is implemented in link classes. Capacitance is not a property of the GUNNS node classes, but is instead a property of a capacitor link connecting two nodes.

Similar to other effects, we define positive flux sign as travelling from port 0 to 1:

w = w0 = –w1

Now, say we have two nodes 0 and 1 with a capacitance C between them. Writing the flow equation for each node, and noting that the net flux on any node must be zero, by KCL:

Node 0: w0 = (p0 t – p1 t) · C/dt – (p0 t-1 – p1 t-1) · C/dt = 0
Node 1: w1 = –w0 = –(p0 t – p1 t) · C/dt + (p0 t-1 – p1 t-1) · C/dt = 0

The potentials p at the previous time t-1 are known, and GUNNS is solving for the potentials at the new time t. Grouping all of the unknown products on the left and the knowns on the right:

Node 0: p0 t · C/dt – p1 t · C/dt = (p0 t-1 – p1 t-1) · C/dt
Node 1: –p0 t · C/dt + p1 t · C/dt = –(p0 t-1 – p1 t-1) · C/dt

By inspection we can write this in matrix form. This is the generic footprint of all capacitance effects in the network’s system of equations:

Companion Model

In the Companion Model, a capacitor is exactly equal to a conductance G = C/dt in parallel with a flow source w = –dp t-1·C/dt:

In most applications of capacitance in fluid and thermal networks, the capacitance is between a node and Ground. Since the Ground node always has potential p = 0 and is outside the system of equations, the footprint of the capacitance effect in the network’s system of equations reduces to one row/column:

p t·C/dt = (p t-1)·C/dt.

If no other effects are on the node, that node’s row in the system of equations reduces to p t = p t-1, which means the potential in a node will remain constant in time if there are no other affects on it.

Discretization Error

The Backwards Euler discretization results in error in our solution proportional to the size of the integration time step. Smaller integration steps result in smaller error and a closer approximation to the “truth” system response, but at the cost of more network solutions and CPU load. So there is a trade-off between accuracy and computer resources.

Consider the following very simple case of a capacitance = 1 discharging to ground through a conductance = 5:

This equation for this system is derived as follows. Combine the equations for a conductor and capacitor above on the node, and by KCL the sum of the currents on the node is zero. The sign on the conductance term is negative because current is leaving the node through the conductor:

I = -V · G = C · dV/dt = 0
dV/dt = ( V t – V t-1 )/dt
-V t · G = C · (V t – V t-1 )/dt
-V t · G = C · V t /dt – C · V t-1 /dt
C · V t /dt + G · V t = C · V t-1 /dt
(C/dt + G) · V t = V t-1 · C/dt

This fits the form of our system of equations:
A · x = b, where A = C/dt + G, x = V t, b = V t-1 · C/dt

We can also write this as a differential equation:

V’ = (-G/C) · V,

which has the exact solution:

V(t) = V(t=0) · e -t · G/C

We can run the same network at differing time steps, and compare the resulting node 0 potentials over time:

This illustrates the discretization error. There is little discernible difference in this case between a timestep of 0.01 seconds and the exact solution. We see diminishing returns with using smaller time steps beyond a certain point, and in this case the time step of 0.01 appears to have approached “truth”. However, at larger and larger time steps, the error becomes more and more apparent. The error in the 0.1 case is maybe acceptable, but the 1.0 case is probably not. It depends on how much accuracy you need and your CPU budget, etc.

The error is also proportional to how rapidly the capacitor potential is changing. This is affected by the ratio of the incident conductances and the capacitance. Since the conductance and capacitance are usually constant properties of the system you are trying to model, the time step is usually what you have the most control over. The general proportionality is:

Discretization Error ∝ time step · conductance / capacitance

Thus every case is different: the above illustration does not represent the error in every case and there is no universally ideal time step to use.

Capacitance Value

In the thermal & electrical aspects, the capacitance is usually a constant property of the physical object.

  • An electrical capacitor usually has a constant rated capacitance. In GUNNS, this has units of Farad (though this is not a Trick-recognized unit).
  • In the thermal aspect, any physical mass represented in the network is a a thermal capacitor. A thermal capacitor is a thermal mass — a mass of material multiplied by its specific heat. In GUNNS, this has units of (J/K).
  • Fluid capacitance is equal to the moles of fluid times its compressibility, and has Trick units of (kg*mol/kPa). See Fluid_Capacitance.

Other Notes

  • Capacitance is an effect that introduces the concept of time into a network. In fact, so far this is the only effect where time matters. Another time-dependent effect would be inductance, but so far we’ve not needed to model that effect in GUNNS.
  • Because time only exists in capacitance (or links that model a capacitance-like effect), networks or areas of networks that have no capacitance are not time-dependent. Given the same set of inputs, they always solve to the same potentials every time. The opposite is true of capacitive networks – once perturbed they take time to flow to an equilibrium state.
  • Quantity is only stored in a capacitance effect.
  • Nodes that have a capacitance effect on them are called Capacitive Nodes. Those that do not are called Non-Capacitive Nodes. As discussed above, the capacitance effect is applied between nodes by a capacitor (or similar) link, and capacitance is not actually a property of the nodes.
  • Capacitance C is not, strictly speaking, identical to Q/p. If you have a location with a stored quantity Q and potential p, it is not correct to say that C = Q/p. Capacitance at any condition can actually be non-linear or a function of different parameters than just Q and p. Capacitance defines the relative changes in quantity and potential, not the static ratio of quantity to potential. So, if a node happens to have a potential of 5 and a quantity of 10, the capacitance is not necessarily 10/5 = 2. At this point, the capacitance might instead be 3, and adding a quantity of 1 to the node increases the potential by 1/3, changing the ratio of Q/p. Thus, we should stick to the strict definition of C = δQ/δp. This is a very important distinction for understanding capacitance in GUNNS. For electrical and thermal aspects, capacitance is usually constant so we tend to forget about this distinction. However for fluids, capacitance is never constant, but varies with temperature, density, mixture, and phase.
  • Since capacitance doesn’t do it, nothing in GUNNS strictly couples quantity to potential. Links, via their [A] and {w} contributions to the system, ask the solver to change the node potentials. The GUNNS solver dutifully solves the new node potential values, but knows nothing about quantity. It is the link’s responsibility to move quantity around between nodes to follow the change in node potentials. In other words, the transport of potential and quantity are uncoupled and can actually diverge in a network. This is particularly a problem in the fluid aspect (as electrical & thermal aspects don’t currently track stored charge or heat). Fluids have state equations that strictly tie their quantity (mass density) and potential (pressure) together. However, GUNNS doesn’t enforce this relationship, and quantity and potential can diverge until the fluid’s state equation is no longer satisfied. This translates into non-conservation of mass1. To avoid this pressure & mass divergence in GUNNS, fluid capacitive nodes attempt to correct any divergence between node mass and pressure so that the fluid’s state equation remains satisfied. See Fluid_State_Error.

See Also

Fluid_Capacitance
Network_Capacitance

1 This complete decoupling and divergence was a regular problem in PFN: you could have normal-looking pressures in nodes that actually contained negative mass!

⚠️ **GitHub.com Fallback** ⚠️