Power distribution network secondary service real-time simulation method based on coroutine and discrete event queue
By using a simulation method based on coroutines and discrete event queues, the problems of insufficient topological consistency and efficiency in the simulation of secondary services in distribution networks are solved. Stable action chain reproduction and hard real-time constraints are achieved, improving simulation efficiency and scalability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JIANGSU KUNYOU ENERGY TECH CO LTD
- Filing Date
- 2026-02-12
- Publication Date
- 2026-05-29
AI Technical Summary
In the simulation of secondary services in distribution networks, topology consistency is difficult to guarantee, simulation efficiency and scalability are insufficient, hard real-time closed loops are easily blocked, and background behavior modeling lacks verifiable standards, resulting in unstable action chain reproduction and wasted computing resources.
A simulation method based on coroutines and discrete event queues is adopted. Through the overall modeling of Entity-Component-Topology-System (ECTS), the primary electrical topology, secondary communication topology and primary-secondary mapping relationship are centrally encapsulated. Discrete event queues are used to advance the virtual clock. Coroutine tasks are executed in a suspend-wake-short-suspend pattern. Budget concession and asynchronous sinking mechanism for heavy tasks are introduced to achieve non-blocking closed-loop data exchange.
It achieves stable reproduction of topology-dependent scenarios in secondary business simulation, reduces computational overhead and latency, ensures hard real-time constraints, provides verifiable behavioral consistency verification, and improves simulation efficiency and scalability.
Smart Images

Figure CN122114584A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of power system automation and power cyber-physical system simulation technology, specifically to a real-time simulation method for secondary services in distribution networks based on coroutines and discrete event queues. Background Technology
[0002] As the scale of active distribution networks expands and control strategies become more complex, the bottleneck in engineering verification has shifted from the ability to solve electromagnetic transient waveforms to the large-scale modeling and closed-loop integration of massive secondary service objects. Existing technologies, such as real-time physical simulation and hardware-in-the-loop (HIL) technology, can provide high-fidelity waveforms and real-time interfaces. However, the sheer number of secondary objects, the strong coupling of service logic (e.g., protection, automatic backup power supply switching, feeder automation), and frequent strategy iterations make modeling and integration costs the main constraint on system-level verification.
[0003] For large-scale modeling and closed-loop integration of massive secondary business objects, traditional simulations often employ a fixed-step cyclic update mechanism to ensure compatibility with continuous physical processes. However, secondary business logic exhibits typical characteristics of being "waiting-type and sparsely triggered": it spends most of its time waiting for events such as sudden measurement changes, faults, alarms, commands, and topology changes; and when faults or limit violations occur, short-term concurrent bursts can occur. Therefore, using the fixed-step approach of traditional simulations easily generates a large amount of invalid computation, wasting computational resources.
[0004] Another traditional approach is to use a multi-process, multi-simulator co-simulation framework, achieving collaboration through synchronization and data exchange. However, in tightly coupled closed-loop scenarios, strict synchronization can easily introduce additional overhead and may pass the uncertain time consumption of secondary business calculations to the physical simulation step size, thereby affecting hard real-time constraints.
[0005] In addition, some researchers have attempted to apply data organization architecture, which is common in software engineering, to the real-time simulation of secondary business in power distribution networks, based on the ability of data organization architecture to improve data access efficiency. However, when directly applied to secondary power business, key challenges remain: secondary business is highly dependent on primary electrical topology, secondary communication topology, and primary-secondary mapping relationship, which is difficult to reflect in practice; if topology and mapping data are maintained separately, engineering problems such as inconsistent views, cache failure, and unstable reproduction of action chains are likely to occur.
[0006] It is evident that at least the following problems exist in the current secondary service simulation technology for power distribution networks: 1) Topology consistency is difficult to guarantee: When primary electrical networks, secondary communication networks and their mapping relationships are maintained separately, the network views obtained by the business algorithms may be inconsistent, resulting in unstable action chains and timing reproduction.
[0007] 2) Insufficient simulation efficiency and scalability: Fixed step size advancement generates a lot of idle time in "waiting" business; thread-level scheduling and context switching have significant overhead under massive objects.
[0008] 3) Hard real-time closed loop is easily blocked: If the secondary business calculation adopts strict handshake synchronization, the uncertain time consumption on the secondary side may block the fixed step size execution of the physical simulation, thus violating the hard real-time constraints.
[0009] 4) Simplified modeling lacks verifiable standards: If the background behavior modeling does not replicate the details of the internal mechanism, it is necessary to clarify the verifiable "behavioral equivalence" criteria, otherwise it is difficult to guarantee the credibility and reproducibility of the project. Summary of the Invention
[0010] To address the aforementioned problems, the purpose of this invention is to propose a real-time simulation method for secondary services in distribution networks based on coroutines and discrete event queues. By performing overall ECTS modeling of the entity-component-topology-service system, specific data interaction is achieved between the secondary service simulation and the actual physical simulation. Furthermore, the objects and operational logic of the secondary service simulation are optimized, thereby solving the following problems: the difficulty in maintaining global consistency between primary electrical topology, secondary communication topology, and primary-secondary mapping in secondary service simulation, leading to unstable reproduction of action chains; the ineffective computation and high operational overhead caused by fixed-step advancement and traditional thread scheduling in scenarios with massive secondary objects; the problem of uncertain secondary service computation time causing the hard real-time step size of physical simulation to be blocked; and the lack of verifiable equivalence criteria for background behavior models, making regression verification difficult.
[0011] This was achieved through the following technical solutions: A real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues includes the following steps: S1. In the secondary business simulation module, each simulation object is abstracted into a single entity, and an entity set is constructed. Each entity carries a unique identifier. Each entity is attached with a corresponding component, and each component serves as a data container for the corresponding entity. Based on each entity, a global topology is constructed to record the mapping relationship between the primary electrical network, the secondary communication network, and the primary electrical network and the secondary communication network. Based on each business logic, a business system is constructed. The business system is used to call the global topology and read and write the corresponding components to execute the corresponding business logic after the corresponding coroutine task is awakened by the event scheduler. S2. Establish a discrete event queue based on the order of the timestamps of each observable event; the event scheduler is used to implement cyclic control on the discrete event queue. The cyclic control includes: taking the observable event with the earliest timestamp from the discrete event queue; advancing the virtual clock of the secondary business simulation module to the corresponding timestamp; waking up and executing the coroutine task that matches the corresponding observable event according to the subscription conditions of each coroutine task; and inserting new observable events generated during the execution process into the discrete event queue. S3. Instantiate each business logic into a corresponding coroutine task; each coroutine task is controlled by the event scheduler, which sets each coroutine task to a suspended-wake-short-process-resuspend execution mode to start the simulation; during the execution of any coroutine task, a tail delay suppression mechanism is also set to deal with situations where the computational overhead exceeds a preset threshold or any coroutine task is a computationally intensive task; the tail delay suppression mechanism includes budget concession or asynchronous sinking of heavy tasks.
[0012] Optionally, each entity in step S1 includes a busbar, line, circuit breaker, switch, protection device, terminal device, automatic backup power supply switching device, master station application module, and communication node; each data container includes corresponding indication data, and the types of indication data include: switch status, failure to operate / blocking flag, setpoint parameter and delay parameter, measurement mapping relationship, command queue index, alarm and event subscription relationship, and service status.
[0013] Optionally, the types of business logic in step S1 may include at least: protection, feeder automation, self-healing, automatic backup power supply switching, master station application, and virtual power plant frequency regulation. Defining core secondary business functions enables the simulation method to model typical business scenarios; improves the practicality and relevance of the method, and meets various verification needs of the distribution network.
[0014] Optionally, in step S2, the types of observable events include faults, measurement mutations, exceeding limits, trip commands, switch changes, closed-loop confirmations, and transfer instructions; any observable event includes at least: timestamp, event type, event source object identifier, event target object identifier, and event load field.
[0015] Optionally, in step S2, the discrete event queue is further equipped with an insertion mechanism. This mechanism includes abstracting faults, measurement mutations, control commands, or state changes into corresponding observable events and inserting them into the discrete event queue. Using this insertion mechanism, various business-related events can be effectively placed into the queue, ensuring dynamic updates to the queue and enabling the simulation process to continue.
[0016] Optionally, in step S3, the event scheduler is also used to manage the state of each coroutine task, which includes at least a suspended state and a ready state. Each coroutine task completes initialization before being handed over to the event scheduler for control, and registers the subscription conditions for each observable event with the event scheduler. When the event scheduler retrieves any observable event from the discrete event queue, the event scheduler switches the coroutine task matching the corresponding observable event from the suspended state to the ready state and resumes execution according to the corresponding subscription conditions. After the corresponding coroutine task completes the processing corresponding to the observable event, it actively relinquishes the execution right and re-enters the suspended state.
[0017] Optionally, the event scheduler controls the waking up or suspending of each coroutine task based on event type, alarm, and event subscription relationship. This makes computational overhead strongly correlated with event occurrence, reducing polling overhead and thread-level context switching overhead.
[0018] Optionally, during the execution of any coroutine task in step S3, budget concession includes: setting a preset threshold for execution; when the execution of any coroutine task exceeds the preset threshold, the coroutine task actively saves its state and pauses execution, splitting its unexecuted portion into new observable events and placing them into a discrete event queue. Budget concession avoids increased delays in subsequent event processing caused by excessively long execution times of individual tasks, while the splitting also enables computational fragmentation and schedulability.
[0019] Optionally, during the execution of any coroutine task in step S3, the asynchronous sinking of heavy tasks includes: when the event scheduler recognizes that any coroutine task is a computationally intensive task, the event scheduler first wakes it up, then sinks the any coroutine task to the thread pool or asynchronous execution unit for sinking processing. After the sinking processing is completed, a completion event or completion notification is generated, and the event scheduler restores the corresponding coroutine task to continue execution and then enters the suspended state.
[0020] Optionally, in step S3, before starting the simulation, it is also necessary to control the secondary service real-time simulation and the physical simulation module to perform closed-loop data interaction. This closed-loop data interaction includes: setting the physical simulation module to run at a fixed step size, and then writing the output measurement snapshots to the shared memory area; the secondary service simulation module reads the measurement changes from the shared memory area, converts them into corresponding observable events, and generates corresponding control commands; wherein, the control commands carry timestamps and are written to the timestamp control command queue in the shared memory area, for the physical simulation module to retrieve and execute when the physical clock reaches the corresponding timestamp. Through the closed-loop joint debugging of the physical simulation module and the secondary service simulation module, the uncertain time consumption of secondary service calculations can be effectively avoided from blocking the physical simulation.
[0021] The beneficial effects of this invention compared to the prior art are: The technical solution of the present invention: 1) A four-element secondary business modeling framework of "entity-component-topology-system" is proposed, and the primary electrical topology, secondary communication topology and primary-secondary mapping are encapsulated into callable topology services to ensure that the business system obtains a consistent network view and improves the stable reproducibility of topology-dependent scenarios.
[0022] 2) A discrete event queue is used to advance the virtual clock, so that secondary services at multiple time scales can be uniformly expressed by event timestamps, avoiding fixed-step idle calculations.
[0023] 3) Use coroutines to implement massive secondary business tasks, achieving a lightweight execution pattern of "wait-wake-short processing-wait again", reducing the overhead of polling and thread context switching.
[0024] 4) For non-preemptive execution of coroutines, a budget transfer and asynchronous sinking mechanism for heavy tasks is introduced to suppress tail delays and ensure the upper bound of the delay for critical event processing.
[0025] 5) Propose a verifiable behavioral consistency verification approach: Achieve regressive verification of the background behavioral model by matching key events, maintaining causal order, and ensuring consistency with key delay statistics.
[0026] 6) A decoupled closed-loop joint debugging mechanism with shared memory on the same machine is proposed. Non-blocking data exchange is achieved through the measurement snapshot buffer and the control command queue with timestamps, so that the uncertainty of secondary business calculation does not block the execution of physical simulation with fixed step size. Attached Figure Description
[0027] Figure 1 A flowchart of a real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues; Figure 2 This is an example diagram of an event scheduler driving a coroutine task. Detailed Implementation
[0028] The technical solutions in the embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0029] like Figure 1 The diagram shows a flowchart of a real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues. By performing overall modeling of the entity-component-topology-system (ECTS), the secondary service simulation and the actual physical simulation are made to interact with each other in a specific way. The objects and running logic of the secondary service simulation are optimized to ensure the fixed step size execution of the actual physical simulation, thereby improving stability, reducing latency and resource consumption. ECTS stands for Entity–Component–Topology–System.
[0030] The real-time simulation method for secondary services in the power distribution network includes the following steps: S1. In the secondary service simulation module, each simulation object is abstracted into a single entity and a set of entities is constructed. Each entity carries a unique identifier, which indicates what kind of device each entity is, such as busbar, line, circuit breaker, switch, protection device, terminal device, automatic backup power supply switching device, master station application module, and communication node.
[0031] Next, each entity is attached with its corresponding component. Each component serves as a data container for the corresponding entity, and each data container contains corresponding indicator data. The types of indicator data include: switch status, failure to operate / lockdown flag, setpoint parameters and delay parameters, measurement mapping relationships, command queue index, alarm and event subscription relationships, and business status. These indicator data represent the operating status or operating logic of the corresponding entity.
[0032] Then, based on each entity, a global topology is constructed to record the mapping relationships between the primary electrical network, secondary communication network, and the primary electrical network and secondary communication network. A business system is built based on each business logic, with each business logic instantiated as a coroutine task. After the coroutine task is awakened by the event scheduler, it calls the global topology query service and reads and writes component data to execute the corresponding business logic. After processing, the coroutine task is suspended again, waiting for the next event trigger. The types of business logic include at least: protection, feeder automation, self-healing, automatic backup power supply connection, master station application, and virtual power plant frequency regulation. Core secondary business functions are defined to enable the simulation method to simulate typical business scenarios, improving the practicality and relevance of the method and meeting various verification needs of the distribution network. The business system executes in an event-triggered manner and completes business logic by calling the topology service and reading and writing component data.
[0033] S2. Based on the timestamp of each observable event, establish a discrete event queue in the order of the corresponding timestamps. The types of observable events include faults, measurement mutations, limit violations, trip commands, switch changes, closed-loop confirmations, and transfer instructions; any observable event must include at least: timestamp, event type, event source object identifier, event target object identifier, and event load field.
[0034] Any observable event within the discrete event queue is subject to cyclic control on the event scheduler. Cyclic control includes: the event scheduler retrieving the earliest timestamp of the observable event from the discrete event queue; advancing the virtual clock of the secondary service simulation module to the corresponding timestamp; and waking up the coroutine task matching the observable event according to the subscription conditions to resume execution. During execution, the coroutine task generates new observable events, which are then reinserted into the discrete event queue by the event scheduler, thus achieving dynamic updates to the discrete event queue. Simultaneously, observable events such as protection delay, communication and processing delay, master station periodic verification, and minute-level strategies can all be described using event timestamps, eliminating the need for a unified minimum fixed step size, thereby reducing unnecessary computation and achieving a unified expression across multiple time scales.
[0035] In this embodiment, the discrete event queue is also equipped with an insertion mechanism. This mechanism includes abstracting faults, measurement mutations, control commands, or state changes into corresponding observable events and inserting them into the discrete event queue. Using this insertion mechanism, various business-related events can be effectively placed into the queue, ensuring dynamic updates to the queue and enabling the simulation process to continue.
[0036] S3. Instantiate each business logic into a corresponding coroutine task. Each coroutine task is controlled by the event scheduler, which sets each coroutine task to a suspended-wake-short-process-resuspend execution pattern to begin simulation. The event scheduler can control the wake-up or suspension of each coroutine task based on event type, alarms, and event subscription relationships. This makes computational overhead strongly correlated with event occurrence, reducing polling overhead and thread-level context switching overhead.
[0037] In this embodiment, a tail delay suppression mechanism is also set during the execution of any coroutine task to deal with situations where the computational overhead exceeds a preset threshold or the any coroutine task is a computationally intensive task; the tail delay suppression mechanism includes budget concession or asynchronous sinking of heavy tasks.
[0038] During the execution of any coroutine task, budget concession includes: setting a preset threshold for execution (which can be set according to time or number of instructions); when the execution of an arbitrary coroutine task exceeds the preset threshold, the arbitrary coroutine task actively saves its state and pauses execution, splitting its unexecuted portion into new observable events and placing them into a discrete event queue. Budget concession avoids increased delays in subsequent event processing caused by excessively long execution times of individual tasks, and the splitting mechanism also enables computational fragmentation and schedulability.
[0039] During the execution of any coroutine task, the asynchronous sinking of heavy tasks includes: when the event scheduler recognizes that any coroutine task is a computationally intensive task, the event scheduler first wakes it up, and then sinks the coroutine task to the thread pool or asynchronous execution unit for sinking processing, replacing short processing with sinking processing. After the sinking processing is completed, a completion event or completion notification is generated, and the event scheduler uses this to resume the coroutine task to continue execution and then enter the suspended state again, thereby decoupling the computation time from the event loop and suppressing tail latency.
[0040] In this embodiment, the event scheduler is also used to manage the state of each coroutine task, which includes at least a suspended state and a ready state. Before being controlled by the event scheduler, each coroutine task is initialized and registers the subscription conditions for each observable event with the event scheduler. When the event scheduler retrieves any observable event from the discrete event queue, it switches the coroutine task matching the corresponding observable event from the suspended state to the ready state and resumes execution according to the subscription conditions. After the corresponding coroutine task completes the short processing corresponding to the observable event, the corresponding coroutine task voluntarily relinquishes its execution right and re-enters the suspended state.
[0041] It's important to note that when converting each business logic into a corresponding coroutine task, various tools / languages can be used for instantiation, such as C++20 coroutines, Rust async / await, C# async / await, Java Virtual Threads / Coroutine libraries, Go goroutines (with event loop / timer abstractions), etc., as long as they possess the capability of "suspendable / resumeable cooperative tasks (coroutines / fibers / asynchronous tasks / user-mode threads)." Language is merely the implementation vehicle; the core of this solution lies in the combination of the method and system architecture of "coroutine semantics + event scheduler + discrete event queue + tail delay suppression + decoupling and closed-loop shared memory with fixed-step physical simulation." Furthermore, this solution uses coroutine tasks because, compared to multithreading, coroutine tasks avoid the operating system kernel-level context switching overhead, reducing memory consumption; simultaneously, compared to callback functions or state machines, coroutines allow asynchronous business logic to be written with synchronous code logic, also improving the readability and maintainability of complex secondary business logic (such as protection action chains).
[0042] like Figure 2 The diagram shown is an example of an event scheduler driving a coroutine task. Figure 2As shown in the diagram, the light blue box represents the event scheduler, which maintains a global event queue ordered by time. The scheduler retrieves the earliest event and wakes up the associated coroutine. When the protection system coroutine receives a fault event, it is woken up and executes the code for "protection logic → delay → exit" sequentially; after completion, it suspends again, waiting for the next event to trigger. The frequency modulation system coroutine is woken up when it detects a frequency change event, and similarly suspends after performing steps such as "frequency modulation simulation → power update". The entire process is event-driven; the coroutines do not consume any CPU resources while waiting, achieving efficient parallel simulation across multiple services and time scales.
[0043] In this embodiment, before starting the simulation, it is necessary to control the closed-loop data interaction between the secondary service real-time simulation module and the physical simulation module. This closed-loop data interaction includes: setting the physical simulation module to run at a fixed step size and writing the measurement snapshots output after each step into the measurement snapshot buffer in the shared memory area; the secondary service simulation module reads measurement changes from the measurement snapshot buffer and converts them into observable events, inserting them into the discrete event queue within the secondary service simulation module, thereby generating control commands; these control commands carry timestamps and are written to the timestamp control command queue in the shared memory area, allowing the physical simulation module to retrieve and execute the corresponding timestamp control command queue when the physical clock reaches the corresponding timestamp, thus avoiding blocking caused by strict handshake synchronization. Furthermore, deviations between the actual physical clock and the secondary virtual clock, including those within the engineering tolerance (determined based on actual needs), are allowed to ensure the determinism of the fixed step size in the physical simulation.
[0044] In addition, to illustrate the function of the real-time simulation method for secondary services of distribution networks, two application scenarios are briefly illustrated here: one is the real-time simulation of distribution network protection and network reconfiguration, and the other is the real-time simulation of massive objects for primary frequency regulation of virtual power plants.
[0045] Firstly, in the real-time simulation of distribution network protection and network reconfiguration, modeling is performed first. Entities include: busbars, lines, circuit breakers / switches, protection devices, automatic transfer switches for backup power, master station application modules, and communication nodes. Components include: switch status, failure-to-operate flag, setting and delay parameters, measurement mapping, command channel index, service status, and event subscription relationships. Topology services centrally maintain the primary electrical network, secondary communication network, and primary-secondary mapping; providing query interfaces for fault path judgment, connectivity analysis, and power restoration path identification. Business systems include: protection system, circuit breaker execution system, automatic transfer switch for backup power and network reconfiguration system, master station application system, and event recording and verification system. During operation, a fault event is generated when a fault occurs; the protection system coroutine is awakened and generates a trip command event after a delay; the circuit breaker execution system coroutine receives the command and decides whether to change position based on the failure-to-operate flag; if the failure to operate results in the fault not being isolated, the upstream backup protection coroutine continues to operate based on the topology service judgment; the network reconfiguration coroutine generates a transfer and closing event after meeting the conditions; ultimately, a stable action chain and event record are formed. As a result, the event logs can verify that the key action types, causal order, and key delay statistics meet the preset tolerance, proving that the model can reproduce complex topological dependent business chains.
[0046] Secondly, real-time simulation of massive objects for primary frequency regulation in virtual power plants: Modeling treats electric vehicle charging piles and energy storage units as entities; states of charge, power constraints, frequency regulation parameters, and subscription relationships as components; partitioning or aggregation relationships as logical relationships in the topology service; and implements the frequency regulation calculation logic as business system coroutines. Operation involves broadcasting frequency change events at fixed intervals; each device coroutine, upon being awakened, performs a frequency regulation calculation and updates the power, then suspends again to await the next event. Performance management utilizes budget concessions or asynchronous task rollover mechanisms to suppress tail latency and maintain real-time event processing when computationally intensive steps occur. Scalability is ensured, maintaining real-time operation even when the secondary equipment scales to tens of thousands to eighty thousand units, with a gradual increase in memory usage.
[0047] In summary, this invention constructs an overall ECTS model of entity-component-topology-system, centralizes topology services, and ensures a global view. Figure 1 This approach enables the stable reproduction of complex action chains. In terms of execution, it integrates discrete event-driven programming with C++ coroutines, uses event stamps to advance the virtual clock, and organizes massive business processes in a lightweight task format, effectively eliminating the overhead of fixed-step idle operations and the high cost of thread scheduling. It also introduces budget concession and asynchronous sinking mechanisms to effectively suppress tail latency and maintain real-time performance boundaries. Furthermore, it designs a decoupling closed-loop mechanism based on shared memory to ensure that the computational uncertainty of secondary simulation does not affect the hard real-time step size of physical simulation, demonstrating significant progress.
[0048] The above embodiments are merely illustrative of the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. Any modifications made to the technical solutions based on the technical concept proposed in this invention shall fall within the scope of protection of this invention.
Claims
1. A real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues, characterized in that, Includes the following steps: S1. In the secondary business simulation module, each simulation object is abstracted into a single entity and a set of entities is constructed. Each entity carries a unique identifier. Each entity is attached to a corresponding component, and each component is used as a data container for the corresponding entity. Based on each entity, a global topology is constructed to record the mapping relationship between the primary electrical network, the secondary communication network, and the primary electrical network and the secondary communication network; based on each business logic, a business system is constructed, which is used to call the global topology and read and write the corresponding components to execute the corresponding business logic after the corresponding coroutine task is awakened by the event scheduler. S2. Establish a discrete event queue based on the order of the timestamps of each observable event; event The scheduler is used to implement cyclic control on the discrete event queue. The cyclic control includes: retrieving the earliest timestamp of the observable event from the discrete event queue; advancing the virtual clock of the secondary business simulation module to the corresponding timestamp; waking up and executing the coroutine task that matches the corresponding observable event according to the subscription conditions of each coroutine task; and inserting new observable events generated during the execution process into the discrete event queue. S3. Instantiate each business logic into a corresponding coroutine task; each coroutine task is controlled by the event scheduler, which sets each coroutine task to a suspended-wake-short-process-suspend execution mode and starts the simulation. Among them, a tail delay suppression mechanism is set up during the execution of any coroutine task to deal with situations where the computational cost exceeds a preset threshold or the any coroutine task is a computationally intensive task; the tail delay suppression mechanism includes budget concession or asynchronous sinking of heavy tasks.
2. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, Each entity in step S1 includes a busbar, line, circuit breaker, switch, protection device, terminal device, automatic backup power supply switching device, master station application module, and communication node. Each data container includes corresponding indicator data. The types of indicator data include: switch status, failure to operate / lockdown flag, setpoint parameters and delay parameters, measurement mapping relationship, command queue index, alarm and event subscription relationship, and business status.
3. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, The types of business logic in step S1 include at least: protection, feeder automation, self-healing, automatic backup power supply, master station application, and virtual power plant frequency regulation.
4. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, In step S2, the types of observable events include faults, measurement mutations, exceeding limits, trip commands, switch changes, closed-loop confirmations, and transfer instructions; any observable event must include at least: timestamp, event type, event source object identifier, event target object identifier, and event load field.
5. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, In step S2, the discrete event queue is also equipped with an insertion mechanism, which includes: abstracting faults, measurement mutations, control commands, or state changes into corresponding observable events and inserting them into the discrete event queue.
6. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, In step S3, the event scheduler is also used to manage the state of each coroutine task, which includes at least a suspended state and a ready state. Each coroutine task is initialized before being handed over to the event scheduler for control, and registers the subscription conditions for each observable event with the event scheduler; When the event scheduler retrieves any observable event from the discrete event queue, it switches the coroutine task matching the observable event from the suspended state to the ready state and resumes execution based on the corresponding subscription conditions. After the corresponding coroutine task completes the processing corresponding to the observable event, it voluntarily relinquishes the execution right and re-enters the suspended state.
7. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, The event scheduler controls the waking up or suspending of each coroutine task based on the event type, alarm, and event subscription relationship.
8. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, During the execution of the arbitrary coroutine task in step S3, the budget transfer includes: setting a preset threshold during execution; when the execution of the arbitrary coroutine task exceeds the preset threshold, the arbitrary coroutine task actively saves its state and pauses execution, and splits the unexecuted part into new observable events and puts them into the discrete event queue.
9. The real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, During the execution of any coroutine task in step S3, the asynchronous sinking of heavy tasks includes: when the event scheduler recognizes that any coroutine task is a computationally intensive task, the event scheduler first wakes it up, then sinks the any coroutine task to the thread pool or asynchronous execution unit for sinking processing. After the sinking processing is completed, a completion event or completion notification is generated, and the event scheduler restores the corresponding coroutine task to continue execution and then enters the suspended state.
10. A real-time simulation method for secondary services in a distribution network based on coroutines and discrete event queues according to claim 1, characterized in that, In step S3, before starting the simulation, it is also necessary to control the closed-loop data interaction between the secondary service real-time simulation module and the physical simulation module. The closed-loop data interaction includes: The physical simulation module is set to run at a fixed step size, and the measurement snapshots output after the run are written to the shared memory area. The secondary service simulation module reads the measurement changes from the shared memory area, converts them into corresponding observable events, and generates corresponding control commands. The control commands carry timestamps and are written to the timestamp control command queue in the shared memory area, which is used by the physical simulation module to retrieve and execute the timestamp control command queue when the physical clock reaches the corresponding timestamp.