Ejemplo n.º 1
0
    def _resample_matrix(self, actx: ArrayContext, to_group_index,
                         ibatch_index):
        import modepy as mp
        ibatch = self.groups[to_group_index].batches[ibatch_index]
        from_grp = self.from_discr.groups[ibatch.from_group_index]

        nfrom_unit_nodes = from_grp.unit_nodes.shape[1]
        if np.array_equal(from_grp.unit_nodes, ibatch.result_unit_nodes):
            # Nodes are exactly identical? We can 'interpolate' even when there
            # isn't a basis.

            result = np.eye(nfrom_unit_nodes)

        else:
            if len(from_grp.basis()) != nfrom_unit_nodes:
                from meshmode.discretization import NoninterpolatoryElementGroupError
                raise NoninterpolatoryElementGroupError(
                    "%s does not support interpolation because it is not "
                    "unisolvent (its unit node count does not match its "
                    "number of basis functions). Using connections requires "
                    "the ability to interpolate." % type(from_grp).__name__)

            result = mp.resampling_matrix(from_grp.basis(),
                                          ibatch.result_unit_nodes,
                                          from_grp.unit_nodes)

        return actx.freeze(actx.from_numpy(result))
Ejemplo n.º 2
0
def mass_matrix(grp: InterpolatoryElementGroupBase) -> np.ndarray:
    if not isinstance(grp, InterpolatoryElementGroupBase):
        raise NoninterpolatoryElementGroupError(
            f"cannot construct mass matrix on '{type(grp).__name__}'")

    assert grp.is_orthonormal_basis()
    return mp.mass_matrix(grp.basis_obj().functions, grp.unit_nodes)
Ejemplo n.º 3
0
def diff_matrices(grp: InterpolatoryElementGroupBase) -> Tuple[np.ndarray]:
    if not isinstance(grp, InterpolatoryElementGroupBase):
        raise NoninterpolatoryElementGroupError(
            f"cannot construct diff matrices on '{type(grp).__name__}'")

    basis_fcts = grp.basis_obj().functions
    grad_basis_fcts = grp.basis_obj().gradients

    if len(basis_fcts) != grp.unit_nodes.shape[1]:
        raise NoninterpolatoryElementGroupError(
            f"{type(grp).__name__} does not support interpolation because "
            "it is not unisolvent (its unit node count does not match its "
            "number of basis functions). Differentiation requires "
            "the ability to interpolate.")

    result = mp.differentiation_matrices(basis_fcts, grad_basis_fcts,
                                         grp.unit_nodes)

    return result if isinstance(result, tuple) else (result, )
Ejemplo n.º 4
0
    def diff_matrices(self):
        if len(self.basis()) != self.unit_nodes.shape[1]:
            from meshmode.discretization import NoninterpolatoryElementGroupError
            raise NoninterpolatoryElementGroupError(
                "%s does not support interpolation because it is not "
                "unisolvent (its unit node count does not match its "
                "number of basis functions). Differentiation requires "
                "the ability to interpolate." % type(self).__name__)

        result = mp.differentiation_matrices(self.basis(), self.grad_basis(),
                                             self.unit_nodes)

        if not isinstance(result, tuple):
            return (result, )
        else:
            return result
Ejemplo n.º 5
0
    def _resample_matrix(self, to_group_index, ibatch_index):
        import modepy as mp
        ibatch = self.groups[to_group_index].batches[ibatch_index]
        from_grp = self.from_discr.groups[ibatch.from_group_index]

        if len(from_grp.basis()) != from_grp.unit_nodes.shape[1]:
            from meshmode.discretization import NoninterpolatoryElementGroupError
            raise NoninterpolatoryElementGroupError(
                "%s does not support interpolation because it is not "
                "unisolvent (its unit node count does not match its "
                "number of basis functions). Using connections requires "
                "the ability to interpolate." % type(from_grp).__name__)

        result = mp.resampling_matrix(from_grp.basis(),
                                      ibatch.result_unit_nodes,
                                      from_grp.unit_nodes)

        with cl.CommandQueue(self.cl_context) as queue:
            return cl.array.to_device(queue, result).with_queue(None)