Elements
Define the elements that the systems of several fields share.
They hold one nonnegative amount, or the position of a point in a continuous space.
NonnegativeElement(label, *, x=0.0, size=None, space=None)
Bases: Element
An element that holds one nonnegative number x.
The number is an amount, a share, a concentration, or the density at one class of a distribution. The reactions,
flows, and encounters of its system change it, and a value below zero is rejected. With size it holds one number
per member, and with space one number per site, such as a distribution over the classes of a lattice.
Unlike Element, which takes any values, it fixes one value x at zero or above. Choose it when a system tracks an
amount that cannot be negative, such as a count, a mass, or a sum of money.
It appears in many fields. The number of people infected in an epidemic, the moles of a chemical species in a reactor, the money in a bank account, and the tokens in a place of a Petri net are each one nonnegative number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the element, unique among the components of its system. |
required |
x
|
Annotated[object, closed_open(0, oo)]
|
The initial value, a nonnegative number, or one per member or site. |
0.0
|
size
|
int | None
|
The number of members, or |
None
|
space
|
BaseSpace | None
|
The space with one member per site, or |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
default_visual_ |
How the element is drawn by default, the |
Examples:
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.general.elements import NonnegativeElement
>>> System(elements=[NonnegativeElement('A', x=990)]).prepare().simulate(until=2).get_values('A.x').tolist()
[990.0]
>>> System(elements=[NonnegativeElement('A', x=-1.0)]).prepare()
Traceback (most recent call last):
...
skcomplex.core.errors.ValidationError: ...
Source code in src/skcomplex/systems/general/elements/_nonnegative.py
56 57 58 59 60 61 62 63 64 65 | |
PointElement(label, x=0.0, *, values=None, size=None, space=None)
Bases: Element
An element of a point at the position x that the forces on it move.
The forces give the acceleration x'' of the position, and the velocity is the value x', which starts at zero
unless values gives it.
Unlike Element, which takes any values, it names the position x and draws it as a point. Choose it when members
are bodies that move by forces in a continuous space.
It appears in many fields. Atoms of a gas, stars of a cluster, birds of a flock, and pedestrians of a crowd are points that move by the forces on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the point. |
required |
x
|
ArrayLike
|
The initial position. A number applies to every component. |
0.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the starting velocity |
None
|
size
|
int | None
|
The number of points, or |
None
|
space
|
BaseSpace | None
|
The space whose sites hold one point each, or |
None
|
Examples:
>>> import numpy as np
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.general.elements import PointElement
>>> from skcomplex.core.components.interactions import Interaction
>>> from skcomplex.core.components.laws import RateLaw
>>> ball = PointElement('ball', x=np.array([1.0, 0.0]), values={"x'": np.array([0.0, 1.0])})
>>> spring = lambda s: [RateLaw(s.target.x.diff(s.t, 2), -s.target.x)]
>>> well = Interaction('well', roles={'target': 'ball'}, laws=spring)
>>> system = System(elements=[ball], interactions=[well]).prepare()
>>> position = system.simulate(until=np.pi / 2, dt=np.pi / 2).get_values('ball.x')[-1]
>>> round(float(position[1]), 3)
1.0
Source code in src/skcomplex/systems/general/elements/_point.py
59 60 61 62 63 64 65 66 67 68 69 | |