Skip to content

Adding adaptive preconditioner functionality to Cantera (draft)#951

Closed
anthony-walker wants to merge 3 commits intoCantera:mainfrom
anthony-walker:main
Closed

Adding adaptive preconditioner functionality to Cantera (draft)#951
anthony-walker wants to merge 3 commits intoCantera:mainfrom
anthony-walker:main

Conversation

@anthony-walker
Copy link
Copy Markdown
Contributor

Changes proposed in this pull request

This code is adding preconditioning capabilities to Cantera/CVODEs solver interface for reactor networks. It is focused on a specific type of preconditioning but the code is being written with extensibility in mind. It adds a "Preconditioners" file to the numerics portion of cantera which contains a "PreconditionerBase" that is used to write future preconditioners. It also contains a class derived from this called "AdaptivePreconditioner" which is the aforementioned specific preconditioner.

There are also a couple of functions added to specific reactors. IdealGasReactor is one example. Currently, I added a function to evaluate the energy equation which is also done inside of evalEqs but I wanted to avoid touching core Cantera code as much as possible. In this future, I would like to collaborate with the appropriate people to stream line this.

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

@anthony-walker anthony-walker force-pushed the main branch 4 times, most recently from 131a3bf to 0a7d185 Compare January 7, 2021 23:22
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 8, 2021

Codecov Report

Merging #951 (101c75e) into main (b42989f) will decrease coverage by 0.56%.
The diff coverage is 0.27%.

❗ Current head 101c75e differs from pull request most recent head 152dfcb. Consider uploading reports for the commit 152dfcb to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #951      +/-   ##
==========================================
- Coverage   70.67%   70.11%   -0.57%     
==========================================
  Files         362      366       +4     
  Lines       44554    44915     +361     
==========================================
+ Hits        31488    31491       +3     
- Misses      13066    13424     +358     
Impacted Files Coverage Δ
include/cantera/kinetics/Kinetics.h 51.51% <ø> (ø)
include/cantera/numerics/AdaptivePreconditioner.h 0.00% <0.00%> (ø)
include/cantera/numerics/CVodesIntegrator.h 0.00% <ø> (ø)
include/cantera/numerics/FuncEval.h 83.33% <ø> (ø)
include/cantera/numerics/Integrator.h 3.17% <0.00%> (ø)
include/cantera/numerics/PreconditionerBase.h 0.00% <0.00%> (ø)
include/cantera/zeroD/ConstPressureReactor.h 50.00% <ø> (ø)
...clude/cantera/zeroD/IdealGasConstPressureReactor.h 50.00% <ø> (ø)
include/cantera/zeroD/IdealGasReactor.h 50.00% <ø> (ø)
include/cantera/zeroD/Reactor.h 63.15% <ø> (ø)
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b42989f...152dfcb. Read the comment docs.

    implementing the adaptive preconditioner inside of cantera.

    It adds PreconditionerBase and derives AdaptivePreconditioner from this
    base class. PreconditionerBase is intended to be an abstract class so
    other types of preconditioners can be extended in the future.

    AdaptivePreconditioner is a specific type of preconditioning based on a
    tolerance. It was implemented with a double dispatch design pattern which
    requires that each reactor type implement a function to work with it.

    I have started to implement specific functions for each reactor type.

    IdealGasConstPressureReactor - is completed and needs tested still.

    It also adds some functions to interact with the integrator more and has
    a basic python interface.

    Completed simple python interface and plugged into combustor.py with IdealGasConstPressureReactor and it worked w/o convergence error from eigen

    Also removed submodule changes to hopefully fix CI
Copy link
Copy Markdown
Member

@bryanwweber bryanwweber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @anthony-walker Thanks for sharing your work so far! Since this is still in draft mode, I didn't make any comments about the implementation (well, except one I think about SUNDIALS). The comments are some small formatting things to watch out for as you continue working on this. Thanks!


#include "cantera/numerics/Integrator.h"
#include "cantera/base/ctexceptions.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file look spurious, can you remove them?

Comment on lines +96 to +97
virtual void setProblemType(int probtype)
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what changed here, maybe line endings? Can you make sure you're using only "LF" line endings, not "CRLF"?

{
class PreconditionerBase
{
private:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be doing anything here.

return f->eval_nothrow(t, NV_DATA_S(y), NV_DATA_S(ydot));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add any trailing whitespace to lines. You can also configure your editor to remove trailing whitespace.

integrator->m_error_message += "\n";
}

#if CT_SUNDIALS_VERSION>=30 //These functions only work with Sundials 3.0 or newer
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if CT_SUNDIALS_VERSION is less than 3.0? Does the code fail with a useful error message?

Copy link
Copy Markdown
Contributor Author

@anthony-walker anthony-walker Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was updated to pass CI. It throws a CanteraError now. These functions are used within CVodesIntegrator::applyOptions. That is where the error is handled.

@ischoegl
Copy link
Copy Markdown
Member

ischoegl commented Apr 9, 2021

HI @anthony-walker ... I'm likewise happy to see this moving! To add to @bryanwweber 's preliminary review, I have some other minor formatting comments: doublereal should be double, and line lengths should be kept to 88 characters when possible (see coding style guidelines). Once the '(draft)' is removed from the title, I'll have additional comments.

@ischoegl
Copy link
Copy Markdown
Member

ischoegl commented Apr 9, 2021

PS: on a separate note, it looks like you're still on your fork's main branch for this PR (as noted elsewhere). I'm not sure that there is a simple fix that preserves the PR # (there may be), but it may make sense to switch to a feature branch on your fork sooner rather than later.

@anthony-walker
Copy link
Copy Markdown
Contributor Author

@ischoegl I believe I would have to close the PR to change the branch but I will use a feature branch in the future.

@ischoegl
Copy link
Copy Markdown
Member

ischoegl commented Apr 9, 2021

@ischoegl I believe I would have to close the PR to change the branch but I will use a feature branch in the future.

That's likely true, but it would spare you quite a few headaches whenever there is a need to rebase (as you've seen). Thus far, there isn't much attached to this PR, so re-opening won't lose too much information (i.e. what's above are mainly preliminary comments). Losing the commit record was unfortunate btw ... Choice is yours of course!

@anthony-walker
Copy link
Copy Markdown
Contributor Author

Closing pull request to re-open from a feature branch.

@ischoegl
Copy link
Copy Markdown
Member

ischoegl commented Apr 9, 2021

Thank you, @anthony-walker ... for the records, this is continued on #1010.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants