DOF (Degree-of-Freedom) 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 degree-of-freedom arrays for use with Discretization, with one entry in the DOFArray for each ElementGroupBase. The arrays contained within a DOFArray are expected to be logically two-dimensional, with shape (nelements, ndofs_per_element), where nelements is the same as nelements of the associated group. ndofs_per_element is typically, but not necessarily, the same as nunit_dofs of the associated group. This array is derived from numpy.ndarray with dtype object (“an object array”). The entries in this array are further arrays managed by array_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 meshmode.array_context.ArrayContext.

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 per ElementGroupBase).

Parameters

actx – If None, the arrays in res_list must be thaw()ed.

Note

DOFArray instances support elementwise <, >, <=, >=. (numpy object arrays containing arrays do not.)

meshmode.dof_array.thaw(actx: meshmode.array_context.ArrayContext, ary: numpy.ndarray)numpy.ndarray

Call thaw() on the element group arrays making up the DOFArray, using actx.

Vectorizes over object arrays of DOFArrays.

meshmode.dof_array.freeze(ary: numpy.ndarray)numpy.ndarray

Call freeze() on the element group arrays making up the DOFArray, using the ArrayContext in ary.

Vectorizes over object arrays of DOFArrays.

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 the DOFArray.array_context.

Array elements are laid out contiguously, with the element group index varying slowest, element index next, and intra-element DOF index fastest.

Vectorizes over object arrays of DOFArrays.

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 a DOFArray.

Vectorizes over object arrays of DOFArrays.

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 with ArrayContext.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 be thaw()ed.

to_numpy(array)
Returns

array, an array recognized by the context, converted to a numpy.ndarray. array must be thaw()ed.

call_loopy(program, **kwargs)

Execute the loopy program program on the arguments kwargs.

program is a loopy.LoopKernel or loopy.LoopKernel. It is expected to not yet be transformed for execution speed. It must have loopy.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 work-alike 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 from numpy.

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 context-defined array array that is ‘frozen’, i.e. suitable for long-term 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 lazily-evaluated context, it might mean that the array is evaluated and stored.

Freezing makes the array independent of this ArrayContext; it is permitted to thaw() 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 lazily-evaluated 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 uses pyopencl.array.Array instances for DOF arrays.

context

A pyopencl.Context.

queue

A pyopencl.CommandQueue.

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.