Esempio n. 1
0
def write_uvw():
    f = RectilinearGrid('uvw.vtr', (x, y, z))
    f.addPointData(DataArray(r, range(r.ndim), ''), vtk_format='append')
    f.write()
Esempio n. 2
0
    },  # account for overlap
    {
        'x': 2 * N - 1,
        'y': N // 2
    },
]

# Size offsets per rank
offsets = [
    [0, 0],
    [0, N],
    [N, 0],
    [0, 2 * N - 1],
]

x = np.linspace(*bounds[rank]['x'], sizes[rank]['x'])
y = np.linspace(*bounds[rank]['y'], sizes[rank]['y'])

out_name = 'parallel_mpi.pvtr'

xx, yy = np.meshgrid(x, y, indexing='ij', sparse=True)
r = np.sqrt(xx**2 + yy**2)
data = np.exp(-r**2)

# Indicating rank info with a cell array
proc = np.ones((x.size - 1, y.size - 1)) * rank

with PRectilinearGrid(out_name, (x, y), offsets[rank]) as rect:
    rect.addPointData(DataArray(data, range(2), 'gaussian'))
    rect.addCellData(DataArray(proc, range(2), 'proc'))
Esempio n. 3
0
def test_check_array_type_error():
    array = np.array([0, 1, 2], dtype=np.complex128)
    with pytest.raises(TypeError):
        DataArray(array, [0], '')
Esempio n. 4
0
def test_unsupported_format():
    x = np.array([0, 1])

    rect = RectilinearGrid('', x)
    with pytest.raises(ValueError):
        rect.addPointData(DataArray(x, [0]), '#dummy')
Esempio n. 5
0
"Rectilinear grid example with reordering of components"

import numpy as np
from uvw import RectilinearGrid, DataArray

# Creating coordinates
x = np.linspace(-0.5, 0.5, 10)
y = np.linspace(-0.5, 0.5, 20)
z = np.linspace(-0.9, 0.9, 30)

# Creating the file
grid = RectilinearGrid('grid.vtr', (x, y, z), compression=True)

# A centered ball
z, x, y = np.meshgrid(z, y, x, indexing='ij')
r = np.sqrt(x**2 + y**2 + z**2)
ball = r < 0.3

# Some multi-component multi-dimensional data (components order z y x)
data = np.zeros([30, 20, 10, 3, 3])
data[ball, ...] = np.array([[0, 1, 0], [1, 0, 0], [0, 1, 1]])

# Adding the point data (see help(DataArray) for more info)
grid.addPointData(DataArray(data, [2, 1, 0], 'data'))
grid.write()