Ejemplo n.º 1
0
def test_picker_linear_3d(tmpdir):
    """Test vtk picker in 3D."""

    pos = ((0.5, 0.5, 0.5),
           (0.25, 0.75, 0.25))

    err = numpy.array((1.0e-8, 1.0e-8, 1.0e-8))
    fname = tmpdir.join('linear3D.vtu').strpath

    print(fname)

    def vel(pos):
        """ Fluid velocity"""
        return numpy.array((pos[0], pos[1], pos[2]))

    def pres(pos):
        """ Fluid pressure"""
        return pos[0]

    IO.make_unstructured_grid(MESH3D, vel, pres, 0.0, fname)

    system = System.System(temporal_cache=temp_cache('linear3D.vtu',
                                                     tmpdir.strpath))

    part = Particles.Particle((0, 0), system=system)

    for point in pos:

        fluid_velocity, grad_p = part.picker(point, 0.0)

        assert all(abs(fluid_velocity - vel(point)) < err)
        assert all(grad_p == numpy.array((1.0, 0.0, 0.0)))
Ejemplo n.º 2
0
def test_make_unstructured_grid(tmpdir):
    """ Test the make_unstructured_grid routine."""

    mesh = IO.GmshMesh()
    mesh.read("/".join((DATA_DIR, 'Structured.msh')))


    print "/".join((DATA_DIR, 'Structured.msh'))
    num = len(mesh.nodes)

    vel = numpy.zeros((num, 3))
    pres = numpy.zeros((num,))
    time = 0

    ugrid = IO.make_unstructured_grid(mesh, vel, pres, time,
                                      outfile=tmpdir.join('Structured.vtu').strpath)

    assert num > 0
    assert ugrid.GetNumberOfPoints() == num
    assert ugrid.GetNumberOfCells() == len(mesh.elements)
    assert filecmp.cmpfiles(DATA_DIR, tmpdir.strpath, 'Structured.vtu')

    ugrid = IO.make_unstructured_grid(mesh, lambda x: (0, 0, 0),
                                      lambda x: 0, time,
                                      outfile=tmpdir.join('Structured.vtu').strpath)

    assert ugrid.GetNumberOfPoints() == num
    assert ugrid.GetNumberOfCells() == len(mesh.elements)
    assert filecmp.cmpfiles(DATA_DIR, tmpdir.strpath, 'Structured.vtu')
Ejemplo n.º 3
0
def test_make_unstructured_grid(tmpdir):
    """ Test the make_unstructured_grid routine."""

    mesh = IO.GmshMesh()
    mesh.read("/".join((DATA_DIR, 'Structured.msh')))

    print("/".join((DATA_DIR, 'Structured.msh')))
    num = len(mesh.nodes)

    vel = numpy.zeros((num, 3))
    pres = numpy.zeros((num, ))
    time = 0

    ugrid = IO.make_unstructured_grid(
        mesh, vel, pres, time, outfile=tmpdir.join('Structured.vtu').strpath)

    assert num > 0
    assert ugrid.GetNumberOfPoints() == num
    assert ugrid.GetNumberOfCells() == len(mesh.elements)
    assert filecmp.cmpfiles(DATA_DIR, tmpdir.strpath, 'Structured.vtu')

    ugrid = IO.make_unstructured_grid(
        mesh,
        lambda x: (0, 0, 0),
        lambda x: 0,
        time,
        outfile=tmpdir.join('Structured.vtu').strpath)

    assert ugrid.GetNumberOfPoints() == num
    assert ugrid.GetNumberOfCells() == len(mesh.elements)
    assert filecmp.cmpfiles(DATA_DIR, tmpdir.strpath, 'Structured.vtu')
Ejemplo n.º 4
0
def test_picker_linear_3d(tmpdir):
    """Test vtk picker in 3D."""

    pos = ((0.5, 0.5, 0.5),
           (0.25, 0.75, 0.25))

    err = numpy.array((1.0e-8, 1.0e-8, 1.0e-8))
    fname = tmpdir.join('linear3D.vtu').strpath

    print fname

    def vel(pos):
        """ Fluid velocity"""
        return numpy.array((pos[0], pos[1], pos[2]))

    def pres(pos):
        """ Fluid pressure"""
        return pos[0]

    IO.make_unstructured_grid(MESH3D, vel, pres, 0.0, fname)

    system = System.System(temporal_cache=temp_cache('linear3D.vtu',
                                                     tmpdir.strpath))

    part = Particles.Particle((0, 0), system=system)

    for point in pos:

        fluid_velocity, grad_p = part.picker(point, 0.0)

        assert all(abs(fluid_velocity - vel(point)) < err)
        assert all(grad_p == numpy.array((1.0, 0.0, 0.0)))