Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 0 additions & 163 deletions .github/workflows/deploy-dev-release.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from gridappsd.field_interface.agents.agents import (FeederAgent, DistributedAgent,
CoordinatingAgent, SwitchAreaAgent,
SecondaryAreaAgent)
SecondaryAreaAgent, SubstationAgent)

__all__: List[str] = ["FeederAgent", "DistributedAgent", "CoordinatingAgent"]
38 changes: 28 additions & 10 deletions gridappsd-field-bus-lib/gridappsd/field_interface/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,27 @@ def on_control(self, control):
self.control_device(device_id, command)
'''

class SubstationAgent(DistributedAgent):

def __init__(self,
upstream_message_bus_def: MessageBusDefinition,
downstream_message_bus_def: MessageBusDefinition,
agent_config: Dict,
substation_dict=None,
simulation_id=None):
super().__init__(upstream_message_bus_def, downstream_message_bus_def, agent_config,
substation_dict, simulation_id)
self.substation_area = None
self.downstream_message_bus_def = downstream_message_bus_def

self._connect()

if self.agent_area_dict is not None:
substation = cim.Substation(mRID=self.downstream_message_bus_def.id)
self.substation_area = DistributedArea(connection=self.connection,
container=substation,
distributed=True)
self.substation_area.build_from_topo_message(topology_dict=self.agent_area_dict)

class FeederAgent(DistributedAgent):

Expand All @@ -250,12 +271,11 @@ def __init__(self,
self._connect()

if self.agent_area_dict is not None:
feeder = cim.EquipmentContainer(mRID=self.downstream_message_bus_def.id)
feeder = cim.FeederArea(mRID=self.downstream_message_bus_def.id)
self.feeder_area = DistributedArea(connection=self.connection,
container=feeder,
distributed=True)
self.feeder_area.build_from_topo_message(topology_dict=self.agent_area_dict,
centralized_graph=None)
self.feeder_area.build_from_topo_message(topology_dict=self.agent_area_dict)


class SwitchAreaAgent(DistributedAgent):
Expand All @@ -274,12 +294,11 @@ def __init__(self,
self._connect()

if self.agent_area_dict is not None:
container = cim.EquipmentContainer(mRID=self.downstream_message_bus_def.id)
container = cim.SwitchArea(mRID=self.downstream_message_bus_def.id)
self.switch_area = DistributedArea(container=container,
connection=self.connection,
distributed=True)
self.switch_area.build_from_topo_message(topology_dict=self.agent_area_dict,
centralized_graph=None)
self.switch_area.build_from_topo_message(topology_dict=self.agent_area_dict)


class SecondaryAreaAgent(DistributedAgent):
Expand All @@ -298,16 +317,15 @@ def __init__(self,
self._connect()

if self.agent_area_dict is not None:
if len(self.agent_area_dict['addressable_equipment']) == 0:
if len(self.agent_area_dict['AddressableEquipment']) == 0:
_log.warning(
f"No addressable equipment in the secondary area with down stream message bus id: {self.downstream_message_bus.id}."
)
container = cim.EquipmentContainer(mRID=self.downstream_message_bus_def.id)
container = cim.SecondaryArea(mRID=self.downstream_message_bus_def.id)
self.secondary_area = DistributedArea(container=container,
connection=self.connection,
distributed=True)
self.secondary_area.build_from_topo_message(topology_dict=self.agent_area_dict,
centralized_graph=None)
self.secondary_area.build_from_topo_message(topology_dict=self.agent_area_dict)


class CoordinatingAgent:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import List

from gridappsd.field_interface.context_managers.context_manager_agents import (SubstationAreaContextManager,
FeederAreaContextManager,
SwitchAreaContextManager,
SecondaryAreaContextManager)


__all__: List[str] = ["SubstationAreaContextManager","FeederAreaContextManager","SwitchAreaContextManager","SecondaryAreaContextManager"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import argparse
import logging
import json
import os
import time
from typing import Dict


from cimgraph.data_profile import CIM_PROFILE
from gridappsd import GridAPPSD
import gridappsd.topics as t
import gridappsd.field_interface.agents.agents as agents_mod
from gridappsd.field_interface.context_managers.utils import REQUEST_FIELD, get_MessageBusDefinition
from gridappsd.field_interface.context_managers.context_manager_agents import FeederAreaContextManager, SwitchAreaContextManager, SecondaryAreaContextManager

cim_profile = CIM_PROFILE.CIMHUB_2023.value
agents_mod.set_cim_profile(cim_profile=cim_profile, iec61970_301=7)
cim = agents_mod.cim

logging.basicConfig(level=logging.DEBUG)
logging.getLogger('goss').setLevel(logging.ERROR)
logging.getLogger('stomp.py').setLevel(logging.ERROR)

_log = logging.getLogger(__name__)

def _main():

time.sleep(10)
parser = argparse.ArgumentParser()
parser.add_argument(
"--simulation_id",
help="Simulation id to use for communicating with simulated devices on the message bus. \
If simulation_id is not provided then Context Manager assumes to run on deployed field with real devices.",
required=False)
opts = parser.parse_args()
simulation_id = opts.simulation_id

agent_config = {
"app_id":
"context_manager",
"description":
"This agent provides topological context information like neighboring agents and devices to other distributed agents"
}

gapps = GridAPPSD()
response = gapps.get_response(t.PLATFORM_STATUS, {"isField": True})
field_model_mrid = response['fieldModelMrid']

is_field_initialized = False

while not is_field_initialized:
response = gapps.get_response(REQUEST_FIELD, {"request_type": "is_initilized"})
print(response)
is_field_initialized = response['data']['initialized']
time.sleep(1)


field_model_mrid = "49AD8E07-3BF9-A4E2-CB8F-C3722F837B62"

system_message_bus_def = get_MessageBusDefinition(field_model_mrid)
feeder_message_bus_def = get_MessageBusDefinition(field_model_mrid)

#TODO: create access control for agents for different layers
feeder_agent = FeederAreaContextManager(system_message_bus_def,
feeder_message_bus_def,
agent_config,
simulation_id=simulation_id)

#print(feeder_agent.agent_area_dict)
for switch_area in feeder_agent.agent_area_dict['SwitchAreas']:
switch_area_message_bus_def = get_MessageBusDefinition(str(switch_area['@id']))
print("Creating switch area agent " + str(switch_area['@id']))
switch_area_agent = SwitchAreaContextManager(feeder_message_bus_def,
switch_area_message_bus_def,
agent_config,
simulation_id=simulation_id,
switch_area_dict=switch_area)

# create secondary area distributed agents
for secondary_area in switch_area['SecondaryAreas']:
secondary_area_message_bus_def = get_MessageBusDefinition(
str(secondary_area['@id']))
print("Creating secondary area agent " + str(secondary_area['@id']))
secondary_area_agent = SecondaryAreaContextManager(switch_area_message_bus_def,
secondary_area_message_bus_def,
agent_config,
simulation_id=simulation_id,
secondary_area_dict=secondary_area)

while True:
try:
time.sleep(0.1)
except KeyboardInterrupt:
print("Exiting sample")
break


if __name__ == "__main__":
_main()
Loading