|
9 | 9 | Component, |
10 | 10 | ComponentConnection, |
11 | 11 | GridConnectionPoint, |
| 12 | + Hvac, |
12 | 13 | Meter, |
| 14 | + Relay, |
13 | 15 | SolarInverter, |
14 | 16 | WindTurbine, |
15 | 17 | ) |
@@ -124,3 +126,94 @@ def test_wind_turbine_graph() -> None: |
124 | 126 | assert graph.predecessors(ComponentId(3)) == { |
125 | 127 | Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)) |
126 | 128 | } |
| 129 | + |
| 130 | + |
| 131 | +def test_relay_is_passthrough() -> None: |
| 132 | + """`Relay` maps to cg's `Breaker`, a pass-through category. |
| 133 | +
|
| 134 | + A Relay placed between a Meter and a SolarInverter should be |
| 135 | + transparent: cg walks past it when answering `predecessors`/ |
| 136 | + `successors`, and the PV formula references only the Meter and |
| 137 | + the inverter. |
| 138 | + """ |
| 139 | + graph: microgrid_component_graph.ComponentGraph[ |
| 140 | + Component, ComponentConnection, ComponentId |
| 141 | + ] = microgrid_component_graph.ComponentGraph( |
| 142 | + components={ |
| 143 | + GridConnectionPoint( |
| 144 | + id=ComponentId(1), |
| 145 | + microgrid_id=MicrogridId(1), |
| 146 | + rated_fuse_current=100, |
| 147 | + ), |
| 148 | + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 149 | + Relay(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 150 | + SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)), |
| 151 | + }, |
| 152 | + connections={ |
| 153 | + # Grid -> Meter -> Relay -> SolarInverter |
| 154 | + ComponentConnection(source=ComponentId(1), destination=ComponentId(2)), |
| 155 | + ComponentConnection(source=ComponentId(2), destination=ComponentId(3)), |
| 156 | + ComponentConnection(source=ComponentId(3), destination=ComponentId(4)), |
| 157 | + }, |
| 158 | + ) |
| 159 | + |
| 160 | + # Neighbor queries walk past the Relay. |
| 161 | + assert graph.predecessors(ComponentId(4)) == { |
| 162 | + Meter(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 163 | + } |
| 164 | + assert graph.successors(ComponentId(2)) == { |
| 165 | + SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)), |
| 166 | + } |
| 167 | + # And the formula references the Meter and the inverter only -- |
| 168 | + # the Relay (#3) does not appear. |
| 169 | + assert ( |
| 170 | + graph.pv_ac_coalesce_formula(pv_inverter_ids={ComponentId(4)}) |
| 171 | + == "COALESCE(#2, #4)" |
| 172 | + ) |
| 173 | + |
| 174 | + |
| 175 | +def test_hvac_is_passthrough() -> None: |
| 176 | + """`Hvac` maps to cg's `Hvac`, a pass-through category. |
| 177 | +
|
| 178 | + An Hvac placed between the Grid and a Meter should be |
| 179 | + transparent: `successors(Grid)` walks past it to the Meter, |
| 180 | + and the PV formula references only the Meter and the inverter. |
| 181 | + """ |
| 182 | + graph: microgrid_component_graph.ComponentGraph[ |
| 183 | + Component, ComponentConnection, ComponentId |
| 184 | + ] = microgrid_component_graph.ComponentGraph( |
| 185 | + components={ |
| 186 | + GridConnectionPoint( |
| 187 | + id=ComponentId(1), |
| 188 | + microgrid_id=MicrogridId(1), |
| 189 | + rated_fuse_current=100, |
| 190 | + ), |
| 191 | + Hvac(id=ComponentId(2), microgrid_id=MicrogridId(1)), |
| 192 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 193 | + SolarInverter(id=ComponentId(4), microgrid_id=MicrogridId(1)), |
| 194 | + }, |
| 195 | + connections={ |
| 196 | + # Grid -> Hvac -> Meter -> SolarInverter |
| 197 | + ComponentConnection(source=ComponentId(1), destination=ComponentId(2)), |
| 198 | + ComponentConnection(source=ComponentId(2), destination=ComponentId(3)), |
| 199 | + ComponentConnection(source=ComponentId(3), destination=ComponentId(4)), |
| 200 | + }, |
| 201 | + ) |
| 202 | + |
| 203 | + # Neighbor queries walk past the Hvac. |
| 204 | + assert graph.successors(ComponentId(1)) == { |
| 205 | + Meter(id=ComponentId(3), microgrid_id=MicrogridId(1)), |
| 206 | + } |
| 207 | + assert graph.predecessors(ComponentId(3)) == { |
| 208 | + GridConnectionPoint( |
| 209 | + id=ComponentId(1), |
| 210 | + microgrid_id=MicrogridId(1), |
| 211 | + rated_fuse_current=100, |
| 212 | + ), |
| 213 | + } |
| 214 | + # And the formula references the Meter and the inverter only -- |
| 215 | + # the Hvac (#2) does not appear. |
| 216 | + assert ( |
| 217 | + graph.pv_ac_coalesce_formula(pv_inverter_ids={ComponentId(4)}) |
| 218 | + == "COALESCE(#3, #4)" |
| 219 | + ) |
0 commit comments