PyBaMM workarounds#

Workarounds for PyBaMM behaviour that PyTES depends on.

Every workaround lives here, never in a model or submodel. Each one names the upstream issue it works around and the condition under which it can be removed.

class pytes.compat.LimitedFiniteVolume(options=None, regularisation=1e-06)[source]#

Bases: FiniteVolume

Finite volumes with a second-order, limited upwind scheme (MUSCL with the van Albada limiter) for pybamm.upwind().

First-order upwinding takes the value on a face from the cell upstream of it. This scheme adds a limited gradient: on the face j + 1/2 downstream of cell j,

h_{j+1/2} = h_j + g_j (z_{j+1/2} - z_j),

with g_j the van Albada average of the backward and forward gradients,

a = (h_j - h_{j-1}) / (z_j - z_{j-1}), b = (h_{j+1} - h_j) / (z_{j+1} - z_j),

g_j = (a + b) max(a b, 0) / (a^2 + b^2 + eps^2),

so it works on non-uniform meshes. The limited gradient is zero at a local extremum, so no new extremum appears; it is continuous, but its derivative jumps at extrema, as any limiter that prevents oscillations must. eps keeps it defined where both gradients vanish: regularisation times the variable’s scale over the domain length.

At the ends the scheme is first order, as PyBaMM’s: the inflow face takes the inflow value (the ghost node of pybamm.upwind()), and the outflow face takes the value in the last cell, so the outflow value is the boundary value with constant extrapolation (see fluid_spatial_method()). For the gradients, these two values sit on the inflow and outflow faces: the last cell, a first-order donor, holds the value it advects out. A steady linear profile is then reconstructed exactly.

Parameters:
upwind_or_downwind(symbol, discretised_symbol, bcs, direction)[source]#

The values on the cell faces, upwinded with a limited gradient (see the class docstring). Only upwinding is implemented.

Parameters:
  • symbol (pybamm.Symbol) – The advected variable.

  • discretised_symbol (pybamm.Symbol) – The discretised variable.

  • bcs (dict) – The boundary conditions; a Dirichlet condition on the left gives the inflow.

  • direction (str) – “upwind”.

Raises:

NotImplementedError – For downwinding.

pytes.compat.fluid_spatial_method(scheme='second order', regularisation=1e-06)[source]#

The spatial method for the fluid’s flow path: finite volumes whose boundary values are the values in the end cells (constant extrapolation, ignoring boundary conditions), as pytes.compat.upwind_inlet_value() needs, so the outlet value is the value advected out of the domain.

Parameters:
  • scheme (str, optional) – “second order” (default), LimitedFiniteVolume (F-052); or “first order”, PyBaMM’s own upwinding, e.g. pybamm.Simulation(model, spatial_methods={** model.default_spatial_methods, "flow path": fluid_spatial_method("first order")}).

  • regularisation (float, optional) – See LimitedFiniteVolume.

Returns:

pybamm.FiniteVolume

Raises:

ValueError – If the scheme is not recognised.

pytes.compat.resolve_coupled_variables(model)[source]#

Replace every pybamm.CoupledVariable in a model by the variable it names.

Resolves the equations, boundary and initial conditions, events and variables, in place. The caller checks the wiring first (every name provided, no cycles).

Parameters:

model (pybamm.BaseModel) – The model, whose variables provide every coupled name.

pytes.compat.upwind_inlet_value(T, T_in)[source]#

Dirichlet value that makes pybamm.upwind() advect exactly T_in into the domain.

Parameters:
Returns:

pybamm.Symbol – (T_in + T_1) / 2, with T_1 the value in the first cell. This needs constant extrapolation on the flow domain (see pytes.compat.fluid_spatial_method()).