-
-
Notifications
You must be signed in to change notification settings - Fork 572
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
Implement Integrated electrolyte conductivity #1188
Implement Integrated electrolyte conductivity #1188
Conversation
…://github.com/ferranbrosa/PyBaMM into issue-884-electrolyte-integrated-conductivity
…://github.com/ferranbrosa/PyBaMM into issue-884-electrolyte-integrated-conductivity
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 good @brosaplanella , you should also add a test in test_spme.py
(both unit and integration)
@@ -27,7 +27,7 @@ def electrolyte_conductivity_Nyman2008(c_e, T): | |||
0.1297 * (c_e / 1000) ** 3 - 2.51 * (c_e / 1000) ** 1.5 + 3.329 * (c_e / 1000) | |||
) | |||
|
|||
E_k_e = 34700 |
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.
was this a mistake in the original implementation?
you could argue we should just not have the arrhenius term in this case
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.
Not sure if a mistake, or we decided to keep the Arrhenius term from the Marquis2019 set (originally it all was in parameters.csv
. However, if now it is specified as a function I think it would be good to stick to what the paper provides, and it this case, Nyman et al. 2008, does not provide temperature dependence so I removed it.
If that makes sense, I will remove the whole Arrhenius term so it is clearer.
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.
yeah, that makes sense, just remove the arrhenius term and put in a comment
@@ -24,7 +24,7 @@ def electrolyte_diffusivity_Nyman2008(c_e, T): | |||
""" | |||
|
|||
D_c_e = 8.794e-11 * (c_e / 1000) ** 2 - 3.972e-10 * (c_e / 1000) + 4.862e-10 | |||
E_D_e = 37040 |
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.
as above
The domain in which the model holds | ||
|
||
**Extends:** :class:`pybamm.electrolyte_conductivity.BaseElectrolyteConductivity` | ||
""" |
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.
add reference to your paper in the docstring
/ param.gamma_e | ||
) | ||
|
||
integral_n = indef_integral_n - pybamm.boundary_value(indef_integral_n, "left") |
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.
left boundary value of an indefinite integral should always be zero by definition (and implementation) but worth checking
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.
I checked, and maybe it evaluates to zero (actually it should), but is not zero by definition. The definition is
<bound method UnaryOperator.evaluate of BoundaryValue(-0x33bf8d7889aadb3a, boundary value, children=["* integrated w.r.t x_n on ['negative electrode'](3.0 * x_n ** 2.0)"], domain=['current collector'], auxiliary_domains={})>
integral_s = ( | ||
indef_integral_s | ||
- pybamm.boundary_value(indef_integral_s, "left") | ||
+ pybamm.boundary_value(integral_n, "right") |
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.
pybamm.Integral(a)
should give the same value as pybamm.boundary_value(pybamm.IndefiniteIntegral(a), "right")
while building a smaller tree
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.
but maybe it automatically gets simplified down to the same tree anyway
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.
How can I check if they reduce to the same tree? In any case, I think that if they are equivalent, using pybamm.Integral(a)
and removing the boundary values on the left should result in a much more readable code.
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.
Just tried replacing the boundary value at the "right" by Integral
and I get a very long error (see below) which basically looks like a dimension mismatch. So I guess they are not the same object...
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 817, in process_symbol
return self._discretised_symbols[symbol.id]
KeyError: 1041553401910644705
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 817, in process_symbol
return self._discretised_symbols[symbol.id]
KeyError: 2459353937759019131
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 817, in process_symbol
return self._discretised_symbols[symbol.id]
KeyError: 4130260032263747209
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 817, in process_symbol
return self._discretised_symbols[symbol.id]
KeyError: 7060176036539492958
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 817, in process_symbol
return self._discretised_symbols[symbol.id]
KeyError: 8911840126246680561
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 817, in process_symbol
return self._discretised_symbols[symbol.id]
KeyError: -7919469058354380383
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/expression_tree/symbol.py", line 594, in evaluate_for_shape
return self._saved_evaluate_for_shape
AttributeError: 'MatrixMultiplication' object has no attribute '_saved_evaluate_for_shape'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/PyBaMM/pybamm/expression_tree/symbol.py", line 801, in test_shape
self.shape_for_testing
File "/home/ferranbrosa/PyBaMM/pybamm/expression_tree/symbol.py", line 785, in shape_for_testing
evaluated_self = self.evaluate_for_shape()
File "/home/ferranbrosa/PyBaMM/pybamm/expression_tree/symbol.py", line 596, in evaluate_for_shape
self._saved_evaluate_for_shape = self._evaluate_for_shape()
File "/home/ferranbrosa/PyBaMM/pybamm/expression_tree/binary_operators.py", line 201, in _evaluate_for_shape
return self._binary_evaluate(left, right)
File "/home/ferranbrosa/PyBaMM/pybamm/expression_tree/binary_operators.py", line 497, in _binary_evaluate
return left @ right
File "/home/ferranbrosa/coding/reduced-TEC/env/lib/python3.7/site-packages/scipy/sparse/base.py", line 564, in __matmul__
return self.__mul__(other)
File "/home/ferranbrosa/coding/reduced-TEC/env/lib/python3.7/site-packages/scipy/sparse/base.py", line 502, in __mul__
raise ValueError('dimension mismatch')
ValueError: dimension mismatch
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ferranbrosa/miniconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/ferranbrosa/miniconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/ferranbrosa/.vscode-server/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
cli.main()
File "/home/ferranbrosa/.vscode-server/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/home/ferranbrosa/.vscode-server/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "/home/ferranbrosa/miniconda3/lib/python3.7/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/home/ferranbrosa/miniconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/home/ferranbrosa/miniconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/ferranbrosa/coding/reduced-TEC/TSPMe_compare_DFN.py", line 91, in <module>
sim.solve([0, 3700 / Crate])
File "/home/ferranbrosa/PyBaMM/pybamm/simulation.py", line 338, in solve
self.build(check_model=check_model)
File "/home/ferranbrosa/PyBaMM/pybamm/simulation.py", line 291, in build
self._model_with_set_params, inplace=False, check_model=check_model
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 173, in process_model
self.set_internal_boundary_conditions(model)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 419, in set_internal_boundary_conditions
rbc = (boundary_gradient(first_orphan, next_orphan), "Neumann")
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 399, in boundary_gradient
right_symbol_disc = self.process_symbol(right_symbol)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 819, in process_symbol
discretised_symbol = self._process_symbol(symbol)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 853, in _process_symbol
disc_right = self.process_symbol(right)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 819, in process_symbol
discretised_symbol = self._process_symbol(symbol)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 853, in _process_symbol
disc_right = self.process_symbol(right)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 819, in process_symbol
discretised_symbol = self._process_symbol(symbol)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 862, in _process_symbol
disc_child = self.process_symbol(child)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 819, in process_symbol
discretised_symbol = self._process_symbol(symbol)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 852, in _process_symbol
disc_left = self.process_symbol(left)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 819, in process_symbol
discretised_symbol = self._process_symbol(symbol)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 852, in _process_symbol
disc_left = self.process_symbol(left)
File "/home/ferranbrosa/PyBaMM/pybamm/discretisations/discretisation.py", line 821, in process_symbol
discretised_symbol.test_shape()
File "/home/ferranbrosa/PyBaMM/pybamm/expression_tree/symbol.py", line 803, in test_shape
raise pybamm.ShapeError("Cannot find shape (original error: {})".format(e))
I have addressed all the comments except the one about the |
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 @brosaplanella , looks good now, don't worry about the integral thing
model.submodels[ | ||
"electrolyte conductivity" | ||
] = pybamm.electrolyte_conductivity.Integrated(model.param) | ||
model.build_model() |
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.
You might want to provide an option for doing this automatically
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.
I thought about that, but wasn't sure what approach we want to take. We discussed it some time ago, but can't remember what were the arguments against being able to pass options to set all the submodels.
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.
I don't remember the arguments against either. I think you should add the option
…lyte conductivity and made it compatible with surface form
Ready to merge? |
Description
Implementation of the Integrated electrolyte conductivity model as defined in Brosa Planella et al. (2020).
Paper is not yet on arXiv, we can wait to merge until it is to avoid another PR in a couple of weeks.
Fixes #884
Type of change
Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.
Key checklist:
$ flake8
$ python run-tests.py --unit
$ cd docs
and then$ make clean; make html
You can run all three at once, using
$ python run-tests.py --quick
.Further checks: