15#include <unordered_set>
21 int const component_id)
const
26template <
typename ElementIterator>
28 ElementIterator first, ElementIterator last,
29 std::vector<MeshLib::Node*>
const& nodes, std::size_t
const mesh_id,
30 const int comp_id,
const int comp_id_write)
32 std::unordered_set<MeshLib::Node*>
const set_nodes(nodes.begin(),
37 for (ElementIterator e = first; e != last; ++e)
40 indices.reserve((*e)->getNumberOfNodes());
42 for (
auto* n = (*e)->getNodes();
43 n < (*e)->getNodes() + (*e)->getNumberOfNodes();
47 if (set_nodes.find(*n) == set_nodes.end())
56 indices.shrink_to_fit();
57 _rows((*e)->getID(), comp_id_write) = std::move(indices);
61template <
typename ElementIterator>
63 ElementIterator first, ElementIterator last,
64 std::vector<MeshLib::Node*>
const& nodes, std::size_t
const mesh_id,
65 const int comp_id,
const int comp_id_write)
69 std::unordered_set<MeshLib::Node*>
const set_nodes(nodes.begin(),
74 std::size_t elem_id = 0;
75 for (ElementIterator e = first; e != last; ++e, ++elem_id)
78 indices.reserve((*e)->getNumberOfNodes());
80 for (
auto* n = (*e)->getNodes();
81 n < (*e)->getNodes() + (*e)->getNumberOfNodes();
85 if (set_nodes.find(*n) == set_nodes.end())
91 auto const global_index =
93 if (global_index == std::numeric_limits<GlobalIndexType>::max())
97 indices.push_back(global_index);
100 indices.shrink_to_fit();
101 _rows(elem_id, comp_id_write) = std::move(indices);
106 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
109 std::vector<int>(mesh_subsets.size(), 1), order)
114 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
115 std::vector<int>
const& vec_var_n_components,
117 : _mesh_subsets(std::move(mesh_subsets)),
118 _mesh_component_map(_mesh_subsets, order),
119 _variable_component_offsets(
BaseLib::sizesToOffsets(vec_var_n_components))
122 for (
int variable_id = 0;
123 variable_id < static_cast<int>(vec_var_n_components.size());
126 for (
int component_id = 0;
127 component_id < static_cast<int>(vec_var_n_components[variable_id]);
130 auto const global_component_id =
134 std::size_t
const mesh_id = ms.getMeshID();
137 ms.getNodes(), mesh_id, global_component_id,
138 global_component_id);
144 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
145 std::vector<int>
const& vec_var_n_components,
146 std::vector<std::vector<MeshLib::Element*>
const*>
const& vec_var_elements,
148 : _mesh_subsets(std::move(mesh_subsets)),
149 _mesh_component_map(_mesh_subsets, order),
150 _variable_component_offsets(
BaseLib::sizesToOffsets(vec_var_n_components))
152 assert(vec_var_n_components.size() == vec_var_elements.size());
157 std::size_t max_elem_id = 0;
158 for (std::vector<MeshLib::Element*>
const* elements : vec_var_elements)
160 for (
auto e : *elements)
162 max_elem_id = std::max(max_elem_id, e->getID());
167 for (
int variable_id = 0;
168 variable_id < static_cast<int>(vec_var_n_components.size());
171 std::vector<MeshLib::Element*>
const& var_elements =
172 *vec_var_elements[variable_id];
173 for (
int component_id = 0;
174 component_id < static_cast<int>(vec_var_n_components[variable_id]);
177 auto const global_component_id =
181 std::size_t
const mesh_id = ms.getMeshID();
184 var_elements.cbegin(), var_elements.cend(), ms.getNodes(),
185 mesh_id, global_component_id, global_component_id);
191 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
192 std::vector<int>
const& global_component_ids,
193 std::vector<int>
const& variable_component_offsets,
194 std::vector<MeshLib::Element*>
const& elements,
197 : _mesh_subsets(std::move(mesh_subsets)),
198 _mesh_component_map(std::move(mesh_component_map)),
199 _variable_component_offsets(variable_component_offsets)
205 "Number of mesh subsets is not equal to number of components. "
206 "There are {:d} mesh subsets and {:d} components.",
210 for (
int i = 0; i < static_cast<int>(global_component_ids.size()); ++i)
216 std::size_t
const mesh_id = ms.getMeshID();
219 mesh_id, global_component_ids[i], i);
223std::unique_ptr<LocalToGlobalIndexMap>
225 int const variable_id,
226 std::vector<int>
const& component_ids,
229 DBUG(
"Construct reduced local to global index map.");
231 if (component_ids.empty())
233 OGS_FATAL(
"Expected non-empty vector of component ids.");
237 std::vector<MeshLib::Element*>
const& elements =
238 new_mesh_subset.getMesh().getElements();
241 std::vector<int> global_component_ids;
243 transform(cbegin(component_ids), cend(component_ids),
244 back_inserter(global_component_ids),
245 [&](
auto const component_id)
248 auto mesh_component_map =
253 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
254 for (
int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i)
256 all_mesh_subsets.emplace_back(new_mesh_subset);
258 all_mesh_subsets.emplace_back(std::move(new_mesh_subset));
260 return std::make_unique<LocalToGlobalIndexMap>(
261 std::move(all_mesh_subsets), global_component_ids,
266std::unique_ptr<LocalToGlobalIndexMap>
270 DBUG(
"Construct reduced local to global index map.");
273 std::vector<int> global_component_ids;
277 global_component_ids.push_back(i);
281 std::vector<MeshLib::Element*>
const& elements =
282 new_mesh_subset.getMesh().getElements();
284 auto mesh_component_map =
289 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
290 for (
int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i)
292 all_mesh_subsets.emplace_back(new_mesh_subset);
294 all_mesh_subsets.emplace_back(std::move(new_mesh_subset));
296 return std::make_unique<LocalToGlobalIndexMap>(
297 std::move(all_mesh_subsets), global_component_ids,
335 std::size_t
const mesh_item_id,
const int global_component_id)
const
338 _columns(mesh_item_id, global_component_id));
342 std::size_t
const mesh_item_id)
const
344 std::size_t ndof = 0;
346 for (Table::Index c = 0; c <
_rows.cols(); ++c)
348 ndof +=
_rows(mesh_item_id, c).size();
355 std::size_t
const mesh_item_id)
const
358 for (Table::Index c = 0; c <
_rows.cols(); ++c)
360 if (!
_rows(mesh_item_id, c).empty())
369 std::size_t
const mesh_item_id)
const
371 std::vector<int> vec;
377 if (!
_rows(mesh_item_id, comp_id).empty())
383 std::sort(vec.begin(), vec.end());
384 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
391 int const variable_id,
392 int const component_id)
const
422 std::size_t
const range_begin, std::size_t
const range_end)
const
429 int const variable_id,
int const component_id)
const
435 int const global_component_id)
const
443 std::size_t
const max_lines = 10;
444 std::size_t lines_printed = 0;
446 os <<
"Rows of the local to global index map; " << map.
_rows.size()
448 for (std::size_t e = 0; e < map.
size(); ++e)
450 os <<
"== e " << e <<
" ==\n";
453 auto const& line = map.
_rows(e, c);
455 os <<
"c" << c <<
" { ";
456 std::copy(line.cbegin(), line.cend(),
457 std::ostream_iterator<std::size_t>(os,
" "));
461 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.
std::size_t dofSizeWithoutGhosts() const
GlobalIndexType getGlobalIndex(Location const &l, int const comp_id) const
GlobalIndexType getLocalIndex(Location const &l, int const comp_id, std::size_t const range_begin, std::size_t const range_end) const
MeshComponentMap getSubset(std::vector< MeshLib::MeshSubset > const &bulk_mesh_subsets, MeshLib::MeshSubset const &new_mesh_subset) const
std::vector< GlobalIndexType > getGlobalIndices(const Location &l) const
std::size_t dofSizeWithGhosts() const
The number of dofs including the those located in the ghost nodes.
std::vector< GlobalIndexType > const & getGhostIndices() const
Get ghost indices (for DDC).
ComponentOrder
Ordering of components in global matrix/vector.
std::ostream & operator<<(std::ostream &os, LocalToGlobalIndexMap const &map)