def generate_subs(i): deriv_order = i.deriv_order function = i.function dim = i.dimension weights = i.weights fd_order = len(weights) - 1 side = form_side((dim, ), function) stagger = side.get(dim) subs = {} indices, x0 = generate_indices(function, dim, dim.spacing, fd_order, side=None, stagger=stagger) for j in range(len(weights)): subs.update({ function._coeff_symbol(indices[j], deriv_order, function, dim): weights[j] }) return subs
def generate_subs(deriv_order, function, dim): if dim.is_Time: fd_order = function.time_order elif dim.is_Space: fd_order = function.space_order else: # Shouldn't arrive here raise TypeError("Dimension type not recognised") side = form_side((dim, ), function) stagger = side.get(dim) subs = {} indices, x0 = generate_indices(function, dim, dim.spacing, fd_order, side=None, stagger=stagger) coeffs = sympy.finite_diff_weights(deriv_order, indices, x0)[-1][-1] for j in range(len(coeffs)): subs.update({ function._coeff_symbol(indices[j], deriv_order, function, dim): coeffs[j] }) return subs
def generate_subs(i): deriv_order = i.deriv_order function = i.function dim = i.dimension weights = i.weights if isinstance(weights, np.ndarray): fd_order = len(weights)-1 else: fd_order = weights.shape[-1]-1 side = form_side((dim,), function) stagger = side.get(dim) subs = {} indices, x0 = generate_indices(function, dim, dim.spacing, fd_order, side=None, stagger=stagger) # NOTE: This implementation currently assumes that indices are ordered # according to their position in the FD stencil. This may not be the # case in all schemes and should be changed such that the weights are # passed as a dictionary of the form {pos: w} (or something similar). if isinstance(weights, np.ndarray): for j in range(len(weights)): subs.update({function._coeff_symbol (indices[j], deriv_order, function, dim): weights[j]}) else: shape = weights.shape x = weights.dimensions for j in range(shape[-1]): idx = list(x) idx[-1] = j subs.update({function._coeff_symbol (indices[j], deriv_order, function, dim): weights[as_tuple(idx)]}) return subs