13#ifndef BOUNDARY_NORMAL_COLLECTOR_HH
14#define BOUNDARY_NORMAL_COLLECTOR_HH
22 namespace BoundaryNormalCollectorDetail
25 template <
class Gr
idView,
class NormalCollection>
28 std::for_each(gridView.template begin<0>(), gridView.template end<0>(), [&](
typename GridView::template Codim<0>::Iterator::Entity
const& entity)
30 Dune::GeometryType const gt(entity.type().id(), GridView::dimension);
31 std::for_each(gridView.ibegin(entity), gridView.iend(entity), [&](typename GridView::IntersectionIterator::Intersection const& face)
33 if(face.boundary()) for(int vertexId=0; vertexId<face.geometry().corners(); ++vertexId) collection[gridView.indexSet().subIndex(entity, Dune::GenericReferenceElements<typename GridView::ctype,GridView::dimension>::general(gt).subEntity(face.indexInInside(),1,vertexId,GridView::dimension), GridView::dimension)].onBoundary = true;
38 template <
class Gr
idView,
class NormalCollection>
41 std::for_each(gridView.template begin<0>(), gridView.template end<0>(), [&](
typename GridView::template Codim<0>::Iterator::Entity
const& entity)
43 Dune::GeometryType const gt(entity.type().id(), GridView::dimension);
44 std::for_each(gridView.ibegin(entity), gridView.iend(entity), [&](typename GridView::IntersectionIterator::Intersection const& face)
46 if(face.boundary()) for(int edgeId = 0; edgeId < 3; ++edgeId)
47 collection[gridView.indexSet().subIndex(entity, Dune::GenericReferenceElements<typename GridView::ctype,GridView::dimension>::general(gt).subEntity(face.indexInInside(),1,edgeId,GridView::dimension-1), GridView::dimension-1)].onBoundary = true;
53 template <
class Gr
idView,
class NormalContainer>
54 inline void outerBoundaryCheckImpl(GridView
const& gridView, NormalContainer& container, std::integral_constant<int,2>)
60 template <
class Gr
idView,
class NormalContainer>
61 inline void outerBoundaryCheckImpl(GridView
const& gridView, NormalContainer& container, std::integral_constant<int,3>)
68 template <
class Gr
idView,
class NormalContainer>
75 template <
class Gr
idView,
class Entity,
class Face,
class NormalCollection,
class Scalar,
class MergedPolicy>
76 void getEntitiesVertexNormals(GridView
const& gridView, Entity
const& entity,
Face const& face, NormalCollection &collection, Scalar tissue, Dune::GeometryType
const& gt, MergedPolicy
const& policy)
78 const int dim = GridView::dimension;
79 tissue = round(tissue);
80 int local_fidx = face.indexInInside();
81 for(
int i=0; i<face.geometry().corners(); ++i){
83 int local_vidx = Dune::GenericReferenceElements<Scalar,dim>::general(gt).subEntity(local_fidx,1,i,dim);
85 int vidx = gridView.indexSet().subIndex(entity, local_vidx, dim);
87 Scalar tissueNeighbour = -1;
90 if( face.boundary() ){
91 if( policy.ignoreOuterBoundary(face) ){
92 collection[vidx].isRelevant =
false;
99 if(collection[vidx].onBoundary)
continue;
102 tissueNeighbour = round( policy.phaseId(*face.outside()) );
104 if( policy.ignoreInnerBoundary(tissue, tissueNeighbour) ){
105 collection[vidx].isRelevant =
false;
113 if(tissue < tissueNeighbour-1.e-9){
114 collection[vidx].normals.push_back(face.centerUnitOuterNormal());
115 collection[vidx].weights.push_back(1.0/face.geometry().volume());
116 collection[vidx].phaseIds.push_back(tissue);
117 collection[vidx].ids.push_back(gridView.indexSet().index(entity));
120 if(tissue > tissueNeighbour+1.e-9){
121 collection[vidx].normals.push_back(-1.*face.centerUnitOuterNormal());
122 collection[vidx].weights.push_back(1.0/face.geometry().volume());
123 collection[vidx].phaseIds.push_back(tissue);
124 collection[vidx].ids.push_back(gridView.indexSet().index(entity));
130 template <
class Gr
idView,
class Entity,
class Face,
class NormalCollection,
class Scalar,
class MergedPolicy>
131 static void getEntitiesEdgeNormals(GridView
const& gridView, Entity
const& entity,
Face const& face, NormalCollection& collection,
132 Scalar tissue, Dune::GeometryType
const& gt, MergedPolicy
const& policy)
134 constexpr int dim = GridView::dimension;
135 tissue = round(tissue);
138 int local_fidx = face.indexInInside();
140 for(
int i=0; i<3; ++i){
142 int local_eidx = Dune::GenericReferenceElements<Scalar,dim>::general(gt).subEntity(local_fidx,1,i,dim-1);
144 int eidx = gridView.indexSet().subIndex(entity, local_eidx, dim-1);
146 Scalar tissueNeighbour = -1;
148 if(!face.boundary()){
149 tissueNeighbour = round(policy.phaseId(*face.outside()));
150 if(policy.ignoreInnerBoundary(tissue, tissueNeighbour)){
151 collection[eidx].isRelevant =
false;
156 tissueNeighbour = tissue + 1;
161 if(tissue < tissueNeighbour-1.e-9){
162 collection[eidx].normals.push_back(face.centerUnitOuterNormal());
163 collection[eidx].weights.push_back(1.0);
164 collection[eidx].isRelevant = (!policy.ignoreOuterBoundary(face)) && collection[eidx].isRelevant;
165 collection[eidx].phaseIds.push_back(tissue);
166 collection[eidx].ids.push_back(gridView.indexSet().index(entity));
169 if(tissue > tissueNeighbour+1.e-9){
170 collection[eidx].normals.push_back(-1.*face.centerUnitOuterNormal());
171 collection[eidx].weights.push_back(1.0);
172 collection[eidx].phaseIds.push_back(tissue);
173 collection[eidx].ids.push_back(gridView.indexSet().index(entity));
179 template <
class Gr
idView,
class Entity,
class Face,
class NormalContainer,
class Scalar,
class Policy>
180 inline void collectEntityNormals(GridView
const& gridView, Entity
const& entity,
Face const& face, NormalContainer& container, Scalar tissue,
181 Dune::GeometryType
const gt, Policy
const& policy, std::integral_constant<int,2>)
187 template <
class Gr
idView,
class Entity,
class Face,
class NormalContainer,
class Scalar,
class Policy>
188 inline void collectEntityNormals(GridView
const& gridView, Entity
const& entity,
Face const& face, NormalContainer& container, Scalar tissue,
189 Dune::GeometryType
const gt, Policy
const& policy, std::integral_constant<int,3>)
192 getEntitiesEdgeNormals(gridView, entity, face, container.edgeNormals, tissue, gt, policy);
197 template <
class Gr
idView,
class NormalContainer,
class MergedPolicy>
198 void getEntityNormals(GridView
const& gridView, NormalContainer &container, MergedPolicy
const& policy)
200 typedef typename GridView::template Codim<0>::Iterator CellIterator;
201 typedef typename CellIterator::Entity Entity;
202 typedef typename GridView::IntersectionIterator FaceIterator;
203 typedef typename FaceIterator::Intersection
Face;
204 typedef typename NormalContainer::EntryType::Scalar Scalar;
206 std::for_each(gridView.template begin<0>(), gridView.template end<0>(),[&](Entity
const& entity)
208 Scalar tissue = policy.phaseId(entity);
209 Dune::GeometryType const gt(entity.type().id(), GridView::dimension);
211 FaceIterator fi = gridView.ibegin(entity),
212 fend = gridView.iend(entity);
213 for(;fi!=fend;++fi) collectEntityNormals(gridView, entity, *fi, container, tissue, gt, policy, std::integral_constant<int,GridView::dimension>());
222 template <
class NormalContainer>
225 for(
auto& collection : container.vertexNormals) InterpolationTools::computeMeanNormal<true>(collection);
228 template <
class NormalContainer>
231 for(
auto& collection : container.vertexNormals) InterpolationTools::computeMeanNormal<true>(collection);
232 for(
auto& collection : container.edgeNormals) InterpolationTools::computeMeanNormal<false>(collection);
235 template <
class NormalContainer>
250 template<
class GridView,
class OuterBoundaryPolicy = Policy::ConsiderOuterBoundary,
class InnerBoundaryPolicy = Policy::IgnoreInnerBoundary,
251 class Phase =
typename GridView::ctype,
template <
class>
class PhasePolicy = Policy::NoPhaseInfo>
255 static int const dim = GridView::dimension;
261 InnerBoundaryPolicy
const& innerBoundaryPolicy = InnerBoundaryPolicy())
262 : gridView(gridView_), mergedPolicy(outerBoundaryPolicy,innerBoundaryPolicy, Policy::NoPhaseInfo<
Scalar>())
269 BoundaryNormalCollector(GridView
const& gridView_, Phase
const& phase, OuterBoundaryPolicy
const& outerBoundaryPolicy = OuterBoundaryPolicy(),
270 InnerBoundaryPolicy
const& innerBoundaryPolicy = InnerBoundaryPolicy())
271 : gridView(gridView_), mergedPolicy(outerBoundaryPolicy,innerBoundaryPolicy,PhasePolicy<Phase>(phase))
Collects face normals associated to corners (2D,3D) and edges(3D only).
~BoundaryNormalCollector()=default
NormalContainer meanNormals() const
Get average of normals incident to each vertex.
BoundaryNormalCollector()=delete
BoundaryNormalCollector(GridView const &gridView_, Phase const &phase, OuterBoundaryPolicy const &outerBoundaryPolicy=OuterBoundaryPolicy(), InnerBoundaryPolicy const &innerBoundaryPolicy=InnerBoundaryPolicy())
Constructor for the case that phase ids are provided.
NormalContainer normals() const
Get normals of all faces incident to each vertex.
InterpolationTools::NormalContainer< Scalar, dim > NormalContainer
BoundaryNormalCollector(BoundaryNormalCollector const &)=delete
BoundaryNormalCollector(GridView const &gridView_, OuterBoundaryPolicy const &outerBoundaryPolicy=OuterBoundaryPolicy(), InnerBoundaryPolicy const &innerBoundaryPolicy=InnerBoundaryPolicy())
Constructor for the case that no phase ids are provided.
BoundaryNormalCollector & operator=(BoundaryNormalCollector const &)=delete
typename GridView::Intersection Face
The type of faces in the grid view.
void computeMeanNormals(NormalContainer &container)
void outerBoundaryCheckImpl(GridView const &gridView, NormalContainer &container, std::integral_constant< int, 3 >)
void checkForBoundaryVertices(GridView const &gridView, NormalCollection &collection)
void collectEntityNormals(GridView const &gridView, Entity const &entity, Face const &face, NormalContainer &container, Scalar tissue, Dune::GeometryType const gt, Policy const &policy, std::integral_constant< int, 3 >)
void getEntitiesVertexNormals(GridView const &gridView, Entity const &entity, Face const &face, NormalCollection &collection, Scalar tissue, Dune::GeometryType const >, MergedPolicy const &policy)
void outerBoundaryCheck(GridView const &gridView, NormalContainer &container)
void getEntityNormals(GridView const &gridView, NormalContainer &container, MergedPolicy const &policy)
void checkForBoundaryEdges(GridView const &gridView, NormalCollection &collection)
void computeMeanNormalsImpl(NormalContainer &container, std::integral_constant< int, 3 >)