geometry.Geometry.add_field#

Geometry.add_field(data, type='node', name=None)#

Add Field data to the Geometry.

Field data are scalar or vectorial data defined over the Geometry. This convenience function creates a Field object with the specified data and adds it to the Geometry object’s fields dict.

Parameters#

data: array_like

The field data. See Field for details.

type: str

The field type. See Field for details.

name: str

The field name. See Field for details. This name is also used as key to store the Field in the fields dict.

Returns#

Field

The constructed and stored Field object.

See Also#

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)