version 3.11-dev
Loading...
Searching...
No Matches
periodicdofmap.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_PERIODIC_DOF_MAP_HH
13#define DUMUX_DISCRETIZATION_PERIODIC_DOF_MAP_HH
14
15#include <algorithm>
16#include <cstddef>
17#include <type_traits>
18#include <unordered_map>
19#include <utility>
20#include <vector>
21
22namespace Dumux::Detail {
23
28template<class Index>
29void addPeriodicallyMappedDof(std::unordered_map<Index, std::vector<Index>>& periodicDofMap,
30 std::type_identity_t<Index> dofIdx, std::type_identity_t<Index> periodicDofIdx)
31{
32 auto& periodicDofs = periodicDofMap[dofIdx];
33 if (std::ranges::find(periodicDofs, periodicDofIdx) == periodicDofs.end())
34 periodicDofs.push_back(periodicDofIdx);
35}
36
47template<class Index>
48void closePeriodicDofMap(std::unordered_map<Index, std::vector<Index>>& periodicDofMap)
49{
50 std::unordered_map<Index, std::vector<Index>> closedMap;
51 for (const auto& entry : periodicDofMap)
52 {
53 if (closedMap.contains(entry.first))
54 continue;
55
56 std::vector<Index> group{ entry.first };
57 for (std::size_t k = 0; k < group.size(); ++k)
58 if (const auto it = periodicDofMap.find(group[k]); it != periodicDofMap.end())
59 for (const auto periodicDofIdx : it->second)
60 if (std::ranges::find(group, periodicDofIdx) == group.end())
61 group.push_back(periodicDofIdx);
62
63 std::ranges::sort(group);
64 for (const auto dofIdx : group)
65 {
66 auto& periodicDofs = closedMap[dofIdx];
67 for (const auto periodicDofIdx : group)
68 if (periodicDofIdx != dofIdx)
69 periodicDofs.push_back(periodicDofIdx);
70 }
71 }
72
73 periodicDofMap = std::move(closedMap);
74}
75
76} // end namespace Dumux::Detail
77
78#endif
void closePeriodicDofMap(std::unordered_map< Index, std::vector< Index > > &periodicDofMap)
Map every degree of freedom to all others it is identified with.
Definition periodicdofmap.hh:48
void addPeriodicallyMappedDof(std::unordered_map< Index, std::vector< Index > > &periodicDofMap, std::type_identity_t< Index > dofIdx, std::type_identity_t< Index > periodicDofIdx)
Register a degree of freedom as periodically mapped to another one.
Definition periodicdofmap.hh:29
Definition cvfelocalresidual.hh:25