Grid Modeling
If the example circuits we’ve seen so far seem complicated to analyze, then this pales in comparison to the complexity of analyzing and operating the electrical grid. The electrical grid may be just another circuit, but it has rapid, far-reaching, and expensive consequences if it fails. If the grid is operated incorrectly, its voltages and frequencies can be put in jeopardy in a matter of seconds or less, creating a risk of cascading failure. Understanding the grid and how it behaves depending on how it’s operated is crucial to be able to control it correctly. Grid modeling allows operators to not only stay in control of grid voltages and frequencies, but also to dispatch generators in a way that is cost-optimal.
The grid is modeled as a network of electrical buses connected by branches. Power System Model · JuliaGrid, 2026 A bus is a shared point of connection that has minimal electrical impedance. Generators and loads are attached to the buses. Each pair of buses [1] may be connected by a branch—such as a power line or transformer—which has nonzero impedance and can result in voltage and phase differences between buses and . In the grid, each bus has a specific nominal voltage, typically 4 kV to 765 kV per phase depending on whether it is in the transmission or distribution part of the grid. The sets of buses and branches are denoted and , respectively.
For example, consider Figure 1. It shows a simple electrical grid with three buses , two generators (at buses 1 and 2), and a load (at bus 3). Buses 1 and 2 are connected by a line branch, and buses 2 and 3 are connected by a transformer branch. This type of diagram is called a single-line diagram because it depicts the parallel conductors in a single-phase system or balanced three-phase system—like the electrical grid—as single lines for the sake of simplicity.

Figure 1:Single-line diagram of an example electrical grid. (The symbol for “Load” should not be confused with the symbol for electrical ground.)
Figure 2 shows the circuit diagram that corresponds to the above single-line diagram for a three-phase system. Each bus in the single-line diagram corresponds to a set of three nodes in the circuit (one per phase).

Figure 2:Circuit diagram of the example electrical grid in Figure 1.
Each branch has a known series impedance and shunt impedance according to the (Pi) branch model. In grid modeling, these parameters are often expressed as admittance: series admittance and shunt admittance . The branch model applies the shunt admittance in equal parts on the left and right sides, as shown in Figure 3. This results in a single/per-phase circuit diagram that looks like the Greek letter , hence the name.

Figure 3:Per-phase power line model (the branch model).
Transformer branches build upon this in order to model nonideal transformers. Transformer branches are modeled as ideal transformers paired with the branch model, as shown in Figure 4. A complex-valued voltage ratio is used to model both the transformer’s voltage ratio and, in the case of a phase-shifting transformer such as a zigzag transformer, its phase shift . With the ideal transformer adjacent to bus , bus is known as the tap bus and bus as the impedance bus or bus.

Figure 4:Per-phase transformer model (the branch model + ideal transformer).
The Power Flow (PF) Problem¶
At any given time, a grid operator must dispatch generators to serve the loads in its grid. Each load consists of a given active power and reactive power . A dispatch specifies the active power at which to operate each generator . Once a grid operator has decided the generator setpoints, they must be able to validate those setpoints subject to how power will flow through the grid. The grid operator must do this at regular operating intervals (typically 5-minute or 1-hour intervals) because the predicted load and available generation change over time. This consists of:
Validating that power generation will satisfy the loads.
Validating that not too much power is flowing through a given line or transformer. This is to avoid overloading/overheating it.
Validating that voltages are within acceptable margins. This is for the sake of the loads.
The task of determining how power will flow through the grid and whether it will satisfy the loads is known as the power flow (PF) problem Mones, 2020Power Flow · PyPSA, 2026.
Because the grid is a circuit, we can solve the power flow problem the same as we solve any other circuit, by doing nodal analysis and solving a system of KCL equations to determine the voltage at each bus, denoted . In the three-phase case, the voltage magnitude can be assumed to be the same across the three phases at each bus, and the voltage angle can be taken for the first phase only, knowing that the other two phases will be radians apart.
For generality, we will model all branches as transformer branches. For line branches, we can simply set and . We will call branch an -forward branch if bus is the tap bus, or an -reverse branch if bus is the impedance bus. In this sense, the grid model becomes a directed graph rather than an undirected graph, and we must account for the forward and reverse branch directions distinctly. We do this by deriving the current flowing into branch from bus (that is, flowing directly into the ideal transformer), as well as the current flowing into the branch from the opposite bus . To determine , we apply KCL by summing the currents out of node in Figure 4:
And to determine , we apply KCL by summing the currents out of node :
The Bus Injection Model¶
To define the power flow problem, we need to formulate a set of power flow equations. The most common formulation is known as the bus injection model. We start with KCL, which tells us that at a bus with nominal voltage , the current injected due to attached generation and/or load must equal the sum of currents flowing out of the bus:
The subscript “” means “for each bus to which bus is connected by an -forward branch” and the subscript “” means “for each bus to which bus is connected by an -reverse branch”. Substituting and from equations (1) and (2) gives us:
Splitting up the summations and rearranging:
The bus injection model is typically expressed in a way that allows some complexity to be moved into a new matrix , called the bus admittance matrix, which allows the above equation to be rewritten succinctly as:
Or, even more simply, as a matrix equation:
where “” indicates element-wise vector multiplication and is defined as having the following diagonal and off-diagonal elements:
Thus, the admittance matrix does not only specify the admittance values between buses in its off-diagonal elements. Its off-diagonal elements additionally specify whether a branch is present between any -pair of buses (), whether a branch is a transformer (), and its voltage ratio if it is a transformer (), and even its phase shift if it is also a phase-shifting transformer (). Furthermore, the diagonal elements specify, for each bus, the shunt admittances of neighboring branches.
Just as how a branch admittance can be split into real and imaginary parts , where is conductance[2] and is susceptance, the admittance matrix can be split into , which we will leverage shortly.
The bus injection equations are typically arranged as equations for active and reactive power . To describe the power at a given bus , we take the conjugate of Equation (6) and multiply both sides by :
Solver software often expects real-valued equations, so we work towards splitting this equation into a real part and an imaginary part. Furthermore, the bus injection model most commonly uses polar coordinates for voltage and rectangular coordinates for admittance. To satisfy this, we substitute and in the above equation, giving us the following. We will eventually be able to take the imaginary unit out of the picture.
Expanding yields:
Finally, we are able to split this complex-valued equation into the following real-valued power flow equations, for each bus . These are suitable for use with solver software.
For a branch from bus to bus , the power flowing into the branch from bus is:
And the power flowing into the branch from bus is:
Where , , , and are the real and imaginary components of the branch-from-bus admittance matrix and the branch-to-bus admittance matrix , detailed in this chapter’s appendix.
Applying the Per-Unit System¶
The per-unit system is the practice in electrical engineering of normalizing quantities like voltage and power to a dimensionless value between 0 and 1. Each quantity is expressed as a fraction, denoted , of some base quantity, , such that . This can be done with many electrical engineering quantities:
For example, in the per-unit system with a base of , a quantity of would become or .
The per-unit system makes it easier to interpret quantities relative to the voltage and power ratings of equipment such as buses and generators. And when applied to the power flow problem, the per-unit system offers additional advantages Per-Unit System · JuliaGrid, 2026:
It improves the problem’s stability when solving using numerical methods.
As we will see, it allows most transformer branches to be treated simply as line branches because the transformer voltage ratio becomes in the per-unit system.
To express the power flow equations in the per-unit system, we select the nominal bus voltage as the base voltage at each bus , and an arbitrary value as the base power everywhere. We substitute for and for in Equation (5) as follows. We also split the transformer voltage ratio into nominal voltage ratio (which we denote ) times an off-nominal factor (which we denote ). It is not typical to represent transformer voltage ratios in the per-unit system as such—they are dimensionless quantities to begin with—but we use the notation nonetheless for consistency.
Substituting , multiplying both sides by and simplifying:
We now apply the per-unit system to the admittances, defining . If we select as the base admittance , all base terms conveniently cancel out, leaving something that looks exactly like Equation (5), but with “pu” scripts:
When the voltage ratio of a transformer is nominal—that is, equal to the ratio between the nominal voltage at bus and the nominal voltage at bus , then and the equation’s terms concerning the transformer branch simplify to those of a line branch. This is because the differing bus voltages are now accounted for as part of , respectively. The power flow problem is typically expressed in the per-unit system because of this advantage, as well as the advantage of improved numerical stability.
Bus Classifications¶
Our grid model, expressed by the power flow equations, currently has too many unknown variables to be able to solve it. We know the branch admittances, but we do not yet know how the loads should behave or how the bus voltages can be controlled. We now have a model of the grid, but as-is, we cannot use this model to determine how power will flow through the grid. In this section, we will narrow down our definition of the power flow problem.
Each bus and thus each pair of equations (12) has four variables: voltage magnitude , voltage angle , active power , and reactive power . Each bus contributes two equations, for a total of independent equations making up the system of equations. There are unique variables, so half of them must be fixed in order for the system of equations to have an exactly determined solution. The other half of the variables must be left as free variables that can take on whatever values are required to satisfy the system of equations. Which variables we fix and which variables we allow to vary depends on the type of each bus, as we will discuss. In order to support different numbers of buses of each type, half of the variables at each bus must be fixed and the other half free. At most buses, we don’t care about the voltage angle, so we leave as a free variable.
Load bus. A bus to which only load(s) are attached is known as a load bus. At a load bus, and are fixed based on the demands of the load (or loads). Although we wish we could fix to the exact nominal voltage of the bus for the sake of the attached load(s), this is not generally possible without making the system of equations under- or over-determined. Because of this, loads generally accept a voltage range, and system operators are required to keep within an even narrower range. Because only variables and are fixed at a load bus, a load bus is also known as a PQ bus.
Generator bus. A bus to which only generator(s) are attached is known as a generator bus. At a generator bus, is fixed based on the generator setpoints and is fixed to the bus nominal voltage. is allowed to vary at a generator bus to whatever value satisfies the system. Because only variables and are fixed at a generator bus, a generator bus is also known as a PV bus or voltage-controlled bus.
What if a bus has both generator(s) and load(s) attached? The net active power must be fixed because the active powers of both the generator(s) and loads(s) are fixed. The net reactive power must be free to vary because, while the reactive powers of the load(s) are fixed, those of the generator(s) are not. And is fixed, just as in a generator bus. Indeed, if we were to model a combined generator/load bus as a separate generator bus and a separate load bus , connected by a line with zero impedance, then would end up equalling anyway. So, a combined generator/load bus is treated as a generator bus.
And what if a bus has neither generators nor loads attached? In this case, the bus is treated as a load bus with fixed and .
Slack bus. So far, the classifications of variables as fixed versus free means that the number of free variables equals the number of equations. However, this does not necessarily mean that the system of equations has a solution that is feasible or that it has a solution that is unique. Indeed, with only the two bus types we’ve defined so far, there is a feasibility issue and a uniqueness issue. Firstly, active power losses due to electrical resistance in the power lines and transformers mean that the total power supplied by the generators does not necessarily equal the total power demanded by the loads plus the power losses. The deficit must be made up for by one or more generators at one or more buses, at which must thus be free to vary. Otherwise, there would not necessarily be a feasible solution. Secondly, voltage angles are relative, so at one bus, must be fixed to as a reference against which all other s are measured. Otherwise, there would be no unique solution. By convention, both the feasibility issue and the uniqueness issue are solved by the same bus. This third type of bus is known as a slack bus, also known as a swing bus, reference bus, or Vδ bus.
Table 1 summarizes the bus types and their variable classifications.
Table 1:Bus types and their variable classifications.
| Bus type | ||||
|---|---|---|---|---|
| Load/PQ | Fixed by load | Fixed by load | Free | Free |
| Generator/PV | Fixed by dispatch | Free | Fixed by grid operating requirement | Free |
| Slack/Vδ | Free | Free | Fixed by grid operating requirement | Fixed to reference |
As an example of how these bus classifications would apply, consider the electrical grid of Figure 5. Buses 2 and 3 are both load buses (even though bus 2 has no attached load). Either of buses 1 and 4 can be a generator bus (even though bus 4 has an attached load), but one of them must be a slack bus.

Figure 5:Single-line diagram of another example electrical grid.
Power Flow Validation¶
After solving the power flow problem, a grid operator is able to validate their generator dispatch according to the three requirements listed under The Power Flow (PF) Problem:
Validating that power generation will satisfy the loads. More specifically, validating that the slack generation—which is free to vary to whatever value is required to satisfy the loads—is within the maximum power of slack generator :
Validating that not too much power is flowing into or out of a branch (a line or transformer):
We refer to this as the branch flow constraint.
Validating that voltages are within acceptable margins:
The branch flow constraint’s is derived as follows:
The same is done for by replacing with .
The Economic Dispatch (ED) Problem¶
The power flow problem is intended to determine whether generator setpoints are valid, but it alone does not help determine what generator setpoints to use in the first place. When a grid operator decides how to dispatch generators, their goal—within the requirement of satisfying the grid’s loads—is to minimize their operating cost incurred during a given operating interval. Different types of generators have different costs per MWh of electrical energy; for example, operating a hydroelectric generator is less expensive than fuel for a natural-gas-powered generator. Furthermore, a given generator can also have a cost per MWh that increases with the setpoint , in MW, at which the generator is operated. Thus, each generator has its own cost function , and the total operating cost for a given interval of time depends on both on which generators are dispatched, and what setpoint each of those generators is operated at.
The grid operator can achieve their goal of minimizing their operating cost by solving an optimization problem in which the objective function—to be minimized—is the total operating cost, and the decision variables are the generator setpoints. This optimization problem is what is known as the economic dispatch (ED) problem:
How the cost function is formulated depends on the application. If the application is research or planning purposes, then a quadratic fit is typically used to approximately model how the cost per MWh increases as increases. For day-to-day and real-time dispatch by the grid operator, a piecewise linear function is often used for greater accuracy.
So far, we have assumed that all generators are dispatchable (controllable power) and that all loads are non-dispatchable (uncontrollable power). There do exist non-dispatchable generators whose power production cannot be controlled, as well as dispatchable loads (such as smart thermostats and smart EV charging in some cases) whose power consumption can be controlled by the grid operator. Biddle, 2024 However, this does not mean that the grid model discussed so far cannot represent these resources. Non-dispatchable generators can be modeled as loads whose fixed power is positive rather than negative. As for dispatchable loads, they can be modeled as generators whose maximum power is negative rather than positive, and with cost functions that intake and output negative values. This negative cost—associated with consuming, rather than producing—is called utility in economics. Utility quantifies the economic value delivered to consumers (loads) when they are dispatched by the grid operator, in contrast to the cost incurred by producers (generators) by being dispatched.[3]
The Optimal Power Flow (OPF) Problem¶
Not just any solution to the economic dispatch problem will do. Operating costs cannot be minimized without ensuring that the setpoints are valid per the power flow equations (12) and the criteria in the previous section (equations (19), (20), (21)). These become equality and inequality constraints in the optimization problem, respectively. The result of pairing the objective function for economic dispatch with the power flow constraints is known as the optimal power flow (OPF) problem Frank & Rebennack, 2016Mones, 2021:
This OPF problem (26) must be solved for every operating interval, making a dispatch decision and minimizing the total cost incurred over that interval independent of any other interval. However, as we will see, there are OPF variants that require considering multiple intervals in one optimization problem, making a dispatch decision for every interval simultaneously and minimizing the total cost incurred over all intervals. For these purposes, we add an interval index to all time-variant quantities and denote the interval duration as .
Ramp rate limits. The first multi-interval OPF variant that we will discuss involves limits on generators’ ramp rates. How quickly a generator’s power output (in MW) changes from one interval to the next is referred to as its ramp rate (e.g., in MW per minute). If the power output is analogous to velocity, then ramp rate’s analog is acceleration, and there are limits to both. Some generators may not be able to change their power output very quickly. To keep the dispatch decision within such physical limitations, the following constraint is added to respect each generator’s ramp rate limit when ramping up, , and when ramping down, :
Ramp rate limits and are positive and negative values, respectively. For a given , only one side of this two-sided inequality constraint can be active.
The Unit Commitment Problem¶
The basic OPF problem (26) accounts for the power cost that is incurred by operating a generator at a certain setpoint (e.g., incurred due to fuel use). However, there are additional standby costs which depend on whether a generator is in a running state versus an off state over a given operating interval, and there are additional startup and shutdown costs which depend on whether the generator is transitioning from an off state to a running state (or vice versa) from one interval to the next. In order to account for these additional costs in our objective function, we must introduce additional binary decision variables, , specifying whether generator is running () or not () over interval . This requires modifying constraint (19) as:
The variant of the OPF problem that includes standby, startup, and shutdown costs is thus a scheduling problem, and is known as the unit commitment (UC) problem Unit Commitment · PyPSA, 2026. Unit commitment refers to whether a generating unit (that is, a generator) has committed to be running—and thus able to supply power—at a given time.
Standby cost. In addition to a power cost, a generator might have a cost that is incurred as long as it is running, regardless of the generator’s setpoint. This is known as standby cost, , and it disincentivizes a generator from being run (and thus from generating any power) if there is a favorable alternative in terms of cost. For example, the grid operator may be willing to pay a disproportionately higher price to operate an already-running generator at a higher setpoint, rather than running a second generator to supply the extra power, if that second generator’s standby cost is high. Accounting for standby cost, the objective becomes:
Startup and shutdown costs. In addition to a power cost and a standby cost, a generator might have costs associated with starting up and shutting down, denoted and , respectively. Startup and shutdown costs only matter if there are standby costs; if there were no standby costs, there would be no reason to shut down generators and thus no reason to incur startup or shutdown costs. Accounting for startup and shutdown costs in addition to standby cost, the objective function becomes:
where and indicate whether a generator has started up or shut down from one interval to the next, respectively.
Startup and shutdown ramp rate limits. Some generators have stricter ramp rate limits that apply specifically when starting up or shutting down, which can be accounted for using the following constraints:
Minimum uptime and downtime. It may be required that a generator be in a standby/running state, or in an off state, for a minimum number of operating intervals. This can be accounted for using the following constraints:
The Linear Optimal Power Flow (LOPF) Problem¶
The power flow equations (12) contain quadratic terms multiplied with trigonometric functions, and branch flow constraint (20) is even more complicated. The power flow equations being nonlinear is easy enough when solving them as a system of equations, and the branch flow constraint being nonlinear is easy enough when evaluating the power flow solution, but when used as constraints in OPF, the nonlinearity makes the optimization problem significantly more difficult. To simplify (linearize) the power flow equations and branch flow constraint, thereby making the optimization problem easier, the following approximations are applied:
Series resistance is negligible compared to series reactance: and . This approximation is reasonable for transmission lines and, combined with approximation 2, assumes a lossless network.
Shunt conductance and susceptance are negligible: .
Turns ratios are approximately nominal: .
Voltage angle differences and transformer phase shifts are small: and .
Voltage magnitudes are approximately nominal: everywhere. This supports approximation 3 and holds for a lossless network.
We start by applying approximations 1–3 to equation (5) as follows. We will apply approximations 4 and 5 later.
We redefine the bus admittance matrix as:
Equation (33) becomes:
We take the conjugate and multiply both sides by :
Splitting into active and reactive power gives us:
For a branch between buses and , the power flowing into the branch from bus is as follows. ( assumes .)
Applying approximation 4 yields:
And, finally, applying approximation 5 gives us:
Now, when we once again sum the power flowing out of every bus , it includes only active power:
This is the linear power flow equation, which applies to every bus and is much simpler than the original (nonlinear) power flow equation due to the approximations applied. Because the linear power flow equation approximates voltage magnitudes as nominal and assumes zero reactive power, there is no differentiating between PQ and PV buses. Furthermore, the lack of reactive power allows us to simplify the branch flow constraint (20):
When OPF uses the linear power flow equation and the correspondingly simplified branch flow constraint, it is known as linear optimal power flow (LOPF).
Table 2:Linear power flow is analogous to DC circuit analysis.
| Linear power flow | DC circuit analysis |
|---|---|
| Conservation of power flow | Conservation of current flow (KCL) |
| , | , |
| , | , |
Cycle-Based Formulation¶
The LOPF problem uses bus voltage angles as decision variables, but there are advantages to using the branch power flows instead. For such an alternate formulation, we are still constraining the net power injected at each bus to equal the total power flowing into the bus from each connected branch, but we do so in terms of the branch power flow . We refer to the signed incidence matrix () to indicate whether is flowing into or out of bus (+1 or -1, or 0 if is not connected to it):
This increases the number of variables while the number of equations in the system stays the same. To make the system solvable, we apply Kirchhoff’s Voltage Law (KVL), which states that the net voltage difference around each loop or cycle in the circuit/grid is zero. This means that if we add up the voltage difference across every branch in a given cycle, they must add up to zero. Because we assume , this becomes . Ensuring these sum to zero around a given cycle is equivalent to just ensuring that the cycle’s voltage angle differences () sum to zero, or:
where is the set of cycles, and indicates whether branch is in cycle (+1 or -1 depending on the direction, or 0 if absent). Using Equation (40), we can express this in terms of the decision variables as follows, thereby completing the system of equations.
Summary¶
We’ve introduced many concepts; Figure 6 provides a summary of these concepts and how they relate to each other.

Figure 6:This chapter’s concepts and how they inter-relate.
Appendix: Branch-From-Bus and Branch-To-Bus Admittance Matrices¶
The bus admittance matrix is a convenient way to encapsulate the complexity of series admittances (), shunt admittances (), and transformer ratios (). However, because each diagonal element is a sum over every -connected branch, the bus admittance matrix does not allow us to calculate individual branch current and power values ( and ). This can be overcome using the bus admittance matrix with a “branch-from-bus” admittance matrix and a “branch-to-bus” admittance matrix . Both of these matrices are sparse matrices of dimension , where is the number of buses and is the number of branches; both matrices have a row for each branch and a column for each bus. For a branch from bus to bus , row of each matrix has nonzero entries only in columns and :
The familiar bus admittance matrix can be reconstructed from these as follows, using branch-from-bus and branch-to-bus incidence matrices and :
Matrices and are also sparse matrices, consisting mostly of zeroes. contains a “1” entry indicating the bus that each branch originates from. Similarly, indicates which bus each branch goes to.
Index is used instead of to distinguish it from the imaginary unit.
Not to be confused with generator index .
To learn more about the economics of operating the electrical grid, see How Electricity Markets Work.
- Power System Model · JuliaGrid. (n.d.). Retrieved June 6, 2026, from https://mcosovic.github.io/JuliaGrid.jl/stable/tutorials/powerSystemModel/
- Mones, L. (2020, December 4). A Gentle Introduction to Power Flow. Invenia Blog. https://invenia.github.io/blog/2020/12/04/pf-intro/
- Power Flow · PyPSA. (n.d.). Retrieved July 4, 2026, from https://docs.pypsa.org/latest/user-guide/power-flow/
- Per-Unit System · JuliaGrid. (n.d.). Retrieved July 4, 2026, from https://mcosovic.github.io/JuliaGrid.jl/stable/tutorials/perunit/
- Biddle, C. J. (2024, May 1). Understanding the Differences Between Non-Dispatchable and Dispatchable Generation. PCI Energy Solutions. https://www.pcienergysolutions.com/2024/05/01/understanding-the-differences-between-non-dispatchable-and-dispatchable-generation/
- Frank, S., & Rebennack, S. (2016). An Introduction to Optimal Power Flow: Theory, Formulation, and Examples. IIE Transactions, 48(12), 1172–1197. 10.1080/0740817X.2016.1189626
- Mones, L. (2021, June 18). A Gentle Introduction to Optimal Power Flow. Invenia Blog. https://invenia.github.io/blog/2021/06/18/opf-intro/
- Unit Commitment · PyPSA. (n.d.). Retrieved July 28, 2026, from https://docs.pypsa.org/latest/user-guide/optimization/unit-commitment/