diff --git a/MeshLib/NodePartitionedMesh.h b/MeshLib/NodePartitionedMesh.h index 4b3207072c069d3dde1a9d26b608fe19615c4565..2869125ff63ebe46d486f69f2919c96f3ea0c2c3 100644 --- a/MeshLib/NodePartitionedMesh.h +++ b/MeshLib/NodePartitionedMesh.h @@ -37,7 +37,8 @@ public: _n_global_base_nodes(mesh.getNumberOfBaseNodes()), _n_global_nodes(mesh.getNumberOfNodes()), _n_active_base_nodes(mesh.getNumberOfBaseNodes()), - _n_active_nodes(mesh.getNumberOfNodes()) + _n_active_nodes(mesh.getNumberOfNodes()), + _is_single_thread(true) { const auto& mesh_nodes = mesh.getNodes(); for (std::size_t i = 0; i < _nodes.size(); i++) @@ -91,7 +92,8 @@ public: _n_global_base_nodes(n_global_base_nodes), _n_global_nodes(n_global_nodes), _n_active_base_nodes(n_active_base_nodes), - _n_active_nodes(n_active_nodes) + _n_active_nodes(n_active_nodes), + _is_single_thread(false) { } @@ -149,6 +151,8 @@ public: return (*it_max_ncn)->getConnectedNodes().size() + 1; } + bool isForSingleThread() const { return _is_single_thread; } + private: /// Global IDs of nodes of a partition std::vector<std::size_t> _global_node_ids; @@ -164,6 +168,8 @@ private: /// Number of the all active nodes. std::size_t _n_active_nodes; + + const bool _is_single_thread; }; } // namespace MeshLib diff --git a/NumLib/DOF/MeshComponentMap.cpp b/NumLib/DOF/MeshComponentMap.cpp index ccf56041073b339d05801fef8d553e0fc3b518b9..ce4b7516dc560b30ca9666a65c4cd6c1ac000f9f 100644 --- a/NumLib/DOF/MeshComponentMap.cpp +++ b/NumLib/DOF/MeshComponentMap.cpp @@ -30,14 +30,25 @@ GlobalIndexType const MeshComponentMap::nop = MeshComponentMap::MeshComponentMap( std::vector<MeshLib::MeshSubset> const& components, ComponentOrder order) { + // Use PETSc with single thread + const MeshLib::NodePartitionedMesh& partitioned_mesh = + static_cast<const MeshLib::NodePartitionedMesh&>( + components[0].getMesh()); + if (partitioned_mesh.isForSingleThread()) + { + createSerialMeshComponentMap(components, order); + return; + } + + // Use PETSc with multi-thread // get number of unknows GlobalIndexType num_unknowns = 0; for (auto const& c : components) { // PETSc always works with MeshLib::NodePartitionedMesh. - const MeshLib::NodePartitionedMesh& mesh = + const MeshLib::NodePartitionedMesh& p_mesh = static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh()); - num_unknowns += mesh.getNumberOfGlobalNodes(); + num_unknowns += p_mesh.getNumberOfGlobalNodes(); } // construct dict (and here we number global_index by component type) @@ -49,7 +60,7 @@ MeshComponentMap::MeshComponentMap( assert(dynamic_cast<MeshLib::NodePartitionedMesh const*>( &c.getMesh()) != nullptr); std::size_t const mesh_id = c.getMeshID(); - const MeshLib::NodePartitionedMesh& mesh = + const MeshLib::NodePartitionedMesh& p_mesh = static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh()); // mesh items are ordered first by node, cell, .... @@ -67,8 +78,9 @@ MeshComponentMap::MeshComponentMap( " of ComponentOrder::BY_LOCATION"); } global_id = static_cast<GlobalIndexType>( - components.size() * mesh.getGlobalNodeID(j) + comp_id); - const bool is_ghost = mesh.isGhostNode(mesh.getNode(j)->getID()); + components.size() * p_mesh.getGlobalNodeID(j) + comp_id); + const bool is_ghost = + p_mesh.isGhostNode(p_mesh.getNode(j)->getID()); if (is_ghost) { _ghosts_indices.push_back(global_id); @@ -85,7 +97,7 @@ MeshComponentMap::MeshComponentMap( comp_id, global_id)); } - _num_global_dof += mesh.getNumberOfGlobalNodes(); + _num_global_dof += p_mesh.getNumberOfGlobalNodes(); comp_id++; } } @@ -93,27 +105,7 @@ MeshComponentMap::MeshComponentMap( MeshComponentMap::MeshComponentMap( std::vector<MeshLib::MeshSubset> const& components, ComponentOrder order) { - // construct dict (and here we number global_index by component type) - GlobalIndexType global_index = 0; - int comp_id = 0; - for (auto const& c : components) - { - std::size_t const mesh_id = c.getMeshID(); - // mesh items are ordered first by node, cell, .... - for (std::size_t j = 0; j < c.getNumberOfNodes(); j++) - { - _dict.insert(Line( - Location(mesh_id, MeshLib::MeshItemType::Node, c.getNodeID(j)), - comp_id, global_index++)); - } - comp_id++; - } - _num_local_dof = _dict.size(); - - if (order == ComponentOrder::BY_LOCATION) - { - renumberByLocation(); - } + createSerialMeshComponentMap(components, order); } #endif // end of USE_PETSC @@ -361,4 +353,30 @@ GlobalIndexType MeshComponentMap::getLocalIndex( #endif } +void MeshComponentMap::createSerialMeshComponentMap( + std::vector<MeshLib::MeshSubset> const& components, ComponentOrder order) +{ + // construct dict (and here we number global_index by component type) + GlobalIndexType global_index = 0; + int comp_id = 0; + for (auto const& c : components) + { + std::size_t const mesh_id = c.getMeshID(); + // mesh items are ordered first by node, cell, .... + for (std::size_t j = 0; j < c.getNumberOfNodes(); j++) + { + _dict.insert(Line( + Location(mesh_id, MeshLib::MeshItemType::Node, c.getNodeID(j)), + comp_id, global_index++)); + } + comp_id++; + } + _num_local_dof = _dict.size(); + + if (order == ComponentOrder::BY_LOCATION) + { + renumberByLocation(); + } +} + } // namespace NumLib diff --git a/NumLib/DOF/MeshComponentMap.h b/NumLib/DOF/MeshComponentMap.h index a0173dfdcd54dc5f1aaed1b1f51a90490b4b629a..1704cde6a751f2f01e176ee4747f34a2f3ef22be 100644 --- a/NumLib/DOF/MeshComponentMap.h +++ b/NumLib/DOF/MeshComponentMap.h @@ -182,6 +182,12 @@ private: /// Global ID for ghost entries std::vector<GlobalIndexType> _ghosts_indices; + + /// \param components a vector of components + /// \param order type of ordering values in a vector + void createSerialMeshComponentMap( + std::vector<MeshLib::MeshSubset> const& components, + ComponentOrder order); }; } // namespace NumLib