pisces.models.core.base.BaseModel.add_field#
- BaseModel.add_field(name: str, element_shape: tuple[int, ...] = (), units: str | Unit = None, data: unyt_array | ndarray = None, overwrite: bool = False, **kwargs)[source]#
Add a new physical field to the model.
Fields represent physical quantities (e.g., density, temperature, velocity) defined on the model’s spatial grid. This method creates a new field with optional initialization from user-provided data.
- Parameters:
name (
str) – Name of the field (e.g.,"density").element_shape (
tupleofint, optional) – Extra trailing dimensions for vector/tensor fields (e.g.,(3,)). Defaults to().units (
strorunyt.Unit, optional) – Units for the field. IfNone, the field is unitless.data (
unyt_arrayornumpy.ndarray, optional) – Values to initialize the field. IfNone, initialized to zeros. Must have shapegrid.shape + element_shape.overwrite (
bool, optional) – IfTrue, replaces an existing field with the same name. IfFalse, raisesKeyErrorif the field already exists.
- Raises:
ValueError – If provided data does not match the expected shape.
KeyError – If the field already exists and
overwrite=False.
Notes
The field is written to both memory and the on-disk HDF5 file under
/FIELDS/{name}.Unit handling is powered by
unyt.