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_DISC__COMMON__FUNCTION_GROUP__
34 : #define __H__UG__LIB_DISC__COMMON__FUNCTION_GROUP__
35 :
36 : #include <vector>
37 : #include <string>
38 :
39 : #include "common/common.h"
40 : #include "lib_disc/local_finite_element/local_finite_element_id.h"
41 : #include "lib_disc/dof_manager/function_pattern.h"
42 :
43 : namespace ug{
44 :
45 : /** Group of functions represented by integers
46 : * FunctionGroup is just a group of size_t, representing some functions. The
47 : * function group is based on a FunctionPattern and the integer represent the
48 : * position of the function in the function pattern. Selection of functions is
49 : * best via usage of symbolic names of the functions.
50 : */
51 0 : class FunctionGroup
52 : {
53 : public:
54 : /// Default Constructor
55 : FunctionGroup();
56 :
57 : /// Constructor setting function pattern
58 : FunctionGroup(ConstSmartPtr<FunctionPattern> spFuncPattern);
59 :
60 : /// Constructor setting function pattern and function
61 : FunctionGroup(ConstSmartPtr<FunctionPattern> spFuncPattern, const char* name);
62 :
63 : /// Constructor setting function pattern and function
64 : FunctionGroup(ConstSmartPtr<FunctionPattern> spFuncPattern, const std::string& name);
65 :
66 : /// Constructor setting function pattern and functions
67 : FunctionGroup(ConstSmartPtr<FunctionPattern> spFuncPattern, const std::vector<std::string>& vName);
68 :
69 : /// set underlying function pattern
70 : void set_function_pattern(ConstSmartPtr<FunctionPattern> spFuncPattern);
71 :
72 : /// get underlying function pattern
73 : ConstSmartPtr<FunctionPattern> function_pattern() const
74 : {return m_spFunctionPattern;}
75 :
76 : /// adds a function by id to this group
77 : void add(size_t fct);
78 :
79 : /// adds function with a given name to this group
80 : void add(const char* name);
81 :
82 : /// adds function with a given name to this group
83 : void add(const std::string& name);
84 :
85 : /// adds functions with a given names to this group
86 : void add(const std::vector<std::string>& name);
87 :
88 : /// adds all functions of a function group
89 : void add(const FunctionGroup& fctGroup);
90 :
91 : /// selects all subsets in the order of the underlying pattern
92 : void add_all();
93 :
94 : /// removes a function by id from this group
95 : void remove(size_t fct);
96 :
97 : /// removes function with a given name from this group
98 : void remove(const char* name);
99 :
100 : /// removes function with a given name from this group
101 : void remove(const std::string& name);
102 :
103 : /// removes functions with a given names from this group
104 : void remove(const std::vector<std::string>& vName);
105 :
106 : /// clear all subsets
107 : void clear() {m_vFunction.clear();}
108 :
109 : /// sorts the selected functions by increasing unique id
110 : void sort();
111 :
112 : /// returns if function group is empty
113 : bool empty() const {return m_vFunction.empty();}
114 :
115 : /// number of functions in this group
116 : size_t size() const {return m_vFunction.size();}
117 :
118 : /// returns the name of a function
119 : const char* name(size_t i) const;
120 :
121 : /// returns the comma-separted names of all functions
122 : std::string names() const;
123 :
124 : /// returns unique function id of a function
125 : size_t operator[](size_t i) const {return unique_id(i);}
126 :
127 : /// returns unique function id of a function
128 : size_t unique_id(size_t i) const
129 : {
130 : UG_ASSERT(i < size(), "Invalid function access");
131 0 : return m_vFunction[i];
132 : }
133 :
134 : /// dimension of a function
135 : /**
136 : * Returns the dimension of a function. The dimension is defined
137 : * to be the highest dimension of grid entity the function lives on
138 : */
139 : int dim(size_t i) const;
140 :
141 : /// common dimension of all functions
142 : /**
143 : * Returns the commen dimension of all functions of the group. This
144 : * dimension is defined to be the highest dimension of grid entity
145 : * the functions live on
146 : *
147 : * \return -1 if no common dimension available
148 : * dim >= 0 common dimension
149 : */
150 : int dim() const;
151 :
152 : /// returns the trial space of the discrete function fct
153 : /// \{
154 : LFEID local_finite_element_id(size_t i) const;
155 : LFEID lfeid(size_t i) const;
156 : /// \}
157 :
158 : /// returns true if unique id is contained in this group
159 : bool contains(size_t uniqueID) const;
160 :
161 : /// returns true if all unique ids of another function group are contained
162 : bool contains(const FunctionGroup& fctGroup) const;
163 :
164 : /// return index in Function group for a function
165 : size_t local_index(size_t uniqueID) const;
166 :
167 : protected:
168 : /// returns if FunctionGroup is ready for use
169 : bool is_init() const {return m_spFunctionPattern.valid();}
170 :
171 : protected:
172 : /// underlying function pattern
173 : ConstSmartPtr<FunctionPattern> m_spFunctionPattern;
174 :
175 : /// vector holding all selected unique function ids
176 : std::vector<size_t> m_vFunction;
177 : };
178 :
179 : /// describes a mapping between two local index sets
180 : /**
181 : * This class is used to define a mapping between two index sets. The domain index
182 : * set must contain indices in consecutive order [0, ..., N],
183 : * while the codomain index set can have any size.
184 : */
185 0 : class FunctionIndexMapping
186 : {
187 : public:
188 : /// removes all connections
189 : void clear() {m_vMapping.clear();}
190 :
191 : /// adds a mapping between indexFrom and indexTo
192 0 : void push_back(size_t indexTo){m_vMapping.push_back(indexTo);}
193 :
194 : /// returns the number of indices that are mapped
195 : size_t num_fct() const {return m_vMapping.size();}
196 :
197 : /// returns the mapped index
198 : size_t operator[](size_t i) const
199 : {
200 : UG_ASSERT(i < num_fct(), "Invalid index.\n");
201 0 : return m_vMapping[i];
202 : }
203 :
204 : protected:
205 : /// vector holding the mapped indices
206 : std::vector<size_t> m_vMapping;
207 : };
208 :
209 :
210 : inline
211 : std::ostream& operator<< (std::ostream& outStream, const ug::FunctionIndexMapping& map)
212 : {
213 : outStream << '[';
214 : for(size_t i = 0; i < map.num_fct(); ++i)
215 : {
216 : outStream << map[i];
217 : if(i != map.num_fct()-1) outStream << ',';
218 : }
219 : outStream << ']';
220 : return outStream;
221 : }
222 :
223 : inline
224 0 : std::ostream& operator<< (std::ostream& outStream, const ug::FunctionGroup& grp)
225 : {
226 0 : outStream << '[';
227 0 : for(size_t i = 0; i < grp.size(); ++i)
228 : {
229 : outStream << grp[i];
230 0 : if(i != grp.size()-1) outStream << ',';
231 : }
232 0 : outStream << ']';
233 0 : return outStream;
234 : }
235 :
236 : } // end namespace ug
237 :
238 : #endif /*__H__UG__LIB_DISC__COMMON__FUNCTION_GROUP__ */
|