Two-phase zone exchange
Independent zones of a two-phase apparatus.
- Class:
TwoPhaseZoneExchangeSystem - Import:
from skcomplex.systems.physics.statistical_mechanics import TwoPhaseZoneExchangeSystem - Field:
physics/statistical_mechanics - Topics:
jump process,binomial,fluctuations,two-phase flow - References:
- Barsky 2020
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.physics.statistical_mechanics import TwoPhaseZoneExchangeSystem
trajectory = TwoPhaseZoneExchangeSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
n_zones |
100 |
Na |
100.0 |
p |
0.1 |
k |
1.0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | none |
| Laws | jump |
| Randomness | stochastic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class TwoPhaseZoneExchangeSystem(BaseSystem):
"""Independent zones of a two-phase apparatus.
Each zone exchanges particles with the rest of the apparatus.
The zones start empty and their numbers of particles settle on the binomial distribution of mean `Na p` and variance
`Na p (1 - p)`. The system has the numbers `zones.N`.
Args:
n_zones:
The number of independent zones.
Na:
The number of particles in the apparatus and a zone.
p:
The volume fraction of a zone.
k:
The rate of exchange.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import TwoPhaseZoneExchangeSystem
>>> TwoPhaseZoneExchangeSystem(5).prepare().system_.elements[0].size
5
"""
field = 'physics/statistical_mechanics'
topics = ('jump process', 'binomial', 'fluctuations', 'two-phase flow')
references = ('Barsky 2020',)
until = 20.0
dt = 0.5
def __init__(
self,
n_zones: int = 100,
*,
Na: float = 100.0,
p: float = 0.1,
k: float = 1.0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.n_zones = n_zones
self.Na = Na
self.p = p
self.k = k
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the zones and their exchange of particles.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
self.system_ = System(
self.label,
elements=[ZoneElement('zones', size=self.n_zones)],
interactions=[ZoneExchangeInteraction('exchange', target='zones', Na=self.Na, p=self.p, k=self.k)],
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
ZoneElement, fromElement
Interactions:
ZoneExchangeInteraction, fromInteraction
class ZoneElement(Element):
"""Small zones of a two-phase apparatus, with the number `N` of particles in each.
Args:
label:
The label of the zone or the group.
N:
The initial number of particles in the zone, or one number per zone.
size:
The number of zones, or `None` for one.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import ZoneElement
>>> ZoneElement('zone').N
0.0
"""
def __init__(self, label: str, *, N: object = 0.0, size: int | None = None) -> None:
super().__init__(label, size=size)
self.N = N
class ZoneExchangeInteraction(Interaction):
"""Exchange of particles between a small zone and the rest of a two-phase apparatus.
Every one of the `Na` particles enters the zone at the rate `k p` and leaves it at the rate `k (1 - p)`, where
`p = dV / V` is the volume fraction of the zone, so the number in the zone is binomial with mean `Na p`.
Args:
label:
The label of the interaction.
target:
The path of the zones, whose value `N` counts their particles.
Na:
The number of particles in the apparatus and the zone.
p:
The volume fraction of the zone.
k:
The rate of exchange.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import ZoneExchangeInteraction
>>> ZoneExchangeInteraction('exchange', target='zones').Na
100.0
"""
law_classes = (JumpLaw,)
def __init__(
self,
label: str,
*,
target: Role,
Na: Annotated[float, RealSet.closed_open(0, oo)] = 100.0,
p: Annotated[float, RealSet.closed_open(0, oo)] = 0.1,
k: Annotated[float, RealSet.open(0, oo)] = 1.0,
) -> None:
super().__init__(label)
self.target = target
self.Na = Na
self.p = p
self.k = k
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the entries into and exits from the zone.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
s, N = context, context.target.N
self.laws_ = [
JumpLaw(s.k * s.p * (s.Na - N), {N: 1}),
JumpLaw(s.k * (1 - s.p) * N, {N: -1}),
]