Disclosure of Invention
The invention aims to solve the technical problem of providing a method, a device and equipment for automatically generating a system simulation model, which can utilize an XML configuration file to automatically generate a system simulation model code so as to perform quick simulation of the system simulation model.
In order to solve the technical problems, the technical scheme of the invention is as follows:
an automatic generation method of a system simulation model comprises the following steps:
acquiring source codes of at least one subsystem model and an XML configuration file of an extensible markup language, wherein the XML configuration file comprises: a system simulation model engineering description, a subsystem model calling condition description and a system simulation model solving related description;
generating simulation model codes of all subsystem models of the system simulation model according to the source codes of at least one subsystem model and the XML configuration file;
And generating a system simulation model according to the calculation sequence of the simulation model codes of each subsystem model of the system simulation model.
Optionally, generating simulation model codes of each subsystem model of the system simulation model according to the source code of at least one subsystem model and the XML configuration file, including:
generating a system engineering basic information code of a system simulation model according to the system simulation model engineering description in the XML configuration file;
processing source codes of all subsystem models of the system simulation model according to subsystem model calling condition description in the XML configuration file to generate simulation codes of model instances of all subsystem models of the system simulation model;
according to the system simulation model solving related description in the XML configuration file, processing source codes of all subsystem models of the system simulation model to generate solving related codes of all subsystem models of the system simulation model;
and obtaining simulation model codes of all subsystem models of the system simulation model according to the system engineering basic information codes, the simulation codes of the model examples of all subsystem models of the system simulation model and the solving related codes of all subsystem models of the system simulation model.
Optionally, the system simulation model engineering description includes: at least one of an engineering name of the system simulation model, a storage path of the system simulation model, and version information of the system simulation model;
the subsystem model call case description includes: at least one of model types of subsystem models, model instantiations of subsystem models, model instance parameters of subsystem models, interface mapping relations of model instances of subsystem models, and model instance solving configurations of subsystem models;
the system simulation model solving related description comprises the following steps: the solver type and at least one of parameters of the solver, calculation sequence of model instances of the subsystem model, data storage related settings and external interfaces of the subsystem model.
Optionally, according to the description of the subsystem model call condition in the XML configuration file, the source code of each subsystem model of the system simulation model is processed, and the simulation code of the model instance of each subsystem model of the system simulation model is generated, which includes:
generating instance definition and declaration codes of the subsystem model and result pool codes of the model instance of the subsystem model according to the model type of the subsystem model and the model instance of the subsystem model in the XML configuration file;
Generating a parameter assignment code of a subsystem model instance according to the model instance parameters of the subsystem model in the XML configuration file;
generating binding codes of input variables of subsystem model examples and corresponding result variables in a result pool according to the input mapping relation of interfaces of the subsystem model examples in the XML configuration file;
generating codes for storing output variables of subsystem model examples into a result pool according to the output mapping relation of interfaces of the subsystem model examples in the XML configuration file;
and according to the model instance solving configuration of the subsystem model in the XML configuration file, generating codes for calling the solver and configuring parameters of the solver.
Optionally, according to the system simulation model solution related description in the XML configuration file, source codes of subsystem models of the system simulation model are processed, and solution related codes of subsystem models of the system simulation model are generated, including:
generating codes for calling the solver and configuring parameters of the solver according to the types of the solver and the parameters of the solver in the XML configuration file;
generating a subsystem model list and a sequence traversing code according to the calculation sequence of the model instance of the subsystem model in the XML configuration file;
Generating a result storage code according to the data storage related setting in the XML configuration file;
and generating an interface code between the result pool variable and the external environment according to the subsystem model external interface in the XML configuration file.
Optionally, generating the system simulation model according to the calculation sequence of the simulation model codes of each subsystem model of the system simulation model includes:
operating an instance code of a subsystem model of a current subsystem model in a subsystem model list formed by subsystem models of a system simulation model to obtain a first operation result;
operating the parameter assignment code of the model instance of the subsystem model of the current subsystem model according to the first operation result to obtain a second operation result;
initializing a model instance of the current subsystem model according to the second operation result to obtain a sub-model initial value;
writing the initial value of the sub-model of the current subsystem model into a result pool;
and performing time domain iterative solution calculation on the initial value of the sub-model until the simulation code operation of the model instance of each subsystem model of the system simulation model is finished, so as to obtain the system simulation model.
Optionally, performing time domain iterative solution calculation on the initial value of the sub-model includes:
Inputting related variables through an interface of a model instance of the current subsystem model;
according to the related variables, running a solver of a model instance of the current subsystem model and configuring codes of solver parameters to obtain target state variables;
and outputting the target state variable through an external interface of the model instance of the current subsystem model.
The invention also provides an automatic generation device of the system simulation model, which comprises the following steps:
the system comprises an acquisition module for acquiring source codes of at least one subsystem model and an XML configuration file of an extensible markup language, wherein the XML configuration file comprises: a system simulation model engineering description, a subsystem model calling condition description and a system simulation model solving related description;
the processing module generates simulation model codes of all subsystem models of the system simulation model according to the source codes of at least one subsystem model and the XML configuration file; and generating a system simulation model according to the calculation sequence of the simulation model codes of each subsystem model of the system simulation model.
The present invention also provides a computing device comprising: a processor, a memory storing a computer program which, when executed by the processor, performs the method as described above.
The invention also provides a computer readable storage medium storing instructions that, when executed on a computer, cause the computer to perform a method as described above.
The scheme of the invention at least comprises the following beneficial effects:
according to the scheme, the source code of at least one subsystem model and the XML configuration file of the extensible markup language are obtained, and the XML configuration file comprises: a system simulation model engineering description, a subsystem model calling condition description and a system simulation model solving related description; generating simulation model codes of all subsystem models of the system simulation model according to the source codes of at least one subsystem model and the XML configuration file; and generating a system simulation model according to the calculation sequence of the simulation model codes of each subsystem model of the system simulation model. The XML configuration file can be utilized to realize the automatic generation of the system simulation model code, thereby carrying out rapid system simulation model simulation.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
As shown in fig. 1, an embodiment of the present invention provides a method for automatically generating a system simulation model, including:
step 11, acquiring source codes of at least one subsystem model and an XML configuration file of an expansion mark language, wherein the XML configuration file comprises: a system simulation model engineering description, a subsystem model calling condition description and a system simulation model solving related description;
step 12, generating simulation model codes of all subsystem models of the system simulation model according to the source codes of at least one subsystem model and the XML configuration file;
And step 13, generating a system simulation model according to the calculation sequence of the simulation model codes of all subsystem models of the system simulation model.
In this embodiment, as shown in fig. 2, the code generation technology of the XML configuration file is used to implement engineering information configuration, model information configuration, solution related configuration, and the like, and automatically generate the system simulation model code, so that the development difficulty and the task amount in the actual project requirements can be reduced, the rapid development of the system simulation model code can be implemented, and meanwhile, the reliability of the system simulation model code is improved, and the universality and maintainability are enhanced. The method effectively solves the problems that the commercial modeling platform cannot realize the integration system model of the source code subsystem with the solver C, and the integration stage of the commercial integration platform system is inconvenient to debug and poor in expansibility of interface functions, and realizes the generation of the simulation model code of the system according to the code construction of the model code of the multi-source subsystem based on the code generation technology of the XML configuration file.
In an alternative embodiment of the present invention, step 12 may include:
step 121, generating a system engineering basic information code of a system simulation model according to the system simulation model engineering description in the XML configuration file;
step 122, processing the source codes of the subsystem models of the system simulation model according to the subsystem model call condition description in the XML configuration file, and generating simulation codes of model instances of the subsystem models of the system simulation model;
Step 123, processing source codes of subsystem models of the system simulation model according to the system simulation model solving related description in the XML configuration file to generate solving related codes of subsystem models of the system simulation model;
and step 124, obtaining simulation model codes of all subsystem models of the system simulation model according to the system engineering basic information codes, the simulation codes of the model instance of all subsystem models of the system simulation model and the solving related codes of all subsystem models of the system simulation model.
In this embodiment, three aspects including a system simulation model project, a subsystem model calling condition and a system simulation model solving relation are preset in an XML configuration file to describe the simulation task, and a subsystem model C source code is combined according to the description contents of the three parts to generate a system simulation model code.
In an alternative embodiment of the present invention, the system simulation model engineering description includes: at least one of an engineering name of the system simulation model, a storage path of the system simulation model, and version information of the system simulation model;
the subsystem model call case description includes: at least one of model types of subsystem models, model instantiations of subsystem models, model instance parameters of subsystem models, interface mapping relations of model instances of subsystem models, and model instance solving configurations of subsystem models;
The system simulation model solving related description comprises the following steps: the solver type and at least one of parameters of the solver, calculation sequence of model instances of the subsystem model, data storage related settings and external interfaces of the subsystem model.
In this embodiment, the system simulation model engineering is a related computer program file generated for a simulation task, and includes an XML file, a C code, and the like; the subsystem model calling conditions, namely, which sub models are involved in the simulation task, for example, the sub models of an engine, a suspension, a steering mechanism, vehicle dynamics, aerodynamics, a vehicle control unit and the like are involved in the simulation task of a certain type of automobile at a time. The sub-models define types in a model library, and instantiation codes need to be generated in the current simulation task. In a preset XML configuration file, according to the vehicle model characteristics of the simulation task, defining parameters in the sub-model instance and the input-output mapping relation between the sub-models determined by the natural physical characteristics. For example, in the example of vehicle dynamics model simulation, relevant parameters such as weight, wheelbase and the like of the vehicle are set according to the specific situation of the vehicle, and the parameters are all aimed at the current simulation task, so that the parameters of the sub-model example need to be described through an XML configuration file to modify the relevant parameters (default parameters) in the model example into values required in the current simulation task.
And setting the system simulation model solving related description, namely setting the solving of the defined subsystem model, such as the related settings of parameters of a configuration solver, subsystem model calculation sequence, data storage and the like, so as to realize the solving of the system simulation model according to the expected sequence and rule.
In an alternative embodiment of the present invention, step 122 may include:
step 1221, generating an instance definition, a declaration code and a result pool code of the subsystem model according to the model type of the subsystem model and the model instance of the subsystem model in the XML configuration file;
step 1222, generating parameter assignment codes of subsystem model examples according to the model example parameters of the subsystem models in the XML configuration file;
step 1223, generating binding codes of input variables of subsystem model examples and corresponding result variables in a result pool according to the input mapping relation of interfaces of the subsystem model examples in the XML configuration file;
step 1224, generating a code for storing the output variable of the subsystem model instance into a result pool according to the output mapping relation of the interface of the subsystem model instance in the XML configuration file;
And step 1225, according to the model instance solution configuration of the subsystem model in the XML configuration file, generating codes for calling the solver and configuring the parameters of the solver.
In this embodiment, the corresponding relationship between the description content of each part in the XML configuration file and the generated system simulation model code is shown in fig. 3, where the subsystem model calling condition part in the XML configuration file performs model instantiation according to the source code of the subsystem model C in the model library, and synchronously configures model parameters, relationships between input and output interfaces, solution settings, and the like, so as to correspondingly generate the detailed model code of the system simulation model architecture. Taking the model instantiation of step 1221 as an example, the code in the model library defines the type of subsystem, e.g., the motor model class motor, and the subsystem instantiation is described in a preset XML configuration file, e.g.:
<subModels>
<subModel>
<class>motor</class>
<modelName>servoMotor1<modelName>
</subModel>
</subModels>
generating an instantiation simulation code according to the XML configuration file:
motor servoMotor1 = new motor();
in the finally obtained simulation code, the object servoMotor1 (servo motor) is an example of a motor type.
In an alternative embodiment of the present invention, step 123 may include:
step 1231, generating codes for calling the solver and configuring parameters of the solver according to the types of the solver and the parameters of the solver in the XML configuration file;
Step 1232, generating a subsystem model list and a sequence traversing code according to the calculation sequence of the model instance of the subsystem model in the XML configuration file;
step 1233, according to the data storage related settings in the XML configuration file, generating a result storage code;
step 1234, generating an interface code between the result pool variable and the external environment according to the subsystem model external interface in the XML configuration file.
In this embodiment, the system solution correlation is configured, in the above-mentioned instantiated sub-model code, only the right value required by the solver is calculated, and the solver needs to integrate the right value, so that the solver needs to be configured according to the simulation task, for example, the parameters of the solver, such as the integration step length and the integration ending condition, and the configuration subsystem model instance calculation sequence, the relevant configuration storage, and the like, such as specifically selecting which calculation results are stored in the hard disk, and the like. The solver parameters of step 1231 are configured, for example, such that the solver software interface type is class odeSolve, and the main parameters include:
odeSolve.startTime;
odeSolve.stopTime;
odeSolve.method;
odeSolve.tStep;
etc.;
definition in XML:
<solver>
<method>RK45</method>
<stratTime>0.0</startTime>
<stopTime unit=’second’>100.0</stopTime>
<tStep unit=’second’>0.01</tStep >
</solver>
and finally generating codes:
odeSolve sl1 = new odeSolve ();
sl1.method = ‘RK45’;
sl1.stratTime = 0.0;
sl1.stopTime = 100.0;
sl1.tStep = 0.01;
....
in an alternative embodiment of the present invention, step 13 may include:
step 131, running an instance code of a subsystem model of a current subsystem model in a subsystem model list formed by subsystem models of a system simulation model to obtain a first running result;
Step 132, according to the first operation result, operating the parameter assignment code of the model instance of the subsystem model of the current subsystem model to obtain a second operation result;
step 133, initializing a model instance of the current subsystem model according to the second operation result to obtain a sub-model initial value;
step 134, writing the initial value of the sub-model of the current subsystem model into a result pool;
and 135, performing time domain iterative solution calculation on the initial value of the sub-model until the simulation code operation of the model instance of each subsystem model of the system simulation model is finished, and obtaining the system simulation model.
In this embodiment, as shown in fig. 4, the simulation calculation flow of the system simulation model code generated based on the XML configuration file first traverses the subsystem model list, executes the sub-model instantiation, then sequentially executes the parameter assignment code, executes the model initialization code, and writes the initial values of the sub-models into the code of the result pool.
In an optional embodiment of the present invention, performing a time domain iterative solution calculation on the initial value of the sub-model includes:
inputting related variables through an interface of a model instance of the current subsystem model;
According to the related variables, running a solver of a model instance of the current subsystem model and configuring codes of solver parameters to obtain target state variables;
and outputting the target state variable through an external interface of the model instance of the current subsystem model.
In this embodiment, after obtaining the initial value of each sub-model, that is, the right value required by the solver, the configuration parameters of the solver need to be integrated by the solver according to the above embodiment, that is, the time domain iterative solution calculation is performed. For example, using a motor as an example, dy=motor (t, y, u), the related variable u is first obtained through the external interface, and then a single-step inner integration solution iteration is performed: and solving dy, transmitting the dy to a solver for one-step integration, and obtaining a target state variable y after the integration. In the process of carrying out single-step internal integral solving iteration, according to whether the submodel is provided with an independent solver for carrying out respective processing, the operations of reading result pool data as input, single-step calculation of the submodel and writing the result into the result pool are sequentially executed. And finally, storing the calculated data of y, dy and the like into a result pool for other models to use. Finally, the simulation calculation is stopped, and if the next simulation is needed, the steps of setting parameters and initializing are not needed to be executed.
As shown in fig. 5, an embodiment of the present invention further provides an automatic system simulation model generating apparatus 50, including:
the obtaining module 51 obtains source code of at least one subsystem model and an XML configuration file, where the XML configuration file includes: a system simulation model engineering description, a subsystem model calling condition description and a system simulation model solving related description;
a processing module 52 for generating simulation model codes of each subsystem model of the system simulation model according to the source code of at least one subsystem model and the XML configuration file; and generating a system simulation model according to the calculation sequence of the simulation model codes of each subsystem model of the system simulation model.
Optionally, generating simulation model codes of each subsystem model of the system simulation model according to the source code of at least one subsystem model and the XML configuration file, including:
generating a system engineering basic information code of a system simulation model according to the system simulation model engineering description in the XML configuration file;
processing source codes of all subsystem models of the system simulation model according to subsystem model calling condition description in the XML configuration file to generate simulation codes of model instances of all subsystem models of the system simulation model;
According to the system simulation model solving related description in the XML configuration file, processing source codes of all subsystem models of the system simulation model to generate solving related codes of all subsystem models of the system simulation model;
and obtaining simulation model codes of all subsystem models of the system simulation model according to the system engineering basic information codes, the simulation codes of the model examples of all subsystem models of the system simulation model and the solving related codes of all subsystem models of the system simulation model.
Optionally, the system simulation model engineering description includes: at least one of an engineering name of the system simulation model, a storage path of the system simulation model, and version information of the system simulation model;
the subsystem model call case description includes: at least one of model types of subsystem models, model instantiations of subsystem models, model instance parameters of subsystem models, interface mapping relations of model instances of subsystem models, and model instance solving configurations of subsystem models;
the system simulation model solving related description comprises the following steps: the solver type and at least one of parameters of the solver, calculation sequence of model instances of the subsystem model, data storage related settings and external interfaces of the subsystem model.
Optionally, according to the description of the subsystem model call condition in the XML configuration file, the source code of each subsystem model of the system simulation model is processed, and the simulation code of the model instance of each subsystem model of the system simulation model is generated, which includes:
generating instance definition and declaration codes of the subsystem model and result pool codes of the model instance of the subsystem model according to the model type of the subsystem model and the model instance of the subsystem model in the XML configuration file;
generating a parameter assignment code of a subsystem model instance according to the model instance parameters of the subsystem model in the XML configuration file;
generating binding codes of input variables of subsystem model examples and corresponding result variables in a result pool according to the input mapping relation of interfaces of the subsystem model examples in the XML configuration file;
generating codes for storing output variables of subsystem model examples into a result pool according to the output mapping relation of interfaces of the subsystem model examples in the XML configuration file;
and according to the model instance solving configuration of the subsystem model in the XML configuration file, generating codes for calling the solver and configuring parameters of the solver.
Optionally, according to the system simulation model solution related description in the XML configuration file, source codes of subsystem models of the system simulation model are processed, and solution related codes of subsystem models of the system simulation model are generated, including:
generating codes for calling the solver and configuring parameters of the solver according to the types of the solver and the parameters of the solver in the XML configuration file;
generating a subsystem model list and a sequence traversing code according to the calculation sequence of the model instance of the subsystem model in the XML configuration file;
generating a result storage code according to the data storage related setting in the XML configuration file;
and generating an interface code between the result pool variable and the external environment according to the subsystem model external interface in the XML configuration file.
Optionally, generating the system simulation model according to the calculation sequence of the simulation model codes of each subsystem model of the system simulation model includes:
operating an instance code of a subsystem model of a current subsystem model in a subsystem model list formed by subsystem models of a system simulation model to obtain a first operation result;
operating the parameter assignment code of the model instance of the subsystem model of the current subsystem model according to the first operation result to obtain a second operation result;
Initializing a model instance of the current subsystem model according to the second operation result to obtain a sub-model initial value;
writing the initial value of the sub-model of the current subsystem model into a result pool;
and performing time domain iterative solution calculation on the initial value of the sub-model until the simulation code operation of the model instance of each subsystem model of the system simulation model is finished, so as to obtain the system simulation model.
Optionally, performing time domain iterative solution calculation on the initial value of the sub-model includes:
inputting related variables through an interface of a model instance of the current subsystem model;
according to the related variables, running a solver of a model instance of the current subsystem model and configuring codes of solver parameters to obtain target state variables;
and outputting the target state variable through an external interface of the model instance of the current subsystem model.
It should be noted that, the device is a device corresponding to the above method, and all implementation manners in the above method embodiments are applicable to the embodiment of the device, so that the same technical effects can be achieved.
Embodiments of the present invention also provide a computing device comprising: a processor, a memory storing a computer program which, when executed by the processor, performs the method as described above. All the implementation manners in the method embodiment are applicable to the embodiment, and the same technical effect can be achieved.
Embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform a method as described above. All the implementation manners in the method embodiment are applicable to the embodiment, and the same technical effect can be achieved.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, and are not repeated herein.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a usb disk, a removable hard disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc.
Furthermore, it should be noted that in the apparatus and method of the present invention, it is apparent that the components or steps may be disassembled and/or assembled. Such decomposition and/or recombination should be considered as equivalent aspects of the present invention. Also, the steps of performing the series of processes described above may naturally be performed in chronological order in the order of description, but are not necessarily performed in chronological order, and some steps may be performed in parallel or independently of each other. It will be appreciated by those of ordinary skill in the art that all or any of the steps or components of the methods and apparatus of the present invention may be implemented in hardware, firmware, software, or a combination thereof in any computing device (including processors, storage media, etc.) or network of computing devices, as would be apparent to one of ordinary skill in the art after reading this description of the invention.
The object of the invention can thus also be achieved by running a program or a set of programs on any computing device. The computing device may be a well-known general purpose device. The object of the invention can thus also be achieved by merely providing a program product containing program code for implementing said method or apparatus. That is, such a program product also constitutes the present invention, and a storage medium storing such a program product also constitutes the present invention. It is apparent that the storage medium may be any known storage medium or any storage medium developed in the future. It should also be noted that in the apparatus and method of the present invention, it is apparent that the components or steps may be disassembled and/or assembled. Such decomposition and/or recombination should be considered as equivalent aspects of the present invention. The steps of executing the series of processes may naturally be executed in chronological order in the order described, but are not necessarily executed in chronological order. Some steps may be performed in parallel or independently of each other.
While the foregoing is directed to the preferred embodiments of the present invention, it will be appreciated by those skilled in the art that various modifications and adaptations can be made without departing from the principles of the present invention, and such modifications and adaptations are intended to be comprehended within the scope of the present invention.