Universal operation method and device for simulation modeling model
By designing a general method and device for running simulation modeling, and adopting an object-oriented design pattern, a running framework for X language models was constructed. This solved the problem of X language being difficult to run efficiently on hardware platforms, and enabled efficient development of X language models and seamless integration of simulation modeling languages.
Patent Information
- Application Number
- CN202511099052.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-06
- Publication Date
- 2025-11-21
AI Technical Summary
The existing X language simulation modeling technology lacks an effective operating framework, making it difficult to run efficiently on computer hardware platforms.
A general method and device for running simulation modeling models are designed. It adopts an object-oriented design pattern and provides runnable implementations and model management functions for continuous classes, discrete classes, coupled classes, connector classes, method classes, and record classes. It uses the X language to implement features such as type information, model inheritance relationships, parameter definitions, ports, and event mechanisms, constructs a set of simulation modeling models, and uses computer programming languages to represent and deploy them on computing devices for operation.
It enables efficient operation of the X language model on the hardware platform, improves the development efficiency and time of simulation modeling language, breaks through the breakpoints between system-level and physical-level model simulation, and supports seamless integrated simulation of the entire system, the entire process, and multiple perspectives.
Smart Images

Figure CN120995685A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer compilation technology and simulation modeling technology, specifically to a general method and apparatus for running simulation modeling models. Background Technology
[0002] X language is a next-generation integrated modeling and simulation language supporting MBSE (Multi-Physical Environment Response) for complex systems. It provides standardized graphical modeling descriptions during the product concept design phase and can automatically compile these graphical models into text-based low-level simulation models. Driven by a simulation engine, it supports seamless integrated simulation across the entire system, the entire process, and multiple perspectives, achieving unified description and simulation from conceptual model design, system architecture design, multi-physics domain models to simulation models. As a newly designed modeling language, the current work focuses on theoretical foundations and methodologies. A supporting toolset is needed to move from theory to practice, enabling efficient and concise operation on various computer hardware platforms. Currently, the executable model framework technology for X language is lacking. Summary of the Invention
[0003] This invention primarily addresses the problem of designing and implementing an efficient and concise method for running simulation modeling languages. This invention discloses a general method and apparatus for running simulation modeling models.
[0004] In a first aspect, this invention discloses a general method for running a simulation modeling model, comprising:
[0005] S1, Collect a set of physical data; the set of physical data includes a discrete data subset, a continuous data subset, and a coupled data subset;
[0006] S2, Based on the physical data set, a set of simulation modeling models is constructed; the set of simulation modeling models includes discrete models, continuous models, and coupled models;
[0007] S3, Represent the simulation model set using a computer programming language to obtain a set of executable programs for the model;
[0008] S4. Deploy the set of executable programs for the model on a computing device to run it, so as to realize the general operation of the simulation modeling model.
[0009] Each type of model in the simulation modeling model set includes model implementation information and model common characteristic information;
[0010] The common characteristic information of the model includes X language implementation type information, model inheritance relationship, parameter definition, port, connect information, and event mechanism information;
[0011] The model implementation information includes the model's input data definition, output data definition, and pattern implementation method information.
[0012] The set of simulation modeling models constructed based on the physical data set includes:
[0013] S21, Based on a subset of discrete data, a discrete class model is constructed;
[0014] S22, a continuous class model is constructed based on a continuous subset of data;
[0015] S23, Based on the coupled data subset, a coupled class model is constructed;
[0016] S24. Using the discrete class model, continuous class model and coupled class model, a set of simulation modeling models is constructed.
[0017] The continuous class model constructed based on a continuous subset of data includes:
[0018] S221, Perform statistical modeling processing on the continuous data subset to obtain statistical distribution information; the continuous data subset is state collection data collected from the modeling object at several historical moments.
[0019] S222, Based on the statistical distribution information, the preset transition state equation is processed to obtain a continuous class model.
[0020] The statistical modeling process performed on the continuous data subset to obtain statistical distribution information includes:
[0021] S2211, Perform parameter estimation processing on the continuous data subset to obtain a set of parameter estimates; the set of parameter estimates is a set of parameter values obtained by using several parameter estimation methods on the continuous data subset; the parameter estimation methods include method of moments estimation, maximum likelihood estimation, Bayesian estimation, and interval estimation; the parameter types in the set of parameter estimates include mean and variance;
[0022] S2212, Perform hypothesis testing on the set of parameter estimates to obtain a set of parameter estimates that pass the test;
[0023] S2213, perform fusion calculation on the set of parameter estimates that have passed the test to obtain statistical distribution information.
[0024] The process of fusing and calculating the set of parameter estimates that have passed the test to obtain statistical distribution information includes:
[0025] A first fusion calculation is performed on all the means in the set of parameter estimates that have passed the test to obtain the fusion mean;
[0026] A second fusion calculation is performed on all variances in the set of parameter estimates that have passed the test to obtain the fused variance;
[0027] The expression for the first fusion calculation is:
[0028]
[0029] Where a0 is the fusion mean, u i Let ui be the i-th mean in the set of parameter estimates that have passed the test, u0 be the average of all means, and M be the total number of means in the set of parameter estimates that have passed the test.
[0030] The step of representing the simulation model set using a computer programming language to obtain a set of executable programs for the models includes:
[0031] S31, using class definitions in computer programming languages, represents the common characteristic information of each type of model to obtain the corresponding model definition information;
[0032] S32 uses the X language modeling specification and computer programming language to characterize the model implementation information of each type of model, and obtain the model implementation function information corresponding to the model.
[0033] S33, using all the model definition information and model implementation function information, constructs a set of executable programs for the model.
[0034] A second aspect of the present invention discloses a general-purpose running device for simulation modeling models, the device comprising:
[0035] Memory containing executable program code;
[0036] A processor coupled to the memory;
[0037] The processor calls the executable program code stored in the memory to execute the general running method of the simulation modeling model.
[0038] In a third aspect of this invention, a computer-storable medium is disclosed, wherein the computer-storable medium stores computer instructions, and when the computer instructions are invoked by a computer, they are used to execute a general running method for the simulation modeling model.
[0039] In a fourth aspect of this invention, an information data processing terminal is disclosed, which is used to implement a general running method for the simulation modeling model.
[0040] The beneficial effects of this invention are as follows:
[0041] This invention discloses a runtime framework that provides a foundation for running next-generation simulation modeling languages, such as the X language. Engineers can manually convert X language models developed from the perspective of complex system modeling into extension modules under this framework, thereby enabling the X language model to run. This allows the X language to truly move from theoretical design to practical application, improving the running efficiency and development time of simulation modeling languages on hardware platforms.
[0042] The framework implemented in this invention deeply embodies object-oriented and interface-oriented principles. It is highly scalable and has the ability to automatically load and recognize X language C++ models. It provides rules for the compilation and generation of all X language code and lays the foundation for the development of AOT and JIT compilers. Attached Figure Description
[0043] Figure 1 This is a flowchart illustrating the implementation of the method of the present invention. Detailed Implementation
[0044] To better understand the content of this invention, an embodiment is provided here.
[0045] Figure 1 This is a flowchart illustrating the implementation of the method of the present invention.
[0046] In a first aspect, this invention discloses a general method for running a simulation modeling model, comprising:
[0047] S1, Collect a set of physical data; the set of physical data includes a discrete data subset, a continuous data subset, and a coupled data subset;
[0048] S2, Based on the physical data set, a set of simulation modeling models is constructed; the set of simulation modeling models includes discrete models, continuous models, and coupled models;
[0049] S3, Represent the simulation model set using a computer programming language to obtain a set of executable programs for the model;
[0050] S4. Deploy the set of executable programs for the model on a computing device to run it, so as to realize the general operation of the simulation modeling model.
[0051] For a newly designed modeling language to achieve practical engineering capabilities, it requires a runnable model framework as support. This framework must be capable of scheduling and executing according to the characteristics of the X language. This invention comprises a runnable X language model framework implementation. This framework provides concrete, executable interface descriptions for all types and features of the X language, serving as the basic framework for X language compilation. The X language compiler compiles X language code into model extensions within this framework, enabling the compilation and execution of the X language model. The main innovation of this framework lies in its design of a model framework that bridges the simulation breakpoints of system-level and physical-level models, addressing the different simulation scaling requirements of system-level and physical-level models. It proposes a practical and executable solution to achieve the design requirement of bridging simulation breakpoints between system-level and physical-level models in the X language.
[0052] The coupled data subset includes a data subset that simultaneously includes both continuous and discrete data;
[0053] The coupled class refers to one that simultaneously contains both continuous and discrete data;
[0054] Each type of model in the simulation modeling model set includes model implementation information and model common characteristic information;
[0055] The common characteristic information of the model includes X language implementation type information, model inheritance relationship, parameter definition, port, connect information, and event mechanism information;
[0056] The model implementation information includes the model's input data definition, output data definition, and pattern implementation method information;
[0057] The connect information refers to the connection relationship information between the ports of each module; the connection relationship information can be linear connection, series connection, etc.
[0058] The event mechanism information refers to the event implementation method that realizes common characteristics. It is a design pattern for inter-object communication, used to handle scenarios such as state changes or user interactions. It allows an object (called the "event sender") to trigger an "event" under specific conditions, while other objects (called "event receivers") can register and respond to this event, achieving a loosely coupled interaction method.
[0059] The X language implementation type information refers to continuous classes, discrete classes, and coupled classes, etc.
[0060] X language is a modeling and simulation language. It is a new generation modeling and simulation language that supports MBSE (Model-Based Systems Engineering), enabling integrated modeling and simulation of complex systems at the system level and their functional performance verification.
[0061] The set of simulation modeling models constructed based on the physical data set includes:
[0062] S21, Based on a subset of discrete data, a discrete class model is constructed;
[0063] S22, a continuous class model is constructed based on a continuous subset of data;
[0064] S23, Based on the coupled data subset, a coupled class model is constructed;
[0065] S24. Using the discrete class model, continuous class model and coupled class model, a set of simulation modeling models is constructed;
[0066] The continuous class model constructed based on a continuous subset of data includes:
[0067] S221, Perform statistical modeling processing on the continuous data subset to obtain statistical distribution information; the continuous data subset is state collection data of the modeling object collected at several historical moments.
[0068] The modeling object is the object whose physical working process needs to be modeled in the simulation modeling model, and can be a physical object such as an engine;
[0069] The state acquisition data refers to the state acquisition data of the modeling object during operation;
[0070] S222, Based on the statistical distribution information, the preset transition state equation is processed to obtain a continuous class model;
[0071] The statistical modeling process performed on the continuous data subset to obtain statistical distribution information includes:
[0072] S2211, Perform parameter estimation processing on the continuous data subset to obtain a set of parameter estimates; the set of parameter estimates is a set of parameter values obtained by using several parameter estimation methods on the continuous data subset; the parameter estimation methods include method of moments estimation, maximum likelihood estimation, Bayesian estimation, and interval estimation; the parameter types in the set of parameter estimates include mean and variance;
[0073] S2212, Perform hypothesis testing on the set of parameter estimates to obtain a set of parameter estimates that pass the test;
[0074] S2213, perform fusion calculation on the set of parameter estimates that have passed the test to obtain statistical distribution information;
[0075] The hypothesis testing of the parameter estimate set to obtain the parameter estimate set that passes the test involves performing u-test, t-test, and F-test on the parameter values obtained by each parameter estimation method. Only when all three tests pass is the parameter value confirmed to have passed the test. The parameter estimate set that passes the test is constructed using all the parameter estimates that pass the test.
[0076] The process of fusing and calculating the set of parameter estimates that have passed the test to obtain statistical distribution information includes:
[0077] A first fusion calculation is performed on all the means in the set of parameter estimates that have passed the test to obtain the fusion mean;
[0078] A second fusion calculation is performed on all variances in the set of parameter estimates that have passed the test to obtain the fused variance;
[0079] The expression for the first fusion calculation is:
[0080]
[0081] Where a0 is the fusion mean, u i Let ui be the i-th mean in the set of parameter estimates that have passed the test, u0 be the average of all means, and M be the total number of means in the set of parameter estimates that have passed the test.
[0082] The expression for the second fusion calculation is:
[0083]
[0084] Where b0 is the fusion variance, N is the total number of variances in the set of parameter estimates that passed the test, and θ max and θ min Let θ be the maximum and minimum values of all variances, respectively. j Let be the j-th variance in the set of parameter estimates that have passed the test.
[0085] When performing parameter estimation on the continuous data subset, it is assumed that it follows a normal distribution.
[0086] The step of processing the preset transition state equation based on the statistical distribution information to obtain a continuous class model includes:
[0087] The pre-defined expression for the transition state equation is:
[0088] x(k+1)=Φ(k+1,k)x(k)+G(k)w(k)
[0089] Where Φ(k+1,k) represents the state transition matrix at time k, which is a known quantity of the model; G(k) represents the noise matrix at time k, which is a known quantity; w(k) represents the state noise at time k; x(k) represents the input at time k; and x(k+1) represents the output at time k+1.
[0090] Based on the statistical distribution information, state noise w(k) is generated; the state noise w(k) follows a normal distribution with a mean and a variance of a0 and b0, respectively.
[0091] The state noise w(k) is added to the preset transition state equation to obtain a continuous class model. The input of the continuous class model is x(k), and the output is x(k+1).
[0092] The step of representing the simulation model set using a computer programming language to obtain a set of executable programs for the models includes:
[0093] S31, using class definitions in computer programming languages, represents the common characteristic information of each type of model to obtain the corresponding model definition information;
[0094] S32 uses the X language modeling specification and computer programming language to characterize the model implementation information of each type of model, and obtain the model implementation function information corresponding to the model.
[0095] S33, using all the model definition information and model implementation function information, constructs a set of executable programs for the model.
[0096] The X language modeling specification and computer programming language are used to characterize the model implementation information of each type of model, obtaining model implementation function information, including:
[0097] S321 uses the X language modeling specification to represent the model implementation information of each type of model, thus obtaining model representation information;
[0098] S322, the model representation information is escaped to obtain the model implementation function information corresponding to the model;
[0099] The escape processing can be implemented using the lexical analysis function of the C++ compiler GCC;
[0100] The escaping process first establishes a mapping relationship between all model representation information of the modeling language and the corresponding C++ language model implementation function information. Then, the model representation information to be escaped is processed using the mapping relationship to obtain the escaping result information.
[0101] The computer programming language can be C++.
[0102] The common characteristics of the model include features such as X language type implementation, model inheritance relationship, parameter definition, port, and event mechanism;
[0103] The model implementation information includes model implementation equations, mathematical expressions, neural network representations, etc.
[0104] The discrete class model constructed based on discrete data subsets includes:
[0105] The discrete data subset includes the input dataset and the label dataset; the preset discrete class model is a neural network model; specifically, a ResNet network, etc., can be used.
[0106] Using the input dataset and label dataset, a neural network training method, such as the steepest descent method, is employed to train the preset discrete class model, thereby obtaining the discrete class model.
[0107] The coupled class model constructed based on the coupled data subset can be constructed using the same method as the model constructed based on the discrete data subset.
[0108] A second aspect of the present invention discloses a general-purpose running device for simulation modeling models, the device comprising:
[0109] Memory containing executable program code;
[0110] A processor coupled to the memory;
[0111] The processor calls the executable program code stored in the memory to execute the general running method of the simulation modeling model.
[0112] In a third aspect of this invention, a computer-storable medium is disclosed, wherein the computer-storable medium stores computer instructions, and when the computer instructions are invoked by a computer, they are used to execute a general running method for the simulation modeling model.
[0113] In a fourth aspect of this invention, an information data processing terminal is disclosed, which is used to implement a general running method for the simulation modeling model.
[0114] In a fourth aspect of the present invention, a general method for running a simulation model is disclosed.
[0115] The technology described in this invention provides a runnable model framework for a newly designed modeling language, X. This framework adopts an object-oriented design pattern and provides runnable implementations and model management functions for continuous classes, discrete classes, coupled classes, linker classes, method classes, and record classes. The model framework collects and manages the attribute information of the X language model in the form of metadata, supports subclassing to extend the X language model, and provides a compilation target framework for the X language compiler. This enables X language to establish breakpoints between system-level and physical-level model simulations, achieving the design goal of enabling discrete event simulation and continuous solution simulation to be computed and connected in the same spatiotemporal domain.
[0116] The main steps of this invention are as follows:
[0117] 1. Using object-oriented principles, implement C++ base class representations for all X language types, including coupled classes, continuous classes, discrete classes, method classes, record classes, linker classes, and other X language model types. Each X language model type has a C++ class that is the executable representation of its corresponding X language type. The following are the six most important types.
[0118] XLFunction->function class
[0119] XLDiscrete->discrete discrete class
[0120] XLContinuous->continous continuum class
[0121] XLCouple->couple coupling class
[0122] XLRecord->record class
[0123] XLConnector->connector class
[0124] class XLANGUAGECORE_DECL XLDiscrete:public XLObject
[0125] {
[0126] TS_MetaType(XLDiscrete,XLObject);
[0127] TS_DECLARE_PRIVATE(XLDiscrete);
[0128] public:
[0129] XLDiscrete();
[0130] XLDiscrete(PrivateType*p);
[0131] ~XLDiscrete();
[0132] public:
[0133] / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
[0134] / / / <summary> Model Logic Preparation< / summary>
[0135] / / /
[0136] / / / <remarks> This function is not thread-safe. XSimStudio Team, 2015 / 8 / 31.< / remarks>
[0137] / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
[0138] virtual void PrepareData();
[0139] virtual bool Send(XLPortValuePtr PortValue);
[0140] virtual void Step();
[0141] public:
[0142] void SetStateMachine(XLStateMachinePtr Machine);
[0143] XLStateMachinePtr GetStateMachine();
[0144] void AddState(XLStateElementPtr State);
[0145] public:
[0146] virtual void OnReceived(const XLPortDesc&Desc,XLPortValuePtrPortValue);
[0147] };
[0148] Implement the common features of the X language model, including X language type implementation, model inheritance relationships, parameter definitions, ports, connect, event mechanisms, and other features.
[0149] • X language type implementation: Atomic types in the X language include int, real, string, bool, array, list, map, etc. These classes all have corresponding counterparts in C++ syntax. real uses double mapping.
[0150] • Parameter Definition: In the X language design, variables are categorized into temporary variables (mutable at runtime of the model instance) and attribute variables (immutable parameters). The characteristics of temporary variables in the model framework correspond to member variables in C++ classes. Attribute variables are similar to performance parameters of a device; they are identical in templates for the same type. Metadata collection functionality, implemented using C++ template technology, enables dynamic registration and persistence of model attributes. Attribute information is collected through metatype collection macros, providing serialization and deserialization capabilities.
[0151] Macro definition code:
[0152] #define GetXLTypeRegister(Class)\
[0153] (*XLMetaType::Instance())
[0154] #define RegisterXLProperty(VarName,MemberType)\
[0155] AddProperty(ThisType::GetMetaTypeNameStatic(),GetMetaTypeId <thistype>(reinterpret_cast<ThisType*> (0)),TS_TEXT(#VarName),MemberType,®_PROP_FIELD(VarName))
[0156] • Inheritance: The X language supports model inheritance, which can use the properties, methods, ports, etc. of the base class model. This design of the X language is implemented in the model framework using C++ class inheritance.
[0157] Input / output ports: In the X language, input / output ports represent the input and output values of the model in each runtime cycle. The model's input and output ports are linked through the `connect` function in the coupling function. For example, model A has an output port `outp`, and model B has an input port `inputp`. In the coupled model, they are linked using `connect(A.outp, B.inputp)`. When the output port changes, the input port value of model B changes accordingly. In the model framework, the `Input` and `Output` flags are attached during dynamic registration of model attributes to allow the framework to collect port type information.
[0158] • Connect: In the X language, the connect function is used to associate the input and output relationships between models. In the model framework, a mechanism is used to prioritize the execution of static macro command functions when the C++ dynamic library is loaded. A port connection relationship registration macro is designed to register the port relationships between models into the framework when the model library is loaded, so that the feature of mapping the output port to the associated input port as soon as possible when the output port changes during runtime is supported.
[0159] Macro definition code:
[0160] #define RegisterConnectProperty(Source,SPort,Target,TPort)\
[0161] AddConnectProperty(ThisType::GetMetaTypeNameStatic(),GetMetaTypeId <thistype>(reinterpret_cast <ThisType
[0162] *>(0)),TS_TEXT(#Source),TS_TEXT(SPort),TS_TEXT(#Target),TS_TEXT(TPort))
[0163] • Event mechanism: In the X language, the event sending and receiving mechanism is implemented through the send(outputport1 o1) / receive(inputporti1) functions. Messages are divided into output port change events and message events.
[0164] The model framework is implemented in the model base class.
[0165] The virtual bool Send(XLPortValuePtr PortValue) and virtual void OnReceived(const XLPortDesc&Desc,XLPortValuePtr PortValue) functions implement the characteristics of port change events.
[0166] Notes:
[0167] The above are macro definitions declared within the framework for registering various X language attributes and specific types. Below are examples of how macro definitions are used when the compiler generates C++ code for the X language model according to this framework.
[0168] Example of a continuum class in the X language:
[0169] Continuous Engine
[0170] import Interpolation2D;
[0171] parameter:
[0172] real Iei=0.021991488283555904;
[0173] real Tex[]=[0,20,30,40,50,60,70,80,90,100];
[0174] real Tey[]=[800,1200,1600,2000,2400,2800,3200,3600,4000,4400,4800];
[0175] real fun
[10]
[11] =[-40,-44,-49,-53,-57,-61,-65,-70,-74,-78,-82,215,117,85,66,44,29,10,-2,-13,-22,-32,245,208,178,14 8,122,104,85,66,48,33,18,264,260,241,219,193,167,152,133,119,96,85,264,279,282,275,260,238,223,208,189,171,15 2,267,290,293,297,290,275,260,256,234,212,193,267,297,305,305,305,301,293,282,267,249,226,267,301,308,312,319,323,319,316,297,279,253,267,301,312,319,327,327,327,327,312,293,267,267,301,312,319,327,334,334,319,305,175];
[0176] value:
[0177] real Te; #torque
[0178] port:
[0179] input real Ti
[0180] input real Throttle
[0181] Output real Ne# rotation speed
[0182] equation:
[0183] Te=Interpolation2D(Throttle,Ne,fun,Tex,10,Tey,11)
[0184] der(Ne)=(Te-Ti) / Iei
[0185] end
[0186] Example of generated C++ code property registration:
[0187] BEGIN_METADATA(ContinuousEngine)
[0188] REG_BASE(XLContinuous);
[0189] GetXLTypeRegister(ContinuousEngine).RegisterXLProperty(Throttle,XL_EventInputProperty);
[0190] GetXLTypeRegister(ContinuousEngine).RegisterXLProperty(Ti,XL_OutputProperty);
[0191] GetXLTypeRegister(ContinuousEngine).RegisterXLProperty(Ne,XL_OutputProperty).RegisterXLEquation(Der_Ne_Fun,"",true,"Ne","Te,Ti,Iei");
[0192] GetXLTypeRegister(ContinuousEngine).RegisterXLProperty(Te,XL_OutputProperty).RegisterXLEquation(Te_Fun,"Te",false,"Throttle,Ne,fun,Tex,Tey");
[0193] END_METADATA()
[0194] 2. In accordance with the X language modeling specification, discrete classes support a state machine modeling module, which supports declaring state names using X language syntax, executing developed code when entering a state, performing state condition checks (through event acceptance, timer patterns, conditional judgments, etc.), state transitions, state maintenance, event acceptance, and event sending.
[0195] Therefore, the model framework implements a state machine function, implements the XLState state object base class, abstracts virtual interfaces such as Entry, Out, OnReceived, and Send to match the corresponding X language features, and implements state machine classes for state machine scheduling and operation in discrete classes.
[0196] The key features of discrete state machine modeling in the X language are as follows:
[0197] • State Definition: In the X language, a state machine model can be defined in the `state` section. States are declared using the `state` keyword. States are divided into initial states and normal states. The initial state is the state the model initially enters when it starts running. The model framework design uses state classes to implement the response logic for each state in the state machine. During state initialization, the state machine calls the `Entry()` function of the state.
[0198] The `When…then` statement in the X language defines a condition that, when the value of a variable used in the `when` statement changes within the current state of the model, must be checked to see if the condition is met. If it is, the code logic following `then` is executed. Since the properties of the model containing the state class only change during periodic calculations or when external input ports change, the model framework calls the model's activation state check function after these two events occur. If a change occurs, the compiled C++ code following `then` is executed.
[0199] • Transition semantics, state escaping semantics. In the X language, this function triggers state transition operations. In the model framework, the DoTransition function is provided in the state class to complete the state transition operation.
[0200] • The semantics of Timeover and statehold: In the X language, statehold represents maintaining the state for a time X. After the time expires, the timeover() function returns true. The model framework includes the StateHold and OnTimeover functions in the state class to implement the scheduling functionality of this mechanism.
[0201] class XLANGUAGECORE_DECL XLState:public XLStateElement
[0202] {
[0203] TS_MetaType(XLState,XLStateElement);
[0204] TS_DECLARE_PRIVATE(XLState);
[0205] public:
[0206] XLState();
[0207] XLState(PrivateType*p);
[0208] ~XLState();
[0209] public:
[0210] / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
[0211] / / / <summary> Model Logic Preparation< / summary>
[0212] / / /
[0213] / / / <remarks> This function is not thread-safe. XSimStudio Team, 2015 / 8 / 31.< / remarks>
[0214] / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
[0215] virtual void PrepareData();
[0216] virtual void Entry();
[0217] virtual void Out();
[0218] virtual void OnReceived(const XLPortDesc&Desc,XLPortValuePtrPortValue);
[0219] virtual void Send(const std::string&portName,const TSVariant&value);
[0220] template<typename ModelType>
[0221] boost::shared_ptr<typename ModelType>GetParentModelPtr()
[0222] {
[0223] boost::shared_ptr<typename ModelType>VM=TS_CAST(GetStateMachine()->GetDiscrete(),boost::shared_ptr<typename ModelType>);
[0224] return VM? VM : NULL;
[0225] }
[0226] virtual TSVariant GetPropertyValue(std::string Name);
[0227] virtual void SetPropertyValue(std::string Name, double Value);
[0228] virtual void PushTask(const TSTimeDuration& AfterTime, XLTaskScheduler::Task_T Task);
[0229] virtual XLDiscretePtr GetDiscrete();
[0230] virtual double GetTimeSinceStart();
[0231] / / Obtain multiple port information received within a simulation cycle
[0232] XLPortValuePtr GetRMultPortData(XLPortValuePtr PortValue);
[0233] bool MatchPort(XLPortValuePtr PortValue, const std::string& tPortName);
[0234] public:
[0235] void DoTransition(const std::string& StateName);
[0236] void StateHold(const TSTimeDuration& td);
[0237] void StateHoldInfinite();
[0238] public:
[0239] virtual void OnTimeover();
[0240] };
[0241] class XLANGUAGECORE_DECL XLStateMachine:public XLStateElement
[0242] {
[0243] TS_MetaType(XLStateMachine,XLStateElement);
[0244] TS_DECLARE_PRIVATE(XLStateMachine);
[0245] public:
[0246] XLStateMachine();
[0247] XLStateMachine(PrivateType*p);
[0248] ~XLStateMachine();
[0249] public:
[0250] / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
[0251] / / / <summary> Model Logic Preparation< / summary>
[0252] / / /
[0253] / / / <remarks> This function is not thread-safe. XSimStudio Team, 2015 / 8 / 31.< / remarks>
[0254] / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
[0255] virtual void PrepareData();
[0256] virtual void Entry();
[0257] virtual void Out();
[0258] virtual void OnReceived(const XLPortDesc&Desc,XLPortValuePtrPortValue);
[0259] public:
[0260] void SetDiscrete(XLDiscretePtr Discrete);
[0261] void SetCurrentState(XLStateElementPtr State);
[0262] XLDiscretePtr GetDiscrete();
[0263] virtual XLStateContextPtr GetContext();
[0264] virtual XLStateElementPtr GetCurrentState();
[0265] virtual void DoTransition(const std::string&StateName);
[0266] };
[0267] Note: The above describes the framework's implementation of state machine support for discrete classes in the X language. During compilation, each discrete X language model generates a subclass of XLState and the X language state machine code is generated to the corresponding interface. At runtime, it is scheduled and run by XLStateMachine, with execution rules matching the X language design. Below is code for an X language discrete class model:
[0268] discrete ShiftLogic
[0269] #import ComputeThreshold
[0270] parameter:
[0271] real TWAIT=1 #The value is not specified in the document.
[0272] port:
[0273] event input real down_th
[0274] event input real up_th
[0275] event input real VehicleSpeed
[0276] event output string state# signal for up and down shifting of gears
[0277] state:
[0278] initial state steady_state
[0279] when entry()then
[0280] statehold(infinite)
[0281] end
[0282] when up_th < VehicleSpeed then
[0283] transition(upshifting)
[0284] end
[0285] when down_th > VehicleSpeed then
[0286] transition(downshifting)
[0287] end
[0288] end
[0289] state downshifting
[0290] when entry()then
[0291] statehold(TWAIT)
[0292] end
[0293] when timeover()then
[0294] transition(steady_state)
[0295] out:
[0296] send(state,'down')
[0297] end
[0298] end
[0299] state upshifting
[0300] when entry()then
[0301] statehold (TWAIT)
[0302] end
[0303] when timeover()then
[0304] transition(steady_state)
[0305] out:
[0306] send(state,'up')
[0307] end
[0308] end
[0309] end
[0310] The following is a code example of the generated model within this framework:
[0311] #include"stdafx.h"
[0312] #include"ShiftLogic.h"
[0313] using namespace ShiftLogicSpace;
[0314] BEGIN_METADATA(SteadyState)
[0315] REG_BASE(XLState);
[0316] END_METADATA()
[0317] BEGIN_METADATA(DownshiftingState)
[0318] REG_BASE(XLState);
[0319] END_METADATA()
[0320] BEGIN_METADATA(UpshiftingState)
[0321] REG_BASE(XLState);
[0322] END_METADATA()
[0323] SteadyState::SteadyState()
[0324] {
[0325] SetName("steady_state");
[0326] }
[0327] void SteadyState::Entry()
[0328] {
[0329] SuperType::Entry();StateHoldInfinite();PushTask(TSSeconds(0.01),boost::bind(&SteadyState::DoUpdate,this));}
[0330] / / If the speed limit is not exceeded, continue waiting. Otherwise, switch states.
[0331] void SteadyState::DoUpdate()
[0332] {if(GETVARIANT("up_th")!=0)
[0333] {int ii = 0;}
[0334] if(GETVARIANT("VehicleSpeed")>=GETVARIANT("up_th"))
[0335] {DoTransition("Upshifting"); / / State transitions are executed in the subclass. First, the child state transition is performed; if no transition occurs, then the parent state transition is performed.}
[0336] else if(GETVARIANT("VehicleSpeed") <GETVARIANT("down_th"))
[0337] {DoTransition("Downshifting"); / / State transitions are executed in the subclass. First, the child state transition is performed; if it doesn't succeed, then the parent state transition is performed.} else { / / PushTask(TSSeconds(0.001), boost::bind(&SteadyState::DoUpdate,this));}}
[0338] void SteadyState::Out()
[0339] {SuperType::Out();}
[0340] void SteadyState::OnTimeover()
[0341] {SuperType::OnTimeover();}
[0342] void SteadyState::OnReceived(const XLPortDesc&Desc,XLPortValuePtrPortValue)
[0343] {}
[0344] UpshiftingState::UpshiftingState()
[0345] {SetName("Upshifting");}
[0346] void UpshiftingState::Entry()
[0347] {SuperType::Entry();
[0348] StateHold(TSSeconds(2)); / / 100 seconds}
[0349] void UpshiftingState::Out()
[0350] {SuperType::Out();
[0351] Send("state",TSVariant::FromValue(TSString("up")));}
[0352] void UpshiftingState::OnTimeover()
[0353] {SuperType::OnTimeover();
[0354] DoTransition("steady_state");
[0355] }
[0356] void UpshiftingState::OnReceived(const XLPortDesc& Desc, XLPortValuePtr PortValue)
[0357] {}
[0358] DownshiftingState::DownshiftingState()
[0359] {SetName("Downshifting");
[0360] }
[0361] void DownshiftingState::Entry()
[0362] {
[0363] SuperType::Entry();
[0364] StateHold(TSSeconds(2)); / / 100 seconds
[0365] void DownshiftingState::Out()
[0366] {SuperType::Out(); Send("state",
[0367] TSVariant::FromValue(TSString("down")));}
[0368] void DownshiftingState::OnTimeover()
[0369] {SuperType::OnTimeover(); DoTransition("steady_state");
[0370] }
[0371] void DownshiftingState::OnReceived(const XLPortDesc&Desc,XLPortValuePtr PortValue)
[0372] {}
[0373] BEGIN_METADATA(ShiftLogic)
[0374] REG_BASE(XLDiscrete);
[0375] GetXLTypeRegister(ShiftLogic).RegisterXLProperty(down_th,XL_EventInputProperty);
[0376] GetXLTypeRegister(ShiftLogic).RegisterXLProperty(up_th,XL_EventInputProperty);
[0377] GetXLTypeRegister(ShiftLogic).RegisterXLProperty(VehicleSpeed,XL_EventInputProperty);
[0378] GetXLTypeRegister(ShiftLogic).RegisterXLProperty(state,XL_EventOutputProperty);
[0379] END_METADATA()
[0380] ShiftLogic::ShiftLogic()
[0381] {
[0382] VehicleSpeed=0;
[0383] up_th=0;
[0384] down_th=0;
[0385] }
[0386] void ShiftLogic::PrepareData()
[0387] {XLStateMachinePtr ShiftLogicMachine=boost::make_shared <xlstatemachine>();
[0388] std::vector <xlstateelementptr>Elements;
[0389] Elements.push_back(boost::make_shared <steadystate>());
[0390] Elements.push_back(boost::make_shared <upshiftingstate>());
[0391] Elements.push_back(boost::make_shared <downshiftingstate>());
[0392] ShiftLogicMachine->SetStates(Elements);
[0393] SetStateMachine(ShiftLogicMachine);
[0394] SuperType::PrepareData();
[0395] After the above code is compiled and loaded into the framework, it can be driven to execute.
[0396] 3. According to the X language modeling specification, the relationships between variables in the model are described using a system of equations within the continuous class. This is a key characteristic of continuous modeling; modeling is completed by describing the relationships between attributes. This modeling approach can better describe continuously changing physical quantities, meeting the needs of modeling in fields such as heat and electricity. Therefore, the framework needs to sort the equations in all connected continuous classes when solving continuous models and then solve them using a solver. Since the equations are developed by the client, the order of the equations needs to be dynamically arranged when solving each model. The framework includes a registration function for solver elements designed for the equations, dynamically collecting dependency information for all equations, sorting and solving all equations at runtime, and finally determining the solution order of the equations.
[0397] Equation design and sorting rules:
[0398] In the syntax design of the X language, the `equation` field of a continuous class supports writing systems of equations. These systems are then dependent on equations in other continuous classes based on their connection relationships (input ports linked by the `connect` function in the coupled class). During calculation, all connected equations need to be solved simultaneously using a solver. In the model framework, for the requirement of solving simultaneous equations, the common practice is to package all equations to be solved into a single class in the compiler, merging dependent variables and reducing attribute elements (elements using variable names instead of values). During compilation, the equations are ordered according to the dependencies of the elements. When solving simultaneous equation systems, because `der(x) = z` uses the variable `x` (X is an input variable and therefore a known quantity) and the variable `z` (i.e., an attribute element of 1), while `y = k + 1` uses only known quantities and has 0 unknown elements, `y = z + k` has 2 unknown attribute elements (K is a known quantity). Therefore, when using a solver to iteratively solve the system of equations, the existing solution is to generate code.
[0399] Secondordersys_y=Secondordersys_k+1;
[0400] Firstordersys.x=Secondordersys_y;
[0401] Firstordersys_z=der(Firstordersys_x);
[0402] Firstordersys_y=Firstordersys_z+Firstordersys_k;
[0403] The value of Secondordersys_y is obtained by solving the first equation. The value of Firstordersys_x in the third line becomes known, and the value of Firstordersys_z is calculated. Finally, Firstordersys_z and Firstordersys_k become known quantities, and the value of Firstordersys_y is obtained.
[0404] The equations of two classes are merged into a single class for compilation and computation. This approach is also used in the C++ code generated by Simulink. The drawback of this approach is that changing the connection relationships within the model alters the solution order of the equations, necessitating recompilation. This compilation method requires holding the source code of all models used, which is detrimental to the commercial protection and use of the models. This invention proposes a method that registers and stores the attribute metadata used by the equations during the compilation of the X language model. When using these compiled models, only the attribute metadata of the equations needs to be read and dynamically arranged, allowing the use of these models without holding the source code of the contiguous class models containing these equations.
[0405] 4. In accordance with the X language modeling specifications, support is added for other minor language features such as the connect function for coupled classes, including connection ports and action calls, to ensure that the framework covers all functional requirements of the X language runtime framework.
[0406] void XLCouple::RegisterConnector(int key,XLConnectorPtr*pConnector)
[0407] {T_D();
[0408] d->_Connectors[key].push_back(pConnector);}
[0409] void XLCouple::RegisterVariable(int key,XLVariablePtr*pVariable)
[0410] {T_D();d->_Variables[key].push_back(pVariable);}
[0411] XLConnectorPtr XLCouple::CreateConnector(int key)
[0412] {return boost::make_shared <xlconnector>();
[0413] }XLVariablePtr XLCouple::CreateVariable(int key)
[0414] {return boost::make_shared <xlvariable>();}
[0415] void XLCouple::SetCoupleOutputPorts(const TSConUnorderedMap<XLPortDesc,std::vector <xlportdesc>>&OutputPorts)
[0416] {T_D();d->_CoupleOutPorts=OutputPorts;}
[0417] const TSConUnorderedMap<XLPortDesc,std::vector <xlportdesc>>&XLCouple::GetCoupleOutputPorts()
[0418] { / / TODO:insert return statement here
[0419] T_D();
[0420] return d->_CoupleOutPorts;
[0421] void XLCouple::PrepareData()
[0422] {T_D();
[0423] SuperType::PrepareData();
[0424] / / Establish the association between ports and objects
[0425] {TSConUnorderedMap <XLPortDesc,std::vector <xlportdesc>>::iterator it=d->_CoupleOutPorts.begin();
[0426] while(it!=d->_CoupleOutPorts.end())
[0427] {std::vector <xlportreceiver>&Receivers=d->_PortReceivers[it->first];for(size_t i=0;i <it->second.size();++i)
[0428] {XLPortDesc&ReceiverPortDesc=it->second[i];
[0429] TSConUnorderedMap<std::string,XLObjectPtr>::iterator objIt=d->_Objects.find(ReceiverPortDesc.Agent->GetName());
[0430] if(objIt!=d->_Objects.end())
[0431] {XLPortReceiver Receiver;
[0432] Receiver.Desc=ReceiverPortDesc;
[0433] Receiver.Obj=objIt->second;
[0434] Receivers.push_back(Receiver);
[0435] }}++it;}}
[0436] {TSConUnorderedMap<std::string,XLObjectPtr>::iterator it=d->_Objects.begin();
[0437] while(it!=d->_Objects.end())
[0438] {it->second->SetOwner(TS_CAST(shared_from_this(),XLObjectPtr));
[0439] ++it;}}{TSConUnorderedMap<std::string,XLObjectPtr>::iterator it=d->_Objects.begin();
[0440] while(it!=d->_Objects.end())
[0441] {it->second->PrepareData();
[0442] d->_StepObjects.push_back(it->second);
[0443] ++it;}}}
[0444] bool XLCouple::Send(XLPortValuePtr PortValue)
[0445] {UpdateTaskConnectParam(PortValue);
[0446] return true;}
[0447] void XLCouple::Step()
[0448] {T_D();for(size_t i=0;i <d->_StepObjects.size(); ++i)
[0449] {d->_StepObjects[i]->Step();}
[0450] UpdateTaskConnectParam();
[0451] }
[0452] Notes: Support for other minor syntax features, such as scheduling of connect port information and periodic actions.
[0453] The above description is merely an embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principle of the present invention should be included within the scope of the claims of the present invention. < / xlportreceiver> < / xlportdesc> < / xlportdesc> < / xlportdesc> < / xlvariable> < / xlconnector> < / downshiftingstate> < / upshiftingstate> < / steadystate> < / xlstateelementptr> < / xlstatemachine> < / thistype> < / thistype>
Claims
1. A general method for running a simulation model, characterized in that, include: S1, Collect a set of physical data; the set of physical data includes a discrete data subset, a continuous data subset, and a coupled data subset; S2, Based on the physical data set, a set of simulation modeling models is constructed; the set of simulation modeling models includes discrete models, continuous models, and coupled models; S3, Represent the simulation model set using a computer programming language to obtain a set of executable programs for the model; S4. Deploy the set of executable programs for the model on a computing device to run it, so as to realize the general operation of the simulation modeling model.
2. The general running method of the simulation modeling model as described in claim 1, characterized in that, Each type of model in the simulation modeling model set includes model implementation information and model common characteristic information; The common characteristic information of the model includes X language implementation type information, model inheritance relationship, parameter definition, port, connect information, and event mechanism information; The model implementation information includes the model's input data definition, output data definition, and pattern implementation method information.
3. The general running method of the simulation modeling model as described in claim 1, characterized in that, The set of simulation modeling models constructed based on the physical data set includes: S21, Based on a subset of discrete data, a discrete class model is constructed; S22, a continuous class model is constructed based on a continuous subset of data; S23, Based on the coupled data subset, a coupled class model is constructed; S24. Using the discrete class model, continuous class model and coupled class model, a set of simulation modeling models is constructed.
4. The general running method of the simulation modeling model as described in claim 3, characterized in that, The continuous class model constructed based on a continuous subset of data includes: S221, Perform statistical modeling processing on the continuous data subset to obtain statistical distribution information; the continuous data subset is state collection data collected from the modeling object at several historical moments. S222, Based on the statistical distribution information, the preset transition state equation is processed to obtain a continuous class model.
5. The general running method of the simulation modeling model as described in claim 4, characterized in that, The statistical modeling process performed on the continuous data subset to obtain statistical distribution information includes: S2211, Perform parameter estimation processing on the continuous data subset to obtain a set of parameter estimates; the set of parameter estimates is a set of parameter values obtained by using several parameter estimation methods on the continuous data subset; the parameter estimation methods include method of moments estimation, maximum likelihood estimation, Bayesian estimation, and interval estimation; the parameter types in the set of parameter estimates include mean and variance; S2212, Perform hypothesis testing on the set of parameter estimates to obtain a set of parameter estimates that pass the test; S2213, perform fusion calculation on the set of parameter estimates that have passed the test to obtain statistical distribution information.
6. The general running method of the simulation modeling model as described in claim 5, characterized in that, The process of fusing and calculating the set of parameter estimates that have passed the test to obtain statistical distribution information includes: A first fusion calculation is performed on all the means in the set of parameter estimates that have passed the test to obtain the fusion mean; A second fusion calculation is performed on all variances in the set of parameter estimates that have passed the test to obtain the fused variance; The expression for the first fusion calculation is: Where a0 is the fusion mean, u i Let ui be the i-th mean in the set of parameter estimates that have passed the test, u0 be the average of all means, and M be the total number of means in the set of parameter estimates that have passed the test.
7. The general running method of the simulation modeling model as described in claim 1, characterized in that, The step of representing the simulation model set using a computer programming language to obtain a set of executable programs for the models includes: S31, using class definitions in computer programming languages, represents the common characteristic information of each type of model to obtain the corresponding model definition information; S32 uses the X language modeling specification and computer programming language to characterize the model implementation information of each type of model, and obtain the model implementation function information corresponding to the model. S33, using all the model definition information and model implementation function information, constructs a set of executable programs for the model.
8. A universal operating device for simulation modeling, characterized in that, The device includes: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the general running method of the simulation modeling model as described in any one of claims 1 to 7.
9. A computer-storable medium, characterized in that, The computer storage medium stores computer instructions, which, when invoked by the computer, are used to execute a general running method for the simulation modeling model as described in any one of claims 1 to 7.
10. An information data processing terminal, characterized in that, The information data processing terminal is used to implement the general running method of the simulation modeling model as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Model description and generation method of supportive combined model
CN106777450A
Cloud simulation method and system integrated with various simulation software
CN110209471A
X language hybrid model modeling system and method and storage medium
CN113672207A
Method for modeling and simulating native multidisciplinary complex product supporting physical simulation
CN114218746A
Method for converting SysML model to X language model based on meta-model
CN117931206A