(V, E2V=None, mesh_type='tri',
                     pdata=None, pvdata=None,
                     cdata=None, cvdata=None, fname='output.vtk')
Write mesh file for basic types of elements.

    Parameters
    ----------
    fname : {string}
        file to be written, e.g. 'mymesh.vtu'
    V : {array}
        coordinate array (N x D)
    E2V : {array}
        element index array (Nel x Nelnodes)
    mesh_type : {string}
        type of elements: tri, quad, tet, hex (all 3d)
    pdata : {array}
        scalar data on vertices (N x Nfields)
    pvdata : {array}
        vector data on vertices (3*Nfields x N)
    cdata : {array}
        scalar data on cells (Nfields x Nel)
    cvdata : {array}
        vector data on cells (3*Nfields x Nel)

    Returns
    -------
    writes a .vtu file for use in Paraview

    Notes
    -----
    The difference between write_basic_mesh and write_vtu is that write_vtu is
    more general and requires dictionaries of cell information.
    write_basic_mesh calls write_vtu

    Examples
    --------
    >>> import numpy as np
    >>> from pyamg.vis import write_basic_mesh
    >>> V = np.array([[0.0,0.0],
    ...               [1.0,0.0],
    ...               [2.0,0.0],
    ...               [0.0,1.0],
    ...               [1.0,1.0],
    ...               [2.0,1.0],
    ...               [0.0,2.0],
    ...               [1.0,2.0],
    ...               [2.0,2.0],
    ...               [0.0,3.0],
    ...               [1.0,3.0],
    ...               [2.0,3.0]])
    >>> E2V = np.array([[0,4,3],
    ...                 [0,1,4],
    ...                 [1,5,4],
    ...                 [1,2,5],
    ...                 [3,7,6],
    ...                 [3,4,7],
    ...                 [4,8,7],
    ...                 [4,5,8],
    ...                 [6,10,9],
    ...                 [6,7,10],
    ...                 [7,11,10],
    ...                 [7,8,11]])
    >>> pdata=np.ones((12,2))
    >>> pvdata=np.ones((12*3,2))
    >>> cdata=np.ones((12,2))
    >>> cvdata=np.ones((3*12,2))
    >>> write_basic_mesh(V, E2V=E2V, mesh_type='tri',pdata=pdata,
    ...                  pvdata=pvdata, cdata=cdata, cvdata=cvdata,
    ...                  fname='test.vtu')

    See Also
    --------
    write_vtu
Write mesh file for basic types of elements.
Write mesh file for basic types of elements .
def write_basic_mesh(V, E2V=None, mesh_type='tri',
                     pdata=None, pvdata=None,
                     cdata=None, cvdata=None, fname='output.vtk'):
    """Write mesh file for basic types of elements.

    Parameters
    ----------
    fname : {string}
        file to be written, e.g. 'mymesh.vtu'
    V : {array}
        coordinate array (N x D)
    E2V : {array}
        element index array (Nel x Nelnodes)
    mesh_type : {string}
        type of elements: tri, quad, tet, hex (all 3d)
    pdata : {array}
        scalar data on vertices (N x Nfields)
    pvdata : {array}
        vector data on vertices (3*Nfields x N)
    cdata : {array}
        scalar data on cells (Nfields x Nel)
    cvdata : {array}
        vector data on cells (3*Nfields x Nel)

    Returns
    -------
    writes a .vtu file for use in Paraview

    Notes
    -----
    The difference between write_basic_mesh and write_vtu is that write_vtu is
    more general and requires dictionaries of cell information.
    write_basic_mesh calls write_vtu

    Examples
    --------
    >>> import numpy as np
    >>> from pyamg.vis import write_basic_mesh
    >>> V = np.array([[0.0,0.0],
    ...               [1.0,0.0],
    ...               [2.0,0.0],
    ...               [0.0,1.0],
    ...               [1.0,1.0],
    ...               [2.0,1.0],
    ...               [0.0,2.0],
    ...               [1.0,2.0],
    ...               [2.0,2.0],
    ...               [0.0,3.0],
    ...               [1.0,3.0],
    ...               [2.0,3.0]])
    >>> E2V = np.array([[0,4,3],
    ...                 [0,1,4],
    ...                 [1,5,4],
    ...                 [1,2,5],
    ...                 [3,7,6],
    ...                 [3,4,7],
    ...                 [4,8,7],
    ...                 [4,5,8],
    ...                 [6,10,9],
    ...                 [6,7,10],
    ...                 [7,11,10],
    ...                 [7,8,11]])
    >>> pdata=np.ones((12,2))
    >>> pvdata=np.ones((12*3,2))
    >>> cdata=np.ones((12,2))
    >>> cvdata=np.ones((3*12,2))
    >>> write_basic_mesh(V, E2V=E2V, mesh_type='tri',pdata=pdata,
    ...                  pvdata=pvdata, cdata=cdata, cvdata=cvdata,
    ...                  fname='test.vtu')

    See Also
    --------
    write_vtu

    """
    if E2V is None:
        mesh_type = 'vertex'

    map_type_to_key = {'vertex': 1, 'tri': 5, 'quad': 9, 'tet': 10, 'hex': 12}

    if mesh_type not in map_type_to_key:
        raise ValueError(f'Unknown mesh_type={mesh_type}')

    key = map_type_to_key[mesh_type]

    if mesh_type == 'vertex':
        uidx = np.arange(0, V.shape[0]).reshape((V.shape[0], 1))
        E2V = {key: uidx}
    else:
        E2V = {key: E2V}

    if cdata is not None:
        cdata = {key: cdata}

    if cvdata is not None:
        cvdata = {key: cvdata}

    write_vtu(V=V, cells=E2V, pdata=pdata, pvdata=pvdata,
              cdata=cdata, cvdata=cvdata, fname=fname)
def write_basic_mesh ( V , E2V = None , mesh_type = 'tri' , pdata = None , pvdata = None , cdata = None , cvdata = None , fname = 'output.vtk' ) : if E2V is None : mesh_type = 'vertex' map_type_to_key = { 'vertex' : 1 , 'tri' : 5 , 'quad' : 9 , 'tet' : 10 , 'hex' : 12 } if mesh_type not in map_type_to_key : raise ValueError ( f'Unknown mesh_type={mesh_type}' ) key = map_type_to_key [ mesh_type ] if mesh_type == 'vertex' : uidx = np . arange ( 0 , V . shape [ 0 ] ) . reshape ( ( V . shape [ 0 ] , 1 ) ) E2V = { key : uidx } else : E2V = { key : E2V } if cdata is not None : cdata = { key : cdata } if cvdata is not None : cvdata = { key : cvdata } write_vtu ( V = V , cells = E2V , pdata = pdata , pvdata = pvdata , cdata = cdata , cvdata = cvdata , fname = fname )