Dune-Fufem 2.11-git
Loading...
Searching...
No Matches
boundarypatchfactory.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set ts=4 sw=2 et 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_UTILITIES_BOUNDARYPATCH_FACTORY_HH
8#define DUNE_FUFEM_UTILITIES_BOUNDARYPATCH_FACTORY_HH
9
12
14
16template <class GridView>
18
19 using It = typename GridView::Intersection;
20
22
24 bool operator() (const It& it) const {
25
26 for (size_t i=0; i<criteria_.size(); i++)
27 if (!criteria_[i](it))
28 return false;
29
30 return true;
31 }
32
34 void add(std::function<bool(const It&)> insertion) {
35 criteria_.push_back(insertion);
36 }
37
38private:
39 std::vector<std::function<bool(const It&)> > criteria_;
40};
41
43template <class GridView>
45{
46public:
47
68
69 if (!config.hasKey("nCriterions"))
70 return false;
71
72 // setup patch from given criterions
73 int nCriterions = config.get<int>("nCriterions");
75
76 using It = typename GridView::Intersection;
77 Dune::FieldVector<typename GridView::ctype,GridView::dimension-1> zero(0);
78
79 // return whether any criterion was found
80 bool found(false);
81
82 // parse each insertion criterion
83 for (int i=0; i<nCriterions; i++) {
84
85 const auto& sub = config.sub("criterion" + std::to_string(i));
86
87 // so far each criterion has a component and a bound
88 int comp = sub.get<int>("component");
89 auto bound = sub.get<typename GridView::ctype>("bound");
90 auto type = sub.get<std::string>("type");
91
92 if (type=="LowerCentre")
93 faceInsertion.add([=] (const It& it) {return it.geometry().center()[comp]<=bound;});
94 else if (type=="UpperCentre")
95 faceInsertion.add([=] (const It& it) {return it.geometry().center()[comp]>=bound;});
96 else if (type=="LowerNormal")
97 faceInsertion.add([=] (const It& it)
98 {return (!it.neighbor() && (it.unitOuterNormal(zero)[comp]<=bound));});
99 else if (type=="UpperNormal")
100 faceInsertion.add([=] (const It& it)
101 {return (!it.neighbor() && (it.unitOuterNormal(zero)[comp]>=bound));});
102 else
103 DUNE_THROW(Dune::NotImplemented, "There is no insertion criterion "+type);
104
105 found = true;
106 }
107
108 // insert all faces into the boundary patch
109 patch.insertFacesByProperty(faceInsertion);
110 return found;
111 }
112};
113
114#endif
virtual void operator()()=0
#define DUNE_THROW(E,...)
std::string get(const std::string &key, const std::string &defaultValue) const
ParameterTree & sub(const std::string &sub)
bool hasKey(const std::string &key) const
Encapsulate a part of a grid boundary.
Definition boundarypatch.hh:218
void insertFacesByProperty(const InsertionProperty &property)
Insert boundary faces filtered by an insertion property.
Definition boundarypatch.hh:346
Extract faces where multiple criterions are met which are given by lambdas.
Definition boundarypatchfactory.hh:17
CombinedFaceInsertion()=default
void add(std::function< bool(const It &)> insertion)
Add insertion criterion.
Definition boundarypatchfactory.hh:34
typename GridView::Intersection It
Definition boundarypatchfactory.hh:19
Setup a boundary patch from criterions given in a parameter file.
Definition boundarypatchfactory.hh:45
static bool setupBoundaryPatch(const Dune::ParameterTree &config, BoundaryPatch< GridView > &patch)
Setup boundary patch using criterions prescribed in the parameter file.
Definition boundarypatchfactory.hh:67
T push_back(T... args)
T size(T... args)
T to_string(T... args)