FaradayInstitution / BPX

BPX schema in pydantic and JSON schema format, and parsers
MIT License
25 stars 12 forks source link

Validation based on models #34

Closed ikorotkin closed 1 year ago

ikorotkin commented 1 year ago

A (working) attempt to add validation based on the model according to issue #29 and following roadmap #22.

This PR is based on #33 and supports blended electrodes for all models.

Added multiple tests and validation that the given model (SPM, SPMe, or DFN) corresponds to a proper parameter set. In the case of SPM, some of the parameters should not be included:

"Header": {
    "BPX": 1.0,
    "Model": "SPM",
},
"Parameterisation": {
    "Cell": {
        "Ambient temperature [K]": 299.0,
        "Initial temperature [K]": 299.0,
        "Reference temperature [K]": 299.0,
        "Electrode area [m2]": 2.0,
        "External surface area [m2]": 2.2,
        "Volume [m3]": 1.0,
        "Number of electrode pairs connected in parallel to make a cell": 1,
        "Nominal cell capacity [A.h]": 5.0,
        "Lower voltage cut-off [V]": 2.0,
        "Upper voltage cut-off [V]": 4.0,
    },
    "Negative electrode": {
        "Particle radius [m]": 5.86e-6,
        "Thickness [m]": 85.2e-6,
        "Diffusivity [m2.s-1]": 3.3e-14,
        "OCP [V]": {"x": [0, 0.1, 1], "y": [1.72, 1.2, 0.06]},
        "Surface area per unit volume [m-1]": 383959,
        "Reaction rate constant [mol.m-2.s-1]": 1e-10,
        "Maximum concentration [mol.m-3]": 33133,
        "Minimum stoichiometry": 0.01,
        "Maximum stoichiometry": 0.99,
    },
    "Positive electrode": {
        "Thickness [m]": 75.6e-6,
        "Particle": {
            "Primary": {
                "Particle radius [m]": 5.22e-6,
                "Diffusivity [m2.s-1]": 4.0e-15,
                "OCP [V]": {"x": [0, 0.1, 1], "y": [1.72, 1.2, 0.06]},
                "Surface area per unit volume [m-1]": 382184,
                "Reaction rate constant [mol.m-2.s-1]": 1e-10,
                "Maximum concentration [mol.m-3]": 63104.0,
                "Minimum stoichiometry": 0.1,
                "Maximum stoichiometry": 0.9,
            },
            "Secondary": {
                "Particle radius [m]": 10.0e-6,
                "Diffusivity [m2.s-1]": 4.0e-15,
                "OCP [V]": {"x": [0, 0.1, 1], "y": [1.72, 1.2, 0.06]},
                "Surface area per unit volume [m-1]": 382184,
                "Reaction rate constant [mol.m-2.s-1]": 1e-10,
                "Maximum concentration [mol.m-3]": 63104.0,
                "Minimum stoichiometry": 0.1,
                "Maximum stoichiometry": 0.9,
            },
        },
    },
},

Note if we change the Model field to DFN or SPMe in this example, this will produce an error. Also note how we defined blended electrode (positive in this example). Some of the parameters are optional.

codecov[bot] commented 1 year ago

Codecov Report

:exclamation: No coverage uploaded for pull request base (develop@804d758). Click here to learn what that means. Patch has no changes to coverable lines.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #34 +/- ## ========================================== Coverage ? 97.06% ========================================== Files ? 9 Lines ? 307 Branches ? 0 ========================================== Hits ? 298 Misses ? 9 Partials ? 0 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.