diff --git a/MeshLib/NodePartitionedMesh.h b/MeshLib/NodePartitionedMesh.h index 4e4ab688138949db03fc4c6a76966d3cfe9b0bbe..4b3207072c069d3dde1a9d26b608fe19615c4565 100644 --- a/MeshLib/NodePartitionedMesh.h +++ b/MeshLib/NodePartitionedMesh.h @@ -166,4 +166,4 @@ private: std::size_t _n_active_nodes; }; -} // namespace MeshLib +} // namespace MeshLib diff --git a/NumLib/DOF/MeshComponentMap.cpp b/NumLib/DOF/MeshComponentMap.cpp index b1d6ccc730e857ce1c7bd97e2d70544f8ee5a86b..ccf56041073b339d05801fef8d553e0fc3b518b9 100644 --- a/NumLib/DOF/MeshComponentMap.cpp +++ b/NumLib/DOF/MeshComponentMap.cpp @@ -21,7 +21,6 @@ namespace NumLib { - using namespace detail; GlobalIndexType const MeshComponentMap::nop = @@ -35,10 +34,10 @@ MeshComponentMap::MeshComponentMap( GlobalIndexType num_unknowns = 0; for (auto const& c : components) { - // PETSc always works with MeshLib::NodePartitionedMesh. - const MeshLib::NodePartitionedMesh& mesh = - static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh()); - num_unknowns += mesh.getNumberOfGlobalNodes(); + // PETSc always works with MeshLib::NodePartitionedMesh. + const MeshLib::NodePartitionedMesh& mesh = + static_cast<const MeshLib::NodePartitionedMesh&>(c.getMesh()); + num_unknowns += mesh.getNumberOfGlobalNodes(); } // construct dict (and here we number global_index by component type) @@ -116,7 +115,7 @@ MeshComponentMap::MeshComponentMap( renumberByLocation(); } } -#endif // end of USE_PETSC +#endif // end of USE_PETSC MeshComponentMap MeshComponentMap::getSubset( std::vector<MeshLib::MeshSubset> const& bulk_mesh_subsets, @@ -207,8 +206,9 @@ void MeshComponentMap::renumberByLocation(GlobalIndexType offset) { GlobalIndexType global_index = offset; - auto &m = _dict.get<ByLocation>(); // view as sorted by mesh item - for (auto itr_mesh_item=m.begin(); itr_mesh_item!=m.end(); ++itr_mesh_item) + auto& m = _dict.get<ByLocation>(); // view as sorted by mesh item + for (auto itr_mesh_item = m.begin(); itr_mesh_item != m.end(); + ++itr_mesh_item) { Line pos = *itr_mesh_item; pos.global_index = global_index++; @@ -218,7 +218,7 @@ void MeshComponentMap::renumberByLocation(GlobalIndexType offset) std::vector<int> MeshComponentMap::getComponentIDs(const Location& l) const { - auto const &m = _dict.get<ByLocation>(); + auto const& m = _dict.get<ByLocation>(); auto const p = m.equal_range(Line(l)); std::vector<int> vec_compID; for (auto itr = p.first; itr != p.second; ++itr) @@ -230,23 +230,24 @@ std::vector<int> MeshComponentMap::getComponentIDs(const Location& l) const Line MeshComponentMap::getLine(Location const& l, int const comp_id) const { - auto const &m = _dict.get<ByLocationAndComponent>(); + auto const& m = _dict.get<ByLocationAndComponent>(); auto const itr = m.find(Line(l, comp_id)); - assert(itr != m.end()); // The line must exist in the current dictionary. + assert(itr != m.end()); // The line must exist in the current dictionary. return *itr; } GlobalIndexType MeshComponentMap::getGlobalIndex(Location const& l, int const comp_id) const { - auto const &m = _dict.get<ByLocationAndComponent>(); + auto const& m = _dict.get<ByLocationAndComponent>(); auto const itr = m.find(Line(l, comp_id)); - return itr!=m.end() ? itr->global_index : nop; + return itr != m.end() ? itr->global_index : nop; } -std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndices(const Location &l) const +std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndices( + const Location& l) const { - auto const &m = _dict.get<ByLocation>(); + auto const& m = _dict.get<ByLocation>(); auto const p = m.equal_range(Line(l)); std::vector<GlobalIndexType> global_indices; for (auto itr = p.first; itr != p.second; ++itr) @@ -265,7 +266,7 @@ std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndicesByLocation( std::vector<GlobalIndexType> global_indices; global_indices.reserve(ls.size()); - auto const &m = _dict.get<ByLocation>(); + auto const& m = _dict.get<ByLocation>(); for (const auto& l : ls) { auto const p = m.equal_range(Line(l)); @@ -287,7 +288,7 @@ std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndicesByComponent( pairs.reserve(ls.size()); // Create a sub dictionary containing all lines with location from ls. - auto const &m = _dict.get<ByLocation>(); + auto const& m = _dict.get<ByLocation>(); for (const auto& l : ls) { auto const p = m.equal_range(Line(l)); @@ -297,10 +298,9 @@ std::vector<GlobalIndexType> MeshComponentMap::getGlobalIndicesByComponent( } } - auto CIPairLess = [](CIPair const& a, CIPair const& b) - { - return a.first < b.first; - }; + auto CIPairLess = [](CIPair const& a, CIPair const& b) { + return a.first < b.first; + }; // Create vector of global indices from sub dictionary sorting by component. if (!std::is_sorted(pairs.begin(), pairs.end(), CIPairLess)) @@ -330,7 +330,7 @@ GlobalIndexType MeshComponentMap::getLocalIndex( (void)range_end; return global_index; #else - if (global_index >= 0) // non-ghost location. + if (global_index >= 0) // non-ghost location. return global_index - range_begin; // @@ -341,17 +341,16 @@ GlobalIndexType MeshComponentMap::getLocalIndex( // of the local vector: GlobalIndexType const real_global_index = (-global_index == static_cast<GlobalIndexType>(_num_global_dof)) - ? 0 : -global_index; + ? 0 + : -global_index; // TODO Find in ghost indices is O(n^2/2) for n being the length of // _ghosts_indices. Providing an inverted table would be faster. - auto const ghost_index_it = std::find(_ghosts_indices.begin(), - _ghosts_indices.end(), - real_global_index); + auto const ghost_index_it = std::find( + _ghosts_indices.begin(), _ghosts_indices.end(), real_global_index); if (ghost_index_it == _ghosts_indices.end()) { - OGS_FATAL("index %d not found in ghost_indices", - real_global_index); + OGS_FATAL("index %d not found in ghost_indices", real_global_index); } // Using std::distance on a std::vector is O(1). As long as _ghost_indices @@ -362,4 +361,4 @@ GlobalIndexType MeshComponentMap::getLocalIndex( #endif } -} // namespace NumLib +} // namespace NumLib diff --git a/NumLib/DOF/MeshComponentMap.h b/NumLib/DOF/MeshComponentMap.h index 72a4c20f7f6dbd7a24efc1e8fcf072ca5154349e..a0173dfdcd54dc5f1aaed1b1f51a90490b4b629a 100644 --- a/NumLib/DOF/MeshComponentMap.h +++ b/NumLib/DOF/MeshComponentMap.h @@ -12,20 +12,17 @@ #pragma once -#include "numlib_export.h" - -#include "MeshLib/MeshSubset.h" - #include "ComponentGlobalIndexDict.h" +#include "MeshLib/MeshSubset.h" +#include "numlib_export.h" namespace NumLib { - /// Ordering of components in global matrix/vector. enum class ComponentOrder { - BY_COMPONENT, ///< Ordering data by component type - BY_LOCATION ///< Ordering data by spatial location + BY_COMPONENT, ///< Ordering data by component type + BY_LOCATION ///< Ordering data by spatial location }; /// Multidirectional mapping between mesh entities and degrees of freedom. @@ -58,10 +55,7 @@ public: std::vector<int> const& new_global_component_ids) const; /// The number of dofs including the those located in the ghost nodes. - std::size_t dofSizeWithGhosts() const - { - return _dict.size(); - } + std::size_t dofSizeWithGhosts() const { return _dict.size(); } /// Component ids at given location \c l. /// @@ -89,7 +83,7 @@ public: /// | l | comp_id_1 | gi23 | /// | ... | ... | ... | /// | l | comp_id_k | gi45 | - std::vector<GlobalIndexType> getGlobalIndices(const Location &l) const; + std::vector<GlobalIndexType> getGlobalIndices(const Location& l) const; /// Global indices for all components at all given locations \c ls ordered /// by location. The return list is sorted first by location. @@ -124,10 +118,7 @@ public: /// Get the number of local unknowns excluding those associated /// with ghost nodes (for DDC with node-wise mesh partitioning). - std::size_t dofSizeWithoutGhosts() const - { - return _num_local_dof; - } + std::size_t dofSizeWithoutGhosts() const { return _num_local_dof; } /// Get ghost indices (for DDC). std::vector<GlobalIndexType> const& getGhostIndices() const @@ -167,7 +158,8 @@ private: /// Private constructor used by internally created mesh component maps. explicit MeshComponentMap(detail::ComponentGlobalIndexDict& dict) : _dict(dict) - { } + { + } /// Looks up if a line is already stored in the dictionary. /// \attention The line for the location l and component id must exist, @@ -175,13 +167,13 @@ private: /// \return a copy of the line. detail::Line getLine(Location const& l, int const comp_id) const; - void renumberByLocation(GlobalIndexType offset=0); + void renumberByLocation(GlobalIndexType offset = 0); detail::ComponentGlobalIndexDict _dict; /// Number of local unknowns excluding those associated /// with ghost nodes (for domain decomposition). - std::size_t _num_local_dof = 0; + std::size_t _num_local_dof = 0; #ifdef USE_PETSC /// Number of global unknowns. Used internally only. @@ -192,4 +184,4 @@ private: std::vector<GlobalIndexType> _ghosts_indices; }; -} // namespace NumLib +} // namespace NumLib