8#include <unordered_set>
14 int const component_id)
const
19template <
typename ElementIterator>
21 ElementIterator first, ElementIterator last,
22 std::vector<MeshLib::Node*>
const& nodes, std::size_t
const mesh_id,
23 const int comp_id,
const int comp_id_write)
25 std::unordered_set<MeshLib::Node*>
const set_nodes(nodes.begin(),
30 for (ElementIterator e = first; e != last; ++e)
33 indices.reserve((*e)->getNumberOfNodes());
35 for (
auto* n = (*e)->getNodes();
36 n < (*e)->getNodes() + (*e)->getNumberOfNodes();
40 if (set_nodes.find(*n) == set_nodes.end())
49 indices.shrink_to_fit();
50 _rows((*e)->getID(), comp_id_write) = std::move(indices);
54template <
typename ElementIterator>
56 ElementIterator first, ElementIterator last,
57 std::vector<MeshLib::Node*>
const& nodes, std::size_t
const mesh_id,
58 const int comp_id,
const int comp_id_write)
62 std::unordered_set<MeshLib::Node*>
const set_nodes(nodes.begin(),
67 std::size_t elem_id = 0;
68 for (ElementIterator e = first; e != last; ++e, ++elem_id)
71 indices.reserve((*e)->getNumberOfNodes());
73 for (
auto* n = (*e)->getNodes();
74 n < (*e)->getNodes() + (*e)->getNumberOfNodes();
78 if (set_nodes.find(*n) == set_nodes.end())
84 auto const global_index =
86 if (global_index == std::numeric_limits<GlobalIndexType>::max())
90 indices.push_back(global_index);
93 indices.shrink_to_fit();
94 _rows(elem_id, comp_id_write) = std::move(indices);
99 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
102 std::vector<int>(mesh_subsets.
size(), 1), order)
107 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
108 std::vector<int>
const& vec_var_n_components,
115 for (
int variable_id = 0;
116 variable_id < static_cast<int>(vec_var_n_components.size());
119 for (
int component_id = 0;
120 component_id < static_cast<int>(vec_var_n_components[variable_id]);
123 auto const global_component_id =
127 std::size_t
const mesh_id = ms.getMeshID();
130 ms.getNodes(), mesh_id, global_component_id,
131 global_component_id);
137 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
138 std::vector<int>
const& vec_var_n_components,
139 std::vector<std::vector<MeshLib::Element*>
const*>
const& vec_var_elements,
145 assert(vec_var_n_components.size() == vec_var_elements.size());
150 std::size_t max_elem_id = 0;
151 for (std::vector<MeshLib::Element*>
const* elements : vec_var_elements)
153 for (
auto e : *elements)
155 max_elem_id = std::max(max_elem_id, e->getID());
160 for (
int variable_id = 0;
161 variable_id < static_cast<int>(vec_var_n_components.size());
164 std::vector<MeshLib::Element*>
const& var_elements =
165 *vec_var_elements[variable_id];
166 for (
int component_id = 0;
167 component_id < static_cast<int>(vec_var_n_components[variable_id]);
170 auto const global_component_id =
174 std::size_t
const mesh_id = ms.getMeshID();
177 var_elements.cbegin(), var_elements.cend(), ms.getNodes(),
178 mesh_id, global_component_id, global_component_id);
184 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
185 std::vector<int>
const& global_component_ids,
186 std::vector<int>
const& variable_component_offsets,
187 std::vector<MeshLib::Element*>
const& elements,
198 "Number of mesh subsets is not equal to number of components. "
199 "There are {:d} mesh subsets and {:d} components.",
200 _mesh_subsets.size(), global_component_ids.size());
203 for (
int i = 0; i < static_cast<int>(global_component_ids.size()); ++i)
209 std::size_t
const mesh_id = ms.getMeshID();
212 mesh_id, global_component_ids[i], i);
216std::unique_ptr<LocalToGlobalIndexMap>
218 int const variable_id,
219 std::vector<int>
const& component_ids,
222 DBUG(
"Construct reduced local to global index map.");
224 if (component_ids.empty())
226 OGS_FATAL(
"Expected non-empty vector of component ids.");
230 std::vector<MeshLib::Element*>
const& elements =
231 new_mesh_subset.getMesh().getElements();
234 std::vector<int> global_component_ids;
236 transform(cbegin(component_ids), cend(component_ids),
237 back_inserter(global_component_ids),
238 [&](
auto const component_id)
241 auto mesh_component_map =
246 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
247 for (
int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i)
249 all_mesh_subsets.emplace_back(new_mesh_subset);
251 all_mesh_subsets.emplace_back(std::move(new_mesh_subset));
253 return std::make_unique<LocalToGlobalIndexMap>(
254 std::move(all_mesh_subsets), global_component_ids,
259std::unique_ptr<LocalToGlobalIndexMap>
263 DBUG(
"Construct reduced local to global index map.");
266 std::vector<int> global_component_ids;
270 global_component_ids.push_back(i);
274 std::vector<MeshLib::Element*>
const& elements =
275 new_mesh_subset.getMesh().getElements();
277 auto mesh_component_map =
282 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
283 for (
int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i)
285 all_mesh_subsets.emplace_back(new_mesh_subset);
287 all_mesh_subsets.emplace_back(std::move(new_mesh_subset));
289 return std::make_unique<LocalToGlobalIndexMap>(
290 std::move(all_mesh_subsets), global_component_ids,
328 std::size_t
const mesh_item_id,
const int global_component_id)
const
331 _columns(mesh_item_id, global_component_id));
335 std::size_t
const mesh_item_id)
const
337 std::size_t ndof = 0;
339 for (Table::Index c = 0; c <
_rows.cols(); ++c)
341 ndof +=
_rows(mesh_item_id, c).size();
348 std::size_t
const mesh_item_id)
const
351 for (Table::Index c = 0; c <
_rows.cols(); ++c)
353 if (!
_rows(mesh_item_id, c).empty())
362 std::size_t
const mesh_item_id)
const
364 std::vector<int> vec;
370 if (!
_rows(mesh_item_id, comp_id).empty())
376 std::sort(vec.begin(), vec.end());
377 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
384 int const variable_id,
385 int const component_id)
const
415 std::size_t
const range_begin, std::size_t
const range_end)
const
422 int const variable_id,
int const component_id)
const
428 int const global_component_id)
const
436 std::size_t
const max_lines = 10;
437 std::size_t lines_printed = 0;
439 os <<
"Rows of the local to global index map; " << map.
_rows.size()
441 for (std::size_t e = 0; e < map.
size(); ++e)
443 os <<
"== e " << e <<
" ==\n";
446 auto const& line = map.
_rows(e, c);
448 os <<
"c" << c <<
" { ";
449 std::copy(line.cbegin(), line.cend(),
450 std::ostream_iterator<std::size_t>(os,
" "));
454 if (lines_printed++ > max_lines)
GlobalMatrix::IndexType GlobalIndexType
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
A subset of nodes on a single mesh.
RowColumnIndices operator()(std::size_t const mesh_item_id, const int global_component_id) const
std::size_t getNumberOfElementDOF(std::size_t const mesh_item_id) const
LocalToGlobalIndexMap(std::vector< MeshLib::MeshSubset > &&mesh_subsets, NumLib::ComponentOrder const order)
std::vector< MeshLib::MeshSubset > _mesh_subsets
A vector of mesh subsets for each process variables' components.
int getGlobalComponent(int const variable_id, int const component_id) const
NumLib::MeshComponentMap _mesh_component_map
int getNumberOfVariables() const
MathLib::RowColumnIndices< GlobalIndexType > RowColumnIndices
GlobalIndexType getGlobalIndex(MeshLib::Location const &l, int const variable_id, int const component_id) const
void findGlobalIndicesWithElementID(ElementIterator first, ElementIterator last, std::vector< MeshLib::Node * > const &nodes, std::size_t const mesh_id, const int comp_id, const int comp_id_write)
std::vector< int > const _variable_component_offsets
int getNumberOfVariableComponents(int variable_id) const
std::unique_ptr< LocalToGlobalIndexMap > deriveBoundaryConstrainedMap(int const variable_id, std::vector< int > const &component_ids, MeshLib::MeshSubset &&new_mesh_subset) const
MeshLib::MeshSubset const & getMeshSubset(int const variable_id, int const component_id) const
std::size_t dofSizeWithGhosts() const
std::size_t getNumberOfElementComponents(std::size_t const mesh_item_id) const
void findGlobalIndices(ElementIterator first, ElementIterator last, std::vector< MeshLib::Node * > const &nodes, std::size_t const mesh_id, const int comp_id, const int comp_id_write)
GlobalIndexType getLocalIndex(MeshLib::Location const &l, std::size_t const comp_id, std::size_t const range_begin, std::size_t const range_end) const
std::vector< GlobalIndexType > const & getGhostIndices() const
Get ghost indices, forwarded from MeshComponentMap.
std::size_t dofSizeWithoutGhosts() const
int getNumberOfGlobalComponents() const
RowColumnIndices::LineIndex LineIndex
std::vector< GlobalIndexType > getGlobalIndices(const MeshLib::Location &l) const
Forwards the respective method from MeshComponentMap.
std::vector< int > getElementVariableIDs(std::size_t const mesh_item_id) const
Multidirectional mapping between mesh entities and degrees of freedom.
ComponentOrder
Ordering of components in global matrix/vector.
std::ostream & operator<<(std::ostream &os, LocalToGlobalIndexMap const &map)