I wanted to terminate my simulation with conditions that I defined.
I tried these two methods:
run 80000 every 100 " if '(${ekmaxbrdr} > 5 || $t >= 70.0)' then 'quit' "
variable stopcond equal "v_ekmaxbrdr>5 || v_t>=70"
fix terminate all halt 100 v_stopcond == 1 error hard
run 80000
Based on my understanding, the final results should be almost the same, though not identical, right?
However, I found that when an output property was generated from the USER-EPH external package, the two methods produced different results. And the second method produced the same result as run 72200 (with conditions, the simulation stopped at 72200 timestep, so I set this timestep manually).
I’m wondering why these two methods give very different results… (I’ll try to figure it out, but in case someone encountered similar issue and can give me some hint…)
It probably depends on what you have in the rest of your input.
There is a major difference between the two cases due to the implicit values of the “start” and “stop” keywords. When you do:
run 100 every 20
This is the same as
run 20 start 0 end 20
run 20 start 20 end 40
run 20 start 40 end 60
run 20 start 60 end 80
run 20 start 80 end 100
while without the “every” you have
run 100 start 0 end 100
So anything that has a feature which is reset at the beginning of a run or uses a ramp will be different with the “every” keyword unless you use:
I added a plot. In this plot, ‘Quit‘ represent the first method, ‘Halt‘ represent the second method with ‘fix halt‘, the numbers represent the checking frequency (50 and 100 timesteps), and ‘no termination‘ represents running simulations without termination condition.
According to the plot, the second method and the method without termination conditions produce the same results. The first method produce different results; and within this method, different checking frequencies give different results.
Thanks so much. It works. Previously I ignored the pre keyword, which by default reset the initial setup for each shorter runs. In the attached plot, the ‘Quit-interval-100-mew‘ represents the method that you suggested, this time it looks correct.
(Since I use different number of nodes on HPC, so the new method did not produce a line overlapped with lines generated by ‘fix halt‘ method. )
I would recommend to keep using the fix halt approach, though. It is by far the cleaner approach and has much less overhead. Most importantly, you don’t have to exit as “brutally” as you do it. With the variable function is_timeout() you can check after a run if it was stopped through fix halt (which uses the same approach as if you set a maximum wall time and that has expired) and this will actually properly complete the timestep (including output). And then you can decide what to do next and - if needed - reset the timer, change some settings and run again or the next step.
I want to make sure that I understand correctly, by saying ‘exit as “brutally”‘, do you mean that I should not use error hard but error soft ?
And is this the correct way to use timer as you described:
variable timeout equal is_timeout()
variable stopcond equal "v_ekmaxbrdr>5 || v_t>=70"
fix terminate all halt 50 v_stopcond == 1 error soft
run 80000
if ${timeout} then "print 'Run has been terminated'"