Cantera / enhancements

Repository for proposed and ongoing enhancements to Cantera
11 stars 5 forks source link

Implement a steady-state solver for 0-D systems #31

Open bryanwweber opened 4 years ago

bryanwweber commented 4 years ago

Idea

Cantera can solve systems of equations representing physically zero-dimensional (i.e., time dependent-only) or one-dimensional (i.e., time + space) systems. The solution of the 1-D problems is done under the assumption of steady state, resulting in a differential-algebraic system of equations to solve. There is a solver implemented in Cantera as part of the 1-D code that solves these problems. 0-D systems can either be transient or steady state, represented by an ODE or algebraic equation respectively; at the moment, the only way to achieve solutions of the steady state problem is to integrate the transient problem until properties stop changing. We would like to modify or implement the existing steady-state 1-D solver for 0-D systems

Difficulty

Medium-hard

Required Knowledge

C++

Mentors

@bryanwweber

paulblum commented 4 years ago

Hey everyone, I'm Paul, I'm an undergrad student at the University of Connecticut. I worked with @bryanwweber last semester on a few upgrades for the Cantera website, and now I'm working on implementing a 0-D steady-state solver for Cantera as an undergraduate research project. I'll be posting regular progress updates to this thread throughout the development of the solver.

paulblum commented 4 years ago

Theory and model derivation for a well-stirred reactor, the first type of system I'll be implementing:

Well-Stirred Model.pdf

paulblum commented 4 years ago

This project was proposed and accepted to Google Summer of Code 2020!

For a detailed outline of the project, please read the full project proposal.

Stay up to date on this project by reading my biweekly blog posts on the Cantera website!

paulblum commented 4 years ago

Google Summer of Code 2020: Developing a 0-D Steady-State Combustion Solver for Cantera

Paul Blum | @paulblum

Combustion is a fundamental discipline of modern science, and understanding it has enabled the development of our technologies in electricity production, heating, transportation, and industry. Advancements in combustion science have been facilitated by our ability to simulate the phenomenon, made possible by computer software like Cantera. The goal of this project was to add a new solver to Cantera that would allow users to directly simulate zero-dimensional steady-state combustion, which can occur in reactors when internal chemical processes become perfectly balanced with one another. This type of idealized simulation can be used to quickly and accurately approximate the behavior of real combustion systems.

As the project began, discussions with the Cantera community led me to make a few deviations from the project proposal, switching the development language to C++ and the numerical solver to Cantera’s built-in 1D multi-domain damped Newton solver. These changes allowed me to build upon existing Cantera C++ examples to create a simple constant-pressure perfectly-stirred reactor simulator, PSRv0.1. This initial version of the simulation tool could find solutions only to systems with simple reactions, but it was invaluable in helping me understand how the Cantera solver worked and how I would need to implement the governing equations in future versions.

Improving PSRv0.1 required extensive research on existing implementations of perfectly-stirred reactor solvers, and experimentation with different mathematical models of the governing equations. A simplification of these equations and the incorporation of time-stepping to improve convergence intervals led to the development of PSRv0.2, an accurate and broadly-capable version of the simulator.

With a working proof-of-concept simulator, the next step was to introduce compatibility with Cantera’s existing reactor network module, which would need to provide initial conditions and reactor-specific governing equations to the steady-state solver. Documentation at this implementation depth of Cantera’s source code was limited; becoming familiar with it required a detailed study of the code with line-by-line walkthroughs of a few example simulations. To better my own understanding and share what I had learned with the Cantera community, I wrote a developer-oriented overview of the module’s implementation, and created a new C++ example problem that uses the module’s fundamental solution tools to solve the governing equations that I had been working on. Based on the external-solver usage in Cantera’s reactor network module, I created a dedicated nonlinear algebraic solver interface, Cantera_NonLinSol, to be used by the reactor network module to simulate steady-state systems. Usage of this interface is demonstrated in PSRv0.3.

At this point, incorporating steady-state simulation into the reactor network module was relatively straightforward because most of the solution process took place in the external Cantera_NonLinSol interface. After including the interface appropriately and providing implementations for problem-specific system-defining pure virtual functions, the reactor network module was ready to simulate 0-D steady-state combustion at constant pressure. Usage of this feature is demonstrated in PSRv0.4, and more detailed information about its implementation and mathematical modeling are provided in my final GSoC blog post.

The next step in this project’s development is to generalize the governing equations to allow steady-state simulation at variable or unknown reactor pressures. I’ve already begun working on adding this capability, and I’m expecting it to be operational very soon! Future updates will be posted here, so be sure to stay tuned for the release of the finished steady-state solver.

This project has been one of the most challenging that I’ve ever worked on, but ultimately one of the most rewarding. I’ve learned an incredible amount about combustion and open-source programming, and I’m ready to continue using and advancing these skillsets to contribute even more code in the future. I’d like to extend a special thank you to my mentor @bryanwweber for making this experience possible, and for all of the help he provided along the way.

bryanwweber commented 3 years ago

@paulblum When you get a chance, can you please link this to your open PR and provide any necessary updates? Thanks

rwest commented 3 years ago

This seems an appropriate place to share the proceedings paper: Implementing a Steady-State Solver for Zero-Dimensional Reactors in Cantera Paul Blum @paulblum, Bryan Weber @bryanwweber , and Raymond Speth @speth. 12th U.S. National Combustion Meeting, 2021. 2E08.pdf

I'm assuming the relevant PR is https://github.com/Cantera/cantera/pull/1021