Exemple #1
0
    def from_polygonmesh_test(self, plot=True):
        node = np.array([(0.0, 0.0), (0.0, 1.0), (0.0, 2.0), (1.0, 0.0),
                         (1.0, 1.0), (1.0, 2.0), (2.0, 0.0), (2.0, 1.0),
                         (2.0, 2.0)],
                        dtype=np.float)
        cell = np.array([0, 3, 4, 4, 1, 0, 1, 4, 5, 2, 3, 6, 7, 4, 4, 7, 8, 5],
                        dtype=np.int)
        cellLocation = np.array([0, 3, 6, 10, 14, 18], dtype=np.int)

        mesh = PolygonMesh(node, cell, cellLocation)
        a = mesh.entity_measure('cell')

        mesh = HalfEdgePolygonMesh.from_polygonmesh(mesh)
        a = mesh.entity_measure('cell')
        mesh.print()

        if plot:
            fig = plt.figure()
            axes = fig.gca()
            mesh.add_plot(axes)
            mesh.find_node(axes, showindex=True)
            mesh.find_edge(axes, showindex=True)
            mesh.find_cell(axes, showindex=True)
            plt.show()
Exemple #2
0
    Tbd = spdiags(bdIdx, 0, gdof, gdof)
    T = spdiags(1-bdIdx, 0, gdof, gdof)
    AA = T@AA@T + Tbd

    FF[isBdDof] = x[isBdDof]

    x[:] = spsolve(AA, FF)
    tuh[:] = x[:tudof]
    tph[:] = x[tudof:]

    tuspace.project_to_complete_space(pde.source, tuh, tph, uh, ph)
    up = uspace.project_to_smspace(uh)
    tup = tuspace.project_to_smspace(tuh)

    integralalg = uspace.integralalg
    area = sum(mesh.entity_measure('cell'))

    def strain(x, index):
        val = tup.grad_value(x, index)
        return (val + val.swapaxes(-1, -2))/2


    errorMatrix[0, i] = integralalg.L2_error(pde.velocity, tup)

    iph = integralalg.integral(tph)/area
    def tpressure(x, index):
        return tph.value(x, index) - iph
    errorMatrix[1, i] = integralalg.L2_error(pde.pressure, tpressure)

    errorMatrix[2, i] = integralalg.L2_error(pde.strain, strain)
    errorMatrix[3, i] = integralalg.L2_error(pde.velocity, up)