emulsim.elements.fields module
Provides elements that represent extended, discretized fields.
Element representing a homogeneous, changing field. |
|
Element representing a homogeneous, constant field. |
|
Element representing a scalar spatially-resolved field. |
|
Element representing multiple spatially-resolved fields. |
|
Element representing the scalar field of a boundary of a field. |
- class FieldCollectionElement(data: ndarray | None = None, parameters: dict[str, Any] | None = None)[source]
Bases:
ArrayElementBaseElement representing multiple spatially-resolved fields.
- Parameters Dictionary:
grid: The grid on which the fields are discretized (default=None)
label: The name of the field collection (default=’’)
plot_args: Extra arguments for plotting this element (default={})
- Parameters:
data – The data describing the state
parameters – Additional parameters that affect the element
Parameters of FieldCollectionElement:
- plot_args
Extra arguments for plotting this element (Default value:
{})- grid
The grid on which the fields are discretized. The grid also determines the space dimension and its extension. (Default value:
None)- label
The name of the field collection (Default value:
'')
- copy(method: Literal['clean', 'shallow', 'data'], data=None)[source]
Create a copy of the state.
- Parameters:
method (str) – Determines whether a clean, shallow, or data copy is performed. See
copy()for details.data – Data to be used instead of the one in the current state. This data is used as is and not copied!
- Returns:
A copy of the current state object
- property field: FieldCollection
all fields.
- Type:
- classmethod from_fields(fields: FieldCollection) FieldCollectionElement[source]
Create a scalar field element from a scalar field.
- Parameters:
field (
FieldCollection) – The field collection that initializes the element- Returns:
The initialized instance
- Return type:
- get_concentrations(points: ndarray)[source]
Determine concentrations at the given points.
- Parameters:
points (
ndarray) – The coordinates of the single point or the list of points at which the concentrations are returned
- property grid: CartesianGrid
discretization grid.
- Type:
- make_add_amounts_compiled() Callable[source]
Get a compiled function for adding amount to the field.
- make_get_concentrations_compiled() Callable[source]
Get a compiled function for obtaining concentrations.
- parameters_default = [Parameter(name='grid', default_value=None, cls=<class 'object'>, description='The grid on which the fields are discretized. The grid also determines the space dimension and its extension.', choices=None, required=False, hidden=False, extra={'serializer': <function FieldCollectionElement.<lambda>>, 'unserializer': <bound method GridBase.from_state of <class 'pde.grids.base.GridBase'>>}), Parameter(name='label', default_value='', cls=<class 'str'>, description='The name of the field collection', choices=None, required=False, hidden=False, extra={})]
parameters (with default values) of this subclass
- Type:
- class FieldElementBase(data: ndarray | None = None, parameters: dict[str, Any] | None = None)[source]
Bases:
ArrayElementBaseBase class for field elements.
- Parameters Dictionary:
plot_args: Extra arguments for plotting this element (default={})
- Parameters:
data – The data describing the state
parameters – Additional parameters that affect the element
Parameters of FieldElementBase:
- plot_args
Extra arguments for plotting this element (Default value:
{})
- abstractmethod add_amount(point: ndarray, amount: float)[source]
Add the given amount to the field.
- check_coupling_dim(dim: int) None[source]
Checks the dimension of a coupled field.
- Parameters:
dim (int) – The dimension of the element that needs to be coupled to this field
- Raises:
DimensionError – if the dimensions are incompatible
- abstractmethod get_concentration(points)[source]
Determine concentration at the given points.
- Parameters:
points (
ndarray) – The coordinates of the single point or the list of points at which the concentration is returned
- abstract property grid: CartesianGrid
discretization grid.
- make_add_amount_compiled() Callable[source]
Get a compiled function for adding amount to the field.
- make_get_concentration_compiled() Callable[source]
Get a compiled function for obtaining concentrations.
- class MeanfieldElement(data: float = 0, parameters: dict[str, Any] | None = None)[source]
Bases:
FieldElementBaseElement representing a homogeneous, changing field.
- Parameters Dictionary:
bounds: Sets the size of the Cartesian space covered by this element (default=None)
plot_args: Extra arguments for plotting this element (default={})
volume: Volume of the element (default=-1.0)
- Parameters:
Parameters of MeanfieldElement:
- plot_args
Extra arguments for plotting this element (Default value:
{})- bounds
Sets the size of the Cartesian space covered by this element. This should be a list of tuples, where each element denotes the lower and upper bounds of an axis. The number of elements then determines the dimension of the space (Default value:
None)- volume
Volume of the element. If negative, the volume is determine from bounds (Default value:
-1.0)
- add_amount(point: ndarray, amount: float)[source]
Add the given amount to the field.
- Parameters:
point – Not used and only retained to match the interface
amount – The total amount added to the field
- check_coupling_dim(dim: int) None[source]
Checks the dimension of a coupled field.
- Parameters:
dim (int) – The dimension of the element that needs to be coupled to this field
- property field: ScalarField
representation as a scalar field.
- Type:
- classmethod from_field(field: ScalarField, parameters: dict[str, Any] | None = None) MeanfieldElement[source]
Create a mean field element from a scalar field.
- Parameters:
field (
ScalarField) – The scalar field that initializes the elementparameters (dict) – Additional parameters determining how the element behaves. Note that the entry ‘bounds’ will be overwritten by the data from field.
- Returns:
The initialized instance
- Return type:
- get_concentration(points: ndarray)[source]
Determine concentration at the given points.
- Parameters:
points (
ndarray) – The coordinates of the single point or the list of points at which the concentration is returned
- grid
discretization grid.
- make_add_amount_compiled() Callable[source]
Get a compiled function for adding amount to the field.
- make_get_concentration_compiled() Callable[source]
Get a compiled function for obtaining concentrations.
- parameters_default = [Parameter(name='bounds', default_value=None, cls=<class 'object'>, description='Sets the size of the Cartesian space covered by this element. This should be a list of tuples, where each element denotes the lower and upper bounds of an axis. The number of elements then determines the dimension of the space', choices=None, required=True, hidden=False, extra={}), Parameter(name='volume', default_value=-1, cls=<class 'float'>, description='Volume of the element. If negative, the volume is determine from `bounds`', choices=None, required=False, hidden=False, extra={})]
parameters (with default values) of this subclass
- Type:
- plot(color='tab:blue', *args, title: str | None = None, filename: str | None = None, action: Literal['auto', 'close', 'none', 'sca', 'show'] = 'auto', ax_style: dict[str, Any] | None = None, fig_style: dict[str, Any] | None = None, ax=None, **kwargs)[source]
Plot the field.
- Parameters:
color – The color in which the field is shown. All matplotlib color specifications are allowed.
title (str) – Title of the plot. If omitted, the title might be chosen automatically.
filename (str, optional) – If given, the plot is written to the specified file.
action (str) – Decides what to do with the final figure. If the argument is set to show,
matplotlib.pyplot.show()will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling
matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling
matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.ax (
matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.
- class ReservoirElement(data: float = 0, parameters: dict[str, Any] | None = None)[source]
Bases:
ArrayElementBaseElement representing a homogeneous, constant field.
- Parameters Dictionary:
plot_args: Extra arguments for plotting this element (default={})
- Parameters:
data (float) – The concentration in the field
- add_amount(point: ndarray, amount: float)[source]
Add the given amount to the field.
- Parameters:
point – Not used and only retained to match the interface
amount – The total amount added to the field
- dim = None
- get_concentration(points: ndarray)[source]
Determine concentration at the given points.
- Parameters:
points (
ndarray) – The coordinates of the single point or the list of points at which the concentration is returned
- make_add_amount_compiled() Callable[source]
Get a compiled function for adding amount to the field.
- make_get_concentration_compiled() Callable[source]
Get a compiled function for obtaining concentrations.
- plot(color='tab:blue', *args, title: str | None = None, filename: str | None = None, action: Literal['auto', 'close', 'none', 'sca', 'show'] = 'auto', ax_style: dict[str, Any] | None = None, fig_style: dict[str, Any] | None = None, ax=None, **kwargs)[source]
Plot the field.
- Parameters:
color – The color in which the field is shown. All matplotlib color specifications are allowed.
title (str) – Title of the plot. If omitted, the title might be chosen automatically.
filename (str, optional) – If given, the plot is written to the specified file.
action (str) – Decides what to do with the final figure. If the argument is set to show,
matplotlib.pyplot.show()will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling
matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling
matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.ax (
matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.
- class ScalarBoundaryFieldElement(data: int | float | complex | number | ndarray[Any, dtype[number]] = 0, parameters: dict[str, Any] | None = None)[source]
Bases:
ScalarFieldElementElement representing the scalar field of a boundary of a field.
Note
The data described by this element are volume concentrations with units length**-dim, where dim is the dimension of the bulk (so the boundary has dimensions dim - 1). To convert the concentration in a particular cell into a total amount it has to be multiplied by the cell volume and the thickness of the boundary.
- Parameters Dictionary:
axis: Axis along which the boundary is placed (default=-1)
axis_position: Position of the boundary along the axis (default=nan)
grid: The grid on which the field is discretized (default=None)
label: The name of the field (default=’’)
plot_args: Extra arguments for plotting this element (default={})
plot_thickness: Thickness used when plotting the boundary (default=1.0)
thickness: Thickness of the boundary, which affects calculations of total amounts and potentially boundary conditions (default=1.0)
- Parameters:
Parameters of ScalarBoundaryFieldElement:
- plot_args
Extra arguments for plotting this element (Default value:
{})- grid
The grid on which the field is discretized. The grid also determines the space dimension and its extension. (Default value:
None)- label
The name of the field (Default value:
'')- axis
Axis along which the boundary is placed (Default value:
-1)- axis_position
Position of the boundary along the axis. If omitted, the boundary might not support some operations. (Default value:
nan)- thickness
Thickness of the boundary, which affects calculations of total amounts and potentially boundary conditions (Default value:
1.0)- plot_thickness
Thickness used when plotting the boundary (Default value:
1.0)
- check_coupling_dim(dim: int) None[source]
Checks the dimension of a coupled field.
- Parameters:
dim (int) – The dimension of the element that needs to be coupled to this field
- Raises:
DimensionError – if the dimensions are incompatible
- classmethod from_bulk_grid(grid: CartesianGrid, axis: int, upper: bool | None = None, data: int | float | complex | number | ndarray[Any, dtype[number]] = 0, parameters: dict[str, Any] | None = None) ScalarBoundaryFieldElement[source]
Create a scalar boundary element using a grid describing the full domain.
- Parameters:
grid (
CartesianGrid) – The scalar field describing the full domainaxis (int) – The axis along which the boundary is initialized
upper (bool) – Specified whether the upper or lower boundary along the given axis is specified by this field.
data (
ndarrayor float, optional) – Field values at the support points of the gridparameters (dict) – Additional parameters determining how the element behaves.
- classmethod from_field(field: ScalarField, parameters: dict[str, Any] | None = None) ScalarBoundaryFieldElement[source]
Create a scalar boundary element from a scalar field.
- Parameters:
field (
ScalarField) – The scalar field that initializes the elementparameters (dict) – Additional parameters determining how the element behaves.
- Returns:
The initialized instance
- Return type:
- make_add_amount_compiled() Callable[source]
Get a compiled function for adding amount to the field.
- parameters_default = [Parameter(name='grid', default_value=None, cls=<class 'object'>, description='The grid on which the field is discretized. The grid also determines the space dimension and its extension.', choices=None, required=False, hidden=False, extra={'serializer': <function ScalarBoundaryFieldElement.<lambda>>, 'unserializer': <bound method GridBase.from_state of <class 'pde.grids.base.GridBase'>>}), Parameter(name='axis', default_value=-1, cls=<class 'int'>, description='Axis along which the boundary is placed', choices=None, required=False, hidden=False, extra={}), Parameter(name='axis_position', default_value=nan, cls=<class 'float'>, description='Position of the boundary along the axis. If omitted, the boundary might not support some operations.', choices=None, required=False, hidden=False, extra={}), Parameter(name='thickness', default_value=1, cls=<class 'float'>, description='Thickness of the boundary, which affects calculations of total amounts and potentially boundary conditions', choices=None, required=False, hidden=False, extra={}), Parameter(name='plot_thickness', default_value=1, cls=<class 'float'>, description='Thickness used when plotting the boundary', choices=None, required=False, hidden=False, extra={}), Parameter(name='label', default_value='', cls=<class 'str'>, description='The name of the field', choices=None, required=False, hidden=False, extra={})]
parameters (with default values) of this subclass
- Type:
- plot(colorbar: bool = False, *args, title: str | None = None, filename: str | None = None, action: Literal['auto', 'close', 'none', 'sca', 'show'] = 'auto', ax_style: dict[str, Any] | None = None, fig_style: dict[str, Any] | None = None, ax=None, **kwargs)[source]
Plot the boundary field element.
- Parameters:
title (str) – Title of the plot. If omitted, the title might be chosen automatically.
filename (str, optional) – If given, the plot is written to the specified file.
action (str) – Decides what to do with the final figure. If the argument is set to show,
matplotlib.pyplot.show()will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling
matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling
matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.ax (
matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.colorbar (bool) – Flag determining whether a colorbar is shown.
**kwargs – All remaining parameters are forwarded to
matplotlib.axes.Axes.pcolormesh
- class ScalarFieldElement(data: int | float | complex | number | ndarray[Any, dtype[number]] = 0, parameters: dict[str, Any] | None = None)[source]
Bases:
FieldElementBaseElement representing a scalar spatially-resolved field.
- Parameters Dictionary:
grid: The grid on which the field is discretized (default=None)
label: The name of the field (default=’’)
plot_args: Extra arguments for plotting this element (default={})
- Parameters:
Parameters of ScalarFieldElement:
- plot_args
Extra arguments for plotting this element (Default value:
{})- grid
The grid on which the field is discretized. The grid also determines the space dimension and its extension. (Default value:
None)- label
The name of the field (Default value:
'')
- copy(method: Literal['clean', 'shallow', 'data'] = 'data', data=None)[source]
Create a copy of the state.
- Parameters:
method (str) – Determines whether a clean, shallow, or data copy is performed. See
copy()for details.data – Data to be used instead of the one in the current state. This data is used as is and not copied!
- Returns:
A copy of the current state object
- property field: ScalarField
the scalar field.
- Type:
- classmethod from_field(field: ScalarField, parameters: dict[str, Any] | None = None) ScalarFieldElement[source]
Create a scalar field element from a scalar field.
- Parameters:
field (
ScalarField) – The scalar field that initializes the elementparameters (dict) – Additional parameters determining how the element behaves. Note that the entries ‘grid’ and ‘label’ will be overwriten by the data from field.
- Returns:
The initialized instance
- Return type:
- get_concentration(points: ndarray)[source]
Determine concentration at the given points.
- Parameters:
points (
ndarray) – The coordinates of the single point or the list of points at which the concentration is returned
- property grid: CartesianGrid
discretization grid.
- Type:
- make_add_amount_compiled() Callable[source]
Get a compiled function for adding amount to the field.
- make_get_concentration_compiled() Callable[source]
Get a compiled function for obtaining concentrations.
- parameters_default = [Parameter(name='grid', default_value=None, cls=<class 'object'>, description='The grid on which the field is discretized. The grid also determines the space dimension and its extension.', choices=None, required=False, hidden=False, extra={'serializer': <function ScalarFieldElement.<lambda>>, 'unserializer': <bound method GridBase.from_state of <class 'pde.grids.base.GridBase'>>}), Parameter(name='label', default_value='', cls=<class 'str'>, description='The name of the field', choices=None, required=False, hidden=False, extra={})]
parameters (with default values) of this subclass
- Type: