6#include <dune/common/hybridutilities.hh>
7#include <dune/common/std/type_traits.hh>
9#include <amdis/Boundary.hpp>
10#include <amdis/common/Concepts.hpp>
22 template <
class Intersection>
25 return boundaryIds_[intersection.boundarySegmentIndex()];
28 std::vector<BoundaryType>
const& boundaryIds()
const
34 std::vector<BoundaryType> boundaryIds_;
59 enum { dim = Grid::dimension };
60 enum { dow = Grid::dimensionworld };
62 using Segment =
typename Grid::LevelGridView::Intersection;
63 using Domain =
typename Grid::template Codim<0>::Geometry::GlobalCoordinate;
69 :
Super(grid->numBoundarySegments())
83 auto gv = grid_->leafGridView();
84 for (
auto const& e : elements(gv))
86 for (
auto const& segment : intersections(gv,e)) {
87 if (!segment.boundary())
90 auto n = segment.centerUnitOuterNormal();
91 auto index = segment.boundarySegmentIndex();
93 for (
int i = 0; i < dow; ++i) {
95 boundaryIds_[index] = ids[2*i];
97 boundaryIds_[index] = ids[2*i+1];
105 template <
class Indicator,
109 auto gv = grid_->leafGridView();
110 for (
auto const& e : elements(gv))
112 for (
auto const& segment : intersections(gv,e)) {
113 if (!segment.boundary())
116 auto index = segment.boundarySegmentIndex();
117 boundaryIds_[index] = indicator(segment.geometry().center());
128 auto gv = grid_->leafGridView();
129 for (
auto const& e : elements(gv))
131 for (
auto const& segment : intersections(gv,e)) {
132 if (!segment.boundary())
135 auto index = segment.boundarySegmentIndex();
136 if (pred(segment.geometry().center()))
137 boundaryIds_[index] = id;
144 using HasBoundaryId =
decltype(std::declval<I>().boundaryId());
149 if (!Dune::Std::is_detected<HasBoundaryId, Segment>::value)
152 auto gv = grid_->leafGridView();
153 for (
auto const& e : elements(gv))
155 for (
auto const& segment : intersections(gv,e)) {
156 if (!segment.boundary())
159 if constexpr (Dune::Std::is_detected<HasBoundaryId, Segment>::value) {
160 auto index = segment.boundarySegmentIndex();
161 boundaryIds_[index] = segment.boundaryId();
168 void setBoundaryIds(std::vector<I>
const& ids)
170 test_exit(ids.size() == boundaryIds_.size(),
"Number of boundary IDs does not match!");
171 std::copy(ids.begin(), ids.end(), boundaryIds_.begin());
175 std::shared_ptr<Grid> grid_;
176 using Super::boundaryIds_;
Definition: BoundaryManager.hpp:15
BoundaryType boundaryId(Intersection const &intersection) const
Return the stored boundary id for the given intersection.
Definition: BoundaryManager.hpp:23
Manage boundary ids of boundary segments in a grid.
Definition: BoundaryManager.hpp:54
void setBoundaryId()
Set boundary ids as stored in the grid, e.g. read by grid reader.
Definition: BoundaryManager.hpp:147
BoundaryManager(std::shared_ptr< G > const &grid)
Definition: BoundaryManager.hpp:68
void setIndicator(Indicator const &indicator)
Set indicator(center) for all boundary intersections.
Definition: BoundaryManager.hpp:107
void setPredicate(Predicate const &pred, BoundaryType id)
Set id for all boundary intersections with pred(center) == true.
Definition: BoundaryManager.hpp:126
void setBoxBoundary(std::array< BoundaryType, 2 *dow > const &ids)
Set boundary ids [left,right, front,back, bottom,top] for cube domains.
Definition: BoundaryManager.hpp:81
constexpr bool Predicate
A predicate is a function that returns a boolean.
Definition: Concepts.hpp:141
constexpr bool Functor
A Functor is a function F with signature Signature.
Definition: Concepts.hpp:133