{"id":13572823,"url":"https://github.com/PVKonovalov/topogrid","last_synced_at":"2025-04-04T11:30:49.842Z","repository":{"id":62343666,"uuid":"556252277","full_name":"PVKonovalov/topogrid","owner":"PVKonovalov","description":"Package topogrid contains implementations of basic power grid algorithms based on the grid topology.","archived":false,"fork":false,"pushed_at":"2024-11-13T18:47:33.000Z","size":1617,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-13T19:34:59.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PVKonovalov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-23T12:29:47.000Z","updated_at":"2024-11-13T18:46:15.000Z","dependencies_parsed_at":"2024-06-21T07:44:03.845Z","dependency_job_id":null,"html_url":"https://github.com/PVKonovalov/topogrid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PVKonovalov%2Ftopogrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PVKonovalov%2Ftopogrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PVKonovalov%2Ftopogrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PVKonovalov%2Ftopogrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PVKonovalov","download_url":"https://codeload.github.com/PVKonovalov/topogrid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247169965,"owners_count":20895386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:00:21.287Z","updated_at":"2025-04-04T11:30:44.835Z","avatar_url":"https://github.com/PVKonovalov.png","language":"Go","funding_links":[],"categories":["Frameworks and libraries"],"sub_categories":[],"readme":"# Topogrid\nPackage topogrid contains implementations of basic power grid algorithms based on the grid topology.\nWe use three main things - node, edge and equipment. Each power equipment can be represented as a topological node or edge.\nThe [wonderful library](https://github.com/yourbasic/graph) is used to represent the graph.\n\n## List of terms and abbreviations\n* Edge: A link between two nodes. From the point of view of electrical network equipment, edge can imagine circuit \nbreakers, disconnectors, power transformers, earthing switches, etc. All electrical network equipment with more \nthan one terminal.\n* Node: The name for any single junction. Nodes are connected to one another by edges. E.g. power supply, DERs, \nConsumer transformer substations, ground (earth) etc. \n* Terminal: The endpoint of a power grid equipment, represented by node.\n## Distribution grid example\n![Configuration database schema](assets/ExampleGrid.png)\n* FSW - feeder switch\n* REC - recloser (Automatic circuit breaker with reclosing function)\n* DS - disconnect switch\n* TS - transformer substation (consumer)\n* SW - switch (SW10 - bus coupler circuit breaker)\n## Graph example\n![Graph example](assets/ExampleGridGraph.svg)\n## Database\nThe power system topology is stored in the database as a set of tables.\n![Configuration database schema](assets/TopoGridDatabase.png)\n## Usage\n\n```go\ntype EquipmentStruct struct {\n\tid              int\n\ttypeId          int\n\tname            string\n\telectricalState uint8\n\tpoweredBy       map[int]int64\n\tswitchState     int\n}\n\ntype NodeStruct struct {\n\tidx             int\n\tid              int\n\tequipmentId     int\n\telectricalState uint8\n}\n\ntype TerminalStruct struct {\n\tnode1Id          int\n\tnode2Id          int\n\tnumberOfSwitches int64\n}\n\ntype EdgeStruct struct {\n\tidx         int\n\tid          int\n\tequipmentId int\n\tterminal    TerminalStruct\n}\n```\n```go\ntopology := topogrid.New(len(nodes))\n\nfor _, node := range nodes {\n  topology.AddNode(node.Id, \n    node.EquipmentId, \n    node.EquipmentTypeId, \n    node.EquipmentName)\n}\n\nfor _, edge := range edges {\n  err := topology.AddEdge(edge.Id, \n    edge.Terminal1, \n    edge.Terminal2, \n    edge.StateNormal, \n    edge.EquipmentId, \n    edge.EquipmentTypeId, \n    edge.EquipmentName)\n  if err != nil {\n    log.Errorf(\"%v\", err)\n  }\n}\n```\n### EquipmentNameByEquipmentId\nReturns a string with node name from the equipment id\n```go\nfunc (t *TopologyGridStruct) EquipmentNameByEquipmentId(equipmentId int) string\n```\n\n### EquipmentNameByNodeIdx \nReturns a string with node name from the node index\n```go\nfunc (t *TopologyGridStruct) EquipmentNameByNodeIdx(idx int) string\n```\n\n###  EquipmentNameByNodeId\nReturns a string with node name from the node id\n```go\nfunc (t *TopologyGridStruct) EquipmentNameByNodeId(id int) string\n```\n\n### EquipmentNameByNodeIdArray\nReturns a string with node names separated by ',' from an array of node ids\n```go\nfunc (t *TopologyGridStruct) EquipmentNameByNodeIdArray(idArray []int) string\n```\n\n### EquipmentNameByEdgeIdx\nReturns a string with node name from the node index\n```go\nfunc (t *TopologyGridStruct) EquipmentNameByEdgeIdx(idx int) string\n```\n\n### EquipmentNameByEdgeId\nReturns a string with node name from the node id\n```go\nfunc (t *TopologyGridStruct) EquipmentNameByEdgeId(id int) string\n```\n\n### EquipmentNameByEdgeIdArray\nReturns a string with node names separated by ',' from an array of node ids\n```go\nfunc (t *TopologyGridStruct) EquipmentNameByEdgeIdArray(idArray []int) string\n```\n\n### EquipmentIdByEdgeId\nReturns equipment identifier by corresponded edge id\n```go\nfunc (t *TopologyGridStruct) EquipmentIdByEdgeId(edgeId int) (int, error)\n```\n\n### SetSwitchStateByEquipmentId\nSet switchState field and changes current topology graph\n```go\nfunc (t *TopologyGridStruct) SetSwitchStateByEquipmentId(equipmentId int, switchState int) error\n```\n\n### AddNode\nAdd node to grid topology\n```go\nfunc (t *TopologyGridStruct) AddNode(id int, equipmentId int, equipmentTypeId int, equipmentName string)\n```\n\n### AddEdge\nAdd edge to grid topology\n```go\nfunc (t *TopologyGridStruct) AddEdge(id int, terminal1 int, terminal2 int, state int, equipmentId int, equipmentTypeId int, equipmentName string) error\n```\n\n### NodeIsPoweredBy\nGet an array of nodes id with the type of equipment \"TypePower\" from which the specified node is powered with the current 'switchState' (On/Off) of the circuit breakers\n![Node is powered by](assets/IsPoweredBy.png)\n```go\nfunc (t *TopologyGridStruct) NodeIsPoweredBy(nodeId int) ([]int, error)\n```\n```go\nfor _, node := range nodes {\n  poweredBy, err := topology.NodeIsPoweredBy(node.Id)\n    if err != nil {\n      log.Errorf(\"%v\", err)\n    }\n    log.Debugf(\"%d:%s \u003c- %v:%s\", node.Id, topology.EquipmentNameByNodeId(node.Id), poweredBy, topology.EquipmentNameByNodeIdArray(poweredBy))\n}\n```\n### NodeCanBePoweredBy \nGet an array of nodes id with the type of equipment \"Power\", from which the specified node can be powered regardless of the current 'switchState'  (On/Off) of the circuit breakers\n![Node is powered by](assets/CanBePoweredBy.png)\n```go\nfunc (t *TopologyGridStruct) NodeCanBePoweredBy(nodeId int) ([]int, error)\n```\n```go\nfor _, node := range nodes {\n  poweredBy, err := topology.NodeCanBePoweredBy(node.Id)\n    if err != nil {\n      log.Errorf(\"%v\", err)\n    }\n    log.Debugf(\"%d:%s \u003c- %v:%s\", node.Id, topology.EquipmentNameByNodeId(node.Id), poweredBy, topology.EquipmentNameByNodeIdArray(poweredBy))\n}\n```\n### CircuitBreakersNextToNode \nGet an array of IDs of circuit breakers next to the node. If we need to isolate some area of the electrical network, we need to find all circuit breakers near a node in that area.\n![Next to node](assets/NextToNode.png)\n\n```go\nfunc (t *TopologyGridStruct) GetCircuitBreakersEdgeIdsNextToNode(nodeId int) ([]int, error)\n```\n```go\nfor _, node := range nodes {\n  nextTo, err := topology.CircuitBreakersNextToNode(node.Id)\n    if err != nil {\n      log.Errorf(\"%v\", err)\n    }\n    log.Debugf(\"%d:%s \u003c- %v:%s\", node.Id, topology.EquipmentNameByNodeId(node.Id), poweredBy, topology.EquipmentNameByNodeIdArray(nextTo))\n}\n```\n### BfsFromNodeId \nTraverses current graph in breadth-first order starting at nodeStart\n```go\nfunc (t *TopologyGridStruct) BfsFromNodeId(nodeIdStart int) []TerminalStruct \n```\n### GetAsGraphMl \nReturns a string with a graph represented by the [graph modeling language](https://en.wikipedia.org/wiki/Graph_Modelling_Language) \n```go\nfunc (t *TopologyGridStruct) GetAsGraphMl() string \n```\n\n### SetEquipmentElectricalState\nSet electrical states for equipment. Use this method to set colors on your single line diagram (SLD).\n![Configuration database schema](assets/ElectricalState.svg)\n```go\n// Equipment electrical states\nconst (\n\tStateIsolated    uint8 = 0x00\n\tStateEnergized   uint8 = 0x01\n\tStateGrounded    uint8 = 0x02\n\tStateOvercurrent uint8 = 0x04\n\tStateFault       uint8 = 0x08\n)\n```\n```go\nfunc (t *TopologyGridStruct) SetEquipmentElectricalState()\n```\n\n### CopyEquipmentSwitchState\nCopy equipment switch state frim one topogrid object to this\n```go\nfunc (t *TopologyGridStruct) CopyEquipmentSwitchState(from *TopologyGridStruct) error\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPVKonovalov%2Ftopogrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPVKonovalov%2Ftopogrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPVKonovalov%2Ftopogrid/lists"}