Robust, distributed and optimal control of smart grids

Summary. — These lecture notes provide an overview of recent research on the modeling and control of smart grids using distributed algorithms. In particular, energy-based modeling of general AC power networks using the framework of port-Hamiltonian systems theory is presented, and the relevance of such a formulation for stability analysis and control design is discussed. Low-level control design aspects (at a physical layer) for DC microgrids are also considered, achieving objectives such as fair load sharing among distributed generation units and (average) voltage regulation using limited data and measurements from the system. Finally, general frameworks for the optimal control of smart grids are introduced to consider both physical and economic constraints and exploit the ﬂexibility brought up by storage devices and demand response from the grid’s prosumers.


-Introduction
Energy system operators and stakeholders worldwide are currently striving to make the energy sector more sustainable so that future generations have access to secure and affordable energy [1].A promising approach for achieving sustainability consists in substantially increasing the presence of renewable energy sources, such as solar and wind.However, renewable sources' uncertain and widely variable nature drastically contrasts with those conventionally used for energy production -usually large-scale thermal plants based on coal, gas, and oil-imposing great design and operational challenges for the efficient and reliable supply of energy to end-users.Critically, existing tools to monitor, control, and optimize large-scale energy systems are becoming progressively inadequate to guarantee optimized and robust system operation [2].
We provide an overview of recent contributions on robust, distributed, and optimal control of smart grids.Smart grids exploit information technologies as well as scalable and re-configurable control infrastructures to guarantee secure, resilient, and costoptimized grid operations [3] (see also [4]).In particular, we report on the following contributions: C1: The first contribution, originally reported in [5], refers to the development of a systematic framework for modeling AC power networks.A dynamic model of a general power system composed of synchronous machines, dynamic power lines, and nonlinear loads is obtained using graph theory and the framework of port-Hamiltonian systems.In addition, a discussion is presented on how such a model can be simplified so that open-loop stability analysis can be conducted.
C2: The second contribution, initially reported in [6], pertains to the design of a distributed control scheme that achieves (average) voltage regulation as well as proportional current sharing among DGUs of a DC microgrid containing linear loads.Some of the main contributions of [6] are: i) the consideration of an arbitrary meshed microgrid topology with resistive-inductive (and hence dynamic) power lines; ii) the satisfaction of a notion of voltage regulation using only current measurements.
C3: The third contribution, firstly reported in [7], concerns a price-based approach for achieving congestion management in AC distribution power systems with distributed, renewable generation units.The main goal is to maximize a social welfare function, which includes net revenues of end-users and the cost of power losses, while guaranteeing that voltage magnitudes are within prescribed bounds and that the grid operates within its capacity.Some simulation results on a modified IEEE-37 bus benchmark, which uses realistic data on photovoltaic generation units, are briefly discussed.
C4: The final contribution is concerned with the study of a distributed, optimal control framework to minimize the imbalance between supply and demand in smart grids with high penetration of renewable sources.One of the main features of this contribution is that it relies on demand response thereby shifting the production or consumption of energy assets in time, allowing to reduce or avoid load peaks.This contribution is reported in [8].
The rest of this document is structured as follows.Contributions C1-C4 are discussed in sects.2-5, respectively.Some concluding remarks appear in sect.6.
Notation: R denotes the set of real numbers; C 1 is the set of continuously differentiable functions; ∇f is the transpose of the gradient of a function f : R n → R; A is the transpose of a matrix A ∈ R n×n ; graphs are denoted by G = (N, E), where N represents its nodes, E its edges, B its incidence matrix, L its Laplacian matrix, and E i the edges incident to any i ∈ N .We let diag(x i ) i∈I denote a diagonal matrix with diagonal elements equal to x i ordered according to the index set I, and col

-Port-Hamiltonian modeling of AC power grids
The vast energy demand of modern societies has urged the development of very complex power systems for the production, transmission, and distribution of electricity [9].Even though production has been mostly based on fossil fuels, there is currently a transition towards a more sustainable energy sector characterized by the increasing presence of renewable sources, such as photovoltaic arrays and wind farms [10,11]; see fig. 1.
One of the main goals of a power system is to guarantee the supply of energy to end-users reliably, with minimum costs and minimum environmental impact [9,12].In particular, reliability is strongly related to the notion of system stability around desired operation regimes, which is tightly coupled with control systems design and implementation.A fundamental step towards the conceptualization of optimization and control algorithms is the development of a model that qualitatively and quantitatively describes the behavior of the devices and physical phenomena occurring during system operations [2,13].In this regard, dynamic models are useful to investigate the response against disturbances, e.g., power outages, whereas static (steady-state) models are more often employed in optimization analysis (see, e.g., [13,15]).
A well-established theory for dynamic modeling of complex physical systems is referred to as port-Hamiltonian systems theory.This theory provides a framework for modeling, analysis, and control of multi-physics systems in general [16] and allows to view complex systems as the interconnection of a small set of elements that store, dissipate, and transport/convert energy [17].Notably, energy becomes a common language to interrelate systems from different domains, such as mechanical, electrical, hydraulic, and thermal ones [18].Furthermore, physical systems with different time and spatial scales can be naturally integrated as the port-Hamiltonian representation is preserved during the interconnection of individual subsystems (see [19,18]).For these reasons, port-Hamiltonian systems theory is suitable to model large-scale, networked multi-energy systems.
In this section, following the exposition in [5], port-Hamiltonian modeling of AC power systems is discussed.For the sake of brevity, a general class of port-Hamiltonian systems is defined next which is suitable to represent the class of energy systems treated in these lecture notes.Following [20], let T be a real interval, let x : T → R n be the state and let u, y : T → R m be the input and output, respectively.Then, the following dynamic equation describes a port-Hamiltonian system (see also [18]): Each component of the state x represents a variable that determines the energy stored on a given physical device present in the system, e.g., the electric charge of a capacitor.Also, H : R n → R + continuously differentiable is the Hamiltonian, which represents the total energy stored in the devices conforming the overall physical system.Moreover, the matrices J(x) = −J (x) ∈ R n×n and R(x) = R (x) ∈ R n×n , which have entries depending smoothly on x, are respectively referred to as interconnection (or structure) and dissipation matrices.Also, g(x) ∈ R n×m can be referred to as the port or input vectorfield and the specific choice of y is referred to as the natural passive output.
Next some instrumental steps that lead to representing AC power system models as in (1) are explained.Before that, we would like to remark that any solution of (1) satisfies the following power balance equation: Note that the left-hand side of (2) represents of the rate of change of the stored energy in the system, whereas the right-hand side is the total power provided by the external input u minus the total energy dissipated, e.g., by electric resistors.Under some convexity assumptions on H, and with R(x) ≥ 0, eq. ( 2) implies that port-Hamiltonian systems represented as in eq. ( 1) are passive [18] (see also [16]) with storage function being the Hamiltonian, and with respect to the input output pair (u, y), i.e., Ḣ ≤ u y.Even though this is sufficient to guarantee open-loop stability when u = 0, such conclusions are not enough to understand stability properties of power systems in general, in which the forced equilibrium of interest is not the origin (see sect.4.1 in [5]).

2
. 1. AC grids as graphs.-Consider a power network represented as a directed (and connected) graph G = (N, E).The set of nodes N are the network's buses and the edges E are the generators, loads and power lines.It is assumed there is a single reference bus which is at ground potential, and that one node of each generator or load edge is necessarily the reference bus.For simplicity, the presence of interior nodes is neglected, i.e., each node in N is either an end node of a generator or a load.Without loss of generality, the sets of nodes can be split as N = N g ∪ N ∪ N r , where N g and N would be the generation and load buses, and N r the reference bus.
For the transmission lines a Π-model is adopted (see [9]).Then, each line consists of a series connection of an inductor and a resistor and, at each end node of the line, it is considered that there is a capacitor.One end node of such a capacitor is assumed to be the grid's reference node.In the case that more than one transmission line is incident to a given load or generation bus, then all capacitive effects are lumped into a single capacitor per generation or load bus.In view of the Π-model, the set of edges are conveniently split as E = E g ∪ E ∪ E c ∪ E T , where E g and E are generation and load edges, E c are the capacitor edges, and E T are the R − L components of each power line.The diagram of an exemplary power system and its graph representation is shown in fig. 2.
Note that a 3-phase power system is considered, then each node or edge associated to any generator, load or transmission line corresponds in fact to three different nodes and edges representing three different phases.Next, the dynamics of each edge of the system is written in port-Hamiltonian form (see eq. ( 1)).After that, algebraic interconnection equations are established (based on Kirchhoff's laws) from which the overall power system model can be obtained.
denote its stator and rotor flux linkages.Also, let θ i ∈ R and p i ∈ R denote the rotation angle and momentum of the rotor, respectively.Then, the total energy of the synchronous machine, which is the sum of the electric and mechanical energy, can be written as follows: (3) is the generator's inductance matrix, the components of which codify self and mutual inductances between the stator and rotor windings (see [9]).Also, J i > 0 is the rotational inertia of the rotor.Using basic physical laws, such as Maxwell's and Newton's laws, in combination with port-based modeling [17] it is possible to arrive to the following port-Hamiltonian model for the generator (further modeling details appear in [9]) where are the state, input and output vectors of each generator, respectively.The input vector u i is comprised by the stator voltages V s,i , the voltage applied across the rotor windings E r,i , and the mechanical torque T m,i acting on the rotor.The output vector y i is conformed by the stator currents I i , the current through the rotor windings I f,i and rotor's angular velocity ω i .Note that u i and y i are conjugated in the sense that their product u i y i represents power.The interconnection and damping matrices in (4) are, respectively, given by ( 5) are positive definite diagonal matrices containing in their main diagonal the resistances associated with the stator and rotor windings, respectively.The term d i is the total mechanical damping (due to viscous friction).Due to space constraints g i (x i ) is not shown here, however its explicit form appears in [5], eq. ( 7).

2
. 3. Load model .-Let i ∈ E be an arbitrary load edge.For the sake of simplicity, loads are represented by static (algebraic) relations as follows: where V i and I i are the voltage across, and the current through, the load, respectively.Note that the second inequality imposes that each load corresponds to a dissipative device, i.e., it drains power from the network, and it cannot store energy.

2
. 4. Power line dynamics.-Let i ∈ E T be an arbitrary power line, which we recall is conformed by a series connection of a resistor and an inductor (one per phase).Let I i , Ψ i ∈ R 3 denote the current through, and the flux linkages of, the inductors.Also, let R i and L i denote 3 × 3 diagonal, positive definite matrices with the line resistances and inductances in their main diagonals.Then, the total energy stored in the power line is given by , which represents the line's total magnetic energy.Through Kirchhoff's laws it is possible to obtain the following line dynamics: where x i = Ψ i is the state and y i = I i is the output.The input u i = V i represents the voltage across the R − L component of the line.Also, R i = R i .Note that mutual inductance among the lines of the different phases is neglected.
Let i ∈ E c be an arbitrary capacitor at some end node of a given transmission line.Let Q i , V i , I i ∈ R 3 denote its electrical charge, voltage and current (per phase).If C i is a 3 × 3 diagonal matrix with the capacitances, then the total energy stored at the capacitor is given by It follows from the constitutive relations for the capacitor that the following dynamic equation holds: where x i = Q i is the state, u i = I i is the input and y i = V i is the output.

2
. 5. Overall AC grid model .-Until this point dynamic equations for any edge of the graph have been defined.Next diverse algebraic relationships are introduced, based on Kirchhoff's laws (see [21] for more details), to couple the edges' dynamics according to the physical interconnection of the devices in the network.Note that since the reference node is at ground potential, then V i = [0, 0, 0] for i ∈ N r .In addition, since at each load or generation bus there is a capacitor, whose other terminal is connected to ground potential, it follows that for each i ∈ E g ∪ E there exists a unique j ∈ E c such that V i = y j = ∇H j (x j ).Moreover, for each i ∈ E T there exists a unique pair (j, k) On the other hand, the law of conservation of electrical charge at each load or bus node dictates that for each i ∈ E c there exists a unique j ∈ E g ∪ E and a subset E T,i ⊂ E T of transmission lines incident to the i-th generation or load bus such that I i + I j + m∈ET,i I m = 0, or equivalently, that  (7), and for I i , i ∈ E c , into (8), the overall, ODE-based model of the power network is obtained.The explicit form of the overall power network's dynamics, which can be found in [5], eq. ( 21), can be shown to be written as in eq. ( 1) through a suitable definition of a state vector x, a total Hamiltonian H = i∈Eg∪ET∪Ec H i and matrices R, J and g(x).Additional contributions reported in [5] refer to the specialization of the load model (6) to consider linear, resistive loads.The resulting model is further simplified by virtue of the Dq0 transformation (see, e.g., [22]) through which the dependence of the inductance matrix in (3) with respect to the rotor angle θ i can be eliminated.This allows a construction of an equivalent quotient system whose steady states are characterized by equilibrium points and not by periodic solutions as for the primal model.An open-loop stability analysis is carried out for the quotient system, which relies on a key result from [23] for the stability analysis of a general port-Hamiltonian around non-zero equilibria.The conclusion drawn from this analysis, which imply explicitly finding a Lyapunov function (see [5], eq. ( 68)), is that the a single synchronous machine connected to a linear load is stable.However, the results are valid under the assumption that there is no energy dissipation in the stator windings, which should be relaxed for representing synchronous machines more accurately.
This section is concluded by noting that even though control design has not been covered, the description of a physical system using the port-Hamiltonian formalism can be considered as a starting point for the design of nonlinear, robust control algorithms [16].Indeed, it is now widely recognized that physical relationships that are intrinsic to the system under consideration, e.g., balance and conservation laws, can be exploited in the design of control schemes [18]; see also [24] and [25].The latter aspect can be instrumental in providing closed-loop stability guarantees, which would be fundamental for the reliable operation of power systems.The interested reader is referred to [26][27][28] for the design and analysis of different control algorithms based on Lyapunov, passivity, sliding mode and output regulation theory to regulate the frequency in power networks, where each area is modelled by an equivalent generator including turbine-governor dynamics, and where the areas are nonlinearly coupled.

-DC microgrids
The concept of microgrids, firstly introduced in [10], refers to relatively small-scale (AC or DC) power networks that are mainly composed of distributed generation units (DGUs), storage devices, and loads.These networks can operate autonomously with respect to the main grid, and in many contexts, DC microgrids may be more advantageous than their AC counterpart (see [29]).For example, a large proportion of DC loads in data centers can be directly energized by any readily available DC-based DGU (such as photovoltaic panels), provided that a small-scale distribution network is available.Is it noteworthy that so far DC microgrids have found wide implementation in trains and aircraft and further placement can be expected due to the increasing presence of DGUs based on DC power (more details can be found in [29][30][31][32][33][34][35][36][37][38] and references therein).
-Following [6], consider a DC microgrid composed of n DGUs and m resistive-inductive power lines, which are respectively viewed as the nodes N and the edges E of a connected graph G = (N, E), as done in sect. 2 for AC power networks.As depicted in fig.3, each DGU's voltage source u i represents the main source of energy.Part of this energy is supplied through a Buck converter to a local load whose current is denoted by I ,i and whose measurement is not available for control design purposes.For any i ∈ N , the dynamic behavior of the current through its inductor L g,i and the voltage across the capacitor C g,i is described by the following equations: where E i ⊂ E denotes the power lines that are incident to i ∈ N and through which the i-th DGU can exchange power with neighboring DGUs.Also, the current through any line k ∈ E is represented by I k .In addition, let L k and R k be the inductance and resistance of the power line k ∈ E.Then, the dynamic behavior of I k is described by (10) L where i, j ∈ N are the end nodes of k.
Let B represent the incidence matrix of G.Then, eqs.( 9) and ( 10) can be gathered and written in vector form as follows: where Before stating the control objectives of interest, note that since the DC microgrid's graph G is connected, it follows that 1 B = 0.One implication of this is that, at the equilibrium, the equality 1 Īg = 1 I must hold, which indicates that the overall current generated in the microgrid by the DGUs must match the overall current demand from the loads.However, note that there are degrees of freedom on the actual current each DGU can inject.Motivated by this observation, the first control objective is stated next: Objective 1: , where (12a) where w i > 0 are weights specified by each DGU.The above objective implies the regulation of the DGU's currents towards a proportional current sharing regime defined by the weighting factors w i .Note that if the value of w i , i ∈ N , is chosen to be inversely proportional to its respective DGU's capacity, then the DGU's with higher capacities will have higher current values in steady state.
It can be verified from the equilibrium equations associated with (11) that achieving Objective 1 imposes a restriction on the DGUs' steady-state voltage values that are admissible.Nonetheless, it can be shown that, at any equilibrium, the vector of voltages V satisfies B V = B ( V + a1), where a ∈ R is any scalar.This motivates a second control objective, which pertains the attainment of average voltage regulation.More precisely, let V ∈ R n represent a vector of desired DGU voltages.Then, it is of interest to satisfy the following: Objective 2: where W = diag(w i ) i∈N contains in the main diagonal the same weights used in (12).

. 2. Control design and simulation results.
-Following [6], in this subsection a distributed, dynamic control law is presented for the input u such that when the system (11) is in closed loop with it Objectives 1 and 2 specified above are met.It is assumed that the measurement of the current I g,i of each DGU i ∈ N is available for control purposes.Also, it is assumed that there is a connected, undirected -and weighted-communication graph G com = (N com , E com , Γ com ) involving all DGUs, i.e., N com = N but it does not have (necessarily) the same topology of the microgrid's graph G.Then, the following controller makes the considered DC microgrid attain Objectives 1 and 2: where T θ , T φ , K ∈ R n×n are positive-definite diagonal matrices whose components are control parameters to adjust, e.g., the closed-loop system's transient response.Also, L com is the (weighted) Laplacian matrix associated to G com .
Observe that the first subequation of ( 14) is a consensus dynamics.It is often used in power systems control design to achieve either fair power or current sharing among DGUs: note that the equilibrium current Īg necessarily satisfies W Īg ∝ 1, which is equivalent to (12b).The introduction of the variable φ, which acts as a filter on I g without altering its desired equilibrium value, showed in simulations to be useful to attenuate oscillations.In addition, the proportional term −K(I g −φ) in u is fundamental to guarantee convergence of solutions of the closed-loop system towards a constant steady state.Finally, the term W L com θ + V stems from the desire to establish a passive interconnection with the state θ and simultaneously address Objective 2: in closed loop, the steady-state relation − V + W L com θ + V = 0 holds, which after (pre) multiplication by 1 W −1 leads to (13).In [6], the steady-state properties discussed above are complemented with a formal stability analysis -based on LaSalle's stability theorem-from which the solutions of the overall closed-loop system are shown to exponential convergence towards a steady-state satisfying (12b) and (13).
The transient performance of the controller (14) was assessed in [6] through simulations about a microgrid with four DGUs and four power lines as depicted in fig.4(a).The numerical values of the physical parameters can be found in tables II, III of [39] and all control parameters, such as T θ and T φ , in sect.VI of [6].For the simulation results displayed in fig. 4 establishing a new steady-state and asymptotically converging to it.Note that, except for the scenario in which K = 0 (gray plots), there are no significant oscillations nor overshoots and Objectives 1 and 2 are clearly met.
The following are some extensions to the aforementioned work on DC microgrids.In [40], a slightly modified version of the controller ( 14), which makes it suitable to handle constant impedance and constant power loads (and not only constant current loads), was satisfactorily validated through experiments on a real-world microgrid with four DGUs connected through a common bus to a single load: both Objectives 1 and 2 were met with adequate transient performances.In [41] the problem of regulating DGU voltages in DC microgrids containing a widely used class of nonlinear loads and subject to time-varying disturbances is considered.The problem was addressed by designing two decentralized, passivity-based control schemes whose conception strongly relied on representing the microgrid's dynamics in port-Hamiltonian form (see sect. 2) and which probably makes the overall system admit an exponentially stable equilibrium point (with specified voltage values).Finally, in [42], the control strategy developed in [6] is extended to AC microgrids comprising electrical loads with both constant impedance and constant current components.Unlike work on DC networks, the additional objective of decoupling the DGUs' active and reactive powers is achieved, whose satisfaction permits a more straightforward manipulation of the active power injected by each DGU.

-Utility optimization
Following [7], consider an AC power distribution network that is composed of n buses and m power lines.As before, the network is represented as a graph G = (N, E), where the nodes N are the buses and the edges E the power lines.Then, the active and reactive power flows in the network are described by the following equations [9,12]: where P i , Q i , V i and θ i represent active power, reactive power, voltage magnitude and phase angle of i ∈ N .Also, E i ⊂ E is the subset of power lines which are incident to i ∈ N .θ i,j := θ i − θ j denotes the relative angle between any two i, j ∈ N , and G i,j , B i,j are the conductance and susceptance of line (i, j) ∈ E, respectively.
At each i ∈ N it is assumed there is an end user with the ability to generate, consume and store active power at rates P g,i , P ,i and P s,i , respectively.Such an end user can also generate and consume reactive power at rates Q g,i and Q ,i , respectively.It follows that P i and Q i in ( 15) can be written as follows: ( 16) It is assumed that loads are constant all the time, whereas power generation (active and reactive) will be viewed as decision variables of an optimization problem to be defined.Moreover, it is assumed that the energy stored by the end user evolves in time according to the following discrete model: where E s,i (k) is the amount of stored energy at instant k and η s,i is the efficiency of the storage system: storage units are considered to be charging if P s,i ≥ 0, and discharging otherwise.
Next, the power losses incurred in during normal operation of the power system are computed.One source of losses is due to dissipation in the power lines, which implies costs to the network operator and whose total value can be computed from ( 16): (18) P r loss = i∈N P g,i − P ,i + P s,i .
In addition, the losses associated to the production of electric power at each end user are also considered.Such losses are attributed to the operation of power electronic components used in, for example, photovoltaic inverters in the case of end users with solar panels.The following model is adopted to represent the generation losses: where ρ inv,i is a coefficient which will be assumed to be dependent on the price of the energy (more details ahead).Note that the costs associated with energy dissipation in each storage unit are neglected in this work.
Let f 0 : R 3n → R denote the cost due to power line losses, which are covered by the network operator, and let f i : R n → R be the profit of end user i for selling electric energy.Consider then the following problem: In particular, f 0 is characterized as f 0 (x) = γ p P r loss /| i∈N P ,i |, where γ p is the exogenous price for active power and P r loss is given in (18).On the other hand, f i (x i ) = γ p P g,i + γ q Q g,i + γ s P s,i − C i (P g,i , P s,i , Q g,i ), where γ q and γ s are the exogenous price signals for reactive and stored (active) power.Also, C i is each end user's cost for producing and storing energy: energy production is directly taken as in (19) (20), they are defined for each i ∈ N as (21) and restricts the end users' generated active, reactive and stored power to be within predefined intervals.The same applies to the voltage magnitudes and to the relative angle between any two nodes i, j ∈ N .With abuse of notation, the last constraint shown in (21) considers the capacity limits of the grid, which is actually a coupling constraint.Part of the contributions reported in [7] refers to finding a solution to the problem (20).One key step for achieving this involves the linearization of (15) to attain an approximate yet convex problem.Then, an associated Lagrangian dual problem can be defined, together with explicit necessary and sufficient optimality (K.K.T.) conditions [43].In particular, the dual problem allows for decomposing the (approximate) optimization problem into several sub-problems with a hierarchical feature, leading to a scheme to solve the overall optimization problem through a distributed algorithm (which is highly desirable in large-scale networks).The decomposition is also beneficial to ensure a certain level of privacy since it let end users not share all their data with the network operator.Although all details about the proposed solution algorithm can be found in [7], Prop. 1, it is emphasized that the theoretical developments described above were tested in [7] on a numerical case study based on the IEEE 37 bus distribution system containing photovoltaic power generation, active and reactive power loads and storage systems, as modeled in [44] and references therein.The results depict (see a sample in fig.5) that giving incentives to end users to adapt their network usage, e.g., by actively using storage units, is effective in maintaining the desired grid operation.
More recently in [37], a novel optimization problem has been formulated which also seeks to maximize a social welfare function (but in DC grids) and integrates prosumers' motives in the utility function; the design of a distributed control scheme with convergence guarantees is also reported therein.Moreover, in [45] second-order behavior and personal norm-based models have been developed, which are consistent with some studies on opinion dynamics for describing and predicting human activities related to the final use of energy in AC grids, where psychological variables, financial incentives, and social interactions are considered.

-Distributed optimal control of power systems, market layer
Weather conditions strongly impact the power output of renewable sources, which can lead to large fluctuations in supply causing a mismatch between the forecast (day ahead) and the actual supply and demand of energy.Thus, minimizing the imbalance in supply and demand is of utmost importance in smart grids to avoid network overload and commercial losses.Smart grids utilize flexible appliances that can shift their load to overcome this challenge, thus changing the electricity production or consumption in time.The contribution to the balancing problem from the end-user side is generally referred to as demand response.
In this section, following the exposition in [8], we discuss about supply-demand matching in smart grids.Then, an optimal control problem is formulated which seeks to minimize imbalance through demand response regulation and employing distributed model predictive control (MPC) algorithms for its solution.We note that, as discussed in [46], the distributed structure of MPC conforms the decentralised nature of renewable power generation, moreover, it also improves the robustness of the system.The embedding of demand response regulation in the market structure of the Universal Smart Energy Framework (USEF) is also covered, following the ideas of [47].

5
. 1. Demand response regulation.-One way to achieve demand response is to control the flexible devices of the households, both on the production and the consumption side.
Here the problem of minimising the overall imbalance (between supply and demand) in a network of households is considered, exploiting flexibility in a cooperative manner.Let I be the set of prosumers, and let f i [k] and g i [k] be the flexible and the fixed load of prosumer i ∈ I, respectively, at discrete time step k.Load is the sum of supply (production) and demand (consumption), with the convention of using positive sign for the supply and negative for the demand.The imbalance of a prosumer, denoted by xi [k], is the sum of its net flexible and net fixed load, (22) xi As a consequence, the evolution of imbalance can be described by xi is the change in the flexible and the fixed load, respectively.The prosumers are dynamically linked in order to exchange information which can be represented by a weighted, directed graph, in which an existing edge (i, j) means that information is sent from prosumer i to prosumer j.The weight on the edge characterises the importance of the shared information.The system model can be incorporated in the extended dynamics as (23) x where the tilde notation is omitted as x i [k] is no longer the physical imbalance but rather information about imbalance.The difference is that the latter is a weighted accumulation of the self-imbalance and the imbalances of the connected neighbours.The total imbalance information should be equal to the total physical imbalance, i.e., . This connection structure was proposed in [48][49][50].The condition is satisfied if coefficients A ij are elements of a stochastic matrix A with properties: i) A ij ≥ 0, ii) A ij = 0, if no information is sent from agent i to j, iii) i A ij = 1.This matrix corresponds to the graph of the network, which is required to be strongly connected, i.e., there exists a directed path between every pair i and j in both directions.
A quadratic cost function to minimize overall imbalance is defined as L Then the optimal control problem is to minimise k∈K i∈I x 2 i [k], subject to ( 22), ( 23), and boundary conditions u i ∈ U i , w i ∈ W i .This problem is solved using the distributed MPC approach as discussed in [46].

5
. 2. Embedding of demand response regulation in the market structure.-In this subsection, the initiative USEF is described and an explanation about how the demand response regulation can be embedded into this market structure is provided.

5
. and allows for active balancing through optimization between supply and demand.The framework is designed to offer fair market access and benefits to the stakeholders, and is accessible to anyone internationally.
The following USEF stakeholders are considered: the Balance Responsible Parties (BRP), aggregators, prosumers, and the Distribution System Operator (DSO).Electricity is traded between the suppliers and the BRPs over the wholesale energy market (day ahead) and imbalance market (operation time).The BRPs dispatch the electricity to the aggregators, which in turn deliver to the prosumers.The aggregator is a new stakeholder in energy grids that groups the prosumers into clusters.Its responsibility is to accumulate and offer flexibility on behalf of the connected prosumers, with the aim of maximizing the value of flexibility.The DSO is responsible for the distribution of power and to resolve any disturbances that might interfere with that task.In this context, the main task of the DSO is to detect and resolve any congestion that might occur in the distribution lines.USEF employs a market-based control mechanism, which consists of five phases: contract, plan, validate, operate, and settlement.Contractual agreements between the stakeholders are established in the first phase.In the plan phase, a day-ahead forecast of the energy consumption is made, which is then validated by the DSO in the validate phase.The two phases are iterated until an agreement is reached on the forecast.In the operate phase, the system aims to follow the plan that has been created in the first two phases, and balances between the forecast and actual electricity load by procuring flexibility.Financial reconciliation is completed in the settlement phase.An overview of the USEF structure and market-based control mechanism is shown in fig.6.

5
. 2.2.Demand response in USEF.The distributed MPC method is embedded in the operation phase of USEF, assuming that the energy portfolio has already been forecasted and agreed on by the aggregators, BRP, and DSO.Each prosumer is equipped with one appliance, either a heat pump (representing consumption) or a μCHP (representing production).The algorithm is implemented on both the prosumer and aggregator levels, with the aggregators accumulating the imbalance and the flexible and fixed loads of their prosumers.The objective of minimising the total imbalance is now extended to the aggregators, hence the optimal control problem is formulated as minimization of and other constraints from sect. 5 .1, where L is the set of aggregators.The goal function is introduced to couple the two levels and intuitively reflects the flexibility invoked by the aggregators from their prosumers (c.f.[47]).This problem is solved using the distributed MPC approach as discussed in [46].Distributed MPC and dualization for embedding hydrogen in the production and storage side of the power and gas grid resulting in two level optimization problems can be found in [51,52].

-Concluding remarks
Energy systems worldwide are gradually becoming more sustainable through innovations such as implementing demand response strategies, developments in materials aimed at improving energy efficiency, and a significant increase of renewable sources in the overall energy mix.Adversely, the unpredictable and highly varying nature of renewable sources brings about several challenges for the robust and optimal operation of energy systems with a high penetration of these sources, making, in many cases, the control schemes intended for conventional power systems inadequate.
In order to address these challenges, new modeling and control techniques have been developed in recent years.A notable example is the framework of port-Hamiltonian systems, which allows for seamlessly integrating models of diverse physical phenomena, of multiple domains, (e.g., mechanical, electrical), and with various time and space scales into a common energy-based mathematical representation.Such traits have been shown in the literature to be particularly relevant in designing robust control algorithms that exploit intrinsic physical laws to achieve stable closed-loop system operations.In these lecture notes, we described several seminal contributions in these regards, covering modeling aspects of AC power systems using a port-Hamiltonian formulation, the design of distributed and robust controllers for modern DC microgrids, as well as the design of control frameworks that take into consideration economic aspects for optimally managing EPJ Web of Conferences 268, 00016 (2022) LNES 2021 https://doi.org/10.1051/epjconf/202226800016energy assets in smart grids, such as storage devices and controllable loads, while maintaining physically sensible values for signals of interest such as electric frequencies and voltage magnitudes.
Although substantial advances have been made towards the realization of smart grids, many open problems remain, among which we can enlist two we believe to be of primal importance.One of them pertains to the co-optimization and control of hybrid AC and DC networks that appear in, e.g., smart parking lots that allocate electric vehicles, which can have significant benefits in terms of providing flexibility to the main grid (see, e.g., [53]).A second open problem corresponds to the joint design and operation of the three main energy carriers -namely, electricity, gas, and heat-to exploit the influence these exert on each other to obtain socioeconomic, technical, and environmental benefits stemming from the potential flexibility to incorporate renewable sources further (see [54]) and storage devices in each of these domains; the reader is referred to [55][56][57][58][59]19] for comprehensive coverage on modeling and control of heating networks and to [20] and references therein for gas networks.

EPJFig. 2 .
Fig. 2. -(a) Scheme of an exemplary power system with two generation buses, two load buses and five power lines.(b) Graph-based representation of the same system.Figure courtesy of [5].

EPJ
Fig. 3. -Schematic diagram based on [1] of modern electric power distribution systems.

)
Fig. 4. -(a) Scheme of the considered DC microgrid with 4 power converters.The dashed lines represent the communication network; (b) evolution of the DGU voltages (top) and currents (bottom) under the proposed control scheme.For clarity, the satisfaction of Objectives 1 and 2 is enabled after t = 1 s.The gray line represents operation with the gain K = 0, which exhibits an oscillatory behavior.Figure courtesy of [6].

4 . 1 .
Social welfare maximization.-Having established the model for the power network, the optimization problem of interest is now defined.

EPJ
Fig. 5. -Simulation results of the distributed algorithm in [7], Prop. 1, to solve the problem (20) on a tailored IEEE 37 bus benchmark.Note that the net power and voltage magnitudes are within prescribed bounds (in dashed gray).Figure courtesy of [7].
Synchronous generator .-Let i ∈ E g denote an arbitrary synchronous generator in the network and let Ψ s and a strictly EPJ Web of Conferences 268, 00016 (2022) LNES 2021 https://doi.org/10.1051/epjconf/202226800016convex function is considered to represent storage costs.Concerning the constraints X i in [47]USEF[47].USEF is an initiative by a collective of top sector companies to standardize smart grid solutions for the European energy market.Their aim is to create a platform to drive the fastest, most cost-effective route to an integrated smart energy future.USEF delivers a common standard on which to build all smart energy products and services.It unlocks the value of flexibility by making it a tradable commodity, and delivering a market structure, associated rules, and tools to make it work effectively.Flexibility can be invoked for grid capacity management to avoid or reduce peak loads,