Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
grid_statistics.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3 * Authors: Martin Stepniewski, 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__GRID_STATISTICS__
34#define __H__UG__GRID_STATISTICS__
35
36#include <algorithm>
37#include <limits>
38#include <vector>
39#include "lib_grid/lg_base.h"
40
41#ifdef UG_PARALLEL
44#endif
45
46namespace ug
47{
48
49//**********************************************************************
50// declarations
51//**********************************************************************
52
54// AssignTetrahedronAttributesByAspectRatio - mstepnie
57 SubsetHandler& shVolume,
58 AInt& aTetrahedronAspectRatioClass,
59 std::vector<double>& offsets,
60 Grid::VertexAttachmentAccessor<APosition>& aaPos);
61
64
71template <class TIterator>
73 TIterator elemsBegin, TIterator elemsEnd,
74 std::vector<number> intervals)
75{
76 if(intervals.empty()){
77 sh.assign_subset(elemsBegin, elemsEnd, 0);
78 return true;
79 }
80
81// access position
83
84// iterate over all elements
85 for(TIterator iter = elemsBegin; iter != elemsEnd; ++iter)
86 {
87 typename TIterator::value_type elem = *iter;
88 number quality = FaceQuality(elem, aaPos);
89
90 size_t newInd = -1;
91 for(size_t i = 0; i < intervals.size(); ++i){
92 if(intervals[i] < quality)
93 newInd = i;
94 else
95 break;
96 }
97
98 sh.assign_subset(elem, newInd);
99 }
100 return true;
101}
102
103
104template <class TIterator, class TAAPos>
105void PrintElementEdgeRatios(Grid& grid, TIterator elemsBegin, TIterator elemsEnd,
106 TAAPos aaPos)
107{
108 using namespace std;
110 UG_COND_THROW(elem_t::BASE_OBJECT_ID == VERTEX || elem_t::BASE_OBJECT_ID == EDGE,
111 "Can't evaluate anisotropy statistics for vertices or edges.");
112
114
115 number minRatio = 1;
116 number maxRatio = 0;
117 number avRatio = 0;
118 vector<number> ratios;
119 for(TIterator i_elem = elemsBegin; i_elem != elemsEnd; ++i_elem){
120 elem_t* elem = *i_elem;
121
122 #ifdef UG_PARALLEL
123 if(grid.distributed_grid_manager()->is_ghost(elem))
124 continue;
125 #endif
126
127 grid.associated_elements(edges, elem);
128 number shortest = numeric_limits<double>::max();
129 number longest = 0;
130 for_each_in_vec(Edge* e, edges){
131 number l = EdgeLength(e, aaPos);
132 shortest = min(shortest, l);
133 longest = max(longest, l);
134 }end_for;
135
136 number ratio = 0;
137 if(longest > 0)
138 ratio = shortest / longest;
139
140 minRatio = min(minRatio, ratio);
141 maxRatio = max(maxRatio, ratio);
142 avRatio += ratio;
143 ratios.push_back(ratio);
144 }
145
146 int num = (int)ratios.size();
147 #ifdef UG_PARALLEL
149 minRatio = com.allreduce(minRatio, PCL_RO_MIN);
150 maxRatio = com.allreduce(maxRatio, PCL_RO_MAX);
151 num = com.allreduce(num, PCL_RO_SUM);
152 avRatio = com.allreduce(avRatio, PCL_RO_SUM);
153 #endif
154
155 if(num == 0){
156 UG_LOG("---\n");
157 }
158 else{
159 avRatio /= (number)num;
160 UG_LOG("min: " << minRatio << ", max: " << maxRatio << ", av: " << avRatio);
161
162 if(num > 1){
163 number sdSum = 0;
164 for(size_t i = 0; i < ratios.size(); ++i)
165 sdSum += sq(avRatio - ratios[i]);
166
167 #ifdef UG_PARALLEL
168 sdSum = com.allreduce(sdSum, PCL_RO_SUM);
169 #endif
170
171 number sd = sqrt(sdSum / ((number)num - 1));
172 UG_LOG(", sd: " << sd);
173 }
174 UG_LOG(endl);
175 }
176}
177
178}// end of namespace
179
180#endif
Definition pcl_process_communicator.h:70
void allreduce(const void *sendBuf, void *recBuf, int count, DataType type, ReduceOperation op) const
performs MPI_Allreduce on the processes of the communicator.
Definition pcl_process_communicator.cpp:318
bool is_ghost(TElem *elem) const
returns true if the element is a ghost
Definition distributed_grid_impl.hpp:67
Base-class for edges.
Definition grid_base_objects.h:397
Manages the elements of a grid and their interconnection.
Definition grid.h:132
DistributedGridManager * distributed_grid_manager()
returns a pointer to the associated distributed grid manager.
Definition grid_impl.hpp:53
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
Partitions elements of a grid into several subsets.
Definition subset_handler_grid.h:53
void assign_subset(Vertex *elem, int subsetIndex)
assigns a vertex to a subset.
Definition subset_handler_grid.cpp:204
static void PrintElementEdgeRatios(TDomain &dom)
Definition domain_bridge.cpp:365
UG_API number EdgeLength(const EdgeVertices *e, TAAPosVRT &aaPos)
Calculates the length of the given edge.
Definition edge_util_impl.hpp:80
number FaceQuality(FaceVertices *f, Grid::VertexAttachmentAccessor< APosition > aaPos)
a simple measure for the quality of a face
Definition face_util.cpp:203
#define PCL_RO_SUM
Definition pcl_methods.h:63
#define PCL_RO_MAX
Definition pcl_methods.h:61
#define PCL_RO_MIN
Definition pcl_methods.h:62
#define UG_LOG(msg)
Definition log.h:367
#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
Definition smart_pointer.h:814
the ug namespace
GridSubsetHandler SubsetHandler
Definition subset_handler_grid.h:376
Attachment< int > AInt
Definition common_attachments.h:55
bool AssignTetrahedronAttributesByAspectRatio(Grid &grid, SubsetHandler &shVolume, AInt &aTetrahedronAspectRatioClass, vector< double > &offsets, Grid::VertexAttachmentAccessor< APosition > &aaPos)
assigns attributes to tetrahedral elements of a grid respecting their aspect ratio
Definition grid_statistics.cpp:54
@ VERTEX
Definition grid_base_objects.h:60
@ EDGE
Definition grid_base_objects.h:61
APosition aPosition("position", true)
The standard 3d position type.
Definition common_attachments.h:84
bool AssignSubsetsByQuality(Grid &grid, SubsetHandler &sh, TIterator elemsBegin, TIterator elemsEnd, std::vector< number > intervals)
assigns a subset based on the quality of the given element.
Definition grid_statistics.h:72
PointerConstArray< Edge * > secure_container
Definition grid.h:146
void base_type
Definition grid_base_objects.h:1011
#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