DOF (DegreeofFreedom) Arrays¶

class
meshmode.dof_array.
DOFArray
(actx: Optional[meshmode.array_context.ArrayContext], input_array)¶ This array type is a subclass of
numpy.ndarray
intended to hold degreeoffreedom arrays for use withDiscretization
, with one entry in theDOFArray
for eachElementGroupBase
. The arrays contained within aDOFArray
are expected to be logically twodimensional, 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. This array is derived fromnumpy.ndarray
with dtype object (“an object array”). 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
¶

entry_dtype
¶ The (assumed uniform)
numpy.dtype
of the group arrays contained in this instance.

classmethod
from_list
(actx: Optional[meshmode.array_context.ArrayContext], res_list) → meshmode.dof_array.DOFArray¶ Create a
DOFArray
from a list of arrays (one perElementGroupBase
). Parameters
actx – If None, the arrays in res_list must be
thaw()
ed.


meshmode.dof_array.
thaw
(actx: meshmode.array_context.ArrayContext, ary: numpy.ndarray) → numpy.ndarray¶ Call
thaw()
on the element group arrays making up theDOFArray
, using actx.Vectorizes over object arrays of
DOFArray
s.

meshmode.dof_array.
freeze
(ary: numpy.ndarray) → numpy.ndarray¶ Call
freeze()
on the element group arrays making up theDOFArray
, using theArrayContext
in ary.Vectorizes over object arrays of
DOFArray
s.

meshmode.dof_array.
flatten
(ary: numpy.ndarray) → Any¶ Convert a
DOFArray
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 intraelement DOF index fastest.
Vectorizes over object arrays of
DOFArray
s.

meshmode.dof_array.
unflatten
(actx: meshmode.array_context.ArrayContext, discr, ary, ndofs_per_element_per_group: Optional[Iterable[int]] = None) → numpy.ndarray¶ Convert a ‘flat’ array returned by
flatten()
back to aDOFArray
.Vectorizes over object arrays of
DOFArray
s.

meshmode.dof_array.
flat_norm
(ary: meshmode.dof_array.DOFArray, ord=2)¶
Array Contexts¶

meshmode.array_context.
make_loopy_program
(domains, statements, kernel_data=['...'], name='mm_actx_kernel')¶ Return a
loopy.LoopKernel
suitable for use withArrayContext.call_loopy()
.

class
meshmode.array_context.
ArrayContext
¶ An interface that allows a
Discretization
to create and interact with arrays of degrees of freedom without fully specifying their types.
empty
(shape, dtype)¶

zeros
(shape, dtype)¶

empty_like
(ary)¶

zeros_like
(ary)¶

from_numpy
(array: numpy.ndarray)¶  Returns
the
numpy.ndarray
array converted to the array context’s array type. The returned array will bethaw()
ed.

to_numpy
(array)¶  Returns
array, an array recognized by the context, converted to a
numpy.ndarray
. array must bethaw()
ed.

call_loopy
(program, **kwargs)¶ Execute the
loopy
program program on the arguments kwargs.program is a
loopy.LoopKernel
orloopy.LoopKernel
. It is expected to not yet be transformed for execution speed. It must haveloopy.Options.return_dict
set. Returns
a
dict
of outputs from the program, each an array understood by the context.

np
¶ Provides access to a namespace that serves as a workalike to
numpy
. The actual level of functionality provided is up to the individual array context implementation, however the functions and objects available under this namespace must not behave differently fromnumpy
.As a baseline, special functions available through
loopy
(e.g.sin
,exp
) are accessible through this interface.Callables accessible through this namespace vectorize over object arrays, including
meshmode.dof_array.DOFArray
.

freeze
(array)¶ Return a version of the contextdefined array array that is ‘frozen’, i.e. suitable for longterm storage and reuse. Frozen arrays do not support arithmetic. For example, in the context of
Array
, this might mean stripping the array of an associated command queue, whereas in a lazilyevaluated context, it might mean that the array is evaluated and stored.Freezing makes the array independent of this
ArrayContext
; it is permitted tothaw()
it in a different one, as long as that context understands the array format.

thaw
(array)¶ Take a ‘frozen’ array and return a new array representing the data in array that is able to perform arithmetic and other operations, using the execution resources of this context. In the context of
Array
, this might mean that the array is equipped with a command queue, whereas in a lazilyevaluated context, it might mean that the returned array is a symbol bound to the data in array.The returned array may not be used with other contexts while thawed.
New in version 2020.2.


class
meshmode.array_context.
PyOpenCLArrayContext
(queue, allocator=None, wait_event_queue_length=None)¶ A
ArrayContext
that usespyopencl.array.Array
instances for DOF arrays.
context
¶

queue
¶

allocator
¶ A PyOpenCL memory allocator. Can also be None (default) or False to use the default allocator. Please note that running with the default allocator allocates and deallocates OpenCL buffers directly. If lots of arrays are created (e.g. as results of computation), the associated cost may become significant. Using e.g.
pyopencl.tools.MemoryPool
as the allocator can help avoid this cost.
