# Importing previous simulation output into a new simulation using an interpolant

**URL:** <https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236>\
**Category:** Models\
**Created:** [17 March 2025 14:57 UTC](https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236 "2025-03-17T14:57:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![isaac\_basil](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@isaac\_basil](https://pybamm.discourse.group/u/isaac_basil)\
**Post date:** [17 March 2025 14:57 UTC](https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236/1 "2025-03-17T14:57:42Z")

</div>

Hi,  
I am trying to solve 2 simulations sequentially, and use an output from the first simulation as an input to the second. This output is a function of both space and time, j(x,t). I have 2 questions:

1. I’m trying to use an interpolant to do this, although this doesn’t seem ideal, since there is no need to interpolate in space, as the two simulations are defined on the same mesh - is there a better way to do this?

2. I’m getting errors using the interpolant, and I’m wondering if it’s not supposed to be used with a SpatialVariable? I am defining the interpolant as follows:

```auto
x_p = pybamm.SpatialVariable("x_p", domain=["positive electrode"], coord_sys="cartesian")
j_func = pybamm.Interpolant((x_data, t_data), j_data, (x_p, pybamm.t))

```

where, x\_data and t\_data are 1D arrays of length x\_pts and t\_pts and j\_data is a 2d array of shape (x\_pts, t\_pts).

When trying to do

```auto
c_s_p = pybamm.Variable("Positive particle concentration [mol.m-3]", domain="positive electrode")
a = c_s_p + constant * j_func

```

I get the following error:

```auto
cannot reshape array of size 1 into shape (17,1)
AttributeError: 'Interpolant' object has no attribute '_saved_evaluate_for_shape'

```

Is it possible to use the interpolant class with a spatial variable?

Thanks,

Isaac

---

<div class="post-metadata">

**Author:** ![Marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@Marc](https://pybamm.discourse.group/u/Marc)\
**Post date:** [24 March 2025 13:28 UTC](https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236/2 "2025-03-24T13:28:30Z")

</div>

@isaac_basil the `sim.solve` function has a `starting_sol` argument which takes the final step of a previous solution and uses it as the first step of a new simulation. Is that what you’re looking for?

See this example for more details: [Degradation experiments with reference performance tests — PyBaMM v25.1.1 Manual](https://docs.pybamm.org/en/latest/source/examples/notebooks/simulations_and_experiments/rpt-experiment.html)

---

<div class="post-metadata">

**Author:** ![isaac\_basil](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@isaac\_basil](https://pybamm.discourse.group/u/isaac_basil)\
**Post date:** [24 March 2025 13:49 UTC](https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236/3 "2025-03-24T13:49:18Z")

</div>

Hi @Marc thanks for your reply. Unfortunately I need access to the solution at all time steps, so I don’t think that will work for me. Essentially I need to be able to use my solution from Simulation 1 to define j(x,t) which I can use in Simulation 2.

In theory I should be able to do this all in a single simulation. But I’m having problems with that, so I am trying to split into 2 steps to debug.

---

<div class="post-metadata">

**Author:** ![Marc](https://avatars.discourse-cdn.com/v4/letter/m/8dc957/32.png) [@Marc](https://pybamm.discourse.group/u/Marc)\
**Post date:** [27 March 2025 13:27 UTC](https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236/4 "2025-03-27T13:27:38Z")

</div>

Hi @isaac_basil, you might be able to make a 1D interpolant in time for each of the 17 spatial positions of `j(x,t)` and then concatenating them.

---

<div class="post-metadata">

**Author:** ![isaac\_basil](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@isaac\_basil](https://pybamm.discourse.group/u/isaac_basil)\
**Post date:** [29 March 2025 12:19 UTC](https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236/5 "2025-03-29T12:19:50Z")

</div>

Hi @Marc that’s a nice idea I will try that. On that note, I’m not sure where 17 has even come from, since I’m discretising the electrode using 40 nodes.

---

<div class="post-metadata">

**Author:** ![isaac\_basil](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@isaac\_basil](https://pybamm.discourse.group/u/isaac_basil)\
**Post date:** [31 March 2025 06:57 UTC](https://pybamm.discourse.group/t/importing-previous-simulation-output-into-a-new-simulation-using-an-interpolant/236/6 "2025-03-31T06:57:19Z")

</div>

But how would you go about doing this @Marc ? I’ve only used concatenations to combine symbols that are defined on two different domains, so I’m not sure how I could apply that in this case, where each symbol is relevant to a particular x node.
