Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
io_grid_points_ordering.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022: G-CSC, Goethe University Frankfurt
3 * Author: Lukas Larisch
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
34#include "lib_disc/domain.h"
37
39
40namespace ug{
41
42template <typename TDomain, typename TAlgebra>
44{
47
49
50public:
52 {
53
54 m_u = spGridFct->clone_without_values();
55 m_name = name;
56 m_n = 0;
57 m_numVert = 0;
58 m_numElem = 0;
59 m_numConn = 0;
60
62
63 std::vector<size_t> index(m_numVert);
64
65 size_t k = 0;
66
67 typedef typename IteratorProvider<TGridFunction>::template traits<ug::Vertex>::const_iterator const_iterator;
68 const_iterator iterBegin = IteratorProvider<TGridFunction>::template begin<ug::Vertex>(*m_u, -1);
69 const_iterator iterEnd = IteratorProvider<TGridFunction>::template end<ug::Vertex>(*m_u, -1);
70 for( ; iterBegin != iterEnd; ++iterBegin, ++k)
71 {
72 ug::Vertex* v = *iterBegin;
73 index[k] = m_aaVrtIndex[v];
74 }
75
76 k = 0;
77 std::vector<DoFIndex> ind(1);
78
79 iterBegin = IteratorProvider<TGridFunction>::template begin<ug::Vertex>(*m_u, -1);
80 iterEnd = IteratorProvider<TGridFunction>::template end<ug::Vertex>(*m_u, -1);
81 for( ; iterBegin != iterEnd; ++iterBegin, ++k)
82 {
83 ug::Vertex* v = *iterBegin;
84
85 // get vector holding all indices on the vertex
86 m_u->inner_dof_indices(v, 0, ind);
87 DoFRef(*m_u, ind[0]) = index[k];
88 }
89 }
90
91
92 template <typename TElem>
94 {
95// get the grid associated to the solution
96 Grid& grid = *m_u->domain()->grid();
97
98 // get reference element
100
101 // number of corners of element
102 static const int numCo = ref_elem_type::numCorners;
103
104 // get iterators
105 typedef typename IteratorProvider<TGridFunction>::template traits<TElem>::const_iterator const_iterator;
106 const_iterator iterBegin = IteratorProvider<TGridFunction>::template begin<TElem>(*m_u, -1);
107 const_iterator iterEnd = IteratorProvider<TGridFunction>::template end<TElem>(*m_u, -1);
108
109 // loop elements
110 for( ; iterBegin != iterEnd; ++iterBegin)
111 {
112 // get the element
113 TElem *elem = *iterBegin;
114
115 // count number of elements and number of connections;
116 // handle octahedrons separately by splitting into a top and bottom pyramid
117 if(ref_elem_type::REFERENCE_OBJECT_ID != ROID_OCTAHEDRON)
118 {
119 ++m_numElem;
120 m_numConn += numCo;
121 }
122 else
123 {
124 // counting top and bottom pyramid
125 m_numElem += 2;
126 m_numConn += 10;
127 }
128
129 // loop vertices of the element
130 for(int i = 0; i < numCo; ++i)
131 {
132 // get vertex of the element
133 Vertex* v = GetVertex(elem, i);
134
135 // if this vertex has already been counted, skip it
136 if(grid.is_marked(v)) continue;
137
138 // count vertex and mark it
139 ++m_numVert;
140 grid.mark(v);
141 }
142 }
143 }
144
145
146 template <typename TElem>
148 {
149// get the grid associated to the solution
150 Grid& grid = *m_u->domain()->grid();
151
152 // get reference element
153 typedef typename reference_element_traits<TElem>::reference_element_type ref_elem_type;
154 // get iterators
155 typedef typename IteratorProvider<TGridFunction>::template traits<TElem>::const_iterator const_iterator;
156 const_iterator iterBegin = IteratorProvider<TGridFunction>::template begin<TElem>(*m_u, -1);
157 const_iterator iterEnd = IteratorProvider<TGridFunction>::template end<TElem>(*m_u, -1);
158
159 // loop all elements of the subset
160 for( ; iterBegin != iterEnd; ++iterBegin)
161 {
162 // get the element
163 TElem *elem = *iterBegin;
164
165 // loop vertices of the element
166 for(size_t i = 0; i < (size_t) ref_elem_type::numCorners; ++i)
167 {
168 // get vertex of element
169 Vertex* v = GetVertex(elem, i);
170
171 // if vertex has already be handled, skip it
172 if(grid.is_marked(v)) continue;
173
174 // mark the vertex as processed
175 grid.mark(v);
176
177 // number vertex
178 m_aaVrtIndex[v] = m_n++;
179 }
180 }
181 }
182
184// check functions
185 for(size_t fct = 0; fct < m_u->num_fct(); ++fct)
186 {
187 // check if function is defined everywhere
188 if(!m_u->is_def_everywhere(fct))
189 UG_THROW("only serial case implemented!");
190 }
191
192// get the grid associated to the solution
193 Grid& grid = *m_u->domain()->grid();
194
195// attach help indices
196 AVrtIndex aVrtIndex;
197 grid.attach_to_vertices(aVrtIndex);
198 m_aaVrtIndex.access(grid, aVrtIndex);
199
200 int dim = DimensionOfSubsets(*m_u->domain()->subset_handler());
201
202// Count needed sizes for vertices, elements and connections
203 try{
204// reset all marks
205 grid.begin_marking();
206
207// switch dimension
208 switch(dim)
209 {
210 case 0: count_sizes<Vertex>(); break;
211 case 1: count_sizes<RegularEdge>();
212 count_sizes<ConstrainingEdge>(); break;
213 case 2: count_sizes<Triangle>();
214 count_sizes<Quadrilateral>();
215 count_sizes<ConstrainingTriangle>();
216 count_sizes<ConstrainingQuadrilateral>(); break;
217 case 3: count_sizes<Tetrahedron>();
218 count_sizes<Pyramid>();
219 count_sizes<Prism>();
220 count_sizes<Octahedron>();
221 count_sizes<Hexahedron>(); break;
222 default: UG_THROW(name() << "::create_vtkoutput_ordering: Dimension " << dim << " is not supported.");
223 }
224
225// signal end of marking
226 grid.end_marking();
227 }
228 UG_CATCH_THROW(name() << "::create_vtkoutput_ordering: Can not count piece sizes.");
229
230// start marking of vertices
231 grid.begin_marking();
232
233// switch dimension
234 if(m_numVert > 0){
235 switch(dim){
236 case 0: number_points_elementwise<Vertex>(); break;
237 case 1: number_points_elementwise<RegularEdge>();
238 number_points_elementwise<ConstrainingEdge>(); break;
239 case 2: number_points_elementwise<Triangle>();
240 number_points_elementwise<Quadrilateral>();
241 number_points_elementwise<ConstrainingTriangle>();
242 number_points_elementwise<ConstrainingQuadrilateral>(); break;
243 case 3: number_points_elementwise<Tetrahedron>();
244 number_points_elementwise<Pyramid>();
245 number_points_elementwise<Prism>();
246 number_points_elementwise<Octahedron>();
247 number_points_elementwise<Hexahedron>(); break;
248 default: UG_THROW(name() << "::create_vtkoutput_ordering: Dimension " << dim << " is not supported.");
249 }
250 }
251// signal end of marking the grid
252 grid.end_marking();
253 }
254
258
259 const char* name() const {return "GridPointsOrdering";}
260
261private:
263 const char* m_name;
264 size_t m_n;
268
270};
271
272} //namespace
Definition smart_pointer.h:108
A generic specialization of IAttachment.
Definition attachment_pipe.h:263
represents numerical solutions on a grid using an algebraic vector
Definition grid_function.h:121
Definition grid_function_user_data.h:68
Manages the elements of a grid and their interconnection.
Definition grid.h:132
void end_marking()
ends a marking sequence. Call this method when you're done with marking.
Definition grid.cpp:1285
bool is_marked(GridObject *obj) const
returns true if the object is marked, false if not.
Definition grid_impl.hpp:843
void mark(GridObject *obj)
marks the object. Calls are only valid between calls to Grid::begin_marking and Grid::end_marking.
Definition grid_impl.hpp:773
void begin_marking()
begin marking.
Definition grid.cpp:1262
void attach_to_vertices(IAttachment &attachment, bool passOnValues)
Definition grid.h:728
Definition io_grid_points_ordering.cpp:44
int m_numElem
Definition io_grid_points_ordering.cpp:266
GridFunctionNumberData< GridFunction< TDomain, TAlgebra > > TGridFunctionNumberData
Definition io_grid_points_ordering.cpp:46
void number_points_elementwise()
Definition io_grid_points_ordering.cpp:147
GridPointsOrdering(SmartPtr< TGridFunction > spGridFct, const char *name)
Definition io_grid_points_ordering.cpp:51
const char * m_name
Definition io_grid_points_ordering.cpp:263
GridFunction< TDomain, TAlgebra > TGridFunction
Definition io_grid_points_ordering.cpp:45
void count_sizes()
Definition io_grid_points_ordering.cpp:93
void create_vtkoutput_ordering()
Definition io_grid_points_ordering.cpp:183
ug::Attachment< int > AVrtIndex
Definition io_grid_points_ordering.cpp:48
SmartPtr< TGridFunction > m_u
Definition io_grid_points_ordering.cpp:262
size_t m_n
Definition io_grid_points_ordering.cpp:264
int m_numVert
Definition io_grid_points_ordering.cpp:265
Grid::VertexAttachmentAccessor< AVrtIndex > m_aaVrtIndex
Definition io_grid_points_ordering.cpp:269
int m_numConn
Definition io_grid_points_ordering.cpp:267
const char * name() const
Definition io_grid_points_ordering.cpp:259
SmartPtr< TGridFunctionNumberData > get()
Definition io_grid_points_ordering.cpp:255
Base-class for all vertex-types.
Definition grid_base_objects.h:231
Vertex * GetVertex(Vertex *v, size_t i)
returns the i'th vertex of a vertex
Definition grid_util_impl.hpp:99
#define UG_CATCH_THROW(msg)
Definition error.h:64
#define UG_THROW(msg)
Definition error.h:57
the ug namespace
@ ROID_OCTAHEDRON
Definition grid_base_objects.h:84
number & DoFRef(TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
Definition multi_index.h:276
int DimensionOfSubsets(const ISubsetHandler &sh)
Returns the dimension of geometric objects, that are contained in the subset handler.
Definition subset_dim_util.cpp:101
Definition vtkoutput.h:56
traits for reference elements
Definition reference_element_traits.h:48