Seconds, minutes or hours for year-long SIMULINK simulation?

I want to model a physical system, a renewable energy production device (several megawatts) that reacts to environmental forces and I want to understand its behavior over a year or more. I think Simscape is the right tool for this.
I understand SIMULINK/Simscape's time unit is dimensionless. However, there seem to be aspects of SIMULINK/Simscape programming that indicates it is designed for running only in seconds in real time. For example, the 256x max playback increase in the animation, and certain units for certain elements contain seconds (like the damping coefficient of a Revolut Joint being in N*m/(deg/s)).
What is best practice? To keep everything in seconds and just set time steps to be several seconds and stop times to be millions of seconds? Or should I convert everything to e.g. hours (meaning I need to multiply force in Newtons by 13M as it has units kg*m/s^2)?
I am asking now before I get too far along in developing the model at which point it might be very painful to convert (as I will likely miss some time unit in some subsystem of a subsystem and might spend days or weeks debugging during a conversion).

 채택된 답변

Jim Riggs
Jim Riggs 2022년 12월 5일
편집: Jim Riggs 2022년 12월 5일

1 개 추천

There is a great risk of somthing going wrong if you use anything other than seconds in a physics model, since, as you pointed out, there are many physical parameters that we use that have implied units.
I have previously built simulations of planetary motion which run for years of simulation time, but the basic calculations were done in seconds. I define variables like minute = 60, hour = 60*minute and day = 24*hour, and then set my simulation time step = k * hour.

댓글 수: 5

Ulrik
Ulrik 2022년 12월 5일
편집: Ulrik 2022년 12월 5일
Thanks for taking time to help me Jim. What is your reaction to Matlab staff not seeming to recommend against treating time steps as other than seconds? Or the below Stack Exchange heavy-weight actually recommending to not use seconds for longer durations?
Or is my case special as I am using physics models with forces etc. and using Simscape?
Jim Riggs
Jim Riggs 2022년 12월 5일
편집: Jim Riggs 2022년 12월 5일
I don't think I reach the same conclusions that you did looking at the above links.
In the first case, converting from seconds to minutes, the user encountered a difference in performance. We don't know enough about the model to make any conclusions, but it sounds like this model is a relatively simple one, with only a single time-dependent parameter which effects the interpretation of the "time" scale (Kj/s). But even though there is only one parameter to keep track of, the user saw a change in the model behavior. It could be that something was missed, or the problem could be a numerical stability issue, and could be due to the step size being increased, but I have no way to know. If done correctly, there should be no difference in performance, so I interpret this as a case supporting my recommendation that you keep the model in basic scientific units (seconds) to avoid these problems. The Mathworks staff is not going to prohibit you from doing this, but I am saying that it adds potential for error, and takes time to verify, which is counterproductive at best.
In the second link, you can see that there is confusion introduced by changing the time from seconds to hours. The two sides of the conversation are not clear on the units which apply to the .00002 time step. They end up with the step being interpreted in hours, not seconds. They effectively have simply increased the step size by a factor of 3600. There is no reason you could not have accomplished the same thing by run the model with a step size of 0.72 seconds. I do not infer this to be a recommendation to use hours for time, but simply increasing the step size to make the model run faster. Unfortunately, this could be bad advice. In both this case, and the previous one, there is no discussion of the effect of the step size on the accuracy of the answer. This is a fundamental consideration. Both the step size, and the numerical integration method have a profound efect on the speed and accuracy of a digital simulation.
The answer to the question in the third link, again, is based on a misconception regarding the step size and the run time of the simulation. The answer presumes that if the model is configured for hours rather than seconds, it will run 3600 times faster. You can always get the same effect by increasing the step size in seconds by a factor of 3600. Numerically, these are identical. But why would you bother to rearchitect your whole model when you can simply change 1 parameter - the step size?
What all three of these examples are missing is any consideration for the relationship between the step size and the accuracy of the simulation. This is a slightly different topic than the question that you asked.
As for the issue of converting your model to use different units of time, I advise against it because it introduces unnecessary potential for error, and adds a layer of obscurity.
You might want to explore the topic of computational accuracy, and the different integration methods. Here is a link to one such discussion:
(Note tht in this link, I talk about a simulation time step in "hours" but the simulation is running in seconds)
Thanks Jim for your very thoughtful and elaborate answers, I spent some time looking through the discussion in the link you posted. And while I am not yet proficient enough to follow all the details, I take from it that you have good standing as a Matlab user and advisor and it built trust in your advice. Also, it strengthened my intuition that the numerical acrobatics of multiplying forces by ~13M in order to accomodate a changed interpretation of the timestep is unwise.
I will therefore stick to seconds, and if calculations times becomes unwildly I will experiment with different solvers and step sizes.
Also, I plan on doing some test for accuracy: I can always just simulate a day or two of a full year, and compare the differences between solvers and step sizes on this short term simulation in order to make inferences of what errors might have accumulated if running the whole year with the different solvers and step sizes (e.g. in your simple example of planetary motion if one year led to 10k km offset, perhaps a good Fermi estimate might be 10 years leads to a 100k offfset).
Again thanks a lot for your time Jim!
It's always wise to do tests for accuracy when employing numerical methods. This is how you determine what basic step size is needed for the particular problem you are working. Also, in general, there is a great advantage to using higher-order numerical integration methods interms of accuracy and speed of computation, so these are worth becoming familiar with.
If you find my input helpful, it would be nice if you would "accept" my answer.
Thanks.
Sorry for not accepting your answer - even gave you a vote in hopes that it further helps your standing in the community!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simscape Multibody에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2022년 12월 5일

댓글:

2022년 12월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by