Modelica model state preservation methods, apparatus, equipment, media, and products
By determining the necessity of state variables, locking initial values, and providing initial values for nonlinear iterative variables in the Modelica model, and using vendor annotations to mark nonlinear iterative variables, the ambiguity problem of cross-platform translation of the Modelica model is solved, and the consistency and reliability of cross-platform simulation results are achieved.
Patent Information
- Application Number
- CN202511410365.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-29
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2045-09-29
AI Technical Summary
The translation of Modelica models across different platforms or versions is ambiguous, leading to inconsistent simulation results. Existing technologies struggle to achieve cross-platform reliability and consistency.
By determining the necessity of state variables, locking the determinism of initial values, providing initial values for nonlinear iterative variables, and using vendor annotations to mark nonlinear iterative variables, ambiguity in the model translation process is eliminated, and consistency of simulation results across platforms is achieved.
It significantly improves the consistency and reliability of cross-platform simulation results for Modelica models, lowers the modeling threshold, and enhances the modeling efficiency of complex systems and industrial-grade simulation standardization.
Smart Images

Figure CN120874414B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, medium, and product for solidifying the state of a Modelica model. Background Technology
[0002] In the field of multi-domain modeling and simulation of complex cyber-physical systems, Modelica, as an object-oriented, equation-based, open, and efficient modeling language, has become a widely adopted standard tool in industry and academia. Currently, the Modelica technology ecosystem has formed a mature system jointly built by professional model library vendors, research teams, and open-source communities. These entities provide modelers with abundant "plug-and-play" resources by developing standardized basic model components (such as modules for mechanical systems, electrical systems, and thermodynamic systems).
[0003] However, the Modelica model building process is highly dependent on the modeler's experience and understanding of the platform's underlying mechanisms. While the basic model components provide default configurations, such as default initial values (start parameter) and state variable selection priorities, these default settings are typically designed for general scenarios and cannot directly adapt to specific application requirements. Modelers need to customize the components by manually adjusting parameters and supplementing initial constraint equations to ensure the model meets the appropriate mathematical constraints.
[0004] Even with default configurations, the Modelica platform can still translate and simulate models, but the resulting simulation results can fluctuate significantly due to platform differences. That is, the same model may be translated into mathematically inequivalent ODE systems on different platforms or versions, leading to inconsistencies in simulation results. Although existing platforms provide some debugging tools (such as variable tracking and equation printing), requiring modelers to have a deep understanding of Modelica's translation and solution theories to manually eliminate ambiguities is neither practical nor economical. Especially in complex system modeling scenarios (such as multiphysics coupled models with hundreds or thousands of state variables), relying on manual experience to solve uncertainties is not only inefficient but also makes it difficult to guarantee the robustness of the results.
[0005] Therefore, how to automate the state of Modelica models and eliminate ambiguity in the model translation process from the source has become a key technical issue that urgently needs to be addressed to improve the cross-platform portability of models and promote the standardization of industrial simulation. Solving this problem will significantly lower the modeling threshold and promote the deep application of the Modelica ecosystem in cross-platform collaboration, digital twins, and other fields. Summary of the Invention
[0006] This invention provides a method, apparatus, device, medium, and product for solidifying the state of a Modelica model, in order to solve the defect of inconsistent simulation results caused by ambiguity in the translation process of Modelica models in the prior art.
[0007] This invention provides a method for solidifying the state of a Modelica model, comprising:
[0008] In response to the translation simulation request of the model to be solidified, the model to be solidified is translated to obtain the model uncertainty characterization. The model uncertainty characterization includes the state variables selected for translation, the initial values of the initialization variables, the nonlinear iterative variables and their initial values for iteration. The initialization variables refer to the variables that need to be supplemented with initial values.
[0009] Perform at least one of the following steps and finally write it into the model to solidify the state of the translated model: determine the necessity of the state variables, lock the determinism of the initial values, provide initial values for the nonlinear iterative variables and mark the nonlinear iterative variables with vendor annotations.
[0010] According to the Modelica model state fixation method provided by the present invention, determining the mandatory nature of the state variable includes: adding a StateSelect.always attribute to the state variable;
[0011] The determinism of the initial value lock includes: using the initial value selected by the translation as the default initial condition, and adding the attribute fixed=true to the initial variable;
[0012] Providing the initial value for the nonlinear iterative variable includes using the previous simulation result of the nonlinear iterative variable as the initial value for the nonlinear iterative variable.
[0013] According to the Modelica model state solidification method provided by the present invention, the state solidification of the translated model includes:
[0014] Determine whether the state variable, initialization variable, and nonlinear iteration variable are protection variables;
[0015] If so, add the corresponding attributes and / or assign initial values to the protected variables in the vendor annotation;
[0016] If not, add the corresponding attributes and / or assign initial values to the model to be solidified.
[0017] According to the Modelica model state solidification method provided by the present invention, the translation of the model to be solidified to obtain a model uncertainty characterization includes:
[0018] Parse the manufacturer annotations in the model to be solidified, and use the parsing results as additional translation information for the model;
[0019] The model to be solidified is translated based on the additional translation information to obtain the uncertainty characterization of the model.
[0020] According to the Modelica model state solidification method provided by the present invention, before translating the model to be solidified in response to a translation simulation request, the method further includes:
[0021] An initial translation simulation was performed on the model to be solidified, and initial simulation results were obtained.
[0022] The system receives a click operation to save the initial simulation results and determines a translation simulation request for the model to be solidified based on the click operation.
[0023] According to the Modelica model state solidification method provided by the present invention, the translation of the model to be solidified to obtain a model uncertainty characterization includes:
[0024] The model to be solidified is transformed from the original mathematical description differential algebraic equation (DAE) into a solvable initial value ordinary differential equation (ODE), and the uncertainty characterization of the model is determined based on the initial value ordinary differential equation.
[0025] The present invention also provides a Modelica model state solidification device, comprising:
[0026] The model translation unit is used to translate the model to be solidified in response to the translation simulation request of the model to be solidified, and to obtain the model uncertainty characterization. The model uncertainty characterization includes the state variables selected for translation, the initial values of the initialization variables, the nonlinear iterative variables and their initial values for iteration. The initialization variables refer to the variables that need to be supplemented with initial values.
[0027] The state solidification unit is used to perform at least one of the following steps and finally write it into the model to solidify the state of the translated model: determining the necessity of the state variables, locking the determinism of the initial values, providing the initial values of the nonlinear iterative variables and marking the nonlinear iterative variables with vendor annotations.
[0028] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the Modelica model state solidification method as described above.
[0029] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the Modelica model state persistence method as described above.
[0030] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the Modelica model state solidification method as described above.
[0031] The Modelica model state solidification method, apparatus, device, medium, and product provided by this invention avoids inconsistencies in differential-algebraic variable classification caused by heuristic rules on the platform by determining the necessity of state variables, eliminates random fluctuations introduced by the platform's automatic estimation of initial values by locking the determinism of initial values, and ensures the consistency of variable selection by providing and marking the initial values of nonlinear iterative variables, thus avoiding result bifurcation in multi-solution problems. Then, the necessity of state variables, the determinism of initial values, the initial values of nonlinear iterative variables, and the manufacturer's annotations are finally written into the model, thereby eliminating ambiguity in the model translation process and achieving high consistency and reliability of cross-platform simulation results. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in this invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0033] Figure 1 This is one of the flowcharts illustrating the Modelica model state solidification method provided by this invention.
[0034] Figure 2 This is a schematic diagram of the model to be solidified and the translation report provided by the present invention.
[0035] Figure 3 This is a schematic diagram of the state-fixed model and translation report provided by the present invention.
[0036] Figure 4 This is the second flowchart of the Modelica model state solidification method provided by the present invention.
[0037] Figure 5 This is a schematic diagram of the Modelica model state solidification device provided by the present invention.
[0038] Figure 6 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0039] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0040] After extensive research, the inventors discovered that the translational ambiguity of the Modelica model mainly stems from the following technical bottlenecks:
[0041] Uncertainty in state variable selection: Different Modelica platforms or different versions of the same platform may use different heuristic algorithms to select state variables, resulting in the same model being decomposed into different ordinary differential equation (ODE) forms under different environments;
[0042] Non-uniqueness of initial constraints: The platform may supplement the initial constraint equations with unequal ones to make the initial value system satisfy the appropriate mathematical constraints, thus leading to different simulation results;
[0043] Differences in the implementation of nonlinear equation tearing techniques: Modelica platform generally adopts nonlinear equation tearing techniques to reduce solution complexity, but different platforms have different strategies for selecting tearing variables. Especially when there are multiple solutions to the nonlinear equation system, the inconsistency of tearing variables and their initial values for iteration can directly lead to solution bifurcation.
[0044] To ensure the platform portability of Modelica models, potential translational ambiguities must be addressed during the modeling phase. However, most modelers have limited knowledge of the translation and solution theory of Modelica models, making it difficult to build ideal deterministic models. Furthermore, for complex models with hundreds or thousands of state variables, relying on modelers to resolve uncertainties is unreliable and uneconomical.
[0045] To address the aforementioned issues, this invention proposes a Modelica model state solidification method. In this method, in response to a translation simulation request for the model to be solidified, the model is translated to obtain a model uncertainty representation. The model uncertainty representation includes the selected state variables, initial values of the initialization variables, nonlinear iterative variables, and their initial iteration values. The initialization variables refer to variables that require additional initial values. At least one of the following steps is performed and finally written into the model to solidify the translated model state: determining the necessity of the state variables, locking the determinism of the initial values, providing initial iteration values for the nonlinear iterative variables, and marking the nonlinear iterative variables using manufacturer annotations.
[0046] The method provided in this invention fundamentally eliminates model translation ambiguity caused by differences in heuristic algorithms across different Modelica platforms or different versions of the same platform by enforcing constraints on state variable selection rules, initial value fixation logic, and nonlinear iterative variable management. When the same model is simulated on different Modelica platforms or different versions of the same platform, the result difference rate is significantly reduced, meeting the stringent requirements for result consistency in industrial-grade simulations.
[0047] Furthermore, by automating the model translation and state solidification processes, modelers' reliance on the underlying Modelica theory is reduced, significantly improving the modeling efficiency of complex systems. Standardizing the state solidification process enhances the cross-platform portability of Modelica models, promoting unified simulation standards in industry and fostering ecosystem collaboration.
[0048] The embodiments of the present invention can be applied to scenarios requiring Modelica model state fixation. The executing entity of this method can be an electronic device such as a terminal device, computer, server, server cluster, or specially designed Modelica model state fixation device, or it can be a Modelica model state fixation device installed in the electronic device, which can be implemented by software, hardware, or a combination of both.
[0049] Figure 1 This is one of the flowcharts illustrating the Modelica model state solidification method provided by the present invention, such as... Figure 1 As shown, the method includes the following steps:
[0050] Step 110: In response to the translation simulation request of the model to be solidified, translate the model to be solidified to obtain the model uncertainty characterization. The model uncertainty characterization includes the state variables selected for translation, the initial values of the initialization variables, the nonlinear iterative variables and their initial values for iteration. The initialization variables refer to the variables that need to be supplemented with initial values.
[0051] Specifically, the model to be solidified refers to the Modelica model that needs to be state-solidified. The model to be solidified can be the original uncertain model or a model that has already undergone state solidification; this embodiment of the invention does not impose specific limitations on this. The simulation results of the model to be solidified may be inconsistent due to default configurations or platform differences, requiring the elimination of uncertainties through the state solidification process.
[0052] Modelica is an object-oriented, equation-based, open-source, and efficient computer modeling language that enables unified modeling of complex cyber-physical systems across multiple domains, including mechanical, electronic, electrical, hydraulic, thermal, control, and process-oriented subsystem models. Users typically drag and drop model library components and connect them within the Modelica platform, which automatically writes the equations into the text file. Advanced users can also write equations directly into the model text file without using the Modelica platform. Regardless of the modeling method, all model information is ultimately stored in the Modelica text file.
[0053] Translation simulation requests are typically user-initiated instructions that require the Modelica platform to convert model code into a low-level executable simulation format, such as generating ODE equations, compiling solver code, and performing simulation analysis.
[0054] If a user clicks the "Run Simulation" button to trigger a translation simulation, the platform calls the Modelica compiler, such as the MWORKS.Sysplorer compiler, to convert the model code into an intermediate representation.
[0055] During the translation process, the platform automatically identifies differential variables and marks them as candidate state variables based on default rules to complete the selection of state variables; for differential or algebraic variables that do not have explicitly defined start values, it automatically estimates initial values, such as zero initialization or steady-state assumptions; and it identifies tearing variables in nonlinear equation systems through graph theory algorithms.
[0056] The compiler outputs a model translation report, which records information on the model's uncertainty representation, mainly including: the set of state variables, the initial variables and their initial values, and the set of nonlinear iterative variables and their initial values. Figure 2 This is a schematic diagram of the model to be solidified and the translation report provided by the present invention, as shown below. Figure 2 As shown, the left interface displays the loaded model to be solidified, and the right interface displays the selected state variables, the initial values used as initial conditions, the nonlinear system iteration variables and their initial iteration values.
[0057] Step 120: Perform at least one of the following steps and finally write it into the model to solidify the state of the translated model: determine the necessity of state variables, lock the determinism of initial values, provide initial values for nonlinear iterative variables and mark nonlinear iterative variables using vendor annotations.
[0058] Specifically, in the cross-platform simulation of Modelica models, directly using the translated default model may lead to inconsistent simulation results due to platform differences.
[0059] First, different Modelica platforms, or even different versions of the same platform, may employ different heuristic algorithms (such as those based on variable order or equation coupling strength) to select state variables, leading to the same model being translated into mathematically inequivalent systems of ordinary differential equations. For example, some platforms may misclassify higher-order differential variables as algebraic variables, thus disrupting the model's dynamic characteristics. Understandably, not all differential variables will be selected as state variables; therefore, the selection of which variables are chosen as state variables is uncertain. The selection of state variables significantly impacts the subsequent model translation structure, the choice of initial values, and the numerical solution, making it a crucial indicator in model translation.
[0060] Here, determining the mandatory selection of state variables means forcibly specifying certain variables as state variables to avoid platform misjudgment. This can be achieved by explicitly labeling or forcibly constraining key state variables (such as angles and velocities in mechanical systems) to ensure that all platforms follow a unified variable selection rule during translation, thus avoiding distortion of simulation results due to omissions or misjudgments of state variables.
[0061] Secondly, during the translation phase, the platform may automatically estimate the initial values of variables for which no explicit start value is defined, such as based on zero initialization or steady-state assumptions. However, the estimation logic differs between different platforms, leading to inconsistent initial conditions. The goal of this step in ensuring the determinism of initial values is to eliminate the randomness of the platform's automatic estimation of initial values and to eliminate initial condition bias. This can be achieved by explicitly defining the initial values of all initialization variables, ensuring that all platforms start from the same initial state and avoiding simulation result drift caused by initial value deviations, such as transient response curve shifts or steady-state value differences.
[0062] Furthermore, when solving nonlinear equations, the platform may select different nonlinear iteration variables based on graph theory algorithms, and their initial estimates may differ due to variations in platform implementation. If multiple solutions exist for the nonlinear equations, differences in variable selection may cause the solver to converge to different physical solutions. Therefore, it is necessary to provide initial values for the nonlinear iteration variables and mark them using vendor annotations. Since the Modelica language does not have a mechanism to restrict the selection of nonlinear iteration variables, vendor annotations can be used to explicitly define the nonlinear iteration variables. By marking key nonlinear iteration variables with vendor annotations and fixing their initial iteration values, the platform can be constrained to select a consistent set of variables, avoiding result bifurcation under multiple-solution problems and ensuring that the simulation results are unique and conform to physical expectations.
[0063] In addition, since both the initial time and the simulation time may involve nonlinear equations, it is necessary to use labels to explicitly define the initial nonlinear iteration variables and the model nonlinear iteration variables.
[0064] It should be noted that determining the necessity of state variables, locking the determinism of initial values, providing initial values for nonlinear iterative variables, and marking nonlinear iterative variables using vendor annotations can be performed by selecting one or more of these steps to solidify the state of the translated model. When multiple steps are selected, they can be executed sequentially or in parallel. When executed sequentially, there is no restriction on the order of execution.
[0065] After one or more of the above steps are completed, the key parameters or rules that have undergone state solidification, such as determining the mandatory nature of state variables, locking the deterministic nature of initial values, providing initial values for nonlinear iterative variables, and adding vendor annotations, are directly embedded into the model's structure or configuration file, becoming the underlying logic that the model must follow during runtime. The method of writing can depend on the model's carrier form, such as through model files, code, or configuration system solidification; this embodiment of the invention does not specifically limit this.
[0066] In summary, the method provided by this invention avoids inconsistencies in the classification of differential-algebraic variables caused by heuristic rules on the platform by determining the necessity of state variables, eliminates random fluctuations introduced by the platform's automatic estimation of initial values by locking the determinism of initial values, and ensures the consistency of variable selection by providing and labeling initial values for nonlinear iterative variables, thus avoiding result bifurcation under multi-solution problems. This eliminates ambiguity in the model translation process and achieves high consistency and reliability of cross-platform simulation results.
[0067] Based on any of the above embodiments, determining the mandatory nature of the state variable in step 120 specifically includes: adding the StateSelect.always attribute to the state variable; locking the determinism of the initial value includes: using the initial value selected by translation as the default initial condition, and adding the fixed=true attribute to the initial variable; providing the initial value of the nonlinear iterative variable includes: using the previous simulation result of the nonlinear iterative variable as the initial value of the nonlinear iterative variable.
[0068] Specifically, the Modelica language provides the `stateSelect` property to determine the priority of state variable selection. `StateSelect.always`, `StateSelect.prefer`, `StateSelect.default`, `StateSelect.avoid`, and `StateSelect.never` represent mandatory selection, preferred selection, default selection, avoidance selection, and no selection, respectively. Variables with the `stateSelect` property set to `StateSelect.always` must be selected as state variables (otherwise, the Modelica platform should report an error). Conversely, if all selected variables have the `stateSelect` property set to `StateSelect.always`, then the selection of state variables in this model is unique, and there is no ambiguity in state variable selection. Therefore, adding `StateSelect.always` to all state variables selected during the model state solidification process eliminates ambiguity in state variable selection within the model.
[0069] The Modelica language does not require the number of equations to equal the number of variables at the initial time step, as long as they are compatible. This facilitates the development of model libraries and allows modelers to customize the libraries according to their needs. In the absence of initial conditions, the Modelica platform uses a `start` value as a supplementary default initial condition. If there is no `start` value, real and integer variables will be padded with 0 as the initial condition, and boolean variables will be padded with `false`.
[0070] During the model translation process, the numerical solution of the initial value ordinary differential equation requires the initial values of the state variables. Inconsistent selection of state variables, inconsistent selection of start values, and inconsistent selection of start values of discrete variables can all lead to inconsistent results at the initial time, resulting in potentially vastly different simulation results on different platforms.
[0071] Therefore, the determinism of the locked initial value can be achieved by using the initial value selected by the translation as the default initial condition and adding the `fixed=true` attribute to the initialization variables. The Modelica language provides the `fixed=true` attribute to determine the `start` value as the initial condition. During the model state solidification process, the variables corresponding to the initial values supplemented by this translation, i.e., the initialization variables, are given the `fixed=true` attribute, ensuring that the number of equations equals the number of variables at the initial time step, thus eliminating the ambiguity of the default initial condition.
[0072] The model translation process may involve solving nonlinear equations. Most Modelica platforms currently use Newton's iteration method or its variants for this purpose. Not all variables need to be used as nonlinear iteration variables. Different Modelica platforms employ different strategies. Since nonlinear equations often have multiple solutions, different selections of nonlinear iteration variables (also known as nonlinear tearing) can significantly impact the results. Furthermore, even if the same nonlinear variables are selected, different `start` values chosen as the initial values for iteration can affect the final simulation results. In this embodiment, during the model state solidification process, the previous simulation result is used as the initial value for the nonlinear iteration variables. Here, the previous simulation result refers to the result obtained from the previous translation simulation, which includes the values of the nonlinear iteration variables after the previous translation.
[0073] Figure 3 This is a schematic diagram of the state-fixed model and translation report provided by the present invention. For example... Figure 3 As shown, the selected state variables in the translation report on the right side of the interface have the `StateSelect.always` attribute added, the initialization variables have the `fixed=true` attribute added, and the nonlinear iteration variables have a `start` value added. The nonlinear iteration variables are marked in the vendor annotation. Among them, the nonlinear iteration variables are further subdivided into initial value nonlinear iteration variables (`INonLinearVariables`) and model nonlinear iteration variables (`MNonLinearVariables`).
[0074] Based on any of the above embodiments, step 120, which involves state solidification of the translated model, includes:
[0075] Step 121: Determine whether the state variables, initialization variables, and nonlinear iteration variables are protection variables;
[0076] Step 122: If so, add the corresponding attributes and / or assign initial values to the protected variables in the vendor annotation;
[0077] Step 123: If not, add the corresponding attributes and / or assign initial values to the model to be solidified.
[0078] Specifically, in a Modelica model, variables declared as `protected` are typically used to encapsulate internal implementation details, preventing direct access or modification from the outside. Forcibly modifying them could lead to an invalid model. Therefore, when performing the three steps of determining the necessity of state variables, locking the determinism of initial values, and initializing nonlinear iteration variables, it's necessary to determine whether the involved state variables, initialization variables, and nonlinear iteration variables are protected variables. For example, this can be identified by traversing the declaration section of the model (within the model or block) to determine the variable's scope modifier. If the variable is declared within a `protected` block, it is a protected variable; if it is declared in a `public` block or has no explicit modifier, it is a non-protected variable.
[0079] Adding the corresponding attributes and / or assigning initial values here means adding the StateSelect.always attribute to the state variable, using the initial value selected by the translation as the default initial condition, and adding the fixed=true attribute to the initial variable, using the previous simulation result of the nonlinear iteration variable as the initial value of the nonlinear iteration variable.
[0080] If protected variables exist, add corresponding attributes and / or assign initial values to them in the vendor annotation. Vendor annotations are extended metadata tags supported by the Modelica language, defined by the tool vendor, and used to convey fixed constraint information to a specific platform. For example, adding the vendor annotation `StateSelect.always` at the declaration of a protected variable or at the top level of the model forces it to be a state variable.
[0081] If no protected variables exist, add attributes or initial values within the model to be solidified, such as in the global scope or public blocks, to ensure that constraints are visible and enforceable across all platforms.
[0082] The method provided in this invention can systematically solve the ambiguity problem in cross-platform simulation of Modelica models by distinguishing between protected and unprotected variables and fixing variable attributes and initial values by using vendor annotations (for protected variables) or model internal declarations (for unprotected variables).
[0083] Based on the above embodiments, step 110, translating the model to be solidified to obtain a model uncertainty characterization, includes:
[0084] Step 111: Parse the manufacturer annotations in the model to be solidified, and use the parsing results as additional translation information for the model;
[0085] Step 112: Translate the model to be solidified based on additional translation information to obtain the model uncertainty characterization.
[0086] Specifically, considering that the model to be solidified may include vendor annotations, the vendor annotations in the model can be parsed first when translating the model. The explicit intent of the modeler (such as forcing a variable to be a state variable, assigning initial values to variables, etc.) can be directly extracted through the vendor annotations. The parsed results are used as additional translation information for the model, avoiding the platform's default rules from covering key constraints and reducing the source of uncertainty from the outset.
[0087] For example, if a variable is annotated with StateSelect.always in the vendor's annotation, then the additional translation information will definitely show that the variable as a state variable, avoiding the risk that the platform may misjudge it as an algebraic variable.
[0088] By parsing vendor annotations and applying changes to the `stateSelect` attribute, `start` value, and `fixed=true` setting of variables, the unambiguity of state variable selection and initial conditions is ensured during subsequent translation. When selecting variables for nonlinear iteration, the vendor annotations are parsed, and variables appearing in the annotations are prioritized as nonlinear iteration variables, thus ensuring consistency in the selection of nonlinear variables.
[0089] In step 112, combining the annotation constraints in the additional translation information with the platform's default rules, state variables are selected, initial values are added, and nonlinear iterative variables are selected. The compiler then returns the final uncertainty information.
[0090] The method provided in this invention achieves collaborative optimization between vendor annotations and platform default rules by first parsing the vendor annotations and then translating them. This adapts to platform characteristics while ensuring the modeler's intent, and ultimately significantly improves the cross-platform consistency, portability, and simulation reliability of Modelica models.
[0091] Understandably, if the Modelica language specification provides official annotations for adding additional translation information in the future, the model state solidification method provided in this embodiment can be seamlessly migrated to the official annotation system, achieving a smooth transition from vendor-defined annotations to standardized annotations.
[0092] Based on any of the above embodiments, in response to the translation simulation request of the model to be solidified, before translating the model to be solidified, i.e. before step 110, the method further includes:
[0093] Step 101: Perform initial translation simulation on the model to be solidified to obtain initial simulation results;
[0094] Step 102: Receive the click operation to save the initial simulation results, and determine the translation simulation request of the model to be solidified based on the click operation.
[0095] Specifically, the initial translation simulation can be understood as an exploratory simulation performed by directly calling the solver before the model performs state solidification operations. This simulation is used to obtain preliminary behavioral data of the model under default configurations. In the Modelica platform, by selecting necessary settings, the model's uncertainties can be found in the translation report, and the Modelica platform will clearly indicate its selections. The final simulation result is the model's simulation result, i.e., the initial simulation result. The initial simulation result is the simulation data output by the initial translation simulation. It provides the entry point for the model state solidification function, and the initial simulation results also provide data for the model state solidification function.
[0096] Set an explicit button in the simulation results viewing interface, such as "Save current simulation results to model". When the user clicks it, it triggers a second translation simulation, which is the process of solidifying the model state.
[0097] In this embodiment, the initial translation simulation directly exposes the model's default behavior in its unfixed state, such as the state variables automatically selected by the platform and the estimated initial values, providing a clear benchmark for subsequent state fixing. The user is guided to trigger state fixing via an explicit button click, reducing operational complexity.
[0098] This invention achieves full-link automation from default behavior analysis to precise fixation through a closed-loop process of initial translation simulation, user click binding, and state solidification triggering. It not only provides quantifiable benchmark data for cross-platform model consistency, but also lowers the operational threshold through user interaction design, significantly improving the development efficiency and reliability of complex Modelica models.
[0099] Based on any of the above embodiments, the model to be solidified is translated to obtain a characterization of model uncertainty, including:
[0100] The model to be solidified is transformed from the original mathematical description differential algebraic equation (DAE) into a solvable initial value ordinary differential equation (ODE), and the uncertainty characterization of the model is determined based on the initial value ordinary differential equation.
[0101] Specifically, the Modelica model is essentially a language for describing mathematical equations, and its mathematical form is as follows:
[0102]
[0103] Where p is a constant or parameter, t is time, u is a control variable, and x is a differential variable. Let be the derivative of the differential variable, y be the output variable, z be the discrete variable, and pre(z) be the previous value of the discrete variable. Except for time, these variables are typically in vector form. The above equation is a differential-algebraic equation (DAE).
[0104] When translating a Modelica model, the Modelica platform converts the above differential-algebraic equations into solvable initial-value ordinary differential equations (ODEs), expressed by the formula:
[0105]
[0106]
[0107] Where p is a constant or parameter, t is time, u represents the control variable, and x is the state variable. Let y be the derivative of the state variable, y be the output variable, and z be the discrete variable.
[0108] Based on any of the above embodiments Figure 4 This is the second flowchart illustrating the Modelica model state solidification method provided by this invention, as shown below. Figure 4 As shown, the method includes:
[0109] Step S1: Perform translation simulation on the original Modelica model. After the simulation is completed normally, click "Save Simulation Results to Model". The original model can be the model to be solidified. Perform initial translation simulation on the model to be solidified to obtain initial simulation results; receive the click operation to save the initial simulation results, and determine the translation simulation request for the model to be solidified based on the click operation.
[0110] Step S2: Click "Save Simulation Results to Model" to trigger the second translation. That is, in response to the translation simulation request of the model to be solidified, the model to be solidified is translated, and the model uncertainty characterization is found. The model uncertainty characterization includes the initial values of the selected state variables, the initial values of the initialization variables, the nonlinear iterative variables and their initial iteration values.
[0111] Preferably, in the second translation process, the manufacturer's annotations are parsed first, and the parsing results are used as additional translation information for the model. Then, translation simulation is performed based on the additional translation information.
[0112] The process of translating the model to be solidified and finding the uncertainty characterization of the model includes: transforming the original mathematical description differential algebraic equation (DAE) of the model to be solidified into a solvable initial value ordinary differential equation (ODE), and determining the uncertainty characterization of the model based on the initial value ordinary differential equation.
[0113] Step S3: Add the StateSelect.always property to the state variable selected for translation.
[0114] Step S4: Use the selected start value for translation as the default initial condition, and convert it into an initial condition by adding the fixed=true attribute.
[0115] Step S5: Supplement the simulation results of the selected nonlinear iterative variable at the initial time step with its initial iteration value, and clarify the nonlinear iterative variable using the manufacturer's annotation. Steps S3, S4, and S5 do not have a fixed order and can be executed in parallel.
[0116] Step S6: Determine whether the state variables, initialization variables, and nonlinear iteration variables in S3, S4, and S5 are protected variables. If so, save the changes to the protected variables using the manufacturer's annotation.
[0117] The Modelica model state fixation method provided in this embodiment can eliminate translation ambiguity in Modelica models, thereby ensuring consistency of translation results across different platforms. Since Modelica does not allow modification of protected variables and lacks a mechanism for restricting the selection of nonlinear iterative variables, the method provided in this embodiment innovatively saves information for eliminating translation ambiguity through vendor annotations. This adheres to Modelica's grammatical constraints while meeting the cross-platform requirements of complex simulation scenarios through the annotation layer. This method requires the Modelica platform to parse the vendor annotations to completely eliminate model translation ambiguity. Even if the Modelica platform does not parse the vendor annotations, it can still largely avoid model translation ambiguity, ultimately ensuring that the simulation results are essentially consistent when the same model is simulated using the same simulation settings on different Modelica platforms. Because this model state fixation method completes the above operations with a single click, it greatly eliminates users' concerns about inconsistent results caused by upgrading Modelica platform versions or switching Modelica platforms.
[0118] The Modelica model state solidification apparatus provided by the present invention is described below. The Modelica model state solidification apparatus described below and the Modelica model state solidification method described above can be referred to in correspondence.
[0119] Based on the above embodiments, Figure 5 This is a schematic diagram of the Modelica model state solidification device provided by the present invention, as shown below. Figure 5 As shown, the device includes:
[0120] The model translation unit 510 is used to translate the model to be solidified in response to the translation simulation request of the model to be solidified, and to obtain the model uncertainty characterization. The model uncertainty characterization includes the state variables selected for translation, the initial values of the initialization variables, the nonlinear iterative variables and their initial values for iteration. The initialization variables refer to the variables that need to be supplemented with initial values.
[0121] The state solidification unit 520 is used to perform at least one of the following steps and finally write it into the model to solidify the state of the translated model: determining the necessity of the state variables, locking the determinism of the initial values, providing the initial values of the nonlinear iterative variables and marking the nonlinear iterative variables with manufacturer annotations.
[0122] The apparatus provided in this invention avoids inconsistencies in the classification of differential-algebraic variables caused by heuristic rules on the platform by determining the necessity of state variables, eliminates random fluctuations introduced by the platform's automatic estimation of initial values by locking the determinism of initial values, and ensures the consistency of variable selection by providing and marking the initial values of nonlinear iterative variables, thus avoiding result bifurcation in multi-solution problems. Then, the necessity of state variables, the determinism of initial values, the initial values of nonlinear iterative variables, and the manufacturer's annotations are finally written into the model, thereby eliminating ambiguity in the model translation process and achieving high consistency and reliability of cross-platform simulation results.
[0123] Based on the above embodiments, the state curing unit 520 is specifically used for:
[0124] Add the StateSelect.always property to the state variable;
[0125] The initial value selected for translation is used as the default initial condition, and the fixed=true attribute is added to the initial variable;
[0126] The previous simulation result of the nonlinear iterative variable is used as the initial value of the nonlinear iterative variable.
[0127] Based on the above embodiments, the state curing unit 520 is specifically used for:
[0128] Determine whether the state variable, initialization variable, and nonlinear iteration variable are protection variables;
[0129] If so, add the corresponding attributes and / or assign initial values to the protected variables in the vendor annotation;
[0130] If not, add the corresponding attributes and / or assign initial values to the model to be solidified.
[0131] Based on the above embodiments, the model translation unit is specifically used for:
[0132] Parse the manufacturer annotations in the model to be solidified, and use the parsing results as additional translation information for the model;
[0133] The model to be solidified is translated based on the additional translation information to obtain the uncertainty characterization of the model.
[0134] Based on the above embodiments, an initial translation unit is also included, specifically for:
[0135] An initial translation simulation was performed on the model to be solidified, and initial simulation results were obtained.
[0136] The system receives a click operation to save the initial simulation results and determines a translation simulation request for the model to be solidified based on the click operation.
[0137] Based on the above embodiments, the model translation unit is specifically used for:
[0138] The model to be solidified is transformed from the original mathematical description differential algebraic equation (DAE) into a solvable initial value ordinary differential equation (ODE), and the uncertainty characterization of the model is determined based on the initial value ordinary differential equation.
[0139] Figure 6 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 6 As shown, the electronic device may include: a processor 610, a communications interface 620, a memory 630, and a communication bus 640, wherein the processor 610, the communications interface 620, and the memory 630 communicate with each other through the communication bus 640. The processor 610 can call logic instructions in the memory 630 to execute the Modelica model state solidification method, which includes: responding to a translation simulation request of the model to be solidified, translating the model to be solidified to obtain a model uncertainty representation, the model uncertainty representation including the state variables selected for translation, the initial values of the initialization variables, the nonlinear iterative variables and their initial iteration values, the initialization variables being variables that need to be supplemented with initial values; performing at least one of the following steps and finally writing it into the model to solidify the translated model state: determining the necessity of the state variables, locking the determinism of the initial values, providing the initial iteration values of the nonlinear iterative variables and marking the nonlinear iterative variables with manufacturer annotations.
[0140] Furthermore, the logical instructions in the aforementioned memory 630 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0141] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the Modelica model state solidification method provided by the above methods. The method includes: responding to a translation simulation request of the model to be solidified, translating the model to be solidified to obtain a model uncertainty characterization, the model uncertainty characterization including the state variables selected for translation, the initial values of the initialization variables, the nonlinear iterative variables and their initial iteration values, the initialization variables being variables that need to be supplemented with initial values; performing at least one of the following steps and finally writing it into the model to solidify the translated model state: determining the necessity of the state variables, locking the determinism of the initial values, providing the initial iteration values of the nonlinear iterative variables and marking the nonlinear iterative variables using manufacturer annotations.
[0142] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the Modelica model state solidification method provided by the above methods. The method includes: in response to a translation simulation request of the model to be solidified, translating the model to be solidified to obtain a model uncertainty representation, the model uncertainty representation including the translated selected state variables, the initial values of the initialization variables, the nonlinear iterative variables and their initial iteration values, the initialization variables being variables that need to be supplemented with initial values; performing at least one of the following steps and finally writing it into the model to solidify the translated model state: determining the necessity of the state variables, locking the determinism of the initial values, providing the initial iteration values of the nonlinear iterative variables and marking the nonlinear iterative variables using manufacturer annotations.
[0143] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0144] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0145] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method of Modelica model state solidification, characterized by, The method comprises the following steps: in response to a translation simulation request of a model to be solidified, translating the model to be solidified to obtain a model uncertainty representation, wherein the model uncertainty representation comprises state variables selected by translation, initial values of complementary variables, nonlinear iteration variables and their iteration initial values, and the complementary variables refer to variables that need to be supplemented with initial values; performing at least one of the following steps and finally writing into the model to solidify the state of the translated model: determining the necessity of the state variables, determining the certainty of the locked initial values, providing the iteration initial values of the nonlinear iteration variables and marking the nonlinear iteration variables by using vendor annotations; the step of determining the necessity of the state variables comprises adding a StateSelect.always attribute to the state variables; the step of determining the certainty of the locked initial values comprises taking the initial values selected by translation as the default initial conditions and adding a fixed=true attribute to the complementary variables; the step of providing the iteration initial values of the nonlinear iteration variables comprises taking the last simulation result of the nonlinear iteration variables as the iteration initial values of the nonlinear iteration variables.
2. The Modelica model state solidification method of claim 1, wherein, The step of solidifying the state of the translated model comprises: judging whether the state variables, the complementary variables and the nonlinear iteration variables are protected variables; if yes, adding corresponding attributes and / or initial values to the protected variables in the vendor annotations; if no, adding corresponding attributes and / or initial values inside the model to be solidified.
3. The Modelica model state solidification method of claim 2, wherein, The step of translating the model to be solidified to obtain a model uncertainty representation comprises: analyzing the vendor annotations in the model to be solidified and taking the analysis result as additional translation information of the model; based on the additional translation information, translating the model to be solidified to obtain the model uncertainty representation.
4. The Modelica model state solidification method according to any one of claims 1 to 3, characterized in that, Before the step of translating the model to be solidified in response to the translation simulation request, the method further comprises: performing initial translation simulation on the model to be solidified to obtain initial simulation results; receiving a click operation of saving the initial simulation results and determining the translation simulation request of the model to be solidified based on the click operation.
5. The Modelica model state solidification method according to any one of claims 1 to 3, characterized in that, The step of translating the model to be solidified to obtain a model uncertainty representation comprises: converting the model to be solidified from original mathematical description differential algebraic equation (DAE) into solvable initial value ordinary differential equation (ODE), and determining the model uncertainty representation based on the initial value ordinary differential equation.
6. A Modelica model state solidification apparatus, characterized by, The method comprises: a model translation unit, configured to translate a model to be solidified in response to a translation simulation request of the model to be solidified to obtain a model uncertainty representation, wherein the model uncertainty representation comprises state variables selected by translation, initial values of complementary variables, nonlinear iteration variables and their iteration initial values, and the complementary variables refer to variables that need to be supplemented with initial values; a state solidification unit, configured to perform at least one of the following steps and finally write into the model to solidify the state of the translated model: determining the necessity of the state variables, determining the certainty of the locked initial values, providing the iteration initial values of the nonlinear iteration variables and marking the nonlinear iteration variables by using vendor annotations; The determining of the necessity of the state variable comprises adding a StateSelect.always attribute to the state variable; The determining of the certainty of the initial value of the lock comprises taking the initial value of the translation selection as a default initial condition, and adding a fixed=true attribute to the initial variable; The providing of the initial value of the nonlinear iteration variable comprises taking the last simulation result of the nonlinear iteration variable as the initial value of the nonlinear iteration variable.
7. An electronic device comprising a memory, a processor, and a computer program stored on the memory and running on the processor, characterized in that, The processor executes the computer program to realize the Modelica model state solidification method in any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to realize the Modelica model state solidification method in any one of claims 1 to 5.
9. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to realize the Modelica model state solidification method in any one of claims 1 to 5.
Citation Information
Patent Citations
Hierarchical nonlinear physical model compiling optimization method and related equipment
CN119378270A
Modelica model-oriented initial steady-state compiling method and system
CN119396408A