Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
grid_debug.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009-2021: G-CSC, Goethe University Frankfurt
3 * Author: Dmitry Logashenko
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__LIBGRID__GRID_DEBUG__
34#define __H__LIBGRID__GRID_DEBUG__
35
36#include <vector>
37#include <memory>
38
39// ug4 headers:
40#include "grid/grid.h"
41#include "subset_handler.h"
42
43namespace ug
44{
45
47
63{
65 typedef Grid grid_type;
66
67public:
68
70
75 static void create
76 (
77 grid_type& rGrid,
78 ISubsetHandler& rSH
79 )
80 {
81 if (the_object == nullptr)
82 the_object.reset (new grid_global_debug_info_provider (rGrid, rSH));
83 else
84 UG_THROW ("Reinitialization of the grid debugging info provider is not allowed!");
85 };
86
88 static bool elem_in_subset
89 (
90 GridObject * elem,
91 int si
92 )
93 {
94 if (! the_object)
95 return false;
96 return the_object->m_pSH->get_subset_index (elem) == si;
97 };
98
100 static bool elem_in_subsets
101 (
102 GridObject * elem,
103 std::vector<int> si_ar
104 )
105 {
106 if (! the_object)
107 return false;
108 int si = the_object->m_pSH->get_subset_index (elem);
109 for (size_t i = 0; i < si_ar.size (); i++) if (si == si_ar[i]) return true;
110 return false;
111 };
112
114 template <typename TAssElem>
116 (
117 GridObject * elem,
118 int si
119 )
120 {
121 if (! the_object)
122 return false;
123
124 typename Grid::traits<TAssElem>::secure_container ass_elem_list;
125 the_object->m_pGrid->associated_elements (ass_elem_list, elem);
126 for (size_t i = 0; i < ass_elem_list.size (); i++)
127 if (the_object->m_pSH->get_subset_index (ass_elem_list [i]) == si)
128 return true;
129 return false;
130 };
131
133 template <typename TAssElem>
135 (
136 GridObject * elem,
137 std::vector<int> si_ar,
138 bool in_all = false
139 )
140 {
141 if (! the_object)
142 return false;
143 if (si_ar.size () == 0)
144 return in_all; // dummy value ("sum or product over the empty set")
145
146 typedef unsigned long flags_t;
147
148 flags_t flags = 0, all_flags = 1;
149 if (in_all)
150 {
151 if (si_ar.size () > sizeof (flags_t))
152 UG_THROW ("Grid debugging info provider: too many subsets for the in_all flag");
153 all_flags = (all_flags << si_ar.size ()) - 1; // 1s at the positions of the subset indices
154 }
155
156 typename Grid::traits<TAssElem>::secure_container ass_elem_list;
157 int si;
158 the_object->m_pGrid->associated_elements (ass_elem_list, elem);
159 for (size_t i = 0; i < ass_elem_list.size (); i++)
160 {
161 si = the_object->m_pSH->get_subset_index (ass_elem_list [i]);
162 for (size_t j = 0; j < si_ar.size (); j++)
163 if (si == si_ar [j])
164 {
165 if (! in_all) return true;
166 flags |= ((flags_t) 1) << j;
167 }
168 }
169 return flags == all_flags;
170 };
171
172protected:
173
176 (
177 grid_type& rGrid,
178 ISubsetHandler& rSH
179 )
180 : m_pGrid (&rGrid), m_pSH (&rSH)
181 {
182 };
183
184private:
185// Data:
186
187 static std::unique_ptr<grid_global_debug_info_provider> the_object;
188
191};
192
193} // namespace ug
194
195#endif // __H__LIBGRID__GRID_DEBUG__
196
197/* End of File */
Manages the elements of a grid and their interconnection.
Definition grid.h:132
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition grid_base_objects.h:157
Definition subset_handler_interface.h:223
Debugging tool for function that do have no direct access to the grid.
Definition grid_debug.h:63
grid_global_debug_info_provider this_type
Definition grid_debug.h:64
static bool elem_in_subset(GridObject *elem, int si)
checks if an element is in a subset
Definition grid_debug.h:89
Grid grid_type
Definition grid_debug.h:65
grid_global_debug_info_provider(grid_type &rGrid, ISubsetHandler &rSH)
(protected) constructor
Definition grid_debug.h:176
static bool ass_elem_in_subset(GridObject *elem, int si)
checks if one of the associated elements is in a given subset
Definition grid_debug.h:116
grid_type * m_pGrid
current grid
Definition grid_debug.h:189
static std::unique_ptr< grid_global_debug_info_provider > the_object
Pointer to the single (if any) object of the grid debug info provider.
Definition grid_debug.h:187
static void create(grid_type &rGrid, ISubsetHandler &rSH)
creates the object (if it did not exist)
Definition grid_debug.h:76
ISubsetHandler * m_pSH
current SubsetHandler to use
Definition grid_debug.h:190
static bool ass_elem_in_subsets(GridObject *elem, std::vector< int > si_ar, bool in_all=false)
checks if one of the associated elements is in (all or some of the) given subsets
Definition grid_debug.h:135
static bool elem_in_subsets(GridObject *elem, std::vector< int > si_ar)
checks if an element is in subsets from a list
Definition grid_debug.h:101
#define UG_THROW(msg)
Definition error.h:57
the ug namespace
PointerConstArray< TElem * > secure_container
Definition grid.h:146