-
-
Notifications
You must be signed in to change notification settings - Fork 662
Add constant symbol for named constants #5070
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #5070 +/- ##
========================================
Coverage 98.58% 98.58%
========================================
Files 304 304
Lines 23731 23740 +9
========================================
+ Hits 23395 23404 +9
Misses 336 336 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @rtimms, this looks very useful. Presumably these nodes should be replaced by scalars during discretisation, so that they are then simplified? Is this the desired behaviour? If so I think adding a test to make sure this happens would be good.
Yes, good point, I think this is what happens since they get simplified on evaluation, but I'll add a test to confirm this behaviour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks great, thanks @rtimms
Description
Adds a new
Constant
symbol for named constants. This is a subclass ofpybamm.Scalar
and is used to represent named constants such as the gas constant. This avoids constants being simplified out when printing expressions (but they are still simplified when evaluated). For example,pybamm.constants.R + 2
should print2+R
and evaluate to10.314462618
. Counterintuitively, the "is_constant" method is set to False, so that named constants are not simplified when constructed. This is maybe a little confusing, but this is the cleanest way of avoiding simplifications without checking for instances ofConstant
everywhere.Fixes # (issue)
Type of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)
Important checks:
Please confirm the following before marking the PR as ready for review:
nox -s pre-commit
nox -s tests
nox -s doctests