# Error associated with time step

**URL:** <https://pyfr.discourse.group/t/error-associated-with-time-step/509>\
**Category:** General\
**Created:** [7 December 2021 06:52 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509 "2021-12-07T06:52:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aspillai](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@aspillai](https://pyfr.discourse.group/u/aspillai)\
**Post date:** [7 December 2021 06:52 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/1 "2021-12-07T06:52:49Z")

</div>

Dear all  
I am simulating an adverse pressure gradient problem using the `navier-stokes` solver. I started the computation at p=2 and progressively increased to p=5. At p=5, I encounter an error associated with the time step calculation.  
The original setup with `scheme=rk45`, `controller=pi`, `errest-norm=uniform` and `dt-max` gives a `ZeroDivisionError: 0.0 cannot be raised to a negative power`. This error is at `fac = err **-expa * self._errprev** expb`.  
When I try with a fixed dt the solution diverge to NaNs. Any changes made to the `errest-norm` option result in `Minimum time step rejected` error.  
How can I resolve this issue?

---

<div class="post-metadata">

**Author:** ![WillT](https://avatars.discourse-cdn.com/v4/letter/w/bc79bd/32.png) [@WillT](https://pyfr.discourse.group/u/WillT)\
**Post date:** [7 December 2021 08:55 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/2 "2021-12-07T08:55:50Z")

</div>

Although I think there is a fix for your problem, I think this might be a symptom of an issue with your case.

The error message that you’re getting indicates that you are `err` goes to zero in your simulation. This is slightly strange, have you looked at the output from the dtstats plugin? Is it behaving as expected? Given what you have told me about the case you are running, it might be that your case is unstable. What or how much anti-aliasing are you using? Have you looked a the `p=2` flow? Does it look reasonable?

A fix would be to add an epsilon on to `err` to ensure it can’t go to zero, but the error shouldn’t really be going to zero so I am reluctant to suggest this.

---

<div class="post-metadata">

**Author:** ![aspillai](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@aspillai](https://pyfr.discourse.group/u/aspillai)\
**Post date:** [7 December 2021 09:57 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/3 "2021-12-07T09:57:29Z")

</div>

I do not notice anything abnormal in `p=2` and `p=4` solutions. I use `anti-alias = flux,surf-flux`.  
The dtstats output is oscillating. I managed to control that to a certain degree by setting `dtmax`.

---

<div class="post-metadata">

**Author:** ![WillT](https://avatars.discourse-cdn.com/v4/letter/w/bc79bd/32.png) [@WillT](https://pyfr.discourse.group/u/WillT)\
**Post date:** [7 December 2021 10:48 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/4 "2021-12-07T10:48:41Z")

</div>

What is the degree of anti-aliasing you are using at p=4 and p=5? Also do you have a plot of the error and dt at p=4 and p=5?

---

<div class="post-metadata">

**Author:** ![aspillai](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@aspillai](https://pyfr.discourse.group/u/aspillai)\
**Post date:** [7 December 2021 12:28 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/5 "2021-12-07T12:28:14Z")

</div>

The degree is set to 10 for hex elements and 11 for prisms.

 ![dt plot](https://global.discourse-cdn.com/free1/uploads/pyfr/original/1X/72fa6f2a28616f683a9b8201be706104c0ec8ebf.png)  
 ![error](https://global.discourse-cdn.com/free1/uploads/pyfr/original/1X/d306a1b6f4b0b5002a07c129d05950d05d63c08a.png)

---

<div class="post-metadata">

**Author:** ![p.vincent](https://yyz2.discourse-cdn.com/free1/user_avatar/pyfr.discourse.group/p.vincent/32/225_2.png) [@p.vincent](https://pyfr.discourse.group/u/p.vincent)\
**Post date:** [7 December 2021 12:42 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/6 "2021-12-07T12:42:38Z")

</div>

So quad-deg for p5 hexes is set to 10? And I assume you are using GL points? If so then I think you will have less quadrature points than solution points (or maybe the same number). Which would explain what you are seeing.

---

<div class="post-metadata">

**Author:** ![p.vincent](https://yyz2.discourse-cdn.com/free1/user_avatar/pyfr.discourse.group/p.vincent/32/225_2.png) [@p.vincent](https://pyfr.discourse.group/u/p.vincent)\
**Post date:** [7 December 2021 12:47 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/7 "2021-12-07T12:47:37Z")

</div>

If you are running p5, then you will have 6 solution points in each direction in a hex. Thus you probably want 7 quadrature points in each direction in a hex. Hence you want to set quad-deg for a hex to 13. You should also change quad-deg for the prisms, and the quad and tri faces, accordingly.

---

<div class="post-metadata">

**Author:** ![p.vincent](https://yyz2.discourse-cdn.com/free1/user_avatar/pyfr.discourse.group/p.vincent/32/225_2.png) [@p.vincent](https://pyfr.discourse.group/u/p.vincent)\
**Post date:** [7 December 2021 12:48 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/8 "2021-12-07T12:48:45Z")

</div>

@WillT @fdw does that make sense to you?

---

<div class="post-metadata">

**Author:** ![WillT](https://avatars.discourse-cdn.com/v4/letter/w/bc79bd/32.png) [@WillT](https://pyfr.discourse.group/u/WillT)\
**Post date:** [7 December 2021 13:27 UTC](https://pyfr.discourse.group/t/error-associated-with-time-step/509/9 "2021-12-07T13:27:10Z")

</div>

Yep, that makes sense. If you want to check out for more complicated element types what quadrature degree you might need as a minimum you can check the data files in `pyfr.quadrules.*`

For example here: [PyFR/pyfr/quadrules/hex at develop · PyFR/PyFR · GitHub](https://github.com/PyFR/PyFR/tree/develop/pyfr/quadrules/hex)

n in the file name is the total number of points and d is the degree.

But yes try upping the anti-aliasing order. Given that your plots seem to show for p=5 the dt plummeting and the error sky rocketing, this indicates to me that the adaptive time stepper isn’t necessarily the problem. Instead the current configuration is unstable.
