Tutorial 1: running a model#

This is the first of a series of short tutorials, each showing one thing:

  1. Running a model (this notebook)

  2. Finned-tube models

  3. Packed-bed models

  4. Changing parameter values

  5. Plotting

  6. Experiments

PyTES models are PyBaMM models, so if you know PyBaMM you already know most of what follows. If you do not, nothing here assumes it.

Running a model takes three lines: choose a model, wrap it in a pybamm.Simulation, and solve it for a time span in seconds.

import pybamm

import pytes

model = pytes.SharpFrontModel()
simulation = pybamm.Simulation(model)
solution = simulation.solve([0, 3600])

SharpFrontModel is a heat battery made of a block of phase-change material (PCM) with aluminium fins, crossed by a tube carrying water (more on this in the next notebook). Every model comes with default parameter values, a mesh and a solver, so it runs as it is. For this model the defaults are a discharge: the battery starts fully charged, uniform at 70 °C, and water enters at 10 °C and 0.02 kg/s for one hour.

simulation.plot() opens an interactive plot of the main outputs, with a slider for time. Positions are shown in metres with spatial_unit="m" (PyBaMM’s default is micrometres, which suits battery electrodes):

simulation.plot(spatial_unit="m");

The outlet starts at 70 °C, then levels off while the PCM solidifies and releases its latent heat, and finally falls towards the inlet temperature once the PCM has solidified.

Outputs#

The solution holds every output of the model, by name. Each name ends with its units, and temperatures, powers, energies and times come in several units: "Outlet temperature [K]" and "Outlet temperature [degC]", "Power [W]" and "Power [kW]", "Time [s]", "Time [min]" and "Time [h]". .entries gives the values at the solution times, and calling an output gives its value at any time in seconds.

outlet = solution["Outlet temperature [degC]"]
print(f"final outlet temperature: {outlet.entries[-1]:.1f} degC")
print(f"outlet temperature after 30 min: {outlet(1800):.1f} degC")
print(f"energy delivered: {solution['Discharged energy [kWh]'].entries[-1]:.2f} kWh")
final outlet temperature: 12.9 degC
outlet temperature after 30 min: 43.7 degC
energy delivered: 2.42 kWh

To find an output, search the model’s variables:

model.variables.search("energy")
Results for 'energy': ['Heat transfer fluid thermal energy [J]', 'Phase-change material thermal energy [J]', 'Discharged energy [J]', 'Charged energy [J]', 'Storage thermal energy [J]', 'Total thermal energy [J]', 'Heat transfer fluid thermal energy [kWh]', 'Phase-change material thermal energy [kWh]', 'Discharged energy [kWh]', 'Charged energy [kWh]', 'Storage thermal energy [kWh]', 'Total thermal energy [kWh]']

Another model, the same code#

Every PyTES model is used the same way and has the same outputs, whatever its geometry. Here is a packed bed of spherical PCM capsules, whose default is a charge: the bed starts at 32 °C and water enters at 70 °C. Power is positive on discharge, so it is negative here.

bed = pybamm.Simulation(pytes.PackedBedModel())
bed_solution = bed.solve([0, 3600])
bed.plot(spatial_unit="m");

The next two tutorials look at these two families of models in more detail: finned tubes and packed beds.

Next: Tutorial 2: finned-tube models.