ug4
refinement_mark_util_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG_refinement_mark_util_impl
34 #define __H__UG_refinement_mark_util_impl
35 
36 #include <algorithm>
37 #include <limits>
38 #include "refinement_mark_util.h"
39 #include "lib_grid/lg_base.h"
41 
42 namespace ug{
43 
44 template <class TRef, class TIter, class TAAPos>
46  Grid& grid,
47  TRef& ref,
48  number minEdgeRatio,
49  TIter elemsBegin,
50  TIter elemsEnd,
51  TAAPos aaPos)
52 {
53  using namespace std;
54  typedef typename TIter::value_type elem_ptr_t;
55 
56  number minEdgeRatioSq = sq(minEdgeRatio);
58 
59  for(TIter iter = elemsBegin; iter != elemsEnd; ++iter){
60  elem_ptr_t elem = *iter;
61  ref.mark(elem, RM_CLOSURE);
62 
63  grid.associated_elements(assEdges, elem);
64 
65  if(assEdges.size() < 2)
66  continue;
67 
68  // find the length of the shortest and the longest edge
69  number shortestLenSq = numeric_limits<number>::max();
70  number longestLenSq = 0;
71 
72  for_each_in_vec(Edge* e, assEdges){
73  number lenSq = EdgeLengthSq(e, aaPos);
74  shortestLenSq = min(shortestLenSq, lenSq);
75  longestLenSq = max(longestLenSq, lenSq);
76  }end_for;
77 
78  if(longestLenSq < SMALL_SQ)
79  continue;
80 
81  if(shortestLenSq / longestLenSq >= minEdgeRatioSq)
82  continue;
83 
84  // the element is anisotropic mark it and all long edges
85  ref.mark(elem, RM_ANISOTROPIC);
86  // refine all edges that are at least half as long as the longest one
87  number thresholdLenSq = shortestLenSq / minEdgeRatioSq;
88  for_each_in_vec(Edge* e, assEdges){
89  if(EdgeLengthSq(e, aaPos) > thresholdLenSq){
90  ref.mark(e, RM_REFINE);
91  }
92  }end_for;
93  }
94 }
95 
96 template <class TRef, class TEdgeIter, class TAAPos>
98  TRef& ref,
99  TAAPos aaPos,
100  TEdgeIter edgesBegin,
101  TEdgeIter edgesEnd,
102  const typename TAAPos::ValueType& dir,
103  number minDeviationAngle,
104  number maxDeviationAngle,
105  bool selectFlipped)
106 {
107  UG_COND_THROW(!ref.grid(), "The given refiner has to operate on a grid");
108 
109  typedef typename TAAPos::ValueType vector_t;
110 
111  Grid& g = *ref.grid();
112 
113  vector_t n;
114  VecNormalize(n, dir);
115 
116  number maxDot = cos(deg_to_rad(minDeviationAngle));
117  number minDot = cos(deg_to_rad(maxDeviationAngle));
118 
121 
122  for(TEdgeIter eIter = edgesBegin; eIter != edgesEnd; ++eIter){
123  Edge* e = *eIter;
124  vector_t dir;
125  VecSubtract(dir, aaPos[e->vertex(1)], aaPos[e->vertex(0)]);
126  VecNormalize(dir, dir);
127  number d = VecDot(dir, n);
128  if((d >= minDot - SMALL && d <= maxDot + SMALL) ||
129  (selectFlipped && (-d >= minDot - SMALL && -d <= maxDot + SMALL)))
130  {
131  ref.mark(e);
132 
133  g.associated_elements(faces, e);
134  for(size_t i = 0; i < faces.size(); ++i)
135  ref.mark(faces[i], RM_CLOSURE);
136 
137  g.associated_elements(vols, e);
138  for(size_t i = 0; i < vols.size(); ++i)
139  ref.mark(vols[i], RM_CLOSURE);
140 
141  }
142  }
143 }
144 
145 }// end of namespace
146 
147 #endif //__H__UG_refinement_mark_util_impl
Base-class for edges.
Definition: grid_base_objects.h:397
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
void associated_elements(traits< Vertex >::secure_container &elemsOut, TElem *e)
Puts all elements of type TAss which are contained in 'e' or which contain 'e' into elemsOut.
Definition: grid_impl.hpp:466
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
UG_API number EdgeLengthSq(const EdgeVertices *e, TAAPosVRT &aaPos)
Calculates the squared length of the given edge.
Definition: edge_util_impl.hpp:73
@ RM_REFINE
DEPRECATED. Use RM_FULL instead.
Definition: refiner_interface.h:55
@ RM_CLOSURE
Refines elements according to associated marked edges.
Definition: refiner_interface.h:50
@ RM_ANISOTROPIC
DEPRECATED. Use RM_CLOSURE instead.
Definition: refiner_interface.h:52
#define UG_COND_THROW(cond, msg)
UG_COND_THROW(cond, msg) : performs a UG_THROW(msg) if cond == true.
Definition: error.h:61
double number
Definition: types.h:124
TNumber sq(TNumber val)
returns the square of a value (val*val)
Definition: math_util_impl.hpp:91
TNumber deg_to_rad(TNumber deg)
Definition: math_util_impl.hpp:49
void VecNormalize(vector_t &vOut, const vector_t &v)
scales a vector_t to unit length
Definition: math_vector_functions_common_impl.hpp:501
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
returns the dot-product of two vector_ts
Definition: math_vector_functions_common_impl.hpp:385
Definition: smart_pointer.h:814
the ug namespace
const number SMALL
Definition: math_constants.h:41
void MarkForRefinementByDirection(TRef &ref, TAAPos aaPos, TEdgeIter edgesBegin, TEdgeIter edgesEnd, const typename TAAPos::ValueType &dir, number minDeviationAngle, number maxDeviationAngle, bool selectFlipped)
Definition: refinement_mark_util_impl.h:97
const number SMALL_SQ
Definition: math_constants.h:42
void MarkForAnisotropicRefinement(Grid &grid, TRef &ref, number minEdgeRatio, TIter elemsBegin, TIter elemsEnd, TAAPos aaPos)
Definition: refinement_mark_util_impl.h:45
T value_type
Definition: sparsematrix_interface.h:2
#define for_each_in_vec(_vfeDecl, _vfeVec)
Allows iteration over all members of an std::vector compatible type.
Definition: vec_for_each.h:52
#define end_for
Allows iteration over all members of an std::vector compatible type.
Definition: vec_for_each.h:56