Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to improve coupling to other software #543

Closed
TomTranter opened this issue Jul 19, 2019 · 13 comments
Closed

Enhancements to improve coupling to other software #543

TomTranter opened this issue Jul 19, 2019 · 13 comments
Assignees
Labels

Comments

@TomTranter
Copy link
Contributor

Summary
As far as I'm aware PyBaMM does not support saving and loading data for the state of the battery. This would be useful for initializing the variables for transient simulations.

Motivation
I would like to couple solving a transient heat conduction problem using PyBaMM for 1D electrochemistry and heat sources and OpenPNM for 2D or 3D conduction and heat removal. I envisage setting the state of a bunch of 1D PyBaMM models, running them in parallel for a certain period of time and then updating the global temperature in OpenPNM and feeding this back in a loop over time to update temperature dependent variables. I would therefore need to initialize the PyBaMM solvers with the variables such as concentrations and run them completely for a small time period or run them in a piecemeal fashion with the ability to call other programs between timesteps. I anticipate the first method to be simpler to implement and parallelize but perhaps not as efficient.

@TomTranter TomTranter self-assigned this Jul 19, 2019
@valentinsulzer
Copy link
Member

Sounds like a very sensible approach. You're right that there is currently no support for loading and saving (we've been using the pickle module when necessary).
I think @rtimms has a bit of experience trying to use a bunch of 1D models coupled with a 2D conduction problem in FEniCS, so might have some good advice

@TomTranter
Copy link
Contributor Author

After some playing about I got a script working that passes back and forth average particle and electrolyte concentrations as initial conditions and also a heat source and iterates but it is slow because all the entire model structure is being created at each time step. It would be better to create the model once and be able to have greater control over time-stepping. So pass model objects back and forth in partially time-stepped states updating local temperature as you go.

@TomTranter
Copy link
Contributor Author

Saying this I haven't profiled the code yet and not sure if the main time is spent setting up and calling the solver which would have to be done each time in either situation

@valentinsulzer
Copy link
Member

It would be better to create the model once and be able to have greater control over time-stepping.

Yep absolutely! Feel free to edit ODESolver.solve or ODESolver.integrate however you need to achieve this.
For some basic profiling, setting pybamm.set_logging_level("INFO") should at least give some insight into what the solver is spending time on. There is a bit of work setting up (simplifying, making jacobian, etc) which definitely doesn't need to be repeated every time in this case

@rtimms
Copy link
Contributor

rtimms commented Jul 20, 2019

may not be relevant, but the scikits solvers have a step function for solving odes/daes in a stepwise fashion see here. I believe this is the way sundials recommends restarting their solver using the output of the previous step as initial conditions. This may be the way to keep stepping the same model forward, as by this point you aren't making a new model at each step with new initial conditions; you are just taking the discretised algebra system and solving with a new y0

@TomTranter
Copy link
Contributor Author

The way forward would be to have two functions in the solver that both utilize set_up. One called solve_all which accepts a list of times and one that accepts a timestep (dt). The last solution would be saved on the solver object for initializing the stepping to the next solution and solutions are passed back with each call. solve_all would return all solutions in with all timesteps as currently happens with solve and step would return solution for one timestep. The onus is then on the user to amalgamate the timesteps together should they wish. Sundials has similar functionality so it would be a case of writing the right wrapper functions and pointers to the sundial solver object

@valentinsulzer
Copy link
Member

@TomTranter does anything still need to be done on this specific issue?

@TomTranter
Copy link
Contributor Author

Hi @tinosulzer @rtimms @Scottmar93 it would be good to sit down and review this together. I plan to come to Oxford again before xmas

@Scottmar93
Copy link
Contributor

Yeah good idea, @ferranbrosa was planning coming at some point before christmas as well so maybe we can do another implementation day to discuss these things?

@brosaplanella
Copy link
Sponsor Member

I am coming on the 9th of December, but I can join another day via Skype if needed.

@valentinsulzer
Copy link
Member

I can join via Skype or will be there on 19th and 20th December

@valentinsulzer
Copy link
Member

@TomTranter can this be closed now?

@TomTranter
Copy link
Contributor Author

TomTranter commented May 18, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants