Skip to content

Heat

Heat transfer systems.

The package covers diffusion of heat on lattices and meshes, and cooling towards the surroundings.

CoffeeCupElement(label, *, T=90.0)

Bases: Element

Cup of coffee at the temperature T.

Parameters:

Name Type Description Default
label str

The label of the cup.

required
T float

The initial temperature of the coffee.

90.0

Examples:

>>> from skcomplex.systems.physics.heat import CoffeeCupElement
>>> CoffeeCupElement('coffee', T=60.0).T
60.0
Source code in src/skcomplex/systems/physics/heat/_cooling.py
42
43
44
def __init__(self, label: str, *, T: float = 90.0) -> None:
    super().__init__(label)
    self.T = T

CoolingCoffeeSystem(T=90.0, *, room=20.0, k=0.1, label='system', solver='auto', backend='auto')

Bases: BaseSystem

A cup of coffee whose temperature relaxes to that of the room.

The temperature follows T' = -k (T - T_room).

The heat flow is proportional to the discrepancy between the coffee and the room, a balancing feedback loop, so hot coffee cools and iced coffee warms, both exponentially with the time constant 1 / k. The system has the temperature coffee.T.

Parameters:

Name Type Description Default
T float

The initial temperature of the coffee.

90.0
room float

The temperature of the room.

20.0
k float

The rate of heat exchange.

0.1
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.heat import CoolingCoffeeSystem
>>> trajectory = CoolingCoffeeSystem(T=5.0).prepare().simulate(until=10.0)
>>> round(float(trajectory.get_values('coffee.T')[0]), 1)
5.0
Source code in src/skcomplex/systems/physics/heat/_cooling.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def __init__(
    self,
    T: float = 90.0,
    *,
    room: float = 20.0,
    k: float = 0.1,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.T = T
    self.room = room
    self.k = k

HeatDiffusionSystem(shape=(64, 64), *, D=1.0, spacing=1.0, boundary='zero-flux', label='system', solver='auto', backend='auto')

Bases: BaseSystem

Heat diffusing on a plate from a hot square in its middle.

The temperature follows du/dt = D laplacian(u).

The system has the temperature plate.u.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of sites along every dimension.

(64, 64)
D float

The diffusion coefficient.

1.0
spacing float

The distance between sites.

1.0
boundary str

'periodic', 'zero-flux' for an insulated plate, or 'fixed' for edges held at zero.

'zero-flux'
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the one the system chooses.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.heat import HeatDiffusionSystem
>>> HeatDiffusionSystem((10, 10), boundary='fixed').prepare().system_.elements[0].space.boundary
{'u': ('fixed', 0.0)}
Source code in src/skcomplex/systems/physics/heat/_heat.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    D: float = 1.0,
    spacing: float = 1.0,
    boundary: str = 'zero-flux',
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.shape = shape
    self.D = D
    self.spacing = spacing
    self.boundary = boundary

HeatElement(label, *, u=0.0, D=1.0, space=None)

Bases: Element

Sites of a plate with the temperature u and the heat diffusion coefficient D.

Parameters:

Name Type Description Default
label str

The label of the plate.

required
u object

The initial temperature, one value per site or one for all.

0.0
D Annotated[float, closed_open(0, oo)]

The diffusion coefficient.

1.0
space BaseSpace | None

The lattice or the mesh of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.heat import HeatElement
>>> HeatElement('site', D=0.5).D
0.5
Source code in src/skcomplex/systems/physics/heat/_heat.py
49
50
51
52
53
54
55
56
57
58
59
def __init__(
    self,
    label: str,
    *,
    u: object = 0.0,
    D: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.u = u
    self.D = D

HeatLShapeSystem(refine=3, *, D=1.0, temperature=harmonic, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Heat on the L-shaped domain with fixed boundary temperatures.

The domain is discretised by linear finite elements.

The plate starts cold inside, and its temperature relaxes to the solution of Laplace's equation with the boundary temperatures. The default boundary temperature is harmonic, so the steady state is known. The system has the temperature plate.u at the nodes of the mesh.

Parameters:

Name Type Description Default
refine int

The number of uniform refinements of the mesh.

3
D float

The diffusion coefficient.

1.0
temperature Callable[[Array, Array], Array] | float

The boundary temperature, a number or a function of the coordinates.

harmonic
label str

The label of the system, which names it when it is nested in another one.

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for implicit Euler steps of 0.05.

'auto'
backend BaseBackend | str

The backend that evaluates the compiled functions, or 'auto' for the one the system chooses.

'auto'

Examples:

>>> from skcomplex.systems.physics.heat import HeatLShapeSystem
>>> HeatLShapeSystem(1).prepare().system_.elements[0].space.prepare().size_
21
Source code in src/skcomplex/systems/physics/heat/_heat.py
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def __init__(
    self,
    refine: int = 3,
    *,
    D: float = 1.0,
    temperature: Callable[[Array, Array], Array] | float = harmonic,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.refine = refine
    self.D = D
    self.temperature = temperature

NewtonCoolingInteraction(label, *, target, room=20.0, k=0.1)

Bases: Interaction

Newton cooling of a body towards the temperature of the room.

The temperature T of the target follows T' = -k (T - room).

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the body that cools.

required
room float

The temperature of the room.

20.0
k Annotated[float, closed_open(0, oo)]

The rate of heat exchange.

0.1

Examples:

>>> from skcomplex.systems.physics.heat import NewtonCoolingInteraction
>>> NewtonCoolingInteraction('cooling', target='coffee', k=0.2).k
0.2
Source code in src/skcomplex/systems/physics/heat/_cooling.py
73
74
75
76
77
78
79
80
81
82
83
84
def __init__(
    self,
    label: str,
    *,
    target: Role,
    room: float = 20.0,
    k: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
) -> None:
    super().__init__(label)
    self.target = target
    self.room = room
    self.k = k

harmonic(x, y)

Return the harmonic function exp(x) sin(y).

It is a steady temperature known in closed form.

Parameters:

Name Type Description Default
x Array

The first coordinates.

required
y Array

The second coordinates.

required

Returns:

Name Type Description
values Array

The temperatures.

Examples:

>>> from skcomplex.systems.physics.heat import harmonic
>>> float(harmonic(0.0, 0.0))
0.0
Source code in src/skcomplex/systems/physics/heat/_heat.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def harmonic(x: Array, y: Array) -> Array:
    """Return the harmonic function `exp(x) sin(y)`.

    It is a steady temperature known in closed form.

    Args:
        x:
            The first coordinates.

        y:
            The second coordinates.

    Returns:
        values:
            The temperatures.

    Examples:
        >>> from skcomplex.systems.physics.heat import harmonic
        >>> float(harmonic(0.0, 0.0))
        0.0
    """
    return np.exp(x) * np.sin(y)