-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
Issue 1903 power #1917
Merged
Merged
Issue 1903 power #1917
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
611a4ea
#1903 add resistance and explicit power modes
valentinsulzer e7f2b19
#1903 add explicit models
valentinsulzer edae5f6
Merge branch 'surface-form-half-cell' into issue-1903-power
valentinsulzer 1decd19
#1903 test differential power
valentinsulzer c16828d
#1903 add differential resistance and power control
valentinsulzer 41df3cb
#1903 reduce timescale in differential controls
valentinsulzer 921fd7d
Merge branch 'develop' into issue-1903-power
valentinsulzer a2d0b23
#1903 fix lead-acid model
valentinsulzer cc9117e
Merge branch 'develop' into issue-1903-power
valentinsulzer 3b55603
#1903 fix tests, changelog
valentinsulzer c5791a7
#1903 coverage
valentinsulzer 21f0e69
#1903 coverage
valentinsulzer 4b93e6f
merge develop
valentinsulzer 1fa55ba
#1903 rob comments
valentinsulzer cde0406
Merge branch 'develop' into issue-1903-power
valentinsulzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
docs/source/models/submodels/external_circuit/current_control_external_circuit.rst
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
.../source/models/submodels/external_circuit/explicit_control_external_circuit.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Explicit control external circuit | ||
================================= | ||
|
||
Current is explicitly specified, either by a function or in terms of other variables. | ||
|
||
.. autoclass:: pybamm.external_circuit.ExplicitCurrentControl | ||
:members: | ||
|
||
.. autoclass:: pybamm.external_circuit.ExplicitPowerControl | ||
:members: | ||
|
||
.. autoclass:: pybamm.external_circuit.ExplicitResistanceControl | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,12 +65,19 @@ class BatteryModelOptions(pybamm.FuzzyDict): | |
A 2-tuple can be provided for different behaviour in negative and | ||
positive electrodes. | ||
* "operating mode" : str | ||
Sets the operating mode for the model. Can be "current" (default), | ||
"voltage" or "power". Alternatively, the operating mode can be | ||
controlled with an arbitrary function by passing the function directly | ||
as the option. In this case the function must define the residual of | ||
an algebraic equation. The applied current will be solved for such | ||
that the algebraic constraint is satisfied. | ||
Sets the operating mode for the model. This determines how the current | ||
is set. Can be: | ||
|
||
- "current" (default) : the current is explicity supplied | ||
- "voltage"/"power"/"resistance" : solve an algebraic equation for \ | ||
current such that voltage/power/resistance is correct | ||
- "differential power"/"differential resistance" : solve a \ | ||
differential equation for the power or resistance | ||
- "explicit power"/"explicit resistance" : current is defined in terms \ | ||
of the voltage such that power/resistance is correct | ||
- callable : if a callable is given as this option, the function \ | ||
defines the residual of an algebraic equation. The applied current \ | ||
will be solved for such that the algebraic constraint is satisfied. | ||
* "particle" : str | ||
Sets the submodel to use to describe behaviour within the particle. | ||
Can be "Fickian diffusion" (default), "uniform profile", | ||
|
@@ -186,7 +193,17 @@ def __init__(self, extra_options): | |
"reaction-driven", | ||
"stress and reaction-driven", | ||
], | ||
"operating mode": ["current", "voltage", "power", "CCCV"], | ||
"operating mode": [ | ||
"current", | ||
"voltage", | ||
"power", | ||
"differential power", | ||
"explicit power", | ||
"resistance", | ||
"differential resistance", | ||
"explicit resistance", | ||
"CCCV", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the CCCV option isn't listed in the docs |
||
], | ||
"particle": [ | ||
"Fickian diffusion", | ||
"fast diffusion", | ||
|
@@ -885,27 +902,36 @@ def set_external_circuit_submodel(self): | |
e.g. (not necessarily constant-) current, voltage, etc | ||
""" | ||
if self.options["operating mode"] == "current": | ||
self.submodels["external circuit"] = pybamm.external_circuit.CurrentControl( | ||
self.param | ||
) | ||
model = pybamm.external_circuit.ExplicitCurrentControl(self.param) | ||
elif self.options["operating mode"] == "voltage": | ||
self.submodels[ | ||
"external circuit" | ||
] = pybamm.external_circuit.VoltageFunctionControl(self.param) | ||
model = pybamm.external_circuit.VoltageFunctionControl(self.param) | ||
elif self.options["operating mode"] == "power": | ||
self.submodels[ | ||
"external circuit" | ||
] = pybamm.external_circuit.PowerFunctionControl(self.param) | ||
model = pybamm.external_circuit.PowerFunctionControl( | ||
self.param, "algebraic" | ||
) | ||
elif self.options["operating mode"] == "differential power": | ||
model = pybamm.external_circuit.PowerFunctionControl( | ||
self.param, "differential without max" | ||
) | ||
elif self.options["operating mode"] == "explicit power": | ||
model = pybamm.external_circuit.ExplicitPowerControl(self.param) | ||
elif self.options["operating mode"] == "resistance": | ||
model = pybamm.external_circuit.ResistanceFunctionControl( | ||
self.param, "algebraic" | ||
) | ||
elif self.options["operating mode"] == "differential resistance": | ||
model = pybamm.external_circuit.ResistanceFunctionControl( | ||
self.param, "differential without max" | ||
) | ||
elif self.options["operating mode"] == "explicit resistance": | ||
model = pybamm.external_circuit.ExplicitResistanceControl(self.param) | ||
elif self.options["operating mode"] == "CCCV": | ||
self.submodels[ | ||
"external circuit" | ||
] = pybamm.external_circuit.CCCVFunctionControl(self.param) | ||
model = pybamm.external_circuit.CCCVFunctionControl(self.param) | ||
elif callable(self.options["operating mode"]): | ||
self.submodels[ | ||
"external circuit" | ||
] = pybamm.external_circuit.FunctionControl( | ||
model = pybamm.external_circuit.FunctionControl( | ||
self.param, self.options["operating mode"] | ||
) | ||
self.submodels["external circuit"] = model | ||
|
||
def set_tortuosity_submodels(self): | ||
self.submodels["electrolyte tortuosity"] = pybamm.tortuosity.Bruggeman( | ||
|
@@ -1125,10 +1151,11 @@ def set_voltage_variables(self): | |
# Hack to avoid division by zero if i_cc is exactly zero | ||
# If i_cc is zero, i_cc_not_zero becomes 1. But multiplying by sign(i_cc) makes | ||
# the local resistance 'zero' (really, it's not defined when i_cc is zero) | ||
i_cc_not_zero = ((i_cc > 0) + (i_cc < 0)) * i_cc + (i_cc >= 0) * (i_cc <= 0) | ||
i_cc_dim_not_zero = ((i_cc_dim > 0) + (i_cc_dim < 0)) * i_cc_dim + ( | ||
i_cc_dim >= 0 | ||
) * (i_cc_dim <= 0) | ||
def x_not_zero(x): | ||
return ((x > 0) + (x < 0)) * x + (x >= 0) * (x <= 0) | ||
|
||
i_cc_not_zero = x_not_zero(i_cc) | ||
i_cc_dim_not_zero = x_not_zero(i_cc_dim) | ||
|
||
self.variables.update( | ||
{ | ||
|
@@ -1179,9 +1206,16 @@ def set_voltage_variables(self): | |
) | ||
) | ||
|
||
# Power | ||
# Power and resistance | ||
I_dim = self.variables["Current [A]"] | ||
self.variables.update({"Terminal power [W]": I_dim * V_dim}) | ||
I_dim_not_zero = x_not_zero(I_dim) | ||
self.variables.update( | ||
{ | ||
"Terminal power [W]": I_dim * V_dim, | ||
"Power [W]": I_dim * V_dim, | ||
"Resistance [Ohm]": pybamm.sign(I_dim) * V_dim / I_dim_not_zero, | ||
} | ||
) | ||
|
||
def set_degradation_variables(self): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
pybamm/models/submodels/external_circuit/current_control_external_circuit.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
need to change the example script back