# Sampler plugin error

**URL:** https://pyfr.discourse.group/t/sampler-plugin-error/872
**Category:** Cases
**Tags:** plugins
**Created:** [9 July 2023 03:48 UTC](https://pyfr.discourse.group/t/sampler-plugin-error/872 "2023-07-09T03:48:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Zhenyang](https://avatars.discourse-cdn.com/v4/letter/z/ec9cab/32.png) [@Zhenyang](https://pyfr.discourse.group/u/Zhenyang)
#### Post date: [9 July 2023 03:48 UTC](https://pyfr.discourse.group/t/sampler-plugin-error/872/1 "2023-07-09T03:48:30Z")

</div>

Hi,

I noticed a weird phenomena while using the sampler plugin. I am running a case with std rk4 time stepping and dt = 0.00125. I want to sample a bunch of points every 1000 steps. Some configurations are showed as following:

```auto
[solver-time-integrator]
formulation = std
scheme = rk4 ; tvd-rk3
controller = none
tstart = 0.0
tend = 30000
dt = 0.00125

[soln-plugin-sampler]
nsteps = 1000
samp-pts=[a lot of points]
format = primitive
file = point-data.csv
header = true

```

However, when I check sample result, time t is showing something different:

```auto
t,x,y,z,rho,u,v,w,p
1.249999999345, ....
....
2.49999999869, ....
....
3.749999998035, ....
....
4.99999999738, ....
....
6.248749999346, .....
.
.
.
36.24124999935, .....

```

From the 5th output, it shows it samples 999 steps rather than 1000. And it will accumulate error: till t = 36.24125 it missed 7 steps. Do you have any idea about this? I couldn’t see something odd from the source code. Is that because I have sampled too many points?

Regards,  
Zhenyang

---

<div class="post-metadata">

### Author: ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)
#### Post date: [9 July 2023 04:25 UTC](https://pyfr.discourse.group/t/sampler-plugin-error/872/2 "2023-07-09T04:25:57Z")

</div>

This is expected behaviour. Certain plugins (most notably the solution writer) have specific output times. In order to hit these times within a prescribed tolerance, PyFR will vary dt as required. Often these variations can be somewhat non-intuitive due to floating point round-off error.

Case in point, if you run the included Euler vortex example and dump the stats file at `t = 100` you’ll see that it takes `nsteps = 20005` to get to `t = 100` with a `dt = 0.005`.

Floating point math is often non-intuitive. For example:

```auto
sum([0.00125]*2000)
2.500000000000041

```

which would cause anything scheduled to happen at `t = 2.5` to overshoot. Thus, if you have a plugin scheduled to run at this time PyFR will take a smaller step than usual to ensure we don’t overshoot.

Regards, Freddie.

---

<div class="post-metadata">

### Author: ![Zhenyang](https://avatars.discourse-cdn.com/v4/letter/z/ec9cab/32.png) [@Zhenyang](https://pyfr.discourse.group/u/Zhenyang)
#### Post date: [9 July 2023 05:11 UTC](https://pyfr.discourse.group/t/sampler-plugin-error/872/3 "2023-07-09T05:11:36Z")

</div>

Ok. This will cause problems when restarting the program and do spectral analysis with data sampled. I slightly changed time step and it seems sampling at the frequency I want. Thanks for the explain.

Regards,  
Zhenyang

---

<div class="post-metadata">

### Author: ![fdw](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@fdw](https://pyfr.discourse.group/u/fdw)
#### Post date: [9 July 2023 05:24 UTC](https://pyfr.discourse.group/t/sampler-plugin-error/872/4 "2023-07-09T05:24:24Z")

</div>

You can simply put a cubic spline through the sampled data and then use the spline to resample as appropriate.

Regards, Freddie.
