ug4
Loading...
Searching...
No Matches
debug_util_impl.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-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__UG__debug_util_impl__
34#define __H__UG__debug_util_impl__
35
36#include <fstream>
37#include <sstream>
38#include "lib_grid/lg_base.h"
40#include "common/util/table.h"
42
43namespace ug
44{
45
46template <class TElem>
48{
51 return CalculateCenter(elem, aaPos);
52 }
55 vector2 v = CalculateCenter(elem, aaPos);
56 return vector3(v.x(), v.y(), 0);
57 }
60 vector1 v = CalculateCenter(elem, aaPos);
61 return vector3(v.x(), 0, 0);
62 }
63
64 UG_LOG("GetGridObjectCenter failed! No standard position attachment found.\n");
65 return vector3(0, 0, 0);
66}
67
68
70{
71 switch(elem->base_object_id()){
72 case VERTEX: return GetGridObjectCenter(g, static_cast<Vertex*>(elem));
73 case EDGE: return GetGridObjectCenter(g, static_cast<Edge*>(elem));
74 case FACE: return GetGridObjectCenter(g, static_cast<Face*>(elem));
75 case VOLUME: return GetGridObjectCenter(g, static_cast<Volume*>(elem));
76 default: UG_THROW("Unknown base object type.");
77 }
78 return vector3(0, 0, 0);
79}
80
81
82template <class TElem>
83int GetGridObjectIndex(Grid& g, TElem* elem)
84{
85 typedef typename Grid::traits<TElem>::base_object TBase;
86
87 int counter = 0;
88 for(typename Grid::traits<TBase>::iterator iter = g.begin<TBase>();
89 iter != g.end<TBase>(); ++iter, ++counter)
90 {
91 if(*iter == elem)
92 return counter;
93 }
94 return -1;
95}
96
97template <class TElem, class TAValue>
98void WriteDebugValuesToFile(const char* filename, Grid& grid,
99 TAValue& aVal, bool levelWise)
100{
101 typedef typename Grid::traits<TElem>::base_object TBase;
102
103 std::ofstream out(filename);
104 if(!out)
105 return;
106
108
109 Table<std::stringstream> table(grid.num<TElem>() + 1, 3);
110 table(0, 0) << "lvl"; table(0, 1) << "center"; table(0, 2) << "value";
111
112 size_t row = 1;
113 if(levelWise){
115 for(size_t lvl = 0; lvl < goc.num_levels(); ++lvl){
116 for(typename Grid::traits<TElem>::iterator iter = goc.begin<TElem>(lvl);
117 iter != goc.end<TElem>(lvl); ++iter, ++row)
118 {
119 table(row, 0) << lvl;
120 table(row, 1) << GetGridObjectCenter(grid, *iter);
121 table(row, 2) << aaVal[*iter];
122 }
123 }
124 }
125 else if(MultiGrid* pmg = dynamic_cast<MultiGrid*>(&grid)){
126 MultiGrid& mg = *pmg;
127 for(typename Grid::traits<TElem>::iterator iter = grid.begin<TElem>();
128 iter != grid.end<TElem>(); ++iter, ++row)
129 {
130 table(row, 0) << mg.get_level(*iter);
131 table(row, 1) << GetGridObjectCenter(grid, *iter);
132 table(row, 2) << aaVal[*iter];
133 }
134 }
135 else{
136 for(typename Grid::traits<TElem>::iterator iter = grid.begin<TElem>();
137 iter != grid.end<TElem>(); ++iter, ++row)
138 {
139 table(row, 0) << 0;
140 table(row, 1) << GetGridObjectCenter(grid, *iter);
141 table(row, 2) << aaVal[*iter];
142 }
143 }
144
145 out << table;
146 out.close();
147}
148
149}// end of namespace
150
151#endif
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
Manages the elements of a grid and their interconnection.
Definition grid.h:132
size_t num() const
Definition grid_impl.hpp:230
virtual GridObjectCollection get_grid_objects()
returns the the GridObjectCollection of the grid:
Definition grid.cpp:527
geometry_traits< TGeomObj >::iterator begin()
Definition grid_impl.hpp:164
bool has_vertex_attachment(IAttachment &attachment)
Definition grid.h:798
geometry_traits< TGeomObj >::iterator end()
Definition grid_impl.hpp:175
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition grid_object_collection.h:96
geometry_traits< TGeomObj >::iterator begin(size_t level=0)
Definition grid_object_collection_impl.hpp:95
geometry_traits< TGeomObj >::iterator end(size_t level=0)
Definition grid_object_collection_impl.hpp:106
size_t num_levels() const
returns the number of levels
Definition grid_object_collection.h:128
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
Definition multi_grid.h:72
int get_level(TElem *elem) const
Definition multi_grid.h:206
Useful for printing a table to the terminal or into a file.
Definition table.h:84
Base-class for all vertex-types.
Definition grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition grid_base_objects.h:754
void WriteDebugValuesToFile(const char *filename, Grid &grid, TAValue &aVal, bool levelWise)
Writes level and center of each object together with a custom value to a file.
Definition debug_util_impl.hpp:98
int GetGridObjectIndex(Grid &g, TElem *elem)
returns the index of the given element in the given grid.
Definition debug_util_impl.hpp:83
vector3 GetGridObjectCenter(Grid &g, TElem *elem)
Returns the center of the given element (SLOW - for debugging only!)
Definition debug_util_impl.hpp:47
#define UG_THROW(msg)
Definition error.h:57
#define UG_LOG(msg)
Definition log.h:367
void CalculateCenter(vector_t &centerOut, const vector_t *pointSet, size_t numPoints)
calculates the center of a point-set
Definition math_util_impl.hpp:98
MathVector< 1, number > vector1
a 1d vector
Definition ugmath_types.h:66
MathVector< 3, number > vector3
a 3d vector
Definition ugmath_types.h:72
the ug namespace
APosition1 aPosition1("position2", true)
The standard 1d position type.
Definition common_attachments.h:90
@ 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
APosition aPosition("position", true)
The standard 3d position type.
Definition common_attachments.h:84
APosition2 aPosition2("position2", true)
The standard 2d position type.
Definition common_attachments.h:87
TElem::grid_base_object base_object
Definition grid.h:137
geometry_traits< TElem >::iterator iterator
Definition grid.h:143