Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
attachment_util.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009-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__LIB_GRID__ATTACHMENT_UTIL__
34#define __H__LIB_GRID__ATTACHMENT_UTIL__
35
36#include <vector>
37#include "lib_grid/grid/grid.h"
38
39namespace ug
40{
41
51
54template <class TAttachment>
56{
57 public:
58 typedef typename TAttachment::ValueType ValueType;
61
63 MultiElementAttachmentAccessor(Grid& g, TAttachment& a, bool vrts = true,
64 bool edges = true, bool faces = true, bool vols = true)
65 {
66 access(g, a, vrts, edges, faces, vols);
67 }
68
69 bool access(Grid& g, TAttachment& a, bool vrts = true, bool edges = true,
70 bool faces = true, bool vols = true)
71 {
74
75 bool ok = true;
76 if(vrts)
77 ok &= m_aaVrt.access(g, a);
78 if(edges)
79 ok &= m_aaEdge.access(g, a);
80 if(faces)
81 ok &= m_aaFace.access(g, a);
82 if(vols)
83 ok &= m_aaVol.access(g, a);
84 return ok;
85 }
86
94
95 bool is_valid_vertex_accessor() const {return m_aaVrt.valid();}
96 bool is_valid_edge_accessor() const {return m_aaEdge.valid();}
97 bool is_valid_face_accessor() const {return m_aaFace.valid();}
98 bool is_valid_volume_accessor() const {return m_aaVol.valid();}
99
105 {
106 switch(e->base_object_id()){
107 case VERTEX: return m_aaVrt[static_cast<Vertex*>(e)];
108 case EDGE: return m_aaEdge[static_cast<Edge*>(e)];
109 case FACE: return m_aaFace[static_cast<Face*>(e)];
110 case VOLUME: return m_aaVol[static_cast<Volume*>(e)];
111 default: UG_THROW("Unknown element type!");
112 }
113 }
114
115 ConstRefType operator[](Vertex* e) const {return m_aaVrt[e];}
116 ConstRefType operator[](Edge* e) const {return m_aaEdge[e];}
117 ConstRefType operator[](Face* e) const {return m_aaFace[e];}
118 ConstRefType operator[](Volume* e) const {return m_aaVol[e];}
120 {
121 switch(e->base_object_id()){
122 case VERTEX: return m_aaVrt[static_cast<Vertex*>(e)];
123 case EDGE: return m_aaEdge[static_cast<Edge*>(e)];
124 case FACE: return m_aaFace[static_cast<Face*>(e)];
125 case VOLUME: return m_aaVol[static_cast<Volume*>(e)];
126 default: UG_THROW("Unknown element type!");
127 }
128 }
129
134
135 private:
140};
141
142
145
148template <class TElem, class TAttachment>
150{
151 public:
152 CompareByAttachment(Grid& g, TAttachment& aGID)
153 {
154 UG_ASSERT(g.has_attachment<TElem>(aGID),
155 "Can't compare unattached attachments!");
156 m_aaGID.access(g, aGID);
157 }
158
159 bool operator()(TElem* e1, TElem* e2)
160 {
161 return m_aaGID[e1] < m_aaGID[e2];
162 }
163
164 private:
166};
167
169// SetAttachmentValues
171template <class TAttachmentAccessor, class TIter, class TVal>
172void SetAttachmentValues(TAttachmentAccessor& aaVal,
173 TIter elemsBegin, TIter elemsEnd,
174 const TVal& val);
175
177// ConvertMathVectorAttachmentValues
179
193template<class TElem, class TSrcAttachment, class TDestAttachment>
195 TSrcAttachment& srcAttachment,
196 TDestAttachment& destAttachment);
197
198
201
210template <class TElem, class TAttachment>
211bool CopyAttachments(Grid& srcGrid, TAttachment& aSrc,
212 Grid& destGrid, TAttachment& aDest);
213
216
220template <class TElemIter, class TAttachment>
221bool CopyAttachments(Grid& grid, TElemIter elemsBegin, TElemIter elemsEnd,
222 TAttachment& aSrc, TAttachment& aDest);
223
226
230template <class TIterator, class TAAInt>
231void AssignIndices(TIterator begin, TIterator end,
232 TAAInt& aaInt, int baseIndex = 0);
233
236
241template <class TIterator, class TAttAcc>
242TIterator FindElementByValue(TIterator begin, TIterator end,
243 const typename TAttAcc::ValueType& val,
244 TAttAcc& aa);
245
// end of doxygen defgroup command
247}// end of namespace
248
250// include implementations of template methods.
252
253#endif
void invalidate()
Definition attachment_pipe.h:556
bool valid() const
Definition attachment_pipe.h:553
Instances can be used as compare operators, e.g., for std::sort.
Definition attachment_util.h:150
CompareByAttachment(Grid &g, TAttachment &aGID)
Definition attachment_util.h:152
Grid::AttachmentAccessor< TElem, TAttachment > m_aaGID
Definition attachment_util.h:165
bool operator()(TElem *e1, TElem *e2)
Definition attachment_util.h:159
Base-class for edges.
Definition grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition grid_base_objects.h:510
the generic attachment-accessor for access to grids attachment pipes.
Definition grid.h:182
bool access(Grid &grid, TAttachment &a)
Definition grid.h:189
Manages the elements of a grid and their interconnection.
Definition grid.h:132
bool has_attachment(IAttachment &attachment)
Definition grid.h:796
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition grid_base_objects.h:157
virtual int base_object_id() const =0
Accesses attachements in different element types at the same time.
Definition attachment_util.h:56
bool is_valid_face_accessor() const
Definition attachment_util.h:97
ConstRefType operator[](Vertex *e) const
Definition attachment_util.h:115
bool access(Grid &g, TAttachment &a, bool vrts=true, bool edges=true, bool faces=true, bool vols=true)
Definition attachment_util.h:69
RefType operator[](Volume *e)
Definition attachment_util.h:103
Grid::AttachmentAccessor< Face, TAttachment > m_aaFace
Definition attachment_util.h:138
Grid::AttachmentAccessor< Volume, TAttachment > m_aaVol
Definition attachment_util.h:139
RefType operator[](Edge *e)
Definition attachment_util.h:101
ConstRefType operator[](GridObject *e) const
Definition attachment_util.h:119
Grid::AttachmentAccessor< Vertex, TAttachment > & vertex_accessor()
Definition attachment_util.h:130
Grid::AttachmentAccessor< Face, TAttachment > & face_accessor()
Definition attachment_util.h:132
Grid::AttachmentAccessor< Edge, TAttachment > & edge_accessor()
Definition attachment_util.h:131
attachment_value_traits< ValueType >::const_reference ConstRefType
Definition attachment_util.h:60
void invalidate()
Definition attachment_util.h:87
ConstRefType operator[](Volume *e) const
Definition attachment_util.h:118
RefType operator[](Face *e)
Definition attachment_util.h:102
bool is_valid_vertex_accessor() const
Definition attachment_util.h:95
ConstRefType operator[](Edge *e) const
Definition attachment_util.h:116
MultiElementAttachmentAccessor()
Definition attachment_util.h:62
bool is_valid_volume_accessor() const
Definition attachment_util.h:98
ConstRefType operator[](Face *e) const
Definition attachment_util.h:117
TAttachment::ValueType ValueType
Definition attachment_util.h:58
MultiElementAttachmentAccessor(Grid &g, TAttachment &a, bool vrts=true, bool edges=true, bool faces=true, bool vols=true)
Definition attachment_util.h:63
attachment_value_traits< ValueType >::reference RefType
Definition attachment_util.h:59
Grid::AttachmentAccessor< Edge, TAttachment > m_aaEdge
Definition attachment_util.h:137
RefType operator[](GridObject *e)
Definition attachment_util.h:104
Grid::AttachmentAccessor< Vertex, TAttachment > m_aaVrt
Definition attachment_util.h:136
Grid::AttachmentAccessor< Volume, TAttachment > & volume_accessor()
Definition attachment_util.h:133
RefType operator[](Vertex *e)
Definition attachment_util.h:100
bool is_valid_edge_accessor() const
Definition attachment_util.h:96
Base-class for all vertex-types.
Definition grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition grid_base_objects.h:754
bool ConvertMathVectorAttachmentValues(Grid &grid, TSrcAttachment &srcAttachment, TDestAttachment &destAttachment)
Fills the dest-attachment with values from the source-attachment.
Definition attachment_util_impl.hpp:58
TIterator FindElementByValue(TIterator begin, TIterator end, const typename TAttAcc::ValueType &val, TAttAcc &aa)
returns the iterator whose element has the specified attachment value.
Definition attachment_util_impl.hpp:187
bool CopyAttachments(Grid &srcGrid, TAttachment &aSrc, Grid &destGrid, TAttachment &aDest)
copies attachments from one grid to the other
Definition attachment_util_impl.hpp:115
void AssignIndices(TIterator begin, TIterator end, TAAInt &aaInt, int baseIndex=0)
assigns indices to the elements between begin and end.
Definition attachment_util_impl.hpp:178
void SetAttachmentValues(TAttachmentAccessor &aaVal, TIter elemsBegin, TIter elemsEnd, const TVal &val)
sets attachment-values for elements between elemsBegin and elemsEnd.
Definition attachment_util_impl.hpp:44
#define UG_ASSERT(expr, msg)
Definition assert.h:70
#define UG_THROW(msg)
Definition error.h:57
the ug namespace
@ 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
TValue & reference
Definition attachment_pipe.h:112
const TValue & const_reference
Definition attachment_pipe.h:113