Skip to content

Cracking submodel - #1232

Merged
valentinsulzer merged 113 commits into
pybamm-team:developfrom
weilongai:pre-release/cracking
Nov 16, 2020
Merged

Cracking submodel#1232
valentinsulzer merged 113 commits into
pybamm-team:developfrom
weilongai:pre-release/cracking

Conversation

@weilongai

@weilongai weilongai commented Nov 4, 2020

Copy link
Copy Markdown
Contributor

Description

A new submodel for particle cracking in pybamm. No dependencies that are required for this change.

Fixes #671

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.

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • No style issues: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three at once, using $ python run-tests.py --quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Additional notes of the actions:

weilongai and others added 30 commits April 28, 2020 14:34
Test automated build and delployment
Comment thread pybamm/models/submodels/particle_cracking/base_cracking.py Outdated
Comment thread examples/notebooks/submodel_cracking_DFN_or_SPM.ipynb
@weilongai

Copy link
Copy Markdown
Contributor Author

There are errors for testing the crack model, because of not matching shapes as below. Does anyone know how to define them in test functions, e.g. test_SPM, test_DFN and test_crack_propagation? There is no error in notebook examples.

  File "/home/aishine/GEM/PyBaMM/pybamm/models/submodels/particle_cracking/base_cracking.py", line 148, in _get_standard_surface_variables
    a_cr = (roughness - 1) * a0  # normalised crack surface area

  File "/home/aishine/GEM/PyBaMM/pybamm/expression_tree/symbol.py", line 836, in test_shape
    raise pybamm.ShapeError("Cannot find shape (original error: {})".format(e))
pybamm.expression_tree.exceptions.ShapeError: Cannot find shape (original error: operands could not be broadcast together with shapes (11,1) (33,1) )

@valentinsulzer

valentinsulzer commented Nov 15, 2020

Copy link
Copy Markdown
Member

For test_crack_propagation, you need to add auxiliary_domains={"secondary": "current collector"} to the Variable you define in CrackPropagation.get_fundamental_variables. The tests are written with pybamm.settings.debug_mode = True, which performs additional shape checks to make sure the model would be compatible with 2+1D. This isn't a problem in your notebooks because you only ever solve it in 1D.
For test_SPM and test_DFN, it seems like a parameter error, you can comment those out if you want and open a new issue specifically for fixing those.

Edit: the parameter values can be fixed by setting e.g.

        options = {"particle": "Fickian diffusion", "particle cracking": None}
        model = pybamm.lithium_ion.SPM(options)
        chemistry = pybamm.parameter_sets.Ai2020
        parameter_values = pybamm.ParameterValues(chemistry=chemistry)
        modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
        modeltest.test_all()

but then it fails the standard model tests. We can fix in a separate issue

@weilongai

weilongai commented Nov 16, 2020

Copy link
Copy Markdown
Contributor Author

For test_crack_propagation, you need to add auxiliary_domains={"secondary": "current collector"} to the Variable you define in CrackPropagation.get_fundamental_variables. The tests are written with pybamm.settings.debug_mode = True, which performs additional shape checks to make sure the model would be compatible with 2+1D. This isn't a problem in your notebooks because you only ever solve it in 1D.
For test_SPM and test_DFN, it seems like a parameter error, you can comment those out if you want and open a new issue specifically for fixing those.

Edit: the parameter values can be fixed by setting e.g.

        options = {"particle": "Fickian diffusion", "particle cracking": None}
        model = pybamm.lithium_ion.SPM(options)
        chemistry = pybamm.parameter_sets.Ai2020
        parameter_values = pybamm.ParameterValues(chemistry=chemistry)
        modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
        modeltest.test_all()

but then it fails the standard model tests. We can fix in a separate issue

Thanks! Any suggestions to improve the coverage of the functions in parameters? It is strange that they are not covered in /PyBaMM/tests/unit/test_parameters/test_parameter_sets/test_LCO_Ai2020.py

BTW, can I simply delete /PyBaMM/.github/release_checklist.md? I cannot find it in the pybamm main repository.

Comment thread tests/unit/test_parameters/test_parameter_sets/test_LCO_Ai2020.py Outdated
Comment thread pybamm/parameters/lithium_ion_parameters.py Outdated
"anode",
"both",
]:
raise pybamm.OptionError(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To cover this, add a line either in test_base_battery_model.py (see test_options in it) and add a test that catches the error when you pass a bad cracking model.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange because I have added one like in lines 169-171 of test_base_battery_model.py

        # crack model
        with self.assertRaisesRegex(pybamm.OptionError, "particle cracking"):
            pybamm.BaseBatteryModel({"particle cracking": "bad particle cracking"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Then I think you need to add a line in test_options in test_lithium_ion_parameters.py and that should fix it. I think with this, the testing of the parameters and Rob's fix for the DFN & other tests the coverage should be pretty much sorted out.

@rtimms

rtimms commented Nov 16, 2020

Copy link
Copy Markdown
Contributor

looks like the issue with the test is because for some reason c_s_rav has the wrong shape_for_testing:

ipdb> R0.shape_for_testing
(33, 1)
ipdb> R0.domain
['negative electrode']
ipdb> c_s_rav.domain
['negative electrode']
ipdb> c_s_rav.shape_for_testing
(11, 1)

@rtimms

rtimms commented Nov 16, 2020

Copy link
Copy Markdown
Contributor

If you change the definition of _evaluate_for_shape in Integral (line 583 of unary_operators.py) to

    def _evaluate_for_shape(self):
        """ See :meth:`pybamm.Symbol.evaluate_for_shape_using_domain()` """
        return pybamm.evaluate_for_shape_using_domain(
            self.domain, self.auxiliary_domains
        )

then it fixes the tests. Weird that this hadn't caused an error before...


chemistry = pybamm.parameter_sets.Ai2020
parameter_values = pybamm.ParameterValues(chemistry=chemistry)
options = {"particle": "Fickian diffusion", "particle cracking": "anode"}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are almost there. To increase the coverage in the LiCo2 parameters you should include the cathode here, either in this model, or just copy the whole test and run it with cracking in the cathode. This will also improve the coverage in base_lithium_ion_model.py.



# class TestSPMeWithCrack(unittest.TestCase):
# def test_well_posed_none_crack(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Rob's fix sorted out the issue with this test, then uncommenting these lines (for all models) should get the coverage sorted out.

@brosaplanella brosaplanella left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Really nice work Weilong :)

@valentinsulzer valentinsulzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all our comments @weilongai, this looks great now! We should still figure out at some point what the discrepancy is with your model in Matlab

@valentinsulzer

Copy link
Copy Markdown
Member

@all-contributors add @weilongai for code, example, test

@allcontributors

Copy link
Copy Markdown
Contributor

@tinosulzer

I've put up a pull request to add @weilongai! 🎉

@valentinsulzer
valentinsulzer merged commit 931792b into pybamm-team:develop Nov 16, 2020
@weilongai

Copy link
Copy Markdown
Contributor Author

Thanks for all your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add mechanical submodel for particles

7 participants