DOF (DegreeofFreedom) ArraysΒΆ

class
meshmode.dof_array.
DOFArray
(actx, data)ΒΆ This array type holds degreeoffreedom arrays for use with
Discretization
, 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. 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.

__len__
()ΒΆ

__getitem__
(i)ΒΆ
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
ΒΆ
This object supports arithmetic, comparisons, and logic operators.
Note
DOFArray
instances support elementwise<
,>
,<=
,>=
. (numpy
object arrays containing arrays do not.)Basic inplace operations are also supported. Note that not all array types provided by
meshmode.array_context.ArrayContext
implementations support inplace operations. Those based on lazy evaluation are a salient example.
__isub__
(arg)ΒΆ

__imul__
(arg)ΒΆ

__itruediv__
(arg)ΒΆ

__iand__
(arg)ΒΆ

__ixor__
(arg)ΒΆ

__ior__
(arg)ΒΆ
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.
obj_or_dof_array_vectorize
(f, ary)ΒΆ Works like
obj_array_vectorize()
, but recurses on object arrays and also tolerates one final βlayerβ ofDOFArray
s.

meshmode.dof_array.
obj_or_dof_array_vectorized
(f, ary)ΒΆ Works like
obj_array_vectorize()
, but recurses on object arrays and also tolerates one final βlayerβ ofDOFArray
s.

meshmode.dof_array.
obj_or_dof_array_vectorize_n_args
(f, *args)ΒΆ Apply the function f elementwise to all entries of any object arrays or
DOFArray
s in args. All such arrays are expected to have the same shape (but this is not checked). Equivalent to an appropriatelylooped execution of:result[idx] = f(obj_array_arg1[idx], arg2, obj_array_arg3[idx])
Return an array of the same shape as the arguments consisting of the return values of f. If the elements of arrays found in args are further object arrays, recurse. If a
DOFArray
is found, apply f to its entries. If nonobjectarrays are found, apply f to those.

meshmode.dof_array.
obj_or_dof_array_vectorized_n_args
(f, *args)ΒΆ Apply the function f elementwise to all entries of any object arrays or
DOFArray
s in args. All such arrays are expected to have the same shape (but this is not checked). Equivalent to an appropriatelylooped execution of:result[idx] = f(obj_array_arg1[idx], arg2, obj_array_arg3[idx])
Return an array of the same shape as the arguments consisting of the return values of f. If the elements of arrays found in args are further object arrays, recurse. If a
DOFArray
is found, apply f to its entries. If nonobjectarrays are found, apply f to those.

meshmode.dof_array.
thaw
(actx, ary)ΒΆ Call
thaw()
on the element group arrays making up theDOFArray
, using actx.Vectorizes over object arrays of
DOFArray
s. Parameters
actx (meshmode.array_context.ArrayContext) β
ary (Union[meshmode.dof_array.DOFArray, numpy.ndarray]) β
 Return type

meshmode.dof_array.
freeze
(ary)ΒΆ Call
freeze()
on the element group arrays making up theDOFArray
, using theArrayContext
in ary.Vectorizes over object arrays of
DOFArray
s. Parameters
ary (Union[meshmode.dof_array.DOFArray, numpy.ndarray]) β
 Return type

meshmode.dof_array.
flatten
(ary)ΒΆ 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. Parameters
ary (Union[meshmode.dof_array.DOFArray, numpy.ndarray]) β
 Return type
Any

meshmode.dof_array.
unflatten
(actx, discr, ary, ndofs_per_element_per_group=None)ΒΆ Convert a βflatβ array returned by
flatten()
back to aDOFArray
. Parameters
ndofs_per_element β Optional. 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 perelement quantity.actx (meshmode.array_context.ArrayContext) β
ary (Union[Any, numpy.ndarray]) β
ndofs_per_element_per_group (Optional[Iterable[int]]) β
 Return type
Vectorizes over object arrays.

meshmode.dof_array.
array_context_for_pickling
(actx)ΒΆ For the current thread, set the array context to be used for pickling and unpickling
DOFArray
s to actx.New in version 2021.x.
 Parameters
actx (meshmode.array_context.ArrayContext) β
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)ΒΆ  Returns
the
numpy.ndarray
array converted to the array contextβs array type. The returned array will bethaw()
ed. Parameters
array (numpy.ndarray) β

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.


meshmode.array_context.
pytest_generate_tests_for_pyopencl_array_context
(metafunc)ΒΆ Parametrize tests for pytest to use a
pyopencl
array context.Performs device enumeration analogously to
pyopencl.tools.pytest_generate_tests_for_pyopencl()
.Using the line:
from meshmode.array_context import pytest_generate_tests_for_pyopencl as pytest_generate_tests
in your pytest test scripts allows you to use the arguments ctx_factory, device, or platform in your test functions, and they will automatically be run for each OpenCL device/platform in the system, as appropriate.
It also allows you to specify the
PYOPENCL_TEST
environment variable for device selection.