Useful Helper Routines

Object Arrays

hedge.tools.is_obj_array(val)
hedge.tools.to_obj_array(ary)
hedge.tools.join_fields(*args)
hedge.tools.log_shape(array)

Returns the “logical shape” of the array.

The “logical shape” is the shape that’s left when the node-depending dimension has been eliminated.

Operator Expression Helpers

hedge.tools.ptwise_mul(a, b)
hedge.tools.ptwise_dot(logdims1, logdims2, a1, a2)
hedge.tools.make_common_subexpression(fields)
Wrap each component of a vector field in a CSE.

Operator Subsetting

hedge.tools.count_subset(subset)
hedge.tools.full_to_subset_indices(subset, base=0)

Takes a sequence of bools and turns it into an array of indices to be used to extract the subset from the full set.

Example:

>>> full_to_subset_indices([False, True, True])
array([1 2])
hedge.tools.full_to_all_subset_indices(subsets, base=0)

Takes a sequence of bools and generates it into an array of indices to be used to extract the subset from the full set.

Example:

>>> list(full_to_all_subset_indices([[False, True, True], [True,False,True]]))
[array([1 2]), array([3 5]
hedge.tools.partial_to_all_subset_indices(subsets, base=0)

Takes a sequence of bools and generates it into an array of indices to be used to insert the subset into the full set.

Example:

>>> list(partial_to_all_subset_indices([[False, True, True], [True,False,True]]))
[array([0 1]), array([2 3]

Mathematical Helpers

class hedge.tools.SubsettableCrossProduct(op1_subset=(True, True, True), op2_subset=(True, True, True), result_subset=(True, True, True))
A cross product that can operate on an arbitrary subsets of its two operands and return an arbitrary subset of its result.
hedge.tools.normalize(v)
hedge.tools.sign(x)
hedge.tools.orthonormalize(vectors, discard_threshold=None)

Carry out a modified [1] Gram-Schmidt orthonormalization on vectors.

If, during orthonormalization, the 2-norm of a vector drops below discard_threshold, then this vector is silently discarded. If discard_threshold is None, then no vector will ever be dropped, and a zero 2-norm encountered during orthonormalization will throw a RuntimeError.

[1] http://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process

hedge.tools.permutation_matrix(to_indices=None, from_indices=None, h=None, w=None, dtype=None, flavor=None)

Return a permutation matrix.

If to_indices is specified, the resulting permutation matrix P satisfies the condition

P * e[i] = e[to_indices[i]] for i=1,...,len(to_indices)

where e[i] is the i-th unit vector. The height of P is determined either implicitly by the maximum of to_indices or explicitly by the parameter h.

If from_indices is specified, the resulting permutation matrix P satisfies the condition

P * e[from_indices[i]] = e[i] for i=1,...,len(from_indices)

where e[i] is the i-th unit vector. The width of P is determined either implicitly by the maximum of from_indices of explicitly by the parameter w.

If both to_indices and from_indices is specified, a ValueError exception is raised.

hedge.tools.leftsolve(A, B)
hedge.tools.unit_vector(n, i, dtype=None)
Return the i-th unit vector of size n, with the given dtype.
hedge.tools.relative_error(norm_diff, norm_true)
class hedge.tools.AffineMap

Convergence Tests

hedge.tools.estimate_order_of_convergence(abscissae, errors)

Assuming that abscissae and errors are connected by a law of the form

error = constant * abscissa ^ (-order),

this function finds, in a least-squares sense, the best approximation of constant and order for the given data set. It returns a tuple (constant, order).

class hedge.tools.EOCRecorder

Mesh Helpers

hedge.tools.cuthill_mckee(graph)

Return a Cuthill-McKee ordering for the given graph.

See (for example) Y. Saad, Iterative Methods for Sparse Linear System, 2nd edition, p. 76.

graph is given as an adjacency mapping, i.e. each node is mapped to a list of its neighbors.

Flux Helpers

hedge.tools.make_lax_friedrichs_flux(wave_speed, state, fluxes, bdry_tags_states_and_fluxes, strong)

Miscellaneous

hedge.tools.get_spherical_coord(x_vec)
Parameter:x_vec – is an array whose leading dimension iterates over the X, Y, Z axes, and whose further dimensions may iterate over a number of points.
Returns:object array of [r, phi, theta]. phi is the angle in (x,y) in (-\pi,\pi).