ug4
domain_util_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Author: Andreas Vogel
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__LIB_DISC__DOMAIN_UTIL_GENERAL_IMPL__
34 #define __H__UG__LIB_DISC__DOMAIN_UTIL_GENERAL_IMPL__
35 
36 #include "domain_util.h"
37 
38 #include <string>
39 #include <sstream>
40 
42 
43 namespace ug{
44 
47 // CollectCornerCoordinates
50 
51 // returns the corner coordinates of a geometric object
52 template <typename TElem, typename TAAPos>
53 void CollectCornerCoordinates( std::vector<typename TAAPos::ValueType>& vCornerCoordsOut,
54  TElem* elem, const TAAPos& aaPos, bool clearContainer)
55 {
56  if(clearContainer)
57  vCornerCoordsOut.clear();
58 
59  // number of vertices of element
60  const size_t numVertices = NumVertices(elem);
61 
62  // loop vertices
63  for(size_t i = 0; i < numVertices; ++i)
64  {
65  // get element
66  Vertex* vert = GetVertex(elem, i);
67 
68  // write corner coordinates
69  vCornerCoordsOut.push_back(aaPos[vert]);
70  }
71 }
72 
73 // returns the corner coordinates of a geometric object
74 template <typename TElem, typename TAAPos>
75 void CollectCornerCoordinates( std::vector<typename TAAPos::ValueType>& vCornerCoordsOut,
76  const TElem& elem, const TAAPos& aaPos, bool clearContainer)
77 {
78 // cast constness away
79  TElem* pElem = const_cast<TElem*>(&elem);
80 
81 // forward
82  return CollectCornerCoordinates(vCornerCoordsOut, pElem, aaPos, clearContainer);
83 }
84 
86 template <typename TElem, typename TDomain>
87 void CollectCornerCoordinates( std::vector<typename TDomain::position_type>& vCornerCoordsOut,
88  const TElem& elem, const TDomain& domain, bool clearContainer)
89 {
90  // get position accessor
91  const typename TDomain::position_accessor_type& aaPos = domain.position_accessor();
92 
93  CollectCornerCoordinates(vCornerCoordsOut, elem, aaPos, clearContainer);
94 }
95 
97 template <typename TDomain>
98 void CollectCornerCoordinates(int base_object_id,
99  std::vector<typename TDomain::position_type>& vCornerCoordsOut,
100  GridObject& elem, const TDomain& domain, bool clearContainer)
101 {
102  switch(base_object_id)
103  {
104  case VERTEX: CollectCornerCoordinates<Vertex, TDomain>(vCornerCoordsOut, *dynamic_cast< Vertex*>(&elem), domain, clearContainer); return;
105  case EDGE: CollectCornerCoordinates<Edge, TDomain>(vCornerCoordsOut, *dynamic_cast< Edge*>(&elem), domain, clearContainer); return;
106  case FACE: CollectCornerCoordinates<Face, TDomain>(vCornerCoordsOut, *dynamic_cast< Face*>(&elem), domain, clearContainer); return;
107  case VOLUME: CollectCornerCoordinates<Volume, TDomain>(vCornerCoordsOut, *dynamic_cast< Volume*>(&elem), domain, clearContainer); return;
108  default: UG_THROW("CollectCornerCoordinates, base_object_id " << base_object_id << "unknown.");
109  }
110 }
111 
113 template <typename TElem, typename TDomain>
114 void FillCornerCoordinates( typename TDomain::position_type vCornerCoordsOut[],
115  const TElem& elem, const TDomain& domain)
116 {
117  // get position accessor
118  const typename TDomain::position_accessor_type& aaPos = domain.position_accessor();
119 
120  const Vertex* const* vVertex = const_cast<TElem*>(&elem)->vertices();
121 
122  // write corner coordinates
123  for(size_t i = 0; i < TElem::NUM_VERTICES; ++i)
124  vCornerCoordsOut[i] = aaPos[vVertex[i]];
125 }
126 
127 
129 template <typename TDomain>
130 void FillCornerCoordinates( typename TDomain::position_type vCornerCoordsOut[],
131  const RegularVertex& vtx, const TDomain& domain)
132 {
133  // get position accessor
134  const typename TDomain::position_accessor_type& aaPos = domain.position_accessor();
135 
136  // write vertex coordinates
137  vCornerCoordsOut[0] = aaPos[&vtx];
138 }
139 
142 template <typename TElem, typename TPosition>
144 {
145  // corner coords
146  std::vector<TPosition> vCornerCoords;
147 
148  // load corner coords
149  CollectCornerCoordinates(vCornerCoords, elem, aaPos);
150 
151  // get reference element type
153 
154  // dimension of Positions
155  static const int dim = TPosition::Size;
156 
157  // return Element Size
158  return ElementSize<TRefElem, dim>(&vCornerCoords[0]);
159 }
160 
162 template <typename TElem, typename TDomain>
163 number ElementSize(const TElem& elem, const TDomain& domain)
164 {
165  // get position accessor
166  const typename TDomain::position_accessor_type& aaPos = domain.position_accessor();
167 
168  return ElementSize(elem, aaPos);
169 }
170 
172 // ElementDiameter
174 
175 template <typename TElem, typename TDomain>
176 number ElementDiameterSq(TElem& elem, TDomain& domain)
177 {
178  return ElementDiameterSq(*domain.grid(), domain.position_accessor(), &elem);
179 }
180 
181 template <typename TElem, typename TDomain>
182 number ElementDiameter(TElem& elem, TDomain& domain)
183 {
184  return ElementDiameter(*domain.grid(), domain.position_accessor(), &elem);
185 }
186 
187 } // end namespace ug
188 
189 #endif /* __H__UG__LIB_DISC__DOMAIN_UTIL_GENERAL_IMPL__ */
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
A basic vertex-type.
Definition: grid_objects_0d.h:62
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
number ElementDiameter(const TElem &elem, TDomain &domain)
returns the maximal distance between to element vertices
number ElementDiameterSq(const TElem &elem, TDomain &domain)
returns the maximal squared distance between to element vertices
void CollectCornerCoordinates(std::vector< typename TAAPos::ValueType > &vCornerCoordsOut, const TElem &elem, const TAAPos &aaPos, bool clearContainer=true)
returns the corner coordinates of a geometric object
Definition: domain_util_impl.h:75
Vertex * GetVertex(Vertex *v, size_t i)
returns the i'th vertex of a vertex
Definition: grid_util_impl.hpp:99
size_t NumVertices(Vertex *elem)
Returns the number of vertices of the given geometric object.
Definition: grid_util_impl.hpp:123
static const int dim
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
std::pair< counting_iterator< size_t >, counting_iterator< size_t > > vertices(ug::BidirectionalMatrix< T > const &M)
Definition: bidirectional_boost.h:60
const int NUM_VERTICES
Definition: hexahedron_rules.h:45
the ug namespace
void FillCornerCoordinates(typename TDomain::position_type vCornerCoordsOut[], const TElem &elem, const TDomain &domain)
returns the corner coordinates of a geometric object
Definition: domain_util_impl.h:114
@ VOLUME
Definition: grid_base_objects.h:63
@ VERTEX
Definition: grid_base_objects.h:60
@ EDGE
Definition: grid_base_objects.h:61
@ FACE
Definition: grid_base_objects.h:62
number ElementSize(const MathVector< TWorldDim > *vCornerCoords)
Volume of an Element in a given Dimension.
traits for reference elements
Definition: reference_element_traits.h:48