ug4
function_group.h
Go to the documentation of this file.
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"
42 
43 namespace ug{
44 
52 {
53  public:
55  FunctionGroup();
56 
59 
61  FunctionGroup(ConstSmartPtr<FunctionPattern> spFuncPattern, const char* name);
62 
64  FunctionGroup(ConstSmartPtr<FunctionPattern> spFuncPattern, const std::string& name);
65 
67  FunctionGroup(ConstSmartPtr<FunctionPattern> spFuncPattern, const std::vector<std::string>& vName);
68 
71 
74  {return m_spFunctionPattern;}
75 
77  void add(size_t fct);
78 
80  void add(const char* name);
81 
83  void add(const std::string& name);
84 
86  void add(const std::vector<std::string>& name);
87 
89  void add(const FunctionGroup& fctGroup);
90 
92  void add_all();
93 
95  void remove(size_t fct);
96 
98  void remove(const char* name);
99 
101  void remove(const std::string& name);
102 
104  void remove(const std::vector<std::string>& vName);
105 
107  void clear() {m_vFunction.clear();}
108 
110  void sort();
111 
113  bool empty() const {return m_vFunction.empty();}
114 
116  size_t size() const {return m_vFunction.size();}
117 
119  const char* name(size_t i) const;
120 
122  std::string names() const;
123 
125  size_t operator[](size_t i) const {return unique_id(i);}
126 
128  size_t unique_id(size_t i) const
129  {
130  UG_ASSERT(i < size(), "Invalid function access");
131  return m_vFunction[i];
132  }
133 
135 
139  int dim(size_t i) const;
140 
142 
150  int dim() const;
151 
154  LFEID local_finite_element_id(size_t i) const;
155  LFEID lfeid(size_t i) const;
157 
159  bool contains(size_t uniqueID) const;
160 
162  bool contains(const FunctionGroup& fctGroup) const;
163 
165  size_t local_index(size_t uniqueID) const;
166 
167  protected:
169  bool is_init() const {return m_spFunctionPattern.valid();}
170 
171  protected:
174 
176  std::vector<size_t> m_vFunction;
177 };
178 
180 
186 {
187  public:
189  void clear() {m_vMapping.clear();}
190 
192  void push_back(size_t indexTo){m_vMapping.push_back(indexTo);}
193 
195  size_t num_fct() const {return m_vMapping.size();}
196 
198  size_t operator[](size_t i) const
199  {
200  UG_ASSERT(i < num_fct(), "Invalid index.\n");
201  return m_vMapping[i];
202  }
203 
204  protected:
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 std::ostream& operator<< (std::ostream& outStream, const ug::FunctionGroup& grp)
225 {
226  outStream << '[';
227  for(size_t i = 0; i < grp.size(); ++i)
228  {
229  outStream << grp[i];
230  if(i != grp.size()-1) outStream << ',';
231  }
232  outStream << ']';
233  return outStream;
234 }
235 
236 } // end namespace ug
237 
238 #endif /*__H__UG__LIB_DISC__COMMON__FUNCTION_GROUP__ */
Definition: smart_pointer.h:296
Definition: function_group.h:52
size_t local_index(size_t uniqueID) const
return index in Function group for a function
Definition: function_group.cpp:302
FunctionGroup()
Default Constructor.
Definition: function_group.cpp:43
bool is_init() const
returns if FunctionGroup is ready for use
Definition: function_group.h:169
void remove(const std::string &name)
removes function with a given name from this group
ConstSmartPtr< FunctionPattern > function_pattern() const
get underlying function pattern
Definition: function_group.h:73
int dim() const
common dimension of all functions
Definition: function_group.cpp:259
LFEID local_finite_element_id(size_t i) const
Definition: function_group.cpp:231
const char * name(size_t i) const
returns the name of a function
Definition: function_group.cpp:205
size_t operator[](size_t i) const
returns unique function id of a function
Definition: function_group.h:125
bool empty() const
returns if function group is empty
Definition: function_group.h:113
bool contains(size_t uniqueID) const
returns true if unique id is contained in this group
Definition: function_group.cpp:279
size_t unique_id(size_t i) const
returns unique function id of a function
Definition: function_group.h:128
LFEID lfeid(size_t i) const
Definition: function_group.cpp:243
void remove(size_t fct)
removes a function by id from this group
Definition: function_group.cpp:159
void add(size_t fct)
adds a function by id to this group
Definition: function_group.cpp:79
size_t size() const
number of functions in this group
Definition: function_group.h:116
void remove(const std::vector< std::string > &vName)
removes functions with a given names from this group
void add_all()
selects all subsets in the order of the underlying pattern
Definition: function_group.cpp:145
std::string names() const
returns the comma-separted names of all functions
Definition: function_group.cpp:217
ConstSmartPtr< FunctionPattern > m_spFunctionPattern
underlying function pattern
Definition: function_group.h:173
std::vector< size_t > m_vFunction
vector holding all selected unique function ids
Definition: function_group.h:176
void add(const std::string &name)
adds function with a given name to this group
void clear()
clear all subsets
Definition: function_group.h:107
void sort()
sorts the selected functions by increasing unique id
Definition: function_group.cpp:154
void set_function_pattern(ConstSmartPtr< FunctionPattern > spFuncPattern)
set underlying function pattern
Definition: function_group.cpp:72
void add(const std::vector< std::string > &name)
adds functions with a given names to this group
describes a mapping between two local index sets
Definition: function_group.h:186
void push_back(size_t indexTo)
adds a mapping between indexFrom and indexTo
Definition: function_group.h:192
size_t num_fct() const
returns the number of indices that are mapped
Definition: function_group.h:195
size_t operator[](size_t i) const
returns the mapped index
Definition: function_group.h:198
void clear()
removes all connections
Definition: function_group.h:189
std::vector< size_t > m_vMapping
vector holding the mapped indices
Definition: function_group.h:206
Identifier for Local Finite Elements.
Definition: local_finite_element_id.h:98
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition: math_matrix.cpp:38
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
the ug namespace