-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
#1511 add function for initial soc #1512
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -138,6 +138,7 @@ def __init__( | |
# Initialize empty built states | ||
self._model_with_set_params = None | ||
self._built_model = None | ||
self.op_conds_to_built_models = None | ||
self._mesh = None | ||
self._disc = None | ||
self._solution = None | ||
|
@@ -329,7 +330,6 @@ def set_up_model_for_experiment_old(self, model): | |
op_cond[:2]: (new_model, self.parameter_values) | ||
for op_cond in set(self.experiment.operating_conditions) | ||
} | ||
self.op_conds_to_built_models = None | ||
|
||
def set_up_model_for_experiment_new(self, model): | ||
""" | ||
|
@@ -340,7 +340,6 @@ def set_up_model_for_experiment_new(self, model): | |
reduces simulation time since the model formulation is efficient. | ||
""" | ||
self.op_conds_to_model_and_param = {} | ||
self.op_conds_to_built_models = None | ||
for op_cond, op_inputs in zip( | ||
self.experiment.operating_conditions, self._experiment_inputs | ||
): | ||
|
@@ -545,6 +544,7 @@ def solve( | |
save_at_cycles=None, | ||
calc_esoh=True, | ||
starting_solution=None, | ||
initial_soc=None, | ||
**kwargs, | ||
): | ||
""" | ||
|
@@ -585,6 +585,10 @@ def solve( | |
starting_solution : :class:`pybamm.Solution` | ||
The solution to start stepping from. If None (default), then self._solution | ||
is used. Must be None if not using an experiment. | ||
initial_soc : float, optional | ||
Initial State of Charge (SOC) for the simulation. Must be between 0 and 1. | ||
If given, overwrites the initial concentrations provided in the parameter | ||
set. | ||
**kwargs | ||
Additional key-word arguments passed to `solver.solve`. | ||
See :meth:`pybamm.BaseSolver.solve`. | ||
|
@@ -593,6 +597,39 @@ def solve( | |
if solver is None: | ||
solver = self.solver | ||
|
||
if initial_soc is not None: | ||
if ( | ||
hasattr(self, "_built_initial_soc") | ||
and self._built_initial_soc != initial_soc | ||
): | ||
# reset | ||
self._model_with_set_params = None | ||
self._built_model = None | ||
self.op_conds_to_built_models = None | ||
|
||
c_n_init = self.parameter_values[ | ||
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. why do you need to get the initial concentrations here? 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. Oh I see |
||
"Initial concentration in negative electrode [mol.m-3]" | ||
] | ||
c_p_init = self.parameter_values[ | ||
"Initial concentration in positive electrode [mol.m-3]" | ||
] | ||
param = pybamm.LithiumIonParameters() | ||
c_n_max = self.parameter_values.evaluate(param.c_n_max) | ||
c_p_max = self.parameter_values.evaluate(param.c_p_max) | ||
x, y = pybamm.lithium_ion.get_initial_stoichiometries( | ||
initial_soc, self.parameter_values | ||
) | ||
self.parameter_values.update( | ||
{ | ||
"Initial concentration in negative electrode [mol.m-3]": x | ||
* c_n_max, | ||
"Initial concentration in positive electrode [mol.m-3]": y | ||
* c_p_max, | ||
} | ||
) | ||
# Save solved initial SOC in case we need to re-build the model | ||
self._built_initial_soc = initial_soc | ||
|
||
if self.operating_mode in ["without experiment", "drive cycle"]: | ||
self.build(check_model=check_model) | ||
if save_at_cycles is not None: | ||
|
@@ -838,6 +875,15 @@ def solve( | |
"Finish experiment simulation, took {}".format(timer.time()) | ||
) | ||
|
||
# reset parameter values | ||
if initial_soc is not None: | ||
self.parameter_values.update( | ||
{ | ||
"Initial concentration in negative electrode [mol.m-3]": c_n_init, | ||
"Initial concentration in positive electrode [mol.m-3]": c_p_init, | ||
} | ||
) | ||
|
||
return self.solution | ||
|
||
def step( | ||
|
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
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.
This is currently not tested