Example #1
0
def plot_partitioning(axs, field, cell_tasks, gfd, output_dir, size):
    """
    Plot the partitioning of the domain and field DOFs.
    """
    mesh = field.domain.mesh

    ax = pc.plot_wireframe(axs[0], mesh.cmesh)
    coors = field.get_coor()
    econn = field.econn
    ax = pd.plot_global_dofs(ax, coors, econn)
    ax.set_title('global DOFs')
    ax.figure.savefig(os.path.join(output_dir, 'global_dofs.png'),
                      bbox_inches='tight')

    ax = pc.plot_wireframe(axs[1], mesh.cmesh)
    fig = ax.figure
    coors = field.get_coor()
    econn = field.econn

    id_map = gfd.id_map

    colors = nm.zeros((field.n_nod, 4))
    for ir, dof_map in ordered_iteritems(gfd.dof_maps):
        aux = id_map[dof_map[0]]
        colors[aux] = [0, 0, float(ir + 1) / size, 0.6]
        for aux in dof_map[1]:
            colors[id_map[aux]] = [0, 0, float(ir + 1) / size, 0.9]

    from sfepy.discrete.fem.utils import prepare_translate
    aux = prepare_translate(id_map[econn], econn)
    ax = label_dofs(ax, coors[aux], id_map, colors)

    mark_subdomains(ax, mesh.cmesh, cell_tasks, size, 0, 0.7)

    ax.set_title('subdomains of tasks and PETSc DOFs')

    fig.savefig(os.path.join(output_dir, 'petsc_dofs.png'),
                bbox_inches='tight')

    ax.set_title('')

    axis = ax.axis()
    for ir, ocells in enumerate(gfd.overlap_cells):
        aux = nm.zeros_like(cell_tasks)
        aux[ocells] = 10
        aux[gfd.cell_parts[ir]] = 1

        ax = fig.add_axes(ax.get_position(), frameon=False, label='aux')
        mark_subdomains(ax, mesh.cmesh, aux, 11, 1, 0.3, True)
        ax.axis(axis)
        ax.set_title('overlap cells on task %d' % ir)
        fig.savefig(os.path.join(output_dir,
                                 'petsc_overlaps_%02d.png' % ir),
                    bbox_inches='tight')
        fig.delaxes(ax)
Example #2
0
def plot_partitioning(axs, field, cell_tasks, gfd, output_dir, size):
    """
    Plot the partitioning of the domain and field DOFs.
    """
    mesh = field.domain.mesh

    ax = pc.plot_wireframe(axs[0], mesh.cmesh)
    coors = field.get_coor()
    econn = field.econn
    ax = pd.plot_global_dofs(ax, coors, econn)
    ax.set_title('global DOFs')
    ax.figure.savefig(os.path.join(output_dir, 'global_dofs.png'),
                      bbox_inches='tight')

    ax = pc.plot_wireframe(axs[1], mesh.cmesh)
    fig = ax.figure
    coors = field.get_coor()
    econn = field.econn

    id_map = gfd.id_map

    colors = nm.zeros((field.n_nod, 4))
    for ir, dof_map in ordered_iteritems(gfd.dof_maps):
        aux = id_map[dof_map[0]]
        colors[aux] = [0, 0, float(ir + 1) / size, 0.6]
        for aux in dof_map[1]:
            colors[id_map[aux]] = [0, 0, float(ir + 1) / size, 0.9]

    from sfepy.discrete.fem.utils import prepare_translate
    aux = prepare_translate(id_map[econn], econn)
    ax = label_dofs(ax, coors[aux], id_map, colors)

    mark_subdomains(ax, mesh.cmesh, cell_tasks, size, 0, 0.7)

    ax.set_title('subdomains of tasks and PETSc DOFs')

    fig.savefig(os.path.join(output_dir, 'petsc_dofs.png'),
                bbox_inches='tight')

    ax.set_title('')

    axis = ax.axis()
    for ir, ocells in enumerate(gfd.overlap_cells):
        aux = nm.zeros_like(cell_tasks)
        aux[ocells] = 10
        aux[gfd.cell_parts[ir]] = 1

        ax = fig.add_axes(ax.get_position(), frameon=False, label='aux')
        mark_subdomains(ax, mesh.cmesh, aux, 11, 1, 0.3, True)
        ax.axis(axis)
        ax.set_title('overlap cells on task %d' % ir)
        fig.savefig(os.path.join(output_dir, 'petsc_overlaps_%02d.png' % ir),
                    bbox_inches='tight')
        fig.delaxes(ax)
Example #3
0
    def _setup_facet_dofs(self, dim, facet_desc, offset):
        """
        Helper function to setup facet DOF connectivity, works for both
        edges and faces.
        """
        facet_desc = nm.array(facet_desc)
        n_dof_per_facet = facet_desc.shape[1]

        cmesh = self.domain.cmesh

        facets = self.region.entities[dim]
        ii = nm.arange(facets.shape[0], dtype=nm.int32)
        all_dofs = offset + expand_nodes_to_dofs(ii, n_dof_per_facet)

        # Prepare global facet id remapping to field-local numbering.
        remap = prepare_remap(facets, cmesh.num[dim])

        cconn = self.region.domain.cmesh.get_conn(self.region.tdim, dim)
        offs = cconn.offsets

        n_f = self.gel.edges.shape[0] if dim == 1 else self.gel.faces.shape[0]
        n_fp = 2 if dim == 1 else self.gel.surface_facet.n_vertex

        oris = cmesh.get_orientations(dim)
        ap = self.ap

        gcells = self.region.get_cells()
        n_el = gcells.shape[0]

        # Elements of facets.
        iel = nm.arange(n_el, dtype=nm.int32).repeat(n_f)
        ies = nm.tile(nm.arange(n_f, dtype=nm.int32), n_el)

        aux = offs[gcells][:, None] + ies.reshape((n_el, n_f))

        indices = cconn.indices[aux]
        facets_of_cells = remap[indices].ravel()

        # Define global facet dof numbers.
        gdofs = offset + expand_nodes_to_dofs(facets_of_cells,
                                              n_dof_per_facet)

        # DOF columns in econn for each facet (repeating same values for
        # each element.
        iep = facet_desc[ies]

        ap.econn[iel[:, None], iep] = gdofs

        ori = oris[aux].ravel()

        if (n_fp == 2) and (ap.interp.gel.name in ['2_4', '3_8']):
            tp_edges = ap.interp.gel.edges
            ecs = ap.interp.gel.coors[tp_edges]
            # True = positive, False = negative edge orientation w.r.t.
            # reference tensor product axes.
            tp_edge_ori = (nm.diff(ecs, axis=1).sum(axis=2) > 0).squeeze()
            aux = nm.tile(tp_edge_ori, n_el)
            ori = nm.where(aux, ori, 1 - ori)

        if n_fp == 2: # Edges.
            # ori == 1 means the basis has to be multiplied by -1.
            ps = ap.interp.poly_spaces['v']
            orders = ps.node_orders
            eori = nm.repeat(ori[:, None], n_dof_per_facet, 1)
            eoo = orders[iep] % 2 # Odd orders.
            ap.ori[iel[:, None], iep] = eori * eoo

        elif n_fp == 3: # Triangular faces.
            raise NotImplementedError

        else: # Quadrilateral faces.
            # ori encoding in 3 bits:
            # 0: axis swap, 1: axis 1 sign, 2: axis 2 sign
            # 0 = + or False, 1 = - or True
            # 63 -> 000 = 0
            #  0 -> 001 = 1
            # 30 -> 010 = 2
            # 33 -> 011 = 3
            # 11 -> 100 = 4
            #  7 -> 101 = 5
            # 52 -> 110 = 6
            # 56 -> 111 = 7
            # Special cases:
            # Both orders same and even -> 000
            # Both orders same and odd -> 0??
            # Bits 1, 2 are multiplied by (swapped) axial order % 2.
            new = nm.repeat(nm.arange(8, dtype=nm.int32), 3)
            translate = prepare_translate([31, 59, 63,
                                           0, 1, 4,
                                           22, 30, 62,
                                           32, 33, 41,
                                           11, 15, 43,
                                           3, 6, 7,
                                           20, 52, 60,
                                           48, 56, 57], new)
            ori = translate[ori]
            eori = nm.repeat(ori[:, None], n_dof_per_facet, 1)

            ps = ap.interp.poly_spaces['v']
            orders = ps.face_axes_nodes[iep - ps.face_indx[0]]
            eoo = orders % 2
            eoo0, eoo1 = eoo[..., 0], eoo[..., 1]

            i0 = nm.where(eori < 4)
            i1 = nm.where(eori >= 4)

            eori[i0] = nm.bitwise_and(eori[i0], 2*eoo0[i0] + 5)
            eori[i0] = nm.bitwise_and(eori[i0], eoo1[i0] + 6)

            eori[i1] = nm.bitwise_and(eori[i1], eoo0[i1] + 6)
            eori[i1] = nm.bitwise_and(eori[i1], 2*eoo1[i1] + 5)

            ap.ori[iel[:, None], iep] = eori

        n_dof = n_dof_per_facet * facets.shape[0]
        assert_(n_dof == nm.prod(all_dofs.shape))

        return n_dof, all_dofs, remap
Example #4
0
    def _setup_facet_dofs(self, dim, facet_desc, offset):
        """
        Helper function to setup facet DOF connectivity, works for both
        edges and faces.
        """
        facet_desc = nm.array(facet_desc)
        n_dof_per_facet = facet_desc.shape[1]

        cmesh = self.domain.cmesh

        facets = self.region.entities[dim]
        ii = nm.arange(facets.shape[0], dtype=nm.int32)
        all_dofs = offset + expand_nodes_to_dofs(ii, n_dof_per_facet)

        # Prepare global facet id remapping to field-local numbering.
        remap = prepare_remap(facets, cmesh.num[dim])

        cconn = self.region.domain.cmesh.get_conn(self.region.tdim, dim)
        offs = cconn.offsets

        n_f = self.gel.edges.shape[0] if dim == 1 else self.gel.faces.shape[0]
        n_fp = 2 if dim == 1 else self.gel.surface_facet.n_vertex

        oris = cmesh.get_orientations(dim)
        ap = self.ap

        gcells = self.region.get_cells()
        n_el = gcells.shape[0]

        # Elements of facets.
        iel = nm.arange(n_el, dtype=nm.int32).repeat(n_f)
        ies = nm.tile(nm.arange(n_f, dtype=nm.int32), n_el)

        aux = offs[gcells][:, None] + ies.reshape((n_el, n_f))

        indices = cconn.indices[aux]
        facets_of_cells = remap[indices].ravel()

        # Define global facet dof numbers.
        gdofs = offset + expand_nodes_to_dofs(facets_of_cells, n_dof_per_facet)

        # DOF columns in econn for each facet (repeating same values for
        # each element.
        iep = facet_desc[ies]

        ap.econn[iel[:, None], iep] = gdofs

        ori = oris[aux].ravel()

        if (n_fp == 2) and (ap.interp.gel.name in ['2_4', '3_8']):
            tp_edges = ap.interp.gel.edges
            ecs = ap.interp.gel.coors[tp_edges]
            # True = positive, False = negative edge orientation w.r.t.
            # reference tensor product axes.
            tp_edge_ori = (nm.diff(ecs, axis=1).sum(axis=2) > 0).squeeze()
            aux = nm.tile(tp_edge_ori, n_el)
            ori = nm.where(aux, ori, 1 - ori)

        if n_fp == 2:  # Edges.
            # ori == 1 means the basis has to be multiplied by -1.
            ps = ap.interp.poly_spaces['v']
            orders = ps.node_orders
            eori = nm.repeat(ori[:, None], n_dof_per_facet, 1)
            eoo = orders[iep] % 2  # Odd orders.
            ap.ori[iel[:, None], iep] = eori * eoo

        elif n_fp == 3:  # Triangular faces.
            raise NotImplementedError

        else:  # Quadrilateral faces.
            # ori encoding in 3 bits:
            # 0: axis swap, 1: axis 1 sign, 2: axis 2 sign
            # 0 = + or False, 1 = - or True
            # 63 -> 000 = 0
            #  0 -> 001 = 1
            # 30 -> 010 = 2
            # 33 -> 011 = 3
            # 11 -> 100 = 4
            #  7 -> 101 = 5
            # 52 -> 110 = 6
            # 56 -> 111 = 7
            # Special cases:
            # Both orders same and even -> 000
            # Both orders same and odd -> 0??
            # Bits 1, 2 are multiplied by (swapped) axial order % 2.
            new = nm.repeat(nm.arange(8, dtype=nm.int32), 3)
            translate = prepare_translate([
                31, 59, 63, 0, 1, 4, 22, 30, 62, 32, 33, 41, 11, 15, 43, 3, 6,
                7, 20, 52, 60, 48, 56, 57
            ], new)
            ori = translate[ori]
            eori = nm.repeat(ori[:, None], n_dof_per_facet, 1)

            ps = ap.interp.poly_spaces['v']
            orders = ps.face_axes_nodes[iep - ps.face_indx[0]]
            eoo = orders % 2
            eoo0, eoo1 = eoo[..., 0], eoo[..., 1]

            i0 = nm.where(eori < 4)
            i1 = nm.where(eori >= 4)

            eori[i0] = nm.bitwise_and(eori[i0], 2 * eoo0[i0] + 5)
            eori[i0] = nm.bitwise_and(eori[i0], eoo1[i0] + 6)

            eori[i1] = nm.bitwise_and(eori[i1], eoo0[i1] + 6)
            eori[i1] = nm.bitwise_and(eori[i1], 2 * eoo1[i1] + 5)

            ap.ori[iel[:, None], iep] = eori

        n_dof = n_dof_per_facet * facets.shape[0]
        assert_(n_dof == nm.prod(all_dofs.shape))

        return n_dof, all_dofs, remap