15#include <unordered_set>
25 std::vector<T> result(vec.size() + 1, 0);
26 std::partial_sum(vec.begin(), vec.end(), result.begin() + 1);
34 int const component_id)
const
39template <
typename ElementIterator>
41 ElementIterator first, ElementIterator last,
42 std::vector<MeshLib::Node*>
const& nodes, std::size_t
const mesh_id,
43 const int comp_id,
const int comp_id_write)
45 std::unordered_set<MeshLib::Node*>
const set_nodes(nodes.begin(),
50 for (ElementIterator e = first; e != last; ++e)
53 indices.reserve((*e)->getNumberOfNodes());
55 for (
auto* n = (*e)->getNodes();
56 n < (*e)->getNodes() + (*e)->getNumberOfNodes();
60 if (set_nodes.find(*n) == set_nodes.end())
69 indices.shrink_to_fit();
70 _rows((*e)->getID(), comp_id_write) = std::move(indices);
74template <
typename ElementIterator>
76 ElementIterator first, ElementIterator last,
77 std::vector<MeshLib::Node*>
const& nodes, std::size_t
const mesh_id,
78 const int comp_id,
const int comp_id_write)
82 std::unordered_set<MeshLib::Node*>
const set_nodes(nodes.begin(),
87 std::size_t elem_id = 0;
88 for (ElementIterator e = first; e != last; ++e, ++elem_id)
91 indices.reserve((*e)->getNumberOfNodes());
93 for (
auto* n = (*e)->getNodes();
94 n < (*e)->getNodes() + (*e)->getNumberOfNodes();
98 if (set_nodes.find(*n) == set_nodes.end())
104 auto const global_index =
106 if (global_index == std::numeric_limits<GlobalIndexType>::max())
110 indices.push_back(global_index);
113 indices.shrink_to_fit();
114 _rows(elem_id, comp_id_write) = std::move(indices);
119 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
122 std::vector<int>(mesh_subsets.size(), 1), order)
127 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
128 std::vector<int>
const& vec_var_n_components,
130 : _mesh_subsets(std::move(mesh_subsets)),
131 _mesh_component_map(_mesh_subsets, order),
132 _variable_component_offsets(to_cumulative(vec_var_n_components))
135 for (
int variable_id = 0;
136 variable_id < static_cast<int>(vec_var_n_components.size());
139 for (
int component_id = 0;
140 component_id < static_cast<int>(vec_var_n_components[variable_id]);
143 auto const global_component_id =
147 std::size_t
const mesh_id = ms.getMeshID();
150 ms.getNodes(), mesh_id, global_component_id,
151 global_component_id);
157 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
158 std::vector<int>
const& vec_var_n_components,
159 std::vector<std::vector<MeshLib::Element*>
const*>
const& vec_var_elements,
161 : _mesh_subsets(std::move(mesh_subsets)),
162 _mesh_component_map(_mesh_subsets, order),
163 _variable_component_offsets(to_cumulative(vec_var_n_components))
165 assert(vec_var_n_components.size() == vec_var_elements.size());
170 std::size_t max_elem_id = 0;
171 for (std::vector<MeshLib::Element*>
const* elements : vec_var_elements)
173 for (
auto e : *elements)
175 max_elem_id = std::max(max_elem_id, e->getID());
180 for (
int variable_id = 0;
181 variable_id < static_cast<int>(vec_var_n_components.size());
184 std::vector<MeshLib::Element*>
const& var_elements =
185 *vec_var_elements[variable_id];
186 for (
int component_id = 0;
187 component_id < static_cast<int>(vec_var_n_components[variable_id]);
190 auto const global_component_id =
194 std::size_t
const mesh_id = ms.getMeshID();
197 var_elements.cbegin(), var_elements.cend(), ms.getNodes(),
198 mesh_id, global_component_id, global_component_id);
204 std::vector<MeshLib::MeshSubset>&& mesh_subsets,
205 std::vector<int>
const& global_component_ids,
206 std::vector<int>
const& variable_component_offsets,
207 std::vector<MeshLib::Element*>
const& elements,
210 : _mesh_subsets(std::move(mesh_subsets)),
211 _mesh_component_map(std::move(mesh_component_map)),
212 _variable_component_offsets(variable_component_offsets)
218 "Number of mesh subsets is not equal to number of components. "
219 "There are {:d} mesh subsets and {:d} components.",
220 _mesh_subsets.size(), global_component_ids.size());
223 for (
int i = 0; i < static_cast<int>(global_component_ids.size()); ++i)
229 std::size_t
const mesh_id = ms.getMeshID();
232 mesh_id, global_component_ids[i], i);
236std::unique_ptr<LocalToGlobalIndexMap>
238 int const variable_id,
239 std::vector<int>
const& component_ids,
242 DBUG(
"Construct reduced local to global index map.");
244 if (component_ids.empty())
246 OGS_FATAL(
"Expected non-empty vector of component ids.");
250 std::vector<MeshLib::Element*>
const& elements =
251 new_mesh_subset.getMesh().getElements();
254 std::vector<int> global_component_ids;
256 transform(cbegin(component_ids), cend(component_ids),
257 back_inserter(global_component_ids),
258 [&](
auto const component_id)
261 auto mesh_component_map =
266 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
267 for (
int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i)
269 all_mesh_subsets.emplace_back(new_mesh_subset);
271 all_mesh_subsets.emplace_back(std::move(new_mesh_subset));
273 return std::make_unique<LocalToGlobalIndexMap>(
274 std::move(all_mesh_subsets), global_component_ids,
279std::unique_ptr<LocalToGlobalIndexMap>
283 DBUG(
"Construct reduced local to global index map.");
286 std::vector<int> global_component_ids;
290 global_component_ids.push_back(i);
294 std::vector<MeshLib::Element*>
const& elements =
295 new_mesh_subset.getMesh().getElements();
297 auto mesh_component_map =
302 std::vector<MeshLib::MeshSubset> all_mesh_subsets;
303 for (
int i = 0; i < static_cast<int>(global_component_ids.size()) - 1; ++i)
305 all_mesh_subsets.emplace_back(new_mesh_subset);
307 all_mesh_subsets.emplace_back(std::move(new_mesh_subset));
309 return std::make_unique<LocalToGlobalIndexMap>(
310 std::move(all_mesh_subsets), global_component_ids,
348 std::size_t
const mesh_item_id,
const int global_component_id)
const
351 _columns(mesh_item_id, global_component_id));
355 std::size_t
const mesh_item_id)
const
357 std::size_t ndof = 0;
359 for (Table::Index c = 0; c <
_rows.cols(); ++c)
361 ndof +=
_rows(mesh_item_id, c).size();
368 std::size_t
const mesh_item_id)
const
371 for (Table::Index c = 0; c <
_rows.cols(); ++c)
373 if (!
_rows(mesh_item_id, c).empty())
382 std::size_t
const mesh_item_id)
const
384 std::vector<int> vec;
390 if (!
_rows(mesh_item_id, comp_id).empty())
396 std::sort(vec.begin(), vec.end());
397 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
404 int const variable_id,
405 int const component_id)
const
435 std::size_t
const range_begin, std::size_t
const range_end)
const
442 int const variable_id,
int const component_id)
const
448 int const global_component_id)
const
456 std::size_t
const max_lines = 10;
457 std::size_t lines_printed = 0;
459 os <<
"Rows of the local to global index map; " << map.
_rows.size()
461 for (std::size_t e = 0; e < map.
size(); ++e)
463 os <<
"== e " << e <<
" ==\n";
466 auto const& line = map.
_rows(e, c);
468 os <<
"c" << c <<
" { ";
469 std::copy(line.cbegin(), line.cend(),
470 std::ostream_iterator<std::size_t>(os,
" "));
474 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).
std::vector< T > to_cumulative(std::vector< T > const &vec)
ComponentOrder
Ordering of components in global matrix/vector.
std::ostream & operator<<(std::ostream &os, LocalToGlobalIndexMap const &map)