Cantera (Posts about GSoC 2020)https://cantera.org/enContents © 2021 <a href="mailto:steering@cantera.org">Cantera Developers</a> Fri, 03 Sep 2021 13:53:47 GMTNikola (getnikola.com)http://blogs.law.harvard.edu/tech/rss- GSoC 2020 Project Summaryhttps://cantera.org/blog/gsoc-2020-final.htmlPaul Blum<div><h3>Google Summer of Code 2020: <em>Developing a 0-D Steady-State Combustion Solver for Cantera</em></h3>
<p>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.</p>
<p><a href="https://cantera.org/blog/gsoc-2020-final.html">Read more…</a> (3 min remaining to read)</p></div>GSoC 2020https://cantera.org/blog/gsoc-2020-final.htmlMon, 31 Aug 2020 20:20:00 GMT
- GSoC 2020 Blog Post 4https://cantera.org/blog/gsoc-2020-blog-4.htmlPaul Blum<div><p>This summer I've been working to add a dedicated steady-state solver to Cantera's <code>ZeroD</code> reactor network simulation module. Inspired by my study of <code>ZeroD</code>'s current ODE time-integration solver, <code>CVodesIntegrator</code> (see <a href="https://cantera.org/blog/gsoc-2020-blog-3">this post</a>), I developed a nonlinear algebraic solver class called <code>Cantera_NonLinSol</code> to be used by <code>ReactorNet</code> to solve the steady-state problem:</p>
<ul>
<li><strong><em>Class <code>Cantera_NonLinSol</code></em></strong>: A nonlinear algebraic system solver, built upon Cantera's 1D multi-domain damped newton solver as a simplified interface. <ul>
<li>Implemented in <strong>Cantera_NonLinSol.h</strong> (see this on <a href="https://github.com/paulblum/cantera/blob/ca36e253bd28c6d507eace5b6f1199cac64d8909/include/cantera/numerics/Cantera_NonLinSol.h">GitHub</a>)</li>
</ul>
</li>
</ul>
<p>This blog post will go into detail about the mathematical theory behind solving steady-state reactor systems, and how <code>Cantera_NonLinSol</code> can be used to facilitate the process.</p>
<p><a href="https://cantera.org/blog/gsoc-2020-blog-4.html">Read more…</a> (6 min remaining to read)</p></div>GSoC 2020https://cantera.org/blog/gsoc-2020-blog-4.htmlTue, 18 Aug 2020 20:20:00 GMT
- GSoC 2020 Blog Post 3https://cantera.org/blog/gsoc-2020-blog-3.htmlPaul Blum<div><h3><em>How Does Cantera's Reactor Network Time Integration Feature Work?</em></h3>
<p>There's a great description of the science behind Cantera's reactor network simulation capabilities available on the Cantera website, <a href="https://cantera.org/science/reactors.html">here</a>. This post will go into more developer-oriented detail about how the last step, <code>ReactorNet</code>'s <a href="https://cantera.org/science/reactors.html#time-integration">time integration methods</a>, actually work. A <code>ReactorNet</code> object doesn't perform time integration on its own. It generates a system of ODE's based on the combined governing equations of all contained <code>Reactor</code>s, which is then passed off to an <code>Integrator</code> object for solution. What is an <code>Integrator</code>? How does this work?</p>
<p><a href="https://cantera.org/blog/gsoc-2020-blog-3.html">Read more…</a> (8 min remaining to read)</p></div>GSoC 2020https://cantera.org/blog/gsoc-2020-blog-3.htmlSun, 26 Jul 2020 20:20:00 GMT
- GSoC 2020 Blog Post 2https://cantera.org/blog/gsoc-2020-blog-2.htmlPaul Blum<div><h3><em>Developing a 0-D Steady-State Combustion Solver for Cantera</em></h3>
<p>My work since last posting has been characterized by research and experimentation, and this blog post will highlight some of the findings that I've made. I have learned a lot about Cantera and combustion over the past two weeks, but more excitingly, I developed a working proof-of-concept 0-D steady-state solver, PSRv0.2!</p>
<h4>The Energy Equation</h4>
<p>In my last blog post, I discussed the troubles I was having with reaching convergence in systems that included the energy equation, and introduced some ideas I had that might be potential remedies. After doing some research, I found a great resource that addressed these ideas and the numerical solution of perfectly-stirred reactors as a whole. The report provided a new version of the energy equation that considered time-dependent and heat release properties, derived from transient forms of the species conservation and energy balance equations; see the <a href="https://www.researchgate.net/publication/236418395_PSE_a_Fortran_program_for_modeling_well-stirred_reactors">full report</a> for a detailed derivation. Building off of <a href="https://github.com/paulblum/cantera/blob/0DSS/samples/cxx/psr/PSRv1.cpp">PSR v0.1</a> (introduced in the last blog post), I created a version of the solver that used the new energy equation in its solution attempt. Unfortunately, this too had trouble converging without a very good initial guess. Even after introducing time integration and solving the fixed-temperature problem first, the severe nonlinearities of the solution model almost always made convergence impossible.</p>
<h4>Time Integration</h4>
<p>As just hinted at, the solvers that I developed and discussed in my last blog post hadn't been using time integration! I originally thought that this feature of the Cantera solver worked using only the residual function, but this wasn't the case. Time integration is actually done via the backward Euler method. In Cantera's application, the solution at the previous timestep is obtained using the solver's built-in <code>prevSoln()</code> method, and the timestep value <em>dt</em> is incorporated using its passed-in reciprocal, <code>rdt</code>. Each iteration of the backward Euler method needs to be subtracted from the result of the residual function at the corresponding solution vector—the Cantera solver is set up to extract the information that it needs from this difference. Further, modifying values in the <code>diag</code> pointer is also required at each iteration. <code>diag</code> can be thought of as a mask, and in order to activate time stepping for a specific solution component, its corresponding mask entry needs to be set to 1.</p>
<h4>PSR Solver v0.2</h4>
<p>Although time integration didn't help convergence with the energy equation, it was exactly what I needed to get PSR v0.1 working! Adding time integration resulted in a capable and accurate PSR solver. I compared this new version of the solver to Cantera's <code>IdealGasReactor</code> based on the example code in <a href="https://cantera.org/examples/python/reactors/combustor.py.html">combustor.py</a>, and the results were just about <em>exactly</em> the same:</p>
<p><img alt="" src="https://cantera.org/images/gsoc-2020/v0-2-results.png"></p>
<p>Check out the full code for <a href="https://github.com/paulblum/cantera/blob/0DSS/samples/cxx/psr/PSRv2.cpp">PSR v0.2 on GitHub</a>! The energy equation and fixed-temperature versions of the solver are built in for reference, although they weren't used to produce the results above.</p>
<p>As always, I appreciate any suggestions or feedback you might have. Feel free to leave a comment on this project's page in the <a href="https://github.com/Cantera/enhancements/issues/31">Cantera enhancements repository</a>, or email me at <a href="mailto:paul_d_blum@yahoo.com">paul_d_blum@yahoo.com</a>.</p>
<p>Until next time, </p>
<p><a class="magiclink magiclink-github magiclink-mention" href="https://github.com/paulblum" title="GitHub User: paulblum">@paulblum</a></p>
<h4>Keep Reading:</h4>
<p>Next Post - <a href="https://cantera.org/blog/gsoc-2020-blog-3">GSoC 2020 Blog Post 3</a></p>
<p>Previous Post - <a href="https://cantera.org/blog/gsoc-2020-blog-1">GSoC 2020 Blog Post 1</a></p>
<p>Start from the Beginning - <a href="https://cantera.org/blog/gsoc-2020-intro">Introduction</a></p></div>GSoC 2020https://cantera.org/blog/gsoc-2020-blog-2.htmlMon, 29 Jun 2020 18:00:00 GMT
- GSoC 2020 Blog Post 1https://cantera.org/blog/gsoc-2020-blog-1.htmlPaul Blum<div><h3><em>Developing a 0-D Steady-State Combustion Solver for Cantera</em></h3>
<h4>Learning C++ for Cantera Development</h4>
<p>My original <a href="https://drive.google.com/file/d/1vaOjydm6wWKgF2M4J3iFwNZNKHX5laBY/view?usp=sharing">project proposal</a> called for preliminary development in C and Python, primarily because I’ve worked with these languages in the past and would be able to start writing test code right away. However, I ultimately decided to learn and use C++ instead, and I’m very glad that I did. Most of the Cantera source code is written in C++, and being able to easily read and reference it without guessing at the syntax has proven invaluable in development so far.</p>
<p>I learned C++ by following a free <a href="https://www.codecademy.com/learn/learn-c-plus-plus">Codecademy tutorial</a>, which I would definitely recommend to beginning and experienced coders alike. The tutorial was detailed and interactive, and only took me a day to complete. After that, I followed Cantera’s <a href="https://cantera.org/tutorials/cxx-guide/index.html">C++ Interface Tutorial</a>, another excellent resource that I’d say is essential for any beginning Cantera developer. It introduced Cantera-specific technical details needed for C++ development, and provided simple code examples that illustrated how to use Cantera’s functionality to perform some basic calculations.</p>
<h4>Switching Solvers</h4>
<p>The heart of this project is a capable numerical solver that can quickly provide a solution to the <a href="https://drive.google.com/file/d/1vxt3tW1wbvMLTaDygRmpqEJN6yNSO_Lv/view?usp=sharing">set of nonlinear equations</a> that characterize 0-D steady-state combustion systems. In my project proposal I suggested the use of KINSOL, an externally developed code module that uses a version of Newton’s method to solve nonlinear algebraic equations. Stemming from discussions with mentors, I found that Cantera has a built-in and similarly implemented damped Newton solver that should be able to provide the equivalent capability. In efforts not to duplicate existing functionality, as well as to maintain consistency with the rest of the source code, I decided it would be best to use Cantera’s solver in this application. The solver was developed for solving 1-D multi-domain problems, but after some quick testing, I determined that it’s also able to solve 0-D problems with ease. These tests were performed by modifying the residual functions and a few input parameters in the <a href="https://github.com/Cantera/cantera/blob/main/samples/cxx/bvp/blasius.cpp">Blasius sample program</a> to find solutions to arbitrary sets of equations at a single point, rather than along a 1-D array of points.</p>
<h4>Implementing the Simple Solver</h4>
<p>My first development objective was to create a basic standalone solver for the well-stirred reactor model. As mentioned previously, solutions for this type of problem are characterized by a <a href="https://drive.google.com/file/d/1vxt3tW1wbvMLTaDygRmpqEJN6yNSO_Lv/view?usp=sharing">set of nonlinear equations</a> that are typically solved by some numerical analysis software, in this case the one that’s built in to Cantera. The Blasius sample code worked well for my initial tests, so I based the structure of my solver on this program, even directly using the simplified <a href="https://github.com/Cantera/cantera/blob/main/samples/cxx/bvp/BoundaryValueProblem.h">boundary value problem interface</a> to Cantera’s solver. Unfortunately, I couldn’t get this to converge to an appropriate solution. Even given the true solution as an initial vector, the slightest of inaccuracies in inputted properties seemed to result in huge residual values of the energy equation, pushing the solver further from an acceptable solution with each iteration. After doing some research on why this might be, I found that it’s likely due to the exponential dependence of reaction rates on temperature, which makes convergence of the 0-D steady-state equation system quite difficult for a numerical solver. There are a few potential solutions to the issue, which I’m planning on studying in more detail in the coming weeks to get this version of the solver working:</p>
<ul>
<li>The energy equation in the model may need to be replaced with one that considers transient properties</li>
<li>The system may need to be solved twice, first at a fixed temperature (without the energy equation) to obtain a “consistent” initial guess for a second run which will solve for the true solution</li>
<li>Rates of heat release during the reaction may need to be incorporated into the system</li>
<li>A more advanced, problem-specific version of the Cantera solver may need to be used rather than the simplified boundary value problem interface</li>
<li>Something else?</li>
</ul>
<h4>PSR Solver v0.1</h4>
<p>After some brief experimentation with the ideas listed above, I noticed that the well-stirred reactor equations converged very quickly to the correct solution when simulated at arbitrarily fixed temperatures. This confirmed my suspicion that the addition of the energy equation to the system was causing the trouble. At its roots, the energy equation ensures energy conservation through the reactor by forcing the total enthalpy of the exhaust gas mixture at the reactor outlet to match the total enthalpy of the gas mixture at the inlet. The total enthalpy of the exhaust is directly correlated to reactor temperature, which is typically the property that a numerical solver will adjust in attempt to satisfy the energy equation.</p>
<p>I realized that Cantera may provide an alternate way to satisfy the conservation of energy, by keeping total enthalpy fixed via the <code>setState_HP()</code> method of the thermodynamics library. After specifying iteration mass fractions, exhaust enthalpy can be forced to match the inlet enthalpy simply by explicitly setting it this way with <code>setState_HP()</code>. This function will adjust any dependent properties, like temperature, as needed in order to satisfy the laws of thermodynamics. This idea evolved into <a href="https://github.com/paulblum/cantera/blob/0DSS/samples/cxx/psr/PSRv1.cpp">my first working version</a> of a PSR solver! This experimental version of the solver converges quickly for simple reactions, but has trouble finding solutions to more complicated ones. At this point, I’m not entirely sure of the extent of v0.1’s capabilities, but it will be tested thoroughly in the coming weeks and used in the future as seen fit.</p>
<h4>Keep Reading:</h4>
<p>Next Post - <a href="https://cantera.org/blog/gsoc-2020-blog-2">GSoC 2020 Blog Post 2</a></p>
<p>Start from the Beginning - <a href="https://cantera.org/blog/gsoc-2020-intro">Introduction</a></p></div>GSoC 2020https://cantera.org/blog/gsoc-2020-blog-1.htmlMon, 15 Jun 2020 18:00:00 GMT
- GSoC 2020 Introductionhttps://cantera.org/blog/gsoc-2020-intro.htmlPaul Blum<div><h2>Google Summer of Code 2020 - <em>Developing a 0-D Steady-State Combustion Solver for Cantera</em></h2>
<h4>Introduction</h4>
<p>Hello, world! My name is Paul Blum (<a class="magiclink magiclink-github magiclink-mention" href="https://github.com/paulblum" title="GitHub User: paulblum">@paulblum</a>), and I'm an undergraduate student at the University of Connecticut studying Mechanical Engineering and Computer Science & Engineering. I was introduced to Cantera by <a class="magiclink magiclink-github magiclink-mention" href="https://github.com/bryanwweber" title="GitHub User: bryanwweber">@bryanwweber</a>, one of my professors at UConn, as an undergraduate research project that might allow me to jointly apply concepts from both of my fields of study. Since then, I’ve completed some small projects for the Cantera software and its website (<a href="https://github.com/Cantera/cantera/pull/709">Cantera/cantera #709</a>, <a href="https://github.com/Cantera/cantera-website/pull/95">Cantera/cantera-website #95</a>, <a href="https://github.com/Cantera/cantera-website/pull/98">Cantera/cantera-website #98</a>). </p>
<p>Cantera has presented me with the opportunity to challenge myself, learn an incredible amount, and develop my skills as a scientist and an engineer. With this perception, I am excited to announce that I will be developing code for Cantera full-time this summer as part of Google Summer of Code 2020.</p>
<h4>Project Details</h4>
<p>Over the next few months, I'll be working to create a fast and efficient 0-D steady-state combustion solver to integrate as a new feature into Cantera. Solvers for this type of idealized combustion are typically used in applications like studying stabilization and extinction in high velocity combustion, investigating the formation of poisonous nitrogen oxides during burning, determining the values of global reaction parameters in analytical models, and approximating more complex systems like gas-turbine combustors.</p>
<p>Throughout the summer I'll be posting updates on development progress to the <a href="https://cantera.org/blog/index.html">Cantera blog</a> and the <a href="https://github.com/Cantera/enhancements/issues/31">Cantera enhancements repository</a>, so be sure to stay tuned! In the meantime, you can read more about this project via the official GSoC <a href="https://summerofcode.withgoogle.com/projects/#4550970131873792">project description</a>, or my more detailed <a href="https://drive.google.com/file/d/1vaOjydm6wWKgF2M4J3iFwNZNKHX5laBY/view?usp=sharing">project proposal</a>.</p>
<p>If you're interested in learning more about this project, or have any questions or suggestions regarding its development, feel free to email me at <a href="mailto:paul_d_blum@yahoo.com">paul_d_blum@yahoo.com</a>.</p>
<p>Looking forward to a great summer!</p>
<h4>Keep Reading:</h4>
<p>Next Post - <a href="https://cantera.org/blog/gsoc-2020-blog-1">Blog Post 1</a></p></div>GSoC 2020https://cantera.org/blog/gsoc-2020-intro.htmlMon, 01 Jun 2020 20:20:00 GMT