Line data Source code
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_IMPL__
34 : #define __H__LIB_GRID__ATTACHMENT_UTIL_IMPL__
35 :
36 : #include "attachment_util.h"
37 :
38 : namespace ug
39 : {
40 :
41 : ////////////////////////////////////////////////////////////////////////
42 : // SetAttachmentValues
43 : template <class TAttachmentAccessor, class TIter, class TVal>
44 : void SetAttachmentValues(TAttachmentAccessor& aaVal,
45 : TIter elemsBegin, TIter elemsEnd,
46 : const TVal& val)
47 : {
48 0 : while(elemsBegin != elemsEnd)
49 : {
50 0 : aaVal[*elemsBegin] = val;
51 : ++elemsBegin;
52 : }
53 : }
54 :
55 : ////////////////////////////////////////////////////////////////////////
56 : // ConvertMathVectorAttachmentValues
57 : template<class TElem, class TSrcAttachment, class TDestAttachment>
58 0 : bool ConvertMathVectorAttachmentValues(Grid& grid,
59 : TSrcAttachment& srcAttachment,
60 : TDestAttachment& destAttachment)
61 : {
62 : typedef TSrcAttachment ASrc;
63 : typedef TDestAttachment ADest;
64 :
65 : // make sure that the attachments are attached correctly
66 0 : if(!grid.has_attachment<TElem>(srcAttachment))
67 : return false;
68 :
69 0 : if(!grid.has_attachment<TElem>(destAttachment))
70 0 : grid.attach_to<TElem>(destAttachment);
71 :
72 : // get data containers
73 : typename ASrc::ContainerType& cSrc
74 : = *grid.get_attachment_data_container<TElem>(srcAttachment);
75 : typename ADest::ContainerType& cDest
76 : = *grid.get_attachment_data_container<TElem>(destAttachment);
77 :
78 : int srcDim = ASrc::ValueType::Size;
79 : int destDim = ADest::ValueType::Size;
80 :
81 : // iterate through the elements and copy them
82 : // if destDim is smaller than srcDim we only have to copy
83 : if(destDim <= srcDim)
84 : {
85 0 : for(uint i = 0; i < cSrc.size(); ++i)
86 : {
87 : typename ASrc::ValueType& vSrc = cSrc[i];
88 : typename ADest::ValueType& vDest = cDest[i];
89 :
90 0 : for(int j = 0; j < destDim; ++j)
91 0 : vDest[j] = vSrc[j];
92 : }
93 : }
94 : else
95 : {
96 : // we have to fill the higher dimensions with 0
97 0 : for(uint i = 0; i < cSrc.size(); ++i)
98 : {
99 : typename ASrc::ValueType& vSrc = cSrc[i];
100 : typename ADest::ValueType& vDest = cDest[i];
101 :
102 0 : for(int j = 0; j < srcDim; ++j)
103 0 : vDest[j] = vSrc[j];
104 :
105 0 : for(int j = srcDim; j < destDim; ++j)
106 0 : vDest[j] = 0;
107 : }
108 : }
109 :
110 : return true;
111 : }
112 :
113 : ////////////////////////////////////////////////////////////////////////
114 : template <class TElem, class TAttachment>
115 0 : bool CopyAttachments(Grid& srcGrid, TAttachment& aSrc,
116 : Grid& destGrid, TAttachment& aDest)
117 : {
118 : // make sure the attachments are properly attached.
119 0 : if(!srcGrid.has_attachment<TElem>(aSrc))
120 : return false;
121 :
122 0 : if(!destGrid.has_attachment<TElem>(aDest))
123 0 : destGrid.attach_to<TElem>(aDest);
124 :
125 : // access the attachments
126 : Grid::AttachmentAccessor<TElem, TAttachment> aaSrc(srcGrid, aSrc);
127 : Grid::AttachmentAccessor<TElem, TAttachment> aaDest(destGrid, aDest);
128 :
129 : // iterate over the elements
130 : typename geometry_traits<TElem>::iterator iterSrc = srcGrid.begin<TElem>();
131 : typename geometry_traits<TElem>::iterator iterDest = destGrid.begin<TElem>();
132 :
133 : while((iterSrc != srcGrid.end<TElem>())
134 0 : &&(iterDest != destGrid.end<TElem>()))
135 : {
136 : aaDest[*iterDest] = aaSrc[*iterSrc];
137 : ++iterDest;
138 : ++iterSrc;
139 : }
140 :
141 : // done
142 : return true;
143 : }
144 :
145 : ////////////////////////////////////////////////////////////////////////
146 : template <class TElemIter, class TAttachment>
147 : bool CopyAttachments(Grid& grid, TElemIter elemsBegin, TElemIter elemsEnd,
148 : TAttachment& aSrc, TAttachment& aDest)
149 : {
150 : typedef typename PtrToValueType<
151 : typename TElemIter::value_type>::base_type TElem;
152 :
153 : // make sure the attachments are properly attached.
154 : if(!grid.has_attachment<TElem>(aSrc))
155 : return false;
156 :
157 : if(!grid.has_attachment<TElem>(aDest))
158 : grid.attach_to<TElem>(aDest);
159 :
160 : // access the attachments
161 : Grid::AttachmentAccessor<TElem, TAttachment> aaSrc(grid, aSrc);
162 : Grid::AttachmentAccessor<TElem, TAttachment> aaDest(grid, aDest);
163 :
164 : // iterate over the elements
165 : TElemIter iter = elemsBegin;
166 : while(iter != elemsEnd)
167 : {
168 : aaDest[*iter] = aaSrc[*iter];
169 : ++iter;
170 : }
171 :
172 : // done
173 : return true;
174 : }
175 :
176 : ////////////////////////////////////////////////////////////////////////
177 : template <class TIterator, class TAAInt>
178 : void AssignIndices(TIterator begin, TIterator end,
179 : TAAInt& aaInt, int baseIndex)
180 : {
181 0 : for(TIterator iter = begin; iter != end; ++iter)
182 0 : aaInt[*iter] = baseIndex++;
183 : }
184 :
185 : ////////////////////////////////////////////////////////////////////////
186 : template <class TIterator, class TAttAcc>
187 : TIterator FindElementByValue(TIterator begin, TIterator end,
188 : const typename TAttAcc::ValueType& val,
189 : TAttAcc& aa)
190 : {
191 : TIterator iter = begin;
192 : while(iter != end){
193 : if(aa[*iter] == val)
194 : break;
195 : ++iter;
196 : }
197 : return iter;
198 : }
199 :
200 : }// end of namespace
201 :
202 : #endif
|