Line data Source code
1 : /*
2 : * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
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__LIB_GRID__SUBSET_GROUP__
34 : #define __H__UG__LIB_GRID__SUBSET_GROUP__
35 :
36 : #include <vector>
37 : #include <string>
38 : #include "lib_grid/tools/subset_handler_interface.h"
39 :
40 : namespace ug{
41 :
42 : /// Group of subsets
43 : /**
44 : * A SubsetGroup is used to describe a group of Subsets. Therefore, it has an
45 : * underlying SubsetHandler from which the subsets can be chosen. It is very
46 : * light-weight, since internally it is just a vector of the subset indices. But
47 : * it provides several comfort functions. Note, that the subset indices are
48 : * always sorted by increasing index in this subset group.
49 : */
50 0 : class SubsetGroup
51 : {
52 : public:
53 : /// Default Constructor
54 : SubsetGroup();
55 :
56 : /// Constructor setting subset handler
57 : SubsetGroup(ConstSmartPtr<ISubsetHandler> sh);
58 :
59 : /// Constructor setting subset handler and subsets
60 : SubsetGroup(ConstSmartPtr<ISubsetHandler> sh, const char* names);
61 :
62 : /// Constructor setting subset handler and subsets
63 : SubsetGroup(ConstSmartPtr<ISubsetHandler> sh, const std::string& names);
64 :
65 : /// Constructor setting subset handler and subsets
66 : SubsetGroup(ConstSmartPtr<ISubsetHandler> sh, const std::vector<std::string>& vName);
67 :
68 : /// set an underlying subset handler
69 0 : void set_subset_handler(ConstSmartPtr<ISubsetHandler> sh) {m_pSH = sh; clear();}
70 :
71 : /// get underlying subset handler
72 : ConstSmartPtr<ISubsetHandler> subset_handler() const {return m_pSH;}
73 :
74 : /// adds a subset by number to this group
75 : void add(int si);
76 :
77 : /// adds subset with a name to this group
78 : void add(const char* name);
79 :
80 : /// adds subset with a name to this group
81 : void add(const std::string& name);
82 :
83 : /// adds all subset with by name to this group
84 : /**
85 : * This function adds all subset with by name to this group.
86 : * \param[in] vName Name of Subset(s) to be added
87 : */
88 : void add(const std::vector<std::string>& vName);
89 :
90 : /// adds all subsets of another subset to the group
91 : void add(const SubsetGroup& ssGroup);
92 :
93 : /// select all subsets of underlying subset handler
94 : void add_all();
95 :
96 : /// removes a subset from this group
97 : void remove(int si);
98 :
99 : /// removes subset with a given name from this group
100 : void remove(const char* name);
101 :
102 : /// removes subset with a given name from this group
103 : void remove(const std::string& name);
104 :
105 : /// removes subsets with given names from this group
106 : /**
107 : * This function removes all subsets by name from this group
108 : * \param[in] name Name of Subset(s) to be removed
109 : */
110 : void remove(const std::vector<std::string>& vName);
111 :
112 : /// removes all subsets of another subset from the group
113 : void remove(const SubsetGroup& ssGroup);
114 :
115 : /// clear all subsets
116 : void clear() {m_vSubset.clear();}
117 :
118 : /// returns if function group is empty
119 : bool empty() const {return m_vSubset.empty();}
120 :
121 : /// number of subsets in this group
122 : inline size_t size() const
123 : {
124 0 : if (!m_pSH.valid()) return 0;
125 0 : return m_vSubset.size();
126 : }
127 :
128 : /// index of the subset # i in this group
129 : inline int operator[](size_t i) const
130 : {
131 : UG_ASSERT(is_init(), "No SubsetHandler set.");
132 : UG_ASSERT(i < size(), "requested subset does not exist.");
133 0 : return m_vSubset[i];
134 : }
135 :
136 : /// vector of the subset indices in the group
137 : inline const std::vector<int>& index_vector() const
138 : {
139 : return m_vSubset;
140 : }
141 :
142 : /// name of subset
143 : const char* name(size_t i) const;
144 :
145 : /// returns if a subset is a regular grid
146 : bool regular_grid(size_t i) const;
147 :
148 : /// dimension of subset
149 : /**
150 : * Returns the dimension of the subset. The dimension of the subset
151 : * is defined as the highest dimension of geometric objects contained in
152 : * the subset. This maximum is taken over all procs in parallel.
153 : */
154 : int dim(size_t i) const;
155 :
156 : /// highest dimension of all subset
157 : /**
158 : * Returns the highest dimension of all subset. The dimension of a subset
159 : * is defined as the highest dimension of geometric objects contained in
160 : * the subset.
161 : * No check between different processes is performed in parallel.
162 : *
163 : * \return -1 if no dimension available
164 : * dim >= 0 highest dimension of all subsets in this group
165 : */
166 : int get_highest_subset_dimension() const;
167 :
168 : /// returns true if subset is contained in this group
169 : bool contains(int si) const;
170 :
171 : /// returns true if at least one subset of a name is contained in this group
172 : bool contains(const char* name) const;
173 :
174 : protected:
175 : // returns if SubsetGroup is ready for use
176 : bool is_init() const {return m_pSH.valid();}
177 :
178 : protected:
179 : ConstSmartPtr<ISubsetHandler> m_pSH; ///< underlying SubsetHandler
180 : std::vector<int> m_vSubset; ///< selected Subset Indices
181 : };
182 :
183 : /**
184 : * Returns if dimension is the same in all subsets of the subset group
185 : * @param subsetGroup subset group that is checked
186 : * @returns true if dimension is the same in all subsets, else false
187 : */
188 : bool SameDimensionsInAllSubsets(const SubsetGroup& subsetGroup);
189 :
190 : /**
191 : * Removes all subsets from the subset group that have a lower dimension than the
192 : * highest dimension contained in the subset group.
193 : * @param subsetGroup subset group that is modified
194 : */
195 : void RemoveLowerDimSubsets(SubsetGroup& subsetGroup);
196 :
197 : } // end namespace ug
198 :
199 : #endif /*__H__UG__LIB_GRID__SUBSET_GROUP__ */
|