geometry.Geometry.add_field#
- Geometry.add_field(data, type='node', name=None)#
Add
Fielddata to theGeometry.Field data are scalar or vectorial data defined over the Geometry. This convenience function creates a
Fieldobject with the specified data and adds it to the Geometry object’sfieldsdict.Parameters#
- data: array_like
The field data. See
Fieldfor details.- type: str
The field type. See
Fieldfor details.- name: str
The field name. See
Fieldfor details. This name is also used as key to store the Field in thefieldsdict.
Returns#
FieldThe constructed and stored Field object.
See Also#
fields: Return a dict with all Fields on the Geometry.get_field(): Retrieve a Field by its name.del_field(): Delete a Field.convert_field(): Convert the Field to another Field type.field_report(): Return a short overview of the stored Fields
Examples#
>>> from hellotriangle.mesh import Mesh >>> M = Mesh(eltype='quad4').subdivide(2) >>> fld1 = M.add_field(np.asarray([0,1,1,2]), type='elemc', name='elemnr') >>> print(fld1) Field 'elemnr', type 'elemc', shape (4,), n_nodes=9, n_elems=4, nplex=4 [0 1 1 2]
>>> fld2 = M.convert_field('elemnr', totype='node', new_name='onnodes') >>> print(fld2) Field 'onnodes', type 'node', shape (9, 1), n_nodes=9, n_elems=4, nplex=4 [[0. ] [0.5] [1. ] [0.5] [1. ] [1.5] [1. ] [1.5] [2. ]]
>>> print(M.field_report()) Field 'elemnr', fldtype 'elemc', dtype int64, shape (4,) Field 'onnodes', fldtype 'node', dtype float64, shape (9, 1) >>> M.del_field('elemnr') >>> print(M.field_report()) Field 'onnodes', fldtype 'node', dtype float64, shape (9, 1)