diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 880907ec9ca..e2608cf0990 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -26,10 +26,10 @@ if (POLICY CMP0075) endif() #------------------------------------------------------------------------------ -# Use C++14 -set(CMAKE_CXX_STANDARD 14) +# Use C++17 +set(CMAKE_CXX_STANDARD 17) -# Require C++14 +# Require C++17 set(CMAKE_CXX_STANDARD_REQUIRED ON) # Do not enable compler-specific extensions diff --git a/cpp/dolfin/fem/DofMapBuilder.cpp b/cpp/dolfin/fem/DofMapBuilder.cpp index 1930165df28..d3bd610c4a5 100644 --- a/cpp/dolfin/fem/DofMapBuilder.cpp +++ b/cpp/dolfin/fem/DofMapBuilder.cpp @@ -761,14 +761,9 @@ DofMapBuilder::build(const mesh::Mesh& mesh, // Compute node ownership: // (a) Number of owned nodes; // (b) owned and shared nodes (and owned and un-owned): - // -1: unowned, 0: owned and shared, 1: owned and not shared; - // (c) map from shared node to sharing processes; and - std::int32_t num_owned_nodes; - std::vector node_ownership0; - std::unordered_map> - shared_node_to_processes0; - std::set neighbouring_procs; - std::tie(num_owned_nodes, node_ownership0, shared_node_to_processes0) + // -1: unowned, 0: owned and shared, 1: owned and not shared; and + // (c) map from shared node to sharing processes. + auto [num_owned_nodes, node_ownership0, shared_node_to_processes0] = compute_ownership(node_graph0, shared_nodes, mesh, global_dimension); // Build re-ordering map for data locality. Owned dofs are re-ordred diff --git a/cpp/dolfin/function/Function.cpp b/cpp/dolfin/function/Function.cpp index e987f03646d..519f3450649 100644 --- a/cpp/dolfin/function/Function.cpp +++ b/cpp/dolfin/function/Function.cpp @@ -100,9 +100,7 @@ Function Function::sub(int i) const Function Function::collapse() const { // Create new collapsed FunctionSpace - std::shared_ptr function_space_new; - std::vector collapsed_map; - std::tie(function_space_new, collapsed_map) = _function_space->collapse(); + auto [function_space_new, collapsed_map] = _function_space->collapse(); // Create new vector assert(function_space_new); diff --git a/cpp/dolfin/graph/GraphBuilder.cpp b/cpp/dolfin/graph/GraphBuilder.cpp index 33e6b261244..17d1b2fb110 100644 --- a/cpp/dolfin/graph/GraphBuilder.cpp +++ b/cpp/dolfin/graph/GraphBuilder.cpp @@ -429,19 +429,13 @@ graph::GraphBuilder::compute_dual_graph( { LOG(INFO) << "Build mesh dual graph"; - std::vector> local_graph; - std::int32_t num_ghost_nodes; - // Compute local part of dual graph - graph::GraphBuilder::FacetCellMap facet_cell_map; - std::int32_t num_local_edges; - std::tie(local_graph, facet_cell_map, num_local_edges) + auto [local_graph, facet_cell_map, num_local_edges] = graph::GraphBuilder::compute_local_dual_graph(mpi_comm, cell_vertices, cell_type); // Compute nonlocal part - std::int32_t num_nonlocal_edges; - std::tie(num_ghost_nodes, num_nonlocal_edges) = compute_nonlocal_dual_graph( + auto [num_ghost_nodes, num_nonlocal_edges] = compute_nonlocal_dual_graph( mpi_comm, cell_vertices, cell_type, facet_cell_map, local_graph); // Shrink to fit diff --git a/cpp/dolfin/io/HDF5File.cpp b/cpp/dolfin/io/HDF5File.cpp index 04facd4d3e2..4663eaf50ce 100644 --- a/cpp/dolfin/io/HDF5File.cpp +++ b/cpp/dolfin/io/HDF5File.cpp @@ -1366,15 +1366,8 @@ mesh::Mesh HDF5File::read_mesh(const std::string data_path, bool use_partition_from_file, const mesh::GhostMode ghost_mode) const { - mesh::CellType cell_type; - Eigen::Array points; - Eigen::Array - cells; - std::vector global_cell_indices; - std::vector cell_distribution; - // Read local mesh data - std::tie(cell_type, points, cells, global_cell_indices, cell_distribution) + auto [cell_type, points, cells, global_cell_indices, cell_distribution] = read_mesh_data(data_path); if (use_partition_from_file) diff --git a/cpp/dolfin/io/HDF5Utility.cpp b/cpp/dolfin/io/HDF5Utility.cpp index d8d35265ef1..305d9e10779 100644 --- a/cpp/dolfin/io/HDF5Utility.cpp +++ b/cpp/dolfin/io/HDF5Utility.cpp @@ -289,9 +289,7 @@ void HDF5Utility::set_local_vector_values( // Calculate one (global cell, local_dof_index) to associate with // each item in the vector on this process - std::vector global_cells; - std::vector remote_local_dofi; - std::tie(global_cells, remote_local_dofi) = HDF5Utility::map_gdof_to_cell( + auto [global_cells, remote_local_dofi] = HDF5Utility::map_gdof_to_cell( mpi_comm, cells, cell_dofs, x_cell_dofs, input_vector_range); // At this point, each process has a set of data, and for each diff --git a/cpp/dolfin/io/XDMFFile.cpp b/cpp/dolfin/io/XDMFFile.cpp index 5a7b0c8845c..0402fee1215 100644 --- a/cpp/dolfin/io/XDMFFile.cpp +++ b/cpp/dolfin/io/XDMFFile.cpp @@ -1458,15 +1458,8 @@ XDMFFile::read_mesh_data(MPI_Comm comm) const //---------------------------------------------------------------------------- mesh::Mesh XDMFFile::read_mesh(const mesh::GhostMode ghost_mode) const { - - mesh::CellType cell_type; - Eigen::Array points; - Eigen::Array - cells; - std::vector global_cell_indices; - // Read local mesh data - std::tie(cell_type, points, cells, global_cell_indices) + auto [cell_type, points, cells, global_cell_indices] = read_mesh_data(_mpi_comm.comm()); // Permute cells to DOLFIN ordering diff --git a/cpp/dolfin/mesh/DistributedMeshTools.cpp b/cpp/dolfin/mesh/DistributedMeshTools.cpp index f5f380fc0fb..59fea567ca6 100644 --- a/cpp/dolfin/mesh/DistributedMeshTools.cpp +++ b/cpp/dolfin/mesh/DistributedMeshTools.cpp @@ -402,16 +402,13 @@ void DistributedMeshTools::number_entities(const Mesh& mesh, int d) return; } - // Get shared entities map - std::map>& shared_entities - = _mesh.topology().shared_entities(d); - // Number entities - std::vector global_entity_indices; - std::size_t num_global_entities; - std::tie(global_entity_indices, shared_entities, num_global_entities) + auto [global_entity_indices, shared_entities, num_global_entities] = compute_entity_numbering(mesh, d); + // Set shared entities + _mesh.topology().set_shared_entities(d, shared_entities); + // Set global entity numbers in mesh _mesh.topology().set_num_entities_global(d, num_global_entities); _mesh.topology().set_global_indices(d, global_entity_indices); @@ -439,7 +436,7 @@ void DistributedMeshTools::init_facet_cell_connections(Mesh& mesh) Eigen::Array num_global_neighbors( mesh.num_entities(D - 1)); - std::map>& shared_facets + const std::map>& shared_facets = mesh.topology().shared_entities(D - 1); // Check if no ghost cells diff --git a/cpp/dolfin/mesh/Mesh.cpp b/cpp/dolfin/mesh/Mesh.cpp index d7ed42b8e39..5935ed65f83 100644 --- a/cpp/dolfin/mesh/Mesh.cpp +++ b/cpp/dolfin/mesh/Mesh.cpp @@ -170,16 +170,11 @@ compute_point_distribution( // Distribute points to processes that need them, and calculate // shared points. Points are returned in same order as in global_index_set. // Sharing information is (global_index -> [remote sharing processes]). - std::map> shared_points_global; - Eigen::Array - recv_points; - std::tie(shared_points_global, recv_points) + auto [shared_points_global, recv_points] = Partitioning::distribute_points(mpi_comm, points, global_index_set); // Get local to global mapping for points - std::vector local_to_global; - std::array num_vertices_local; - std::tie(local_to_global, num_vertices_local) + auto [local_to_global, num_vertices_local] = compute_local_to_global_point_map(mpi_comm, num_vertices_per_cell, shared_points_global, cell_nodes, type); @@ -259,16 +254,8 @@ Mesh::Mesh( // Compute node local-to-global map from global indices, and compute // cell topology using new local indices - std::array num_vertices_local; - std::vector node_indices_global; - Eigen::Array - coordinate_nodes; - std::map> nodes_shared; - Eigen::Array - points_received; - - std::tie(node_indices_global, nodes_shared, coordinate_nodes, points_received, - num_vertices_local) + auto [node_indices_global, nodes_shared, coordinate_nodes, points_received, + num_vertices_local] = compute_point_distribution(comm, num_vertices_per_cell, cells, points, type); @@ -309,14 +296,14 @@ Mesh::Mesh( _topology = std::make_unique(tdim, num_vertices_local[2], num_vertices_global); _topology->set_global_indices(0, vertex_indices_global); - _topology->shared_entities(0) = shared_vertices; + _topology->set_shared_entities(0, shared_vertices); _topology->init_ghost(0, num_vertices_local[1]); // Set vertex ownership std::vector vertex_owner; for (int i = num_vertices_local[1]; i < num_vertices_local[2]; ++i) vertex_owner.push_back(*(shared_vertices[i].begin())); - _topology->entity_owner(0) = vertex_owner; + _topology->set_entity_owner(0, vertex_owner); // Initialise cell topology _topology->set_num_entities_global(tdim, num_cells_global); diff --git a/cpp/dolfin/mesh/Partitioning.cpp b/cpp/dolfin/mesh/Partitioning.cpp index 31331efefb4..db68af6dca5 100644 --- a/cpp/dolfin/mesh/Partitioning.cpp +++ b/cpp/dolfin/mesh/Partitioning.cpp @@ -552,9 +552,7 @@ PartitionData Partitioning::partition_cells( if (mpi_comm != MPI_COMM_NULL) { // Compute dual graph (for this partition) - std::vector> local_graph; - std::tuple graph_info; - std::tie(local_graph, graph_info) = graph::GraphBuilder::compute_dual_graph( + auto [local_graph, graph_info] = graph::GraphBuilder::compute_dual_graph( mpi_comm, cell_vertices, cell_type); const std::size_t global_graph_size @@ -685,14 +683,12 @@ mesh::Mesh Partitioning::build_from_partition( return mesh; // Copy cell ownership (only needed for ghost cells) - std::vector& cell_owner = mesh.topology().entity_owner(tdim); - cell_owner.clear(); - cell_owner.insert(cell_owner.begin(), - new_cell_partition.begin() + num_regular_cells, - new_cell_partition.end()); + std::vector cell_owner( + new_cell_partition.begin() + num_regular_cells, new_cell_partition.end()); // Assign map of shared cells (only needed for ghost cells) - mesh.topology().shared_entities(tdim) = shared_cells; + mesh.topology().set_entity_owner(tdim, cell_owner); + mesh.topology().set_shared_entities(tdim, shared_cells); DistributedMeshTools::init_facet_cell_connections(mesh); return mesh; @@ -811,8 +807,7 @@ std::map> Partitioning::compute_halo_cells( { // Compute dual graph (for this partition) std::vector> local_graph; - std::tuple graph_info; - std::tie(local_graph, graph_info) = graph::GraphBuilder::compute_dual_graph( + std::tie(local_graph, std::ignore) = graph::GraphBuilder::compute_dual_graph( mpi_comm, cell_vertices, cell_type); graph::CSRGraph csr_graph(mpi_comm, local_graph); diff --git a/cpp/dolfin/mesh/Topology.cpp b/cpp/dolfin/mesh/Topology.cpp index 8aa3edd6ef0..14424884cef 100644 --- a/cpp/dolfin/mesh/Topology.cpp +++ b/cpp/dolfin/mesh/Topology.cpp @@ -103,11 +103,11 @@ const std::vector& Topology::global_indices(std::size_t d) const return _global_indices[d]; } //----------------------------------------------------------------------------- -std::map>& -Topology::shared_entities(int dim) +void Topology::set_shared_entities( + int dim, const std::map>& entities) { assert(dim <= this->dim()); - return _shared_entities[dim]; + _shared_entities[dim] = entities; } //----------------------------------------------------------------------------- const std::map>& @@ -117,9 +117,10 @@ Topology::shared_entities(int dim) const return _shared_entities[dim]; } //----------------------------------------------------------------------------- -std::vector& Topology::entity_owner(int dim) +void Topology::set_entity_owner(int dim, const std::vector& owners) { - return _entity_owner[dim]; + assert(dim <= this->dim()); + _entity_owner[dim] = owners; } //----------------------------------------------------------------------------- const std::vector& Topology::entity_owner(int dim) const diff --git a/cpp/dolfin/mesh/Topology.h b/cpp/dolfin/mesh/Topology.h index 2954540df02..a3c0ffaa33c 100644 --- a/cpp/dolfin/mesh/Topology.h +++ b/cpp/dolfin/mesh/Topology.h @@ -80,19 +80,20 @@ class Topology /// dimension d const std::vector& global_indices(std::size_t d) const; - /// Return map from shared entities (local index) to processes - /// that share the entity - std::map>& shared_entities(int dim); + /// Set the map from shared entities (local index) to processes that + /// share the entity + void set_shared_entities( + int dim, const std::map>& entities); /// Return map from shared entities (local index) to process that /// share the entity (const version) const std::map>& shared_entities(int dim) const; - /// Return mapping from local ghost cell index to owning process. - /// Since ghost cells are at the end of the range, this is just a vector + /// Set map from local ghost cell index to owning process. Since + /// ghost cells are at the end of the range, this is just a vector /// over those cells - std::vector& entity_owner(int dim); + void set_entity_owner(int dim, const std::vector& owners); /// Return mapping from local ghost cell index to owning process /// (const version). Since ghost cells are at the end of the range, diff --git a/cpp/dolfin/refinement/PlazaRefinementND.cpp b/cpp/dolfin/refinement/PlazaRefinementND.cpp index bbd14a2519f..73072150037 100644 --- a/cpp/dolfin/refinement/PlazaRefinementND.cpp +++ b/cpp/dolfin/refinement/PlazaRefinementND.cpp @@ -379,9 +379,7 @@ mesh::Mesh PlazaRefinementND::refine(const mesh::Mesh& mesh, bool redistribute) } common::Timer t0("PLAZA: refine"); - std::vector long_edge; - std::vector edge_ratio_ok; - std::tie(long_edge, edge_ratio_ok) = face_long_edge(mesh); + auto [long_edge, edge_ratio_ok] = face_long_edge(mesh); ParallelRefinement p_ref(mesh); p_ref.mark_all(); @@ -402,9 +400,7 @@ PlazaRefinementND::refine(const mesh::Mesh& mesh, } common::Timer t0("PLAZA: refine"); - std::vector long_edge; - std::vector edge_ratio_ok; - std::tie(long_edge, edge_ratio_ok) = face_long_edge(mesh); + auto [long_edge, edge_ratio_ok] = face_long_edge(mesh); ParallelRefinement p_ref(mesh); p_ref.mark(refinement_marker); diff --git a/cpp/test/unit/CMakeLists.txt b/cpp/test/unit/CMakeLists.txt index 3fbb9f92d14..fd9289de8f6 100644 --- a/cpp/test/unit/CMakeLists.txt +++ b/cpp/test/unit/CMakeLists.txt @@ -4,6 +4,9 @@ project(dolfin-tests) find_package(DOLFIN REQUIRED) include(${DOLFIN_USE_FILE}) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + # Prepare "Catch" library for other executables set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch) diff --git a/cpp/test/unit/mesh/DistributedMesh.cpp b/cpp/test/unit/mesh/DistributedMesh.cpp index 87ee121c48d..4be132fc9f8 100644 --- a/cpp/test/unit/mesh/DistributedMesh.cpp +++ b/cpp/test/unit/mesh/DistributedMesh.cpp @@ -39,15 +39,9 @@ void test_distributed_mesh() io::XDMFFile file(MPI_COMM_WORLD, "mesh.xdmf"); file.write(*mesh); - mesh::CellType cell_type; - Eigen::Array points; - Eigen::Array - cells; - std::vector global_cell_indices; - // Read in mesh in mesh data from XDMF file io::XDMFFile infile(MPI_COMM_WORLD, "mesh.xdmf"); - std::tie(cell_type, points, cells, global_cell_indices) + auto [cell_type, points, cells, global_cell_indices] = infile.read_mesh_data(subset_comm); // Partition mesh into nparts using local mesh data and subset of diff --git a/python/src/mesh.cpp b/python/src/mesh.cpp index dd0b81fac63..82d2fa4e4c5 100644 --- a/python/src/mesh.cpp +++ b/python/src/mesh.cpp @@ -149,8 +149,7 @@ void mesh(py::module& m) py::none()); }, py::return_value_policy::reference_internal) - .def("shared_entities", - py::overload_cast(&dolfin::mesh::Topology::shared_entities)) + .def("shared_entities", &dolfin::mesh::Topology::shared_entities) .def("str", &dolfin::mesh::Topology::str); // dolfin::mesh::Mesh