A co-simulation method and device based on Python and PSD-BPA
By using a joint simulation method combining Python and PSD-BPA, power flow files are parsed and modified to generate stable calculation results. This solves the problem of sample imbalance in existing simulation software for new energy power systems, enables batch generation of stable calculation results, and improves the efficiency and accuracy of data-driven technology.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA ELECTRIC POWER RESEARCH INSTITUTE CO LTD
- Filing Date
- 2023-03-09
- Publication Date
- 2026-04-21
AI Technical Summary
Existing simulation software such as PSASP, PSD-BPA, and PSSE are insufficient to meet the demand for batch generation of stability problems in high-proportion renewable energy power systems, resulting in sample imbalance and low data availability in data-driven models, which cannot effectively cover combinations of various faults and scenarios.
By using a co-simulation method based on Python and PSD-BPA, power flow files are parsed and network data is modified. Power flow and stability calculations are performed using Python's OS library, and result files are generated and judged. Combined with the YAML module to compile card rules, batch generation of stability calculation results is achieved.
It enables batch simulation of critical short-circuit ratio sample sets, avoiding the inefficiency and errors of repetitive manual operations, and provides a data foundation for data-driven technology in the field of voltage support strength.
Smart Images

Figure CN116502401B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large power grid stability analysis and control applications, and more specifically, to a co-simulation method and apparatus based on Python and PSD-BPA. Background Technology
[0002] With the concentrated integration of a high proportion of random, fluctuating, and intermittent renewable energy sources into the power grid, the number of power electronic devices and stable states in the grid are gradually increasing, posing a severe challenge to the safe and stable operation of the system. Meanwhile, the mechanism by which renewable energy affects power system stability remains unclear. To address the stability issues of power systems with a high proportion of renewable energy, using data-driven modeling to analyze the system's stability patterns will provide new insights for related research.
[0003] Data-driven approaches directly extract the mapping relationship between system states and stability indicators from large amounts of data; therefore, obtaining the dataset corresponding to stable states is a fundamental step in related research. Regarding the source of the dataset, the probability of power grid faults and instability is relatively low in actual operation, resulting in a limited amount of measured data. Consequently, measured data cannot cover a large number of "scenario-fault" combinations, leading to insufficient diversity and severe sample imbalance in the dataset, and low usability. Against this backdrop, power system simulation software is needed to generate large amounts of data to cover various combinations of faults and scenarios. Currently, commonly used simulation software all have batch processing modules, such as PSASP, PSD-BPA, and PSSE, but their functionality is insufficient to simultaneously meet the batch generation requirements of different stability problems, causing many inconveniences for data-driven sample generation. Therefore, an interface needs to be developed to meet the batch generation requirements of various stability problems, providing a data foundation for stability problem research. Summary of the Invention
[0004] To address at least one of the problems described in the background section, the present invention provides a co-simulation method and apparatus based on Python and PSD-BPA.
[0005] According to one aspect of the present invention, a co-simulation method based on Python and PSD-BPA is provided, comprising:
[0006] Step 1: Parse the power flow file according to the preset mode, and modify the network data of the DAT file based on the parsing results;
[0007] Step 2: Use Python's OS library to read the storage path of the power flow calculation program and call it. Perform power flow calculation based on the modified DAT file to generate a power flow result file and a power flow result output file. Determine whether the power flow result has converged based on the power flow result output file. If the power flow result has converged, use the OS library to read the storage path of the stability calculation program and call the stability calculation program based on the power flow result file to generate a stability calculation result file. Use the stability calculation program to determine whether the power flow allocation is reasonable. If it is reasonable, proceed to Step 3; otherwise, return to Step 1.
[0008] Step 3: Use the OS library to read the storage path of the stability calculation program, and call the stability calculation program and power flow result file to generate the stability calculation result file and auxiliary output file; call the Python OS library to determine the memory size of the auxiliary output file generated by the simulation. If the memory is less than the threshold, call the stability calculation program again to perform stability calculation. If the memory is greater than or equal to the threshold, save the currently generated stability calculation result file and auxiliary output file.
[0009] Optionally, parsing the power flow file according to a preset mode includes: parsing the power flow file in UTF-8 mode and converting the Chinese characters in the power flow file into bytes and GBK modes.
[0010] Optionally, modifying the network data of the DAT file based on the parsing result includes:
[0011] Based on the analysis results, the node and line information of the entire network is statistically analyzed, and the electrical quantities that need to be modified are determined according to the simulation requirements.
[0012] Based on the dedicated control statements defined in BPA, and using Python's YAML module, the starting positions and placeholder lengths of each card are compiled into yml files according to their functions and string lengths.
[0013] Modify the network data in the DAT file according to simulation requirements.
[0014] Optionally, the step of compiling each starting position and placeholder length into a yml file based on the function and string length of each card includes:
[0015] Define the rules for cards, including card type, card starting position, and placeholder spacing. Use spaces for indentation to indicate levels, with different numbers of spaces used for indentation between different levels. Card type and function are the first level, and card starting position is the second level.
[0016] According to the card rules, define all the functions of the card and the starting position and placeholder interval of related functions in sequence, and compile each starting position and placeholder length into a yml file.
[0017] Optionally, before reading the storage path of the stable calculation program using the OS library, the method further includes: setting up corresponding cards according to simulation requirements and the rules of the YAML module.
[0018] Optionally, the method further includes:
[0019] Based on the required number of samples and the fault set, repeat steps 1 to 3 to obtain the sample set;
[0020] The sample set constitutes the stability domain boundary of the relevant stable form, and the stability index of the stable form is calculated by the program as the prediction label.
[0021] Depending on the type of feature required, extract the electrical quantities of the entire network under steady-state or transient processes as input features;
[0022] The input features and predicted labels of all samples are merged into a two-dimensional array and stored as a CSV file.
[0023] According to another aspect of the present invention, a co-simulation apparatus based on Python and PSD-BPA is provided, comprising:
[0024] The parsing and modification module is used to parse the power flow file according to a preset pattern and modify the network data of the DAT file based on the parsing results.
[0025] The power flow calculation module is used to read and call the storage path of the power flow calculation program using Python's OS library, and perform power flow calculation based on the modified DAT file to generate a power flow result file and a power flow result output file. Based on the power flow result output file, it determines whether the power flow results have converged. If the power flow results have converged, it uses the OS library to read the storage path of the stability calculation program, and calls the stability calculation program based on the power flow result file to generate a stability calculation result file. It uses the stability calculation program to determine whether the power flow allocation is reasonable. If it is reasonable, it proceeds to step 3; otherwise, it returns to step 1.
[0026] The stability calculation module is used to read the storage path of the stability calculation program using the OS library, and call the stability calculation program and power flow result file to generate a stability calculation result file and an auxiliary output file. It calls the Python OS library to determine the memory size of the auxiliary output file generated by the simulation. If the memory is less than the threshold, the stability calculation program is called again to perform stability calculation. If the memory is greater than or equal to the threshold, the currently generated stability calculation result file and auxiliary output file are saved.
[0027] Optionally, the parsing and modification module is specifically used to: parse the power flow file in UTF-8 mode and convert the Chinese characters in the power flow file into bytes and GBK modes.
[0028] According to another aspect of the present invention, a computer-readable storage medium is provided, the storage medium storing a computer program for performing the methods described in any of the above aspects of the present invention.
[0029] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: a processor; a memory for storing executable instructions of the processor; the processor being configured to read the executable instructions from the memory and execute the instructions to implement the method described in any of the preceding aspects of the present invention.
[0030] This invention first parses and modifies the power flow file, then generates power flow results, next calculates the stability results, and finally extracts sample features and calculates labels. This invention achieves batch simulation of critical short-circuit ratio sample sets through dynamic interaction between Python and BPA, avoiding the problems of large workload, low efficiency, and error-proneness associated with repetitive manual operations, and providing a data foundation for introducing data-driven technology into the field of voltage support strength. Attached Figure Description
[0031] Exemplary embodiments of the present invention can be more fully understood by referring to the following figures:
[0032] Figure 1 This is a flowchart illustrating a co-simulation method based on Python and PSD-BPA provided in an exemplary embodiment of the present invention.
[0033] Figure 2 This is a core operational logic diagram provided by an exemplary embodiment of the present invention;
[0034] Figure 3 This is a flowchart illustrating the construction of a critical short-circuit ratio dataset provided in an exemplary embodiment of the present invention;
[0035] Figure 4 This is a label distribution histogram of the CSCR dataset provided in an exemplary embodiment of the present invention;
[0036] Figure 5 This is a schematic diagram of the structure of a co-simulation device based on Python and PSD-BPA provided in an exemplary embodiment of the present invention;
[0037] Figure 6 This is a structural diagram of an electronic device provided in an exemplary embodiment of the present invention. Detailed Implementation
[0038] Hereinafter, exemplary embodiments of the present invention will be described in detail with reference to the accompanying drawings. It is obvious that the described embodiments are merely some embodiments of the present invention, and not all embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described herein.
[0039] It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values of the components and steps described in these embodiments do not limit the scope of the invention.
[0040] Figure 1 A flowchart illustrating the co-simulation method based on Python and PSD-BPA provided by this invention is shown. Figure 1 As shown, the co-simulation method based on Python and PSD-BPA includes:
[0041] Step 1: Parse the power flow file according to the preset mode, and modify the network data of the DAT file based on the parsing results.
[0042] Optionally, parsing the power flow file according to a preset mode includes: parsing the power flow file in UTF-8 mode and converting the Chinese characters in the power flow file into bytes and GBK modes.
[0043] Optionally, modifying the network data of the DAT file based on the parsing results includes: based on the parsing results, statistically analyzing the node and line information of the entire network, and determining the electrical quantities that need to be modified according to simulation requirements; using the Python YAML module to compile each starting position and placeholder length into a yml file according to the dedicated control statements defined by BPA, based on the function and string length of each card; and modifying the network data of the DAT file according to simulation requirements.
[0044] Optionally, the step of compiling each starting position and placeholder length into a yml file based on the function and string length of each card includes: defining card rules, which include the card type, the card's starting position, and the placeholder interval; using spaces for indentation to represent hierarchical levels, with different numbers of spaces used for indentation between different levels; the card type and function being the first level, and the card's starting position being the second level; and, according to the card rules, sequentially defining all the functions of the card and the starting positions and placeholder intervals of related functions, and compiling each starting position and placeholder length into a yml file.
[0045] In this embodiment of the invention, the power flow file (DAT) is first parsed in UTF-8 mode, and Chinese characters are converted to bytes and GBK mode. After parsing, the node and line information of the entire network is statistically analyzed, and the electrical quantities that need to be modified are determined according to simulation requirements, such as the power output level of the power source and the transmission power of the line. Then, according to the dedicated control statements defined in the BPA, the cards that need to be repeatedly edited are written using Python's YAML module. Specifically, based on the function of each card and its string length, the starting position and placeholder length are compiled into a YAML file.
[0046] The editing order of the .yml file is as follows: 1) First, define the card type, its starting position, and placeholder interval. Use spaces for indentation to indicate levels. Different numbers of spaces can be used for indentation between different levels. The card type and function are the first level, and the position is the second level; 2) According to the card rules, define all the functions of the card and the starting position and placeholder interval of related functions in sequence. When modifying any card later, simply fill in the corresponding values according to the card's relative position, and save the set power flow level combination and demand combination (fault card, continuous power flow card) as a CSV file.
[0047] Finally, based on the above rules and simulation requirements, edit or modify the network data in the DAT file. For example, when modifying the active power of a certain renewable energy power station, it is necessary to locate the designated B card (AC node card) and enter the corresponding data in the designated column; otherwise, errors may occur after the power flow calculation program (PFNT) reads the data.
[0048] Step 2: Use Python's OS library to read the storage path of the power flow calculation program and call it. Perform power flow calculation based on the modified DAT file to generate a power flow result file and a power flow result output file. Determine whether the power flow results have converged based on the power flow result output file. If the power flow results have converged, use the OS library to read the storage path of the stability calculation program and call the stability calculation program based on the power flow result file to generate a stability calculation result file. Use the stability calculation program to determine whether the power flow allocation is reasonable. If it is reasonable, proceed to Step 3; otherwise, return to Step 1.
[0049] In this embodiment of the invention, the storage path of the power flow calculation program (PFNT) is first read and called using the Python OS library. Power flow calculation is then performed based on the modified DAT file, generating a power flow result file (BSE) and a power flow result output file (PFO). The program reads the PFO information to determine whether the power flow results have converged. If the power flow results have converged, the storage path of the stability calculation program (SWNT) is read using the OS library, and SWNT is called based on the BSE to generate a stability calculation result file (OUT). Then, the program reads the OUT information to determine whether there are any issues such as generator output exceeding limits, PID limiting, or unreasonable transformer ratios. If no errors are reported, the current power flow state can be considered a normal power flow state, and the process proceeds to step 3; otherwise, the power flow allocation is unreasonable, and the process returns to step 1.
[0050] Step 3: Use the OS library to read the storage path of the stability calculation program, and call the stability calculation program and power flow result file to generate the stability calculation result file and auxiliary output file; call the Python OS library to determine the memory size of the auxiliary output file generated by the simulation. If the memory is less than the threshold, call the stability calculation program again to perform stability calculation. If the memory is greater than or equal to the threshold, save the currently generated stability calculation result file and auxiliary output file.
[0051] Optionally, before reading the storage path of the stable calculation program using the OS library, the method further includes: setting up corresponding cards according to simulation requirements and the rules of the YAML module.
[0052] In this embodiment of the invention, firstly, corresponding cards are set according to the simulation requirements and the rules of the YAML module. For example, if the simulation requirement is fault calculation, the type, location, and duration of the fault card (LI card) are edited. Then, the storage path of the stability calculation program SWNT is read using the OS library, and the stability calculation program SWNT and the power flow result file BSE generated in step 2 are called to generate a stability calculation result file (OUT) and an auxiliary output file (SWX). The memory size of the auxiliary output file SWX generated by the simulation is determined by calling the Python OS library. If the memory is less than 1000KB, the process of calling the stability calculation program SWNT for stability calculation will not respond, and the stability calculation program SWNT needs to be called again based on the current power flow result; otherwise, the simulation order of the samples will be incorrect. If the memory is greater than 1000KB, the currently generated auxiliary output file SWX is saved.
[0053] Optionally, the method further includes: repeating steps 1 to 3 according to the required number of samples and the fault set to obtain a sample set; constructing the stability domain boundary of the relevant stable state from the sample set, and using the program to calculate the stability index of the stable state as the prediction label; extracting the electrical quantities of the entire network under the steady-state or transient process of the system as input features according to the type of required features; merging the input features and prediction labels of all samples into a two-dimensional array and storing it as a CSV file. Figure 2 The core operational logic diagram of the present invention is shown.
[0054] In this embodiment of the invention, steps 1-3 are first repeated based on the required number of samples and the fault set to obtain a large sample set. The sample set constitutes the stability domain boundary of the relevant stable state, and the stability index of the stable state is calculated using a program as a prediction label. Then, based on the type of required features, the electrical quantities of the entire network under steady-state or transient processes are extracted. For example, the voltage amplitude and phase angle of the bus, and the active and reactive power of the lines are used as input features. Finally, the input features and prediction labels of all samples are merged into a two-dimensional array and stored as a CSV file.
[0055] This invention demonstrates its effectiveness using a simulation of a critical short-circuit ratio sample set as an example. The simulation requirements are as follows: Figure 3 As shown, the process is as follows: 1) Randomly divide the active power of each power station according to the total power of new energy sources to obtain the initial power flow state of the system; 2) To obtain the maximum transmittable power of the grid-connected point, the power-voltage curve is repeatedly tracked using the continuous power flow method. First, a certain new energy power station is selected, and its active power is increased according to a constant power factor, where the surplus power is absorbed by the generators of the balancing node. Then, the steady-state behavior of the system under power change is tracked until it approaches the maximum transmittable power of the corresponding grid-connected point; 3) Calculate the critical short-circuit ratio of each grid-connected point as a prediction label according to the calculation formula of the maximum transmittable power and the short-circuit ratio of multiple new energy power stations, and extract the electrical characteristics under the current initial power flow state as input features; 4) Repeat steps 1-3 according to the required number of samples to obtain a large number of static voltage stability critical points. The point set constitutes the static voltage stability domain boundary of each grid-connected point. To facilitate the storage of the dataset, the input features and prediction labels of all samples are merged into a two-dimensional array.
[0056] Following the above procedure, using the CEPRI-102 node system as the test system, a critical short-circuit ratio dataset containing 10,000 samples was constructed, including 6 wind farms and 6 photovoltaic farms, denoted as Wi and Pi, respectively. The distribution of statistical labels is shown below. Figure 4 As shown. Figure 4 The CSCR of each grid connection station is dynamically changing, and the fluctuation range is between 1.2 and 2.3. The distribution of CSCR shows that there are both similarities and differences among the grid connection points, verifying the effectiveness of the invention.
[0057] Therefore, the joint simulation method based on Python and PSD-BPA proposed in this invention realizes the function of batch simulation of critical short-circuit ratio sample sets through the dynamic interaction between Python and BPA, avoiding the problems of large workload, low efficiency and easy error in manual repetitive operation, and providing a data foundation for the introduction of data-driven technology into the field of voltage support strength.
[0058] Exemplary device
[0059] Figure 5 This is a schematic diagram of the structure of a co-simulation device based on Python and PSD-BPA provided in an exemplary embodiment of the present invention. Figure 5 As shown, the device 500 includes:
[0060] The parsing and modification module 510 is used to parse the power flow file according to a preset mode and modify the network data of the DAT file based on the parsing results.
[0061] The power flow calculation module 520 is used to read and call the storage path of the power flow calculation program using Python's OS library, and perform power flow calculation based on the modified DAT file to generate a power flow result file and a power flow result output file. Based on the power flow result output file, it is determined whether the power flow result has converged. If the power flow result has converged, the storage path of the stability calculation program is read using the OS library, and the stability calculation program is called based on the power flow result file to generate a stability calculation result file. The stability calculation program is used to determine whether the power flow allocation is reasonable. If it is reasonable, proceed to step 3; otherwise, return to step 1.
[0062] The stability calculation module 530 is used to read the storage path of the stability calculation program using the OS library, and call the stability calculation program and power flow result file to generate a stability calculation result file and an auxiliary output file. It calls the Python OS library to determine the memory size of the auxiliary output file generated by the simulation. If the memory is less than the threshold, the stability calculation program is called again to perform stability calculation. If the memory is greater than or equal to the threshold, the currently generated stability calculation result file and auxiliary output file are saved.
[0063] Optionally, the parsing and modification module 510 is specifically used to: parse the power flow file in UTF-8 mode and convert the Chinese characters in the power flow file into bytes and GBK modes.
[0064] Optionally, the parsing and modification module 510 is specifically used for:
[0065] Based on the analysis results, the node and line information of the entire network is statistically analyzed, and the electrical quantities that need to be modified are determined according to the simulation requirements.
[0066] Based on the dedicated control statements defined in BPA, and using Python's YAML module, the starting positions and placeholder lengths of each card are compiled into yml files according to their functions and string lengths.
[0067] Modify the network data in the DAT file according to simulation requirements.
[0068] Optionally, the step of compiling each starting position and placeholder length into a yml file based on the function and string length of each card includes:
[0069] Define the rules for cards, including card type, card starting position, and placeholder spacing. Use spaces for indentation to indicate levels, with different numbers of spaces used for indentation between different levels. Card type and function are the first level, and card starting position is the second level.
[0070] According to the card rules, define all the functions of the card and the starting position and placeholder interval of related functions in sequence, and compile each starting position and placeholder length into a yml file.
[0071] Optionally, the device further includes a setting module for setting corresponding cards according to simulation requirements and the rules of the YAML module.
[0072] Optionally, the device further includes:
[0073] The acquisition module is used to repeatedly perform steps 1 to 3 to acquire a sample set based on the required number of samples and the fault set.
[0074] The label determination module is used to construct the stable domain boundary of the relevant stable form from the sample set, and to use the program to calculate the stability index of the stable form as the predicted label.
[0075] The feature determination module is used to extract electrical quantities of the entire network under steady-state or transient processes as input features according to the type of required features.
[0076] The merging module is used to merge the input features and predicted labels of all samples into a two-dimensional array and store it as a CSV file.
[0077] The co-simulation device based on Python and PSD-BPA in the embodiments of the present invention corresponds to the co-simulation method based on Python and PSD-BPA in another embodiment of the present invention, and will not be described again here.
[0078] Exemplary electronic devices
[0079] Figure 6 This is the structure of an electronic device provided in an exemplary embodiment of the present invention. For example... Figure 6As shown, the electronic device 60 includes one or more processors 61 and a memory 62.
[0080] The processor 61 may be a central processing unit (CPU) or other form of processing unit with data processing and / or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
[0081] The memory 62 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 61 may execute the program instructions to implement the methods of the software programs of the various embodiments of the present invention described above, and / or other desired functions. In one example, the electronic device may also include an input device 63 and an output device 64, these components being interconnected via a bus system and / or other forms of connection mechanisms (not shown).
[0082] In addition, the input device 63 may also include, for example, a keyboard, a mouse, etc.
[0083] The output device 64 can output various information to the outside. The output device 64 may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc.
[0084] Of course, for the sake of simplicity, Figure 6 Only some of the components of the electronic device relevant to the present invention are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device may include any other suitable components depending on the specific application.
[0085] Exemplary computer program products and computer-readable storage media
[0086] In addition to the methods and apparatus described above, embodiments of the present invention may also be computer program products, which include computer program instructions that, when executed by a processor, cause the processor to perform the steps of the methods according to various embodiments of the present invention described in the "Exemplary Methods" section above.
[0087] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of the present invention. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0088] Furthermore, embodiments of the present invention may also be computer-readable storage media storing computer program instructions thereon, which, when executed by a processor, cause the processor to perform the steps of the methods according to various embodiments of the present invention described in the "Exemplary Methods" section above.
[0089] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof.
[0090] The basic principles of the present invention have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in the present invention are merely examples and not limitations, and should not be considered as essential features of each embodiment of the present invention. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the present invention to the necessity of employing the aforementioned specific details.
[0091] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments, since they largely correspond to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0092] The block diagrams of devices, systems, devices, and systems involved in this invention are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, systems, devices, and systems can be connected, arranged, and configured in any manner. Words such as “comprising,” “including,” “having,” etc., are open-ended terms meaning “including but not limited to,” and are used interchangeably with them. The terms “or” and “and” as used herein refer to the terms “and / or,” and are used interchangeably with them unless the context clearly indicates otherwise. The term “such as” as used herein refers to the phrase “such as but not limited to,” and is used interchangeably with it.
[0093] The methods and systems of the present invention may be implemented in many ways. For example, they may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above-described order of steps for the methods is for illustrative purposes only, and the steps of the methods of the present invention are not limited to the order specifically described above unless otherwise specifically stated. Furthermore, in some embodiments, the present invention may also be implemented as a program recorded on a recording medium, the program comprising machine-readable instructions for implementing the methods according to the present invention. Thus, the present invention also covers recording media storing programs for performing the methods according to the present invention.
[0094] It should also be noted that in the systems, apparatus, and methods of the present invention, the components or steps can be disassembled and / or recombined. These disassemblies and / or recombinations should be considered equivalents of the present invention. The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use the invention. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein can be applied to other aspects without departing from the scope of the invention. Therefore, the invention is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.
[0095] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of the invention to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations therein.
Claims
1. A co-simulation method based on Python and PSD-BPA, characterized in that, include: Step 1: Parse the power flow file according to the preset mode, and modify the network data in the DAT file based on the parsing results, including: Based on the analysis results, the node and line information of the entire network is statistically analyzed, and the electrical quantities that need to be modified are determined according to the simulation requirements. Based on the dedicated control statements defined in BPA, and using Python's YAML module, the starting positions and placeholder lengths of each card are compiled into yml files according to their functions and string lengths. Modify the network data in the DAT file according to simulation requirements; The process of compiling each starting position and placeholder length into a yml file based on the function and string length of each card includes: Define the rules for cards, including card type, card starting position, and placeholder spacing. Use spaces for indentation to indicate levels, with different numbers of spaces used for indentation between different levels. Card type and function are the first level, and card starting position is the second level. According to the card rules, define all the functions of the card and the starting position and place interval of related functions in sequence, and compile each starting position and place length into a yml file; Step 2: Use Python's OS library to read the storage path of the power flow calculation program and call it. Perform power flow calculation based on the modified DAT file to generate a power flow result file and a power flow result output file. Determine whether the power flow result has converged based on the power flow result output file. If the power flow result has converged, use the OS library to read the storage path of the stability calculation program and call the stability calculation program based on the power flow result file to generate a stability calculation result file. Use the stability calculation program to determine whether the power flow allocation is reasonable. If it is reasonable, proceed to Step 3; otherwise, return to Step 1. Step 3: Use the OS library to read the storage path of the stability calculation program, and call the stability calculation program and power flow result file to generate the stability calculation result file and auxiliary output file; call the Python OS library to determine the memory size of the auxiliary output file generated by the simulation. If the memory is less than the threshold, call the stability calculation program again to perform stability calculation. If the memory is greater than or equal to the threshold, save the currently generated stability calculation result file and auxiliary output file.
2. The method of claim 1, wherein, The step of parsing the power flow file according to the preset mode includes: parsing the power flow file in UTF-8 mode and converting the Chinese characters in the power flow file into bytes and GBK modes.
3. The method of claim 1, wherein, Before using the OS library to read the storage path of the stable calculation program, the process also includes: setting up corresponding cards according to simulation requirements and the rules of the YAML module.
4. The method of claim 1, wherein, The method further includes: Based on the required number of samples and the fault set, repeat steps 1 to 3 to obtain the sample set; The sample set constitutes the stability domain boundary of the relevant stable form, and the stability index of the stable form is calculated by the program as the prediction label. Depending on the type of feature required, extract the electrical quantities of the entire network under steady-state or transient processes as input features; The input features and predicted labels of all samples are merged into a two-dimensional array and stored as a CSV file.
5. A co-simulation device based on Python and PSD-BPA, characterized in that, include: The parsing and modification module is used to parse the power flow file according to a preset pattern and modify the network data of the DAT file based on the parsing results, including: Based on the analysis results, the node and line information of the entire network is statistically analyzed, and the electrical quantities that need to be modified are determined according to the simulation requirements. Based on the dedicated control statements defined in BPA, and using Python's YAML module, the starting positions and placeholder lengths of each card are compiled into yml files according to their functions and string lengths. Modify the network data in the DAT file according to simulation requirements; The process of compiling each starting position and placeholder length into a yml file based on the function and string length of each card includes: Define the rules for the cards, including the card type, the starting position of the card, and the placeholder spacing. Use spaces for indentation to indicate levels, and use different numbers of spaces for indentation between different levels. The card type and function are the first level, and the starting position of the card is the second level. According to the card rules, define all the functions of the card and the starting position and place interval of related functions in sequence, and compile each starting position and place length into a yml file; The power flow calculation module is used to read and call the storage path of the power flow calculation program using Python's OS library, and perform power flow calculation based on the modified DAT file to generate a power flow result file and a power flow result output file. Based on the power flow result output file, it determines whether the power flow results have converged. If the power flow results have converged, it uses the OS library to read the storage path of the stability calculation program, and calls the stability calculation program based on the power flow result file to generate a stability calculation result file. It uses the stability calculation program to determine whether the power flow allocation is reasonable. If it is reasonable, it proceeds to step 3; otherwise, it returns to step 1. The stability calculation module is used to read the storage path of the stability calculation program using the OS library, and call the stability calculation program and power flow result file to generate a stability calculation result file and an auxiliary output file. It calls the Python OS library to determine the memory size of the auxiliary output file generated by the simulation. If the memory is less than the threshold, the stability calculation program is called again to perform stability calculation. If the memory is greater than or equal to the threshold, the currently generated stability calculation result file and auxiliary output file are saved.
6. The apparatus of claim 5, wherein, The parsing and modification module is specifically used to: parse the power flow file in UTF-8 mode and convert the Chinese characters in the power flow file into bytes and GBK modes.
7. A computer-readable storage medium, characterized in that, The storage medium stores a computer program for performing the method described in any one of claims 1-4.
8. An electronic device, comprising: The electronic device includes: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the method described in any one of claims 1-4.