Conversation
088f4f1 to
50bbe3d
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2010 +/- ##
==========================================
+ Coverage 75.18% 75.43% +0.24%
==========================================
Files 454 454
Lines 56812 56773 -39
Branches 9374 9345 -29
==========================================
+ Hits 42715 42825 +110
+ Misses 10919 10785 -134
+ Partials 3178 3163 -15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d664b4f to
4d8f47f
Compare
| try { | ||
| return speciesIndex(nm) + m_sidx; | ||
| } catch (const CanteraError&) { | ||
| throw CanteraError("ConstPressureMoleReactor::componentIndex", | ||
| "Component '{}' not found", nm); |
There was a problem hiding this comment.
I think it would be best to minimize use of this pattern, which could be done by extending the raise argument to ReactorBase::speciesIndex.
There was a problem hiding this comment.
This is somewhat tricky. The ExtensibleReactor mechanism boxes us in here significantly, as a change of signatures is non-trivial (need to register a new delegated function type, thread everything through, and I'm not sure that default arguments work).
I parked another way I could think of in this commit ischoegl@b11e2e9 which, for inexplicable reasons, breaks an extensible reactor test also.
There was a problem hiding this comment.
Fair enough. I'm OK with this approach. Thanks for investigating the alternatives.
4d8f47f to
2fd32ae
Compare
2fd32ae to
c2685dc
Compare
Only raise deprecation warnings if npos or -1 is expected, and the new 'raise' argument is needed.
c2685dc to
392ff53
Compare
|
@speth ... thanks for the review! The suggestion to condition the deprecation warning was great (#2010 (comment)). I rolled back much of the churn that would have been visible on the user-facing end. For avoiding As an aside, I added the |
|
@speth ... this is ready for a review. It does contain a (minor) breaking change for the MATLAB PR #1997, where all the indexing methods need to add the |
I'm a little confused by the plan here. For CLib, the second argument will always be mandatory, since C doesn't support functions with default arguments. |
True, but in the generated CLib specification, you can force a shorter signature with the |
So is the plan for CLib that for Cantera 3.2, you must provide the second argument, and then for Cantera 3.3, you must not, with the behavior being to always indicate an exception for out-of-bounds indices? It might be better to temporarily use a "custom code" implementation for these methods, and avoid requiring downstream changes. |
I guess that's another way. My thought process was that updating MATLAB would be the easiest (the second argument wouldn't be exposed in the user-facing API). But we cannot rule out that someone will adopt CLib and be forced into a change. Easy enough to implement ... in which case this won't be a breaking change to #1997. |
|
Done. I did, however, realize that there is one more affected method, |
5b8932b to
0cd239d
Compare
Prevents future changes in the CLib code despite changes in the C++ API.
0cd239d to
eb4f211
Compare
|
@speth ... I had not anticipated using custom code for something like this, but it works quite well 😄. I believe this should be ready to merge now. |
| try { | ||
| return speciesIndex(nm) + m_sidx; | ||
| } catch (const CanteraError&) { | ||
| throw CanteraError("ConstPressureMoleReactor::componentIndex", | ||
| "Component '{}' not found", nm); |
There was a problem hiding this comment.
Fair enough. I'm OK with this approach. Thanks for investigating the alternatives.
Changes proposed in this pull request
This PR aims to establish a more uniform approach to index lookups, where the current
nposcheck (utilized for internal methods) is transitioned towards standard exception handling (suitable for user-facing APIs).cloneflag in Clone Solution objects used by Reactor / ReactorSurface #1921 ... araiseflag is currently set tofalseand will switch to atruedefault in Cantera 3.2. This is implemented for various index lookups inPhase,MultiPhase, andKinetics.checkABCIndexElement,Species,Reaction, andComponent.Reactor::componentIndex/Reactor::speciesIndexto throw exceptions: almost all uses are in user-facing APIs (and a transition forExtensibleXYZReactorwould be a breaking change).One major advantage of this approach is that exception handling at user-facing APIs will become significantly easier, e.g., in #1997 (the MATLAB API itself is still hand-coded, but other APIs, such as .NET, would require cumbersome workarounds).
If applicable, fill in the issue number this pull request is fixing
Closes #2004
If applicable, provide an example illustrating new features this pull request is introducing
Historically, exception handling was separated into three functions, although the
checkABCwas rarely used, andcheckABCArraySize, which isn't directly related, only appeared in the CLib interface. ForPhase::speciesIndex, this looks as follows:This PR proposes to integrate exception handling into
speciesIndex.After Cantera 3.2, this PR anticipates a default argument of
bool raise=true.checkSpeciesIndexis still useful as an internal function (making itprotectedwould be within the scope of this PR), and is updated to return the correct size as:Regarding
checkABCArraySize, the generated CLib goes a different route, where size checking is enabled by theusesfield of the YAML specification. This could be further streamlined if Cantera/enhancements#237 were to be implemented.As an aside, the Python API widely uses a
ThermoPhase.species_index(int)et al. to validate indices, which unnecessarily complicates the interface, but remains intact.Checklist
scons build&scons test) and unit tests address code coverage