# Loading new initial condition to existing integrator

**URL:** <https://pyfr.discourse.group/t/loading-new-initial-condition-to-existing-integrator/628>\
**Category:** General\
**Created:** [21 June 2022 09:29 UTC](https://pyfr.discourse.group/t/loading-new-initial-condition-to-existing-integrator/628 "2022-06-21T09:29:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fellshock](https://avatars.discourse-cdn.com/v4/letter/f/b5e925/32.png) [@Fellshock](https://pyfr.discourse.group/u/Fellshock)\
**Post date:** [21 June 2022 09:29 UTC](https://pyfr.discourse.group/t/loading-new-initial-condition-to-existing-integrator/628/1 "2022-06-21T09:29:18Z")

</div>

I am writing some custom code to interpolate existing `.pyfrs` files onto a set of user-defined coordinates defined as a numpy array. I’ve been able to get it to work for a single pyfrs file by using a slightly modified `SamplerPlugin` class. Basically, the workflow involves creating a new integrator with the modified sampler plugin, and then running

```auto
interpolation_results = my_integrator.completed_step_handlers[my_plugin_index](my_integrator)

```

Now, I want to extend this. I want to be able to take a single mesh, and repeat the same procedure for a large quantity of `.pyfrs` files. I could theoretically do this by initializing a new integrator every single time, but in practice I want to interpolate the solution to a very large # of points (\>100k) and the vast majority of the time is spent initializing the integrator if I do that. How can I instead keep the same integrator instance but load a new initial condition from a `.pyfrs` file? Basically, what I want to be able to do is something like this:

```python
def get_interpolated_soln(solver,plugin_idx=-1):
   #my plugin returns a numpy array of velocities etc at interpolation pts
   return solver.completed_step_handlers[plugin_idx](solver)

solns = [NativeReader(path) for path in pyfrs_paths]
interpolated_solns = []
#the solver loads my plugin
solver = get_solver(backend, rallocs, mesh, solns[0], cfg)
interpolated_solns.append(get_interpolated_soln(solver))

for soln in solns[1:]:
    #### This is the part I'm struggling with
    solver.load_initial_condition(soln)
    ####
    interpolated_solns.append(get_interpolated_soln(solver))

```

I also tried a previously suggested approach involving exporting the `.pyfrs` files to ParaView format and using the ParaView Python API, however it turned out to be extremely slow for large quantities of points. If I can get this working, since it requires no additional dependencies, I can also open a pull request to the PyFR repository, since sampling specific points after the solution is written out is currently not a supported use case in PyFR.

---

<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:** [21 June 2022 13:08 UTC](https://pyfr.discourse.group/t/loading-new-initial-condition-to-existing-integrator/628/2 "2022-06-21T13:08:18Z")

</div>

The recommended solution remains to use ParaView. The sampler as-is is not guaranteed to be robust for these purposes (see [PyFR/sampler.py at 4910d1f3c27e5c08b17f66bf6704f231708b54ca · PyFR/PyFR · GitHub](https://github.com/PyFR/PyFR/blob/4910d1f3c27e5c08b17f66bf6704f231708b54ca/pyfr/plugins/sampler.py#L77)).

If you still want to call the code, you should do so in a script which simply imports the relevant pieces of PyFR you need without creating an integrator or requiring any modifications to existing code.

Regards, Freddie.
