@pytest.mark.parametrize('ambient_dim', [2, 3])
def test_unstructured_simplex_grid(ambient_dim, nelements=16):
    'Test constructing a grid with a more complicated topology.'
    from pyvisfile.xdmf import TopologyType
    if (ambient_dim == 1):
        topology_type = TopologyType.Polyline
        simplices_per_quad = 1
    if (ambient_dim == 2):
        topology_type = TopologyType.Triangle
        simplices_per_quad = 2
    elif (ambient_dim == 3):
        topology_type = TopologyType.Tetrahedron
        simplices_per_quad = 6
    else:
        raise ValueError('unsupported dimension')
    x = np.linspace((- 1.0), 1.0, (nelements + 1))
    npoints = len(x)
    points = np.empty(((ambient_dim,) + ((npoints,) * ambient_dim)))
    for idim in range(ambient_dim):
        points[idim] = x.reshape(((npoints,) + ((1,) * ((ambient_dim - 1) - idim))))
    from pyvisfile.xdmf import NumpyDataArray
    points = NumpyDataArray(points.reshape(ambient_dim, (- 1)).T, name='points')
    from pyvisfile.xdmf import _XDMF_ELEMENT_NODE_COUNT
    connectivity = _simplex_box_connectivity(npoints=((npoints,) * ambient_dim), nelements=(simplices_per_quad * (nelements ** ambient_dim)), nvertices=_XDMF_ELEMENT_NODE_COUNT[topology_type])
    temperature = (np.sin(((2.0 * np.pi) * points.ary[:, 0])) + np.cos(((2.0 * np.pi) * points.ary[:, 1])))
    temperature = NumpyDataArray(temperature, name='temperature')
    velocity = (points.ary + np.array([0, 1, 2][:ambient_dim]).reshape(1, (- 1)))
    velocity = NumpyDataArray(velocity, name='velocity')
    vorticity = NumpyDataArray(make_obj_array(velocity.ary), name='vorticity')
    from pyvisfile.xdmf import XdmfUnstructuredGrid
    grid = XdmfUnstructuredGrid(points, connectivity, topology_type=topology_type, name='simplex')
    grid.add_attribute(temperature)
    grid.add_attribute(velocity)
    grid.add_attribute(vorticity)
    from pyvisfile.xdmf import XdmfWriter
    writer = XdmfWriter((grid,))
    filename = f'test_unstructured_simplex_{ambient_dim}d.xmf'
    writer.write_pretty(filename)
Test constructing a grid with a more complicated topology.
@pytest.mark.parametrize('ambient_dim', [2, 3])
def test_unstructured_simplex_grid(ambient_dim, nelements=16):
    
    from pyvisfile.xdmf import TopologyType
    if (ambient_dim == 1):
        topology_type = TopologyType.Polyline
        simplices_per_quad = 1
    if (ambient_dim == 2):
        topology_type = TopologyType.Triangle
        simplices_per_quad = 2
    elif (ambient_dim == 3):
        topology_type = TopologyType.Tetrahedron
        simplices_per_quad = 6
    else:
        raise ValueError('unsupported dimension')
    x = np.linspace((- 1.0), 1.0, (nelements + 1))
    npoints = len(x)
    points = np.empty(((ambient_dim,) + ((npoints,) * ambient_dim)))
    for idim in range(ambient_dim):
        points[idim] = x.reshape(((npoints,) + ((1,) * ((ambient_dim - 1) - idim))))
    from pyvisfile.xdmf import NumpyDataArray
    points = NumpyDataArray(points.reshape(ambient_dim, (- 1)).T, name='points')
    from pyvisfile.xdmf import _XDMF_ELEMENT_NODE_COUNT
    connectivity = _simplex_box_connectivity(npoints=((npoints,) * ambient_dim), nelements=(simplices_per_quad * (nelements ** ambient_dim)), nvertices=_XDMF_ELEMENT_NODE_COUNT[topology_type])
    temperature = (np.sin(((2.0 * np.pi) * points.ary[:, 0])) + np.cos(((2.0 * np.pi) * points.ary[:, 1])))
    temperature = NumpyDataArray(temperature, name='temperature')
    velocity = (points.ary + np.array([0, 1, 2][:ambient_dim]).reshape(1, (- 1)))
    velocity = NumpyDataArray(velocity, name='velocity')
    vorticity = NumpyDataArray(make_obj_array(velocity.ary), name='vorticity')
    from pyvisfile.xdmf import XdmfUnstructuredGrid
    grid = XdmfUnstructuredGrid(points, connectivity, topology_type=topology_type, name='simplex')
    grid.add_attribute(temperature)
    grid.add_attribute(velocity)
    grid.add_attribute(vorticity)
    from pyvisfile.xdmf import XdmfWriter
    writer = XdmfWriter((grid,))
    filename = f'test_unstructured_simplex_{ambient_dim}d.xmf'
    writer.write_pretty(filename)