| 55 | } |
| 56 | |
| 57 | void test_vector_cast() |
| 58 | { |
| 59 | using T = double; |
| 60 | using U = float; |
| 61 | |
| 62 | const int mpi_size = dolfinx::MPI::size(MPI_COMM_WORLD); |
| 63 | const int mpi_rank = dolfinx::MPI::rank(MPI_COMM_WORLD); |
| 64 | constexpr int size_local = 100; |
| 65 | |
| 66 | // Create some ghost entries on next process |
| 67 | int num_ghosts = (mpi_size - 1) * 3; |
| 68 | std::vector<std::int64_t> ghosts(num_ghosts); |
| 69 | for (int i = 0; i < num_ghosts; ++i) |
| 70 | ghosts[i] = (mpi_rank + 1) % mpi_size * size_local + i; |
| 71 | |
| 72 | std::vector<int> global_ghost_owner(ghosts.size(), (mpi_rank + 1) % mpi_size); |
| 73 | |
| 74 | // Create an IndexMap |
| 75 | auto index_map = std::make_shared<common::IndexMap>( |
| 76 | MPI_COMM_WORLD, size_local, ghosts, global_ghost_owner); |
| 77 | |
| 78 | la::Vector<T> v(index_map, 1); |
| 79 | std::ranges::fill(v.array(), 1); |
| 80 | |
| 81 | la::Vector<U, std::vector<U>, std::vector<std::int64_t>> v1(v); |
| 82 | |
| 83 | U norm2 = la::squared_norm(v1); |
| 84 | CHECK(norm2 == mpi_size * size_local); |
| 85 | |
| 86 | std::ranges::fill(v1.array(), mpi_rank); |
| 87 | |
| 88 | U sumn2 = size_local * (mpi_size - 1) * mpi_size * (2 * mpi_size - 1) / 6; |
| 89 | CHECK(la::squared_norm(v1) == sumn2); |
| 90 | CHECK(la::norm(v1, la::Norm::l2) == std::sqrt(sumn2)); |
| 91 | CHECK(la::inner_product(v1, v1) == sumn2); |
| 92 | CHECK(la::norm(v1, la::Norm::linf) == static_cast<U>(mpi_size - 1)); |
| 93 | } |
| 94 | } // namespace |
| 95 | |
| 96 | TEMPLATE_TEST_CASE("Linear Algebra Vector", "[la_vector]", double, |
no test coverage detected