Detailed Description
The invention is described in further detail below in connection with examples, which are intended to be illustrative rather than limiting.
To implement an efficient, stable solver in simulation, three main concerns are:
Firstly, a proper calculation method is selected, so that the method has better stability, otherwise, the method is not easy to converge; meanwhile, the numerical solution precision is considered, and the selected numerical algorithm order cannot be too low;
Second, it is sufficient to consider whether the selected algorithm is suitable for typical stiffness problems, including but not limited to: rigid oscillation problems, nonlinear delay differentiation problems, rigid problems with discrete events, etc., which are typical of those that exist extensively in power system simulations;
Finally, in the process of realizing the algorithm, the running efficiency of the code is improved as much as possible, otherwise, the method has no engineering significance.
To this end, the present invention proposes the following methods and strategies to solve.
1. ODE solver developed based on linear multi-step method and Runge-Kutta method
Based on the theories of the linear multi-step method and the range-Kutta method, the solver selects four numerical algorithms, namely BDF, improved BDF and two 4-order single diagonal implicit octaves RK, which have good stability and can meet the requirements on accuracy, as a bottom core processing method. The numerical integral solver suitable for the rigid ordinary differential equation initial value problem can solve the ODE-IVP problem efficiently and stably, and particularly has a good effect on the rigid problem. The solver provides a variable step length mechanism for the four solving methods, and can fully exert the advantages of a large stable domain.
2. Novel method for solving nonlinear equation set least square problem
When solving the initial value problem of the ordinary differential equation by using the hidden format algorithm, the least square problem of the nonlinear equation set needs to be calculated. The solver fuses damping Newton method based on classical Levenberg-Marquardt optimization algorithm, and proposes a dammed-Levenberg-Marquardt optimization method, namely d-LM method. The algorithm can achieve both running efficiency and stability, and the method is equivalent to the foreign commercial tool in efficiency by comparison with similar calculation programs in the foreign commercial tool MATLAB.
3. Optimization strategy for predictive step algorithm
The linear multi-step method is a hidden-format solving method, and the most common method for solving an implicit equation is the "prediction-correction" method, which is also called the PC method class. The general step of the "predict-correct" method is P (EC) m, where P represents the prediction (Predictor), E represents the derivative value of the predicted step result, C represents the correction (Corrector), and m represents multiple iterations.
In order to ensure the convergence and the solving efficiency of m implicit iterations, a prediction result close to a true solution needs to be given as far as possible in a prediction step, and 5 calculation methods are provided by the solver, and 5 groups of prediction results are obtained by respectively applying the 5 calculation methods, wherein a group closest to the true solution is preferably selected as the input of the correction step. Although some calculation efficiency is lost in the prediction step link, the processing method can provide a better iteration initial value for the correction step, further reduce the iteration number m, and find that the processing is obviously improved on the global efficiency through comprehensive balance and a large number of tests.
4. Variable step length new strategy capable of greatly improving integral solving efficiency
Conventional variable step size solving strategies generally attempt to solve for the next value y (h) by taking h as an integral step size, and then reduce the step size (e.g., h/2 or h/3) according to a given ratio to solve for the next value y (h/2) or y (h/3) again. Then, judging whether a certain norm of the y (h)-y(h/2) or the y (h)-y(h/3) is smaller than a preset error epsilon, if so, considering that the current step size is proper, and advancing the time axis forward; if not, the current time step is not suitable, and a new integration step h new needs to be recalculated according to a certain step reduction strategy.
According to the invention, a judgment strategy is additionally added on the basis of the strategy, the concepts of step length adjustment and step length stabilization are introduced in the step length changing process, and when a plurality of integration step lengths h and errors epsilon are continuously kept in a range appointed in advance in the solving process, the current solved model is considered to enter a step length stable state, and the integration step length of the previous step is directly used without solving and adjusting the integration step length in the state; otherwise, the current solved model is considered to enter a step length adjustment state, and then the solution is carried out according to a traditional step length changing solving strategy. The processing method has the greatest advantages that on the premise of ensuring the accuracy of the calculation result, the calculation times are greatly reduced, and the solving efficiency is further improved.
The simulation solving method of the present invention is specifically described below.
The invention provides a numerical integral solving method of an initial value problem of a rigid ordinary differential equation in simulation, which aims to be equivalent to solving the initial value problem of an N-dimensional Chang Weifen equation of a real number domain, and has the expression as follows:
Where y is the derivative variable, y' represents the derivative of y, t is time, t 0 and t end represent the start and end integration times, N is the system of equations dimension (i.e., the dimension of y), and y 0 represents the value of y at time t 0.
Based on the linear multistep method and the theory of the Runge-Kutta method, four numerical algorithms with good stability and accuracy meeting the requirements are selected as the bottom core processing method:
1. classical BDF (3-5 th order) methods, also known as GEAR methods;
2. the BDF method is improved, namely IBDF (3-5 order) algorithm;
the 3.3-level 4-order single-diagonal implicit octaringe-Kutta method is SDISRK algorithm;
The 4.4-level 4-order single-diagonal implicit octaringe-Kutta method is SDISRK algorithm.
On the basis of the method, a set of numerical integral solver suitable for the initial value problem of the rigid ordinary differential equation is constructed, so that the ODE-IVP problem can be solved efficiently and stably, and the method has a good effect especially for the rigid problem; and a variable step length mechanism is provided for the four solving methods, so that the advantages of a large stable domain can be fully exerted.
Referring to fig. 1-5, a numerical integral solution method for an initial value problem of a rigid ordinary differential equation in simulation comprises the following operations:
Step 1: selecting necessary parameters such as an integral solving algorithm, an initial integral step length, a convergence residual error and the like, and continuously executing the step 2 after finishing;
wherein the integral solution algorithm is selected from the BDF algorithm, IBDF algorithm, SDISRK algorithm, and SDISRK algorithm;
step 2: judging according to the selected solving algorithm:
If a multi-step method is adopted, judging that the current solver adopts a BDF or IBDF method (an improved BDF method), and continuing to execute the step 3 after judging;
if a single-step method is adopted, the current solver is judged to adopt SDISRK or SDISRK methods, and the step 5 is carried out after the judgment is completed;
Step 3: constructing a target nonlinear equation set according to the selection of the solving algorithm in the previous step, and continuously executing the step 4 after finishing;
step 4: executing a preferred strategy of a prediction step result, respectively executing a plurality of prediction step algorithms to obtain a plurality of prediction values of real solutions, respectively substituting the prediction values into a target nonlinear equation set, and selecting a group of solution vectors with the smallest error as the solution vectors of the prediction step; after finishing, continuing to execute the step 5;
Step 5: taking the solution vector obtained in the prediction step as an iteration initial value, and solving a least square solution of a target nonlinear equation set by using a d-LM method;
firstly constructing an iteration formula when solving, and introducing damping coefficients of iteration step sizes; updating the iteration step length and judging whether convergence requirements are met or not; if yes, outputting a result as a real solution vector, otherwise, continuously repeating the iterative process to obtain a new solution vector until the convergence error requirement is met;
step 6: performing a variable step integration strategy: respectively executing a step length optimizing mechanism for providing an integral step length, a switching mechanism for judging and changing the integral step length and a variable step length numerical value back-inserting mechanism for ensuring the correct calculation result;
judging whether the error meets the requirement; if yes, executing step 7;
if not, returning to the step 1, and resetting the integral step according to the step-changing strategy.
Step 7: advancing the time axis forward by one time step, and judging whether the simulation needs to be ended or not;
if yes, executing step 8;
if not, returning to the step 1, and resetting the integral step according to the step-changing strategy.
Step 8: and finishing the simulation calculation, and storing and displaying the calculation result.
A more specific step description is given below.
A. In the step 2 of the solution, the solver provides four solving algorithms, namely two linear multi-step methods and two single-step high-precision methods, which are respectively named as a method A to a method D.
Method a (3-5 th order conventional BDF):
Method B (3-5 order modified BDF):
method C (3-level 4-order single diagonal implicit octange-Kutta):
The coefficients of the 3-level 4-order single-diagonal implicit oct method are generally given in the form of a Butcher matrix, as shown in fig. 6.
Method D (4-level 4-order single diagonal implicit octange-Kutta):
the 4-level 4-order single-diagonal implicit octreotide method expression differs from method C only in terms of the coefficients of the Butcher matrix. The Butcher matrix of the 4-level 4-order single-diagonal implicit octark method is shown in fig. 7.
The general equation is obtained by using a method A or a method B, the calculation amount of the solving process of the two methods is small, and the solving efficiency is high.
For some problems such as rigid oscillation, random, discrete-continuous mixing or complex nonlinearity, an attempt can be made to use a method C or a method D, the calculation amount of the solving process of the two methods is large, the solving efficiency is relatively low, but the advantage is that the numerical stability is good (the method C and the method D are A-stable, the method A or the method B is A (alpha) -stable), and meanwhile, the two methods belong to a pungent format (SYMPLECTIC SCHEMES), and have smaller numerical dissipation compared with the method A and the method B, so that the numerical fidelity is better.
B. construction of a set of target nonlinear equations
The four solving algorithms provided by the invention are all implicit solving, so that a target nonlinear equation set is required to be constructed.
The target nonlinear equation set expression of method a is:
the target nonlinear equation set expression of method B is:
In the nonlinear equation set, y n+k is an unknown number to be solved, the rest are known data, and F (y n+k) is a target nonlinear equation set.
The target nonlinear equation system of the method C and the method D solves the coefficients of the hidden RK, and the expression is as follows:
In the nonlinear equation set, K i is an unknown number to be solved, the rest are known data, and F (K i) is a target nonlinear equation set.
C. preferred strategy for predicting step outcome
Prediction step calculation is used in method a and method B. In the prediction step, the solver provides 5 algorithms for making predictions of the true solution:
1. The explicit Euler method is used as a prediction step to obtain a predicted value x 1 of a real solution;
2. displaying a 2-order Runge-Kutta method as a prediction step to obtain a predicted value x 2 of a real solution;
3. Displaying a 3-order Runge-Kutta method as a prediction step to obtain a predicted value x 3 of a real solution;
4. displaying a 4-order Runge-Kutta method as a prediction step to obtain a predicted value x 4 of a real solution;
5. And using the result of the previous step as a prediction step to obtain a predicted value x 5 of the true solution.
The above 5 solution vectors are respectively substituted into a 'target nonlinear equation set', and a set of solution vectors x pre with the smallest error is selected from the solution vectors as an input to a 'correction step'.
D. solving a target nonlinear equation set by using d-LM method
And taking the solution vector x pre obtained in the prediction step as an iteration initial value, and solving a least square solution of a 'target nonlinear equation set' by using a d-LM method, wherein a final result is a true solution vector.
The solving process of the d-LM method is as follows:
1) Introducing a target nonlinear equation set, and constructing an iterative formula based on a Levenberg-Marquardt method
(JTJ+ηI)hLM=-JTF,g=JTF,η≥0 (10)
Wherein F is a target nonlinear equation set to be solved, J is a Jacobian matrix of the target nonlinear equation set F, J T is a transpose matrix of J, eta is an adjustment coefficient between a gradient descent method (first-order optimization algorithm) and a Newton iteration method (second-order optimization algorithm), I is an identity matrix, rho is a trust domain radius, h LM is a convergence step length of each iteration step, and v is a process variable for calculating the trust domain radius.
2) Calculating damping coefficient
The most prominent advantage of newton's method is the fast convergence speed with local second order convergence, but the initial point of basic newton's method needs to be sufficiently "close" to the minimum point, otherwise it may cause the algorithm to not converge. In order to ensure the stability of the calculation process, an iteration step damping coefficient is introduced by using a damping Newton method.
Wherein lambda is the iteration step damping coefficient to be solved, h LM is the convergence step of each iteration step, and x is the solution vector at the current moment.
3) Updating the iteration step length, judging whether the convergence requirement is met, if so, outputting a result, otherwise, continuously repeating the iteration process to continuously obtain a new solution vector x new until the convergence error requirement is met.
hLM=(JTJ+ηI)-1(-JTF) (15)
xnew=x+λhLM (16)
E. Variable step integration strategy (see FIG. 8)
The four solution methods A-D provided by the invention allow the use of a variable step integration strategy, and the strategy can obviously improve the integration solution efficiency; the variable step integration strategy mainly has the following three mechanisms:
the first is an integral step length optimizing mechanism; in this mechanism, the step size is decremented to an exponentially decreasing relationship:
Wherein dt new is the updated integral step length, dt is the current integral step length, error is the current calculation error, epsilon is the preset allowable error, y p is the solution vector obtained by solving the p-step method, and z p+1 is the solution vector obtained by solving the p+1-step method;
Y p and z p+1 are calculated respectively, when error is less than or equal to 1.0, the calculation result meets the given allowable error epsilon requirement, the current calculation result can be accepted, and the current integration step is finished;
the second is a judging and switching mechanism between two states of step length adjustment and step length stabilization
Each integration step should theoretically be given an initial integration step and then iterated through equations (17) and (18) to get an appropriate integration step. Such a compensation adjustment mechanism is the "step adjustment" state. If each integral step is calculated according to the mechanism, the calculation result is necessarily correct, however, the solving efficiency is necessarily very slow, and a step stable state is also provided for further improving the solving efficiency.
When a plurality of continuous (5 continuous) integral step sizes are calculated according to the step size adjustment state, the next time step size can be calculated directly by adopting the average value of the plurality of previous integral step sizes without iteration, but the monitoring is needed by using a formula (18), so that the condition that 0.75 error is less than or equal to 1 is met, the measurement directly considers that the current integral step is calculated, and the time axis can be directly advanced.
The third is a variable step value back-insertion mechanism that is activated only in a multi-step process, and that is not required to be performed in a single step process. When the variable step length solution is adopted, as each integral step length is different, the two linear multistep methods (methods A and B) provided by the solver require that the integral step lengths of the first steps are the same, otherwise, numerical divergence is caused, so that a numerical value back-interpolation method is introduced, wherein Interp _1D is a one-dimensional interpolation function:
The three mechanisms have the following beneficial effects on the solver:
the step length optimizing mechanism provides proper integral step length for the solver, so that the result is not distorted due to overlarge calculation times and the whole solving efficiency is not dragged due to overlarge calculation times;
the judging and switching mechanism of the two states of step adjustment and step stabilization can reasonably judge whether the integral step is required to be changed or not, if not, the integral step is not adjusted as much as possible, the extra calculation amount brought by step adjustment is saved, and the solving efficiency is further improved;
the variable step size numerical value back-insertion mechanism ensures the accuracy of calculation results in a linear multi-step method and avoids result distortion caused by step size change.
The three mechanisms support the variable step integration strategy together, which is indispensable.
Specifically, the solver of the invention adopts C++ as a development language, relies on an open source linear algebraic computation package Eigen (V3.3.9), and adopts an Intel mathematical core function Library (MKL, math Kernel Library) to optimize and accelerate, and the basic code organization architecture is shown in FIG. 9.
Specific examples are given below.
Example 1: efficiency comparison of d-LM method and fsolve commands
BDF and IBDF in the solver are two very efficient solving methods, solving a nonlinear equation set is an indispensable important link, and the solver innovatively provides a d-LM method; in order to verify the solving efficiency, MATLAB is selected as a comparison verification reference, and the difference between the d-LM method based on C++ development and fsolve commands for solving the nonlinear equation set in MATLAB, which are given by the solver, is compared.
The present example selects the following nonlinear equation set as the test object.
The initial value of the solution vector of the equation is [0, 0], d-LM and fsolve of MATLAB of the solver are adopted to solve, and the calculation results are shown in FIG. 10 and FIG. 11 respectively.
From the above calculations, it can be seen that the same solution is obtained for the same mathematical model, i.e. x= [10.0449,4.9796, -0.0653], and the correctness is verified.
In addition, it can be seen that fsolve steps in MATLAB need to iterate 9 steps to enable the equation set to achieve 1e-12 solving accuracy, and the d-LM method provided by the solver can achieve 1e-12 solving accuracy only by 7 steps, so that fewer iteration times mean higher efficiency possibility.
FIG. 12 shows the solution time-consuming statistics of the d-LM method and fsolve of the present invention when repeated 20 solution calculations. As can be seen from the calculation results, the d-LM method and fsolve are at the same level, but the fsolve command is inefficient at the beginning of calculation, and the efficiency is improved after repeated for a plurality of times.
Example 2: example of typical stiffness problem
The following types of reaction velocity equations are often encountered in chemical reactions, where y 1,y2,y3 represents the concentration of the reactants, and this model is a typical stiffness problem, often used for simulation verification of various numerical solutions.
The results shown in FIG. 13 can be obtained by solving the ordinary differential equation above using MATLAB/simulink business tool. Taking the result as a comparison standard, solving the ordinary differential equation by using a 4-step improved BDF algorithm in the solver, and obtaining an error curve shown in figure 14 by making a difference between the obtained result and the simulink result, so that the consistency of the two results is very good.
The variable step convergence error in the current example is 1e-5, so the error of the resulting solution is also substantially around this order. If a more accurate solution is desired, the convergence error of the variable step is further tightened, but this certainly affects the calculation efficiency, which is a pair of contradictions in the solution process and needs to be comprehensively considered.
In addition to comparing accuracy, the present invention also compares the efficiency differences of different solutions. FIG. 15 shows a comparison of the solution efficiency of a dominant business tool abroad compared to the time consumed by the present solver.
As can be seen, the computation time of Simulink and SimulationX is distributed between 0.4 and 2.0s, and the BDF method of the solver is mainly distributed between 0.7 and 1.0s. Overall, the present solver is substantially comparable in computational efficiency to the mainstream business tool abroad. The SDISRK method is an implicit Runge-Kutta method, which is more time-consuming to calculate due to the larger calculation amount of the algorithm.
Example 3: typical Hamilton System oscillation problem
The Hamilton system is a typical kinetic system and is widely used in describing the system dynamics in the fields of celestial motion, mechanical motion, etc.
The Kepler equation is a typical Hamilton system, expressed as:
the Hamilton function is:
when the integral initial value is y 1(0)=0,y2(0)=1,y3(0)=1,y4 (0) =0, the mathematical expression of the analytical solution is:
y1=-sin(t),y2=cos(t),y3=cos(t),y4=sin(t)
The oscillation equations described by formulas (22) and (23) are subjected to numerical integration solution by using the solver, and the obtained results are shown in fig. 16 and 17.
It can be seen that the numerical solution and the theoretical analytical solution have good consistency, and the errors of the two are of the order of 1e-5, which is related to the preset of the solver, but more accurate numerical solutions require more calculation time.
Example 4: lorenz chaotic system
The Lorenz system is a typical chaotic system, the dynamics process of the Lorenz system is complex, and the Lorenz system is a typical means for checking the correctness of a differential equation solving algorithm. The expression of the differential equation is:
The solver is utilized to carry out numerical solution on the Lorenz chaotic system, and the result is drawn into a three-dimensional evolution track which is compared with the MATLAB/simulink calculation result, see FIG. 18, so that the chaotic attractors reflected by the calculation results of the two are completely consistent, and the correctness of the solver can be proved.
Example 5: R-C-R one-dimensional fluid pipeline system
In the multidisciplinary system simulation, the flow resistance (R) and the flow capacity (C) are mainly considered in the pipeline model, the flow resistance mainly represents the resistance of the pipeline, and the flow capacity mainly represents the compressibility of the pipeline. When the pipeline is longer, the pipeline can be processed in a segmented way, and the corresponding model can be represented by R-C-R- & gtC-R.
For a simple circular pipeline with uniform cross section, the circular pipeline can be simply equivalent to an R-C-R model (shown in fig. 19), and the kinetic model is as follows:
wherein P in,out is the inlet and outlet pressure of the pipeline, The flow resistance is R, ρ, η, A, V, A and a speed of sound of fluid medium. In calculation, medium density ρ=1000 kg/m 3, pipeline length 12.73m, pipeline inner diameter 10mm and medium sound velocity a=1400 m/s are taken.
The calculated pressures at the left and right ends of the pipeline are shown in fig. 20, and under the same pipeline model and pressure boundary conditions, the calculation results of the solver and the simulink are calculated and compared, and are shown in fig. 21. It can be seen that the calculation result of the solver is completely consistent with the calculation result of simulink.
The embodiments given above are preferred examples for realizing the present invention, and the present invention is not limited to the above-described embodiments. Any immaterial additions and substitutions made by those skilled in the art according to the technical features of the technical scheme of the invention are all within the protection scope of the invention.