DOF (Degree-of-Freedom) ArraysÂ¶
- class meshmode.dof_array.DOFArray(actx: Optional[arraycontext.context.ArrayContext], data: Tuple[Any])Â¶
This array type holds degree-of-freedom arrays for use with
Discretization
, with one entry in theDOFArray
for eachElementGroupBase
. The arrays contained within aDOFArray
are expected to be logically two-dimensional, with shape(nelements, ndofs_per_element)
, wherenelements
is the same asnelements
of the associated group.ndofs_per_element
is typically, but not necessarily, the same asnunit_dofs
of the associated group. The entries in this array are further arrays managed byarray_context
.One main purpose of this class is to describe the data structure, i.e. when a
DOFArray
occurs inside of further numpy object array, the level representing the array of element groups can be recognized (by people and programs).- array_contextÂ¶
An
ArrayContext
.
- entry_dtypeÂ¶
The (assumed uniform)
numpy.dtype
of the group arrays contained in this instance.
- __len__()Â¶
The following methods and attributes are implemented to mimic the functionality of
ndarray
s. They require theDOFArray
to bethaw()
ed.- shapeÂ¶
- sizeÂ¶
- copy()Â¶
- fill(value)Â¶
- conj()Â¶
- realÂ¶
- imagÂ¶
Implements the usual set of arithmetic operations, including broadcasting of numbers and over numpy object arrays.
Note
DOFArray
instances can be pickled and unpickled while the context managerarray_context_for_pickling
is active. If, for an array to be pickled, theArrayContext
given toarray_context_for_pickling()
does not agree witharray_context
, the array is frozen and rethawed. Ifarray_context
is None, theDOFArray
isthaw()
ed into the array context given toarray_context_for_pickling()
.
- meshmode.dof_array.rec_map_dof_array_container(f: Callable[[Any], Any], ary)Â¶
Applies f recursively to an
ArrayContainer
.Similar to
map_array_container()
, but does not further recurse onDOFArray
s.
- meshmode.dof_array.mapped_over_dof_arrays(f)Â¶
- meshmode.dof_array.rec_multimap_dof_array_container(f: Callable[[Any], Any], *args)Â¶
Applies f recursively to multiple
ArrayContainer
s.Similar to
multimap_array_container()
, but does not further recurse onDOFArray
s.
- meshmode.dof_array.multimapped_over_dof_arrays(f)Â¶
- meshmode.dof_array.flatten(ary: arraycontext.container.ArrayContainer, *, strict: bool = True) â†’ arraycontext.container.ArrayContainerÂ¶
Convert all
DOFArray
s into a â€śflatâ€ť array of degrees of freedom, where the resulting type of the array is given by theDOFArray.array_context
.Array elements are laid out contiguously, with the element group index varying slowest, element index next, and intra-element DOF index fastest.
Recurses into the
ArrayContainer
for allDOFArray
s.
- meshmode.dof_array.unflatten(actx: arraycontext.context.ArrayContext, discr, ary: arraycontext.container.ArrayContainer, ndofs_per_element_per_group: Optional[Iterable[int]] = None, *, strict: bool = True) â†’ arraycontext.container.ArrayContainerÂ¶
Convert all â€śflatâ€ť arrays returned by
flatten()
back toDOFArray
s.This function recurses into the
ArrayContainer
for allDOFArray
s. All class:DOFArrays inside the container ary must agree on the mapping from element group number to number of degrees of freedom, as given by ndofs_per_element_per_group (or via discr).- Parameters
ndofs_per_element â€“ if given, an iterable of numbers representing the number of degrees of freedom per element, overriding the numbers provided by the element groups in discr. May be used (for example) to handle
DOFArray
s that have only one DOF per element, representing some per-element quantity.strict â€“ if True, only
DOFArray
s are allowed as leaves in the container ary. If False, any non-DOFArray
are left as is.
- meshmode.dof_array.unflatten_like(actx: arraycontext.context.ArrayContext, ary: arraycontext.container.ArrayContainer, prototype: arraycontext.container.ArrayContainer, *, strict: bool = True) â†’ arraycontext.container.ArrayContainerÂ¶
Convert all â€śflatâ€ť arrays returned by
flatten()
back toDOFArray
s based on a prototype container.This function allows doing a roundtrip with
flatten()
for containers which haveDOFArray
s with different numbers of degrees of freedom. This is unlikeunflatten()
, where all theDOFArray
s must agree on the number of degrees of freedom per element group. For example, this enables â€śunflatteningâ€ť of arrays associated with differentDiscretization
s within the same container.
- meshmode.dof_array.flatten_to_numpy(actx: arraycontext.context.ArrayContext, ary: arraycontext.container.ArrayContainer, *, strict: bool = True) â†’ arraycontext.container.ArrayContainerÂ¶
Converts all
DOFArray
s into â€śflatâ€ťnumpy.ndarray
s usingflatten()
.
- meshmode.dof_array.unflatten_from_numpy(actx: arraycontext.context.ArrayContext, discr, ary: arraycontext.container.ArrayContainer, ndofs_per_element_per_group: Optional[Iterable[int]] = None, *, strict: bool = True) â†’ arraycontext.container.ArrayContainerÂ¶
Takes â€śflatâ€ť arrays returned by
flatten_to_numpy()
and reconstructs the correspondingDOFArray
s usingunflatten()
.
- meshmode.dof_array.flat_norm(ary, ord=None) â†’ floatÂ¶
Return an element-wise \(\ell^{\text{ord}}\) norm of ary.
- Parameters
ary â€“ may be a
DOFArray
or aArrayContainer
containing them.
- meshmode.dof_array.array_context_for_pickling(actx: arraycontext.context.ArrayContext)Â¶
A context manager that, for the current thread, sets the array context to be used for pickling and unpickling
DOFArray
s to actx.New in version 2021.1.