Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
insertionindexpermutation.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
2// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
3
4#ifndef DUNE_FUFEM_INSERTIONINDEXPERMUTATION_HH
5#define DUNE_FUFEM_INSERTIONINDEXPERMUTATION_HH
6
7#include <cstddef>
8#include <vector>
9#include <algorithm>
10#include <numeric>
11#include <limits>
12
14
16
17
18
19namespace Dune::Fufem {
20
21
22
35template<class Permutation, class DataContainer>
36void permuteInplace(const Permutation& permutation, DataContainer& data)
37{
38 auto processed = std::vector<bool>(data.size(), false);
39 for(auto k : Dune::IntegralRange(data.size()))
40 {
41 if (not processed[k])
42 {
43 auto pos = k;
44 while (std::size_t(permutation[pos]) != k)
45 {
46 std::swap(data[pos], data[permutation[pos]]);
47 processed[pos] = true;
48 pos = permutation[pos];
49 }
50 processed[pos] = true;
51 }
52 }
53}
54
55
56
68template<class GridFactory, class Grid>
70{
71 auto gridView = grid.leafGridView();
72 auto defaultValue = std::numeric_limits<std::size_t>::max();
73 auto indices = std::vector<std::size_t>(grid.numBoundarySegments(), defaultValue);
74
75 for(auto&& intersection : Dune::Fufem::Boundary(gridView))
76 if (gridFactory.wasInserted(intersection))
77 indices[intersection.boundarySegmentIndex()] = gridFactory.insertionIndex(intersection);
78 else
79 indices[intersection.boundarySegmentIndex()] = defaultValue;
80
81 return indices;
82}
83
84
85
102template<class GridFactory, class Grid, class Container>
103void permuteFromBoundarySegmentInsertionIndices(const GridFactory& gridFactory, const Grid& grid, Container& data)
104{
105 auto permutation = boundarySegmentInsertionIndices(gridFactory, grid);
106 Dune::Fufem::permuteInplace(permutation, data);
107}
108
109
110
111}
112
113#endif // DUNE_FUFEM_INSERTIONINDEXPERMUTATION_HH
Definition dunefunctionsboundaryfunctionalassembler.hh:29
void permuteInplace(const Permutation &permutation, DataContainer &data)
Apply inplace permutation to container.
Definition insertionindexpermutation.hh:36
void permuteFromBoundarySegmentInsertionIndices(const GridFactory &gridFactory, const Grid &grid, Container &data)
Permute container according to boundary segment permutation.
Definition insertionindexpermutation.hh:103
std::vector< std::size_t > boundarySegmentInsertionIndices(const GridFactory &gridFactory, const Grid &grid)
Compute permutation of boundary segments.
Definition insertionindexpermutation.hh:69
LeafGridView leafGridView() const
size_t numBoundarySegments() const
virtual unsigned int insertionIndex(const typename Codim< 0 >::Entity &entity) const
virtual bool wasInserted(const typename GridType::LeafIntersection &intersection) const
Encapsulate the set of the boundary intersections of a GridView.
Definition boundary.hh:27
T forward(T... args)
T max(T... args)
T swap(T... args)