def test_InterpolationMatrix(fs, coords):
    "test InterpolationMatrix with multiple processes"

    n_proc = COMM_WORLD.size

    nd = len(coords)

    vec = Function(fs).vector()

    im = InterpolationMatrix(fs, coords)

    if COMM_WORLD.rank == 0:
        gathered_sizes = (nd, nd)
    else:
        gathered_sizes = (0, 0)

    assert im.n_data == nd
    assert im.n_data_local == nd // n_proc
    assert im.n_mesh == vec.size()
    assert im.n_mesh_local == vec.local_size()
    assert_allclose(im.coords, coords)
    assert im.function_space == fs
    assert im.meshspace_vector.size() == vec.size()
    assert im.meshspace_vector.local_size() == vec.local_size()
    assert im.dataspace_distrib.getSizes() == (nd // n_proc, nd)
    assert im.dataspace_gathered.getSizes() == gathered_sizes
    assert im.interp.getSizes() == ((vec.local_size(), vec.size()),
                                    (nd // n_proc, nd))
    assert not im.is_assembled
Пример #2
0
def test_ForcingCovariance_mult_parallel(my_ensemble, fs, fc, cov):
    "test that the multiplication method of ForcingCovariance can be called independently in an ensemble"

    fc.assemble()

    if my_ensemble.ensemble_comm.rank == 0:

        x = Function(fs).vector()
        x.set_local(np.ones(x.local_size()))

        y = Function(fs).vector()

        fc.mult(x, y)

        ygathered = y.gather()

        assert_allclose(ygathered, np.dot(cov, np.ones(nx + 1)))

    elif my_ensemble.ensemble_comm.rank == 1:

        x = Function(fs).vector()
        x.set_local(0.5 * np.ones(x.local_size()))

        y = Function(fs).vector()

        fc.mult(x, y)

        ygathered = y.gather()

        assert_allclose(ygathered, np.dot(cov, 0.5 * np.ones(nx + 1)))
Пример #3
0
def test_ForcingCovariance_mult(fs, fc, cov):
    "test the multiplication method of ForcingCovariance"

    fc.assemble()

    x = Function(fs).vector()
    x.set_local(np.ones(x.local_size()))

    y = Function(fs).vector()

    fc.mult(x, y)

    ygathered = y.gather()

    assert_allclose(ygathered, np.dot(cov, np.ones(nx + 1)))
def test_InterpolationMatrix_interp_mesh_to_data(fs, coords, meshcoords):
    "test method to interpolate from distributed mesh to data gathered at root"

    # simple 1D test

    nd = len(coords)

    im = InterpolationMatrix(fs, coords)
    im.assemble()

    input_ordered = np.array([3., 2., 7., 4., 0., 0., 2., 1., 1., 1., 5.])

    f = Function(fs).vector()

    meshcoords_ordered = np.linspace(0., 1., 11)

    with f.dat.vec as vec:
        imin, imax = vec.getOwnershipRange()
        for i in range(imin, imax):
            vec.setValue(
                i,
                input_ordered[np.where(meshcoords_ordered == meshcoords[i])])

    if COMM_WORLD.rank == 0:
        expected = np.array([1., 0., 5.5, 3.25])
    else:
        expected = np.zeros(0)

    out = im.interp_mesh_to_data(f)

    assert_allclose(out, expected, atol=1.e-10)

    # failure due to bad input sizes

    mesh2 = UnitIntervalMesh(12)
    V2 = FunctionSpace(mesh2, "CG", 1)

    f2 = Function(V2).vector()
    f2.set_local(np.ones(f2.local_size()))

    with pytest.raises(AssertionError):
        im.interp_mesh_to_data(f2)

    im.destroy()