Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
boundarydata.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE-FUFEM Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUFEM_GRID_BOUNDARYDATA_HH
8#define DUNE_FUFEM_GRID_BOUNDARYDATA_HH
9
10
11#include <cstddef>
12#include <limits>
13#include <utility>
14#include <vector>
15
17
18#include <dune/grid/common/gridfactory.hh>
20
21
22namespace Dune::Fufem {
23
24
25
42template<class T=int>
44{
45public:
46
56 : data_(data)
57 {}
58
68 : data_(std::move(data))
69 {}
70
84 template<class Grid>
85 BoundaryData(const std::vector<T>& insertedBoundaryData, const Dune::GridFactory<Grid>& factory, const Grid& grid)
86 : data_()
87 {
88 int defaultValue = std::numeric_limits<int>::max();
89 auto coarseGridView = grid.leafGridView();
90 data_.resize(grid.numBoundarySegments());
91 for(const auto& element : elements(coarseGridView))
92 for(const auto& intersection : intersections(coarseGridView, element))
93 if (intersection.boundary())
94 {
95 if (factory.wasInserted(intersection))
96 data_[intersection.boundarySegmentIndex()] = insertedBoundaryData[factory.insertionIndex(intersection)];
97 else
98 data_[intersection.boundarySegmentIndex()] = defaultValue;
99 }
100 }
101
114 template<class Grid>
115 BoundaryData(const Dune::GmshReader<Grid>& reader, const Dune::GridFactory<Grid>& factory, const Grid& grid)
116 : data_()
117 {
118 if (not reader.hasBoundaryData())
119 DUNE_THROW(Dune::InvalidStateException, "The GmshReader passed to BoundaryData has no stored boundary data.");
120 (*this) = BoundaryData(reader.boundaryData(), factory, grid);
121 }
122
126 template<class Intersection>
127 const T& operator()(const Intersection& intersection) const
128 {
129 return data_[intersection.boundarySegmentIndex()];
130 }
131
135 const T& operator[](std::size_t boundarySegmentIndex) const
136 {
137 return data_[boundarySegmentIndex];
138 }
139
144 {
145 return data_.size();
146 }
147
151 const std::vector<T>& data() const
152 {
153 return data_;
154 }
155
163 {
164 return data_;
165 }
166
167private:
168 std::vector<T> data_;
169};
170
171template<class Grid>
174
175
176
177} // namespace Dune::Fufem
178
179
180#endif // DUNE_FUFEM_GRID_BOUNDARYDATA_HH
#define DUNE_THROW(E,...)
STL namespace.
Definition dunefunctionsboundaryfunctionalassembler.hh:29
size_t boundarySegmentIndex() const
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
bool hasBoundaryData() const
const std::vector< int > & boundaryData() const
Class for storing data associated to boundary segments.
Definition boundarydata.hh:44
BoundaryData(std::vector< T > &&data)
Create BoundaryData.
Definition boundarydata.hh:67
const std::vector< T > & data() const
Access raw container with stored data.
Definition boundarydata.hh:151
BoundaryData(const std::vector< T > &data)
Create BoundaryData.
Definition boundarydata.hh:55
const T & operator[](std::size_t boundarySegmentIndex) const
Access data by boundary segment index.
Definition boundarydata.hh:135
BoundaryData(const std::vector< T > &insertedBoundaryData, const Dune::GridFactory< Grid > &factory, const Grid &grid)
Create BoundaryData.
Definition boundarydata.hh:85
BoundaryData(const Dune::GmshReader< Grid > &reader, const Dune::GridFactory< Grid > &factory, const Grid &grid)
Create BoundaryData.
Definition boundarydata.hh:115
const std::vector< T > & coarseData() const
Access raw container with stored level-0 coarse data.
Definition boundarydata.hh:162
const T & operator()(const Intersection &intersection) const
Map intersection to associated data.
Definition boundarydata.hh:127
std::size_t size() const
Size of the container (number of boundary segments)
Definition boundarydata.hh:143
T max(T... args)