ug4
function_pattern.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__DOF_MANAGER__FUNCTION_PATTERN__
34 #define __H__UG__LIB_DISC__DOF_MANAGER__FUNCTION_PATTERN__
35 
36 #include <vector>
37 #include <string>
38 
39 #include "common/common.h"
45 
46 namespace ug{
47 
48 // predeclaration
49 class FunctionGroup;
50 
52 
60 {
61  public:
64  m_bLocked(false), m_spSH(spSH)
65  {clear();}
66 
69 
72 
74 
79  void add(const std::vector<std::string>& vName, LFEID id);
80 
82 
88  void add(const std::vector<std::string>& vName, LFEID id,
89  const std::vector<std::string>& vSubset);
90 
91  private:
93 
99  void add(const std::vector<std::string>& vName, LFEID id, const SubsetGroup& ssGrp);
100 
101  public:
103  void lock() {m_bLocked = true;}
104 
106  bool is_locked() const {return m_bLocked;}
107 
109  void clear()
110  {
111  if(is_locked()) UG_THROW("Pattern locked.");
112  m_vFunction.clear();
113  }
114 
116  int num_subsets() const {return m_spSH->num_subsets();}
117 
120  {
122  }
123 
126  {
127  SubsetGroup subset_grp(subset_handler());
128  subset_grp.add_all();
129  subset_grp.remove(TokenizeString(names));
130  return subset_grp;
131  }
132 
134  int subset_id_by_name(const char* name) const;
135 
137  int dim_subset(int si) const {return DimensionOfSubset(*m_spSH, si);}
138 
140  const char* subset_name(int si) const {return m_spSH->subset_info(si).name.c_str();}
141 
143  size_t num_fct() const {return m_vFunction.size();}
144 
146  size_t num_fct(int si) const
147  {
148  size_t num = 0;
149  for(size_t fct = 0; fct < num_fct(); ++fct)
150  {
151  if(m_vFunction[fct].is_def_in_subset(si)) num++;
152  }
153  return num;
154  }
155 
158  const LFEID& local_finite_element_id(size_t fct) const
159  {
160  UG_ASSERT(fct < num_fct(), "Invalid index.");
161  return m_vFunction[fct].id;
162  }
163  const LFEID& lfeid(size_t fct) const {return local_finite_element_id(fct);}
165 
167  const char* name(size_t fct) const
168  {
169  UG_ASSERT(fct < num_fct(), "Invalid index.");
170  return m_vFunction[fct].name.c_str();
171  }
172 
174  std::vector<std::string> names() const
175  {
176  std::vector<std::string> vName(num_fct());
177  for(size_t fct = 0; fct < vName.size(); ++fct)
178  vName[fct] = name(fct);
179  return vName;
180  }
181 
183  size_t fct_id(size_t loc_fct, int si) const
184  {
185  size_t fct = 0;
186  for(size_t i = 0; i < loc_fct; ++i)
187  {
188  if(is_def_in_subset(fct, si)) fct++;
189  }
190  return fct;
191  }
192 
194  size_t fct_id_by_name(const char* name) const;
195 
197  int dim(size_t fct) const
198  {
199  UG_ASSERT(fct < num_fct(), "Invalid index.");
200  return m_vFunction[fct].id.dim();
201  }
202 
204  bool is_def_in_subset(size_t fct, int si) const
205  {
206  UG_ASSERT(fct < num_fct(), "Invalid index.");
207  return m_vFunction[fct].is_def_in_subset(si);
208  }
209 
211  bool is_def_everywhere(size_t fct) const
212  {
213  UG_ASSERT(fct < num_fct(), "Invalid index.");
214  return m_vFunction[fct].is_def_everywhere();
215  }
216 
218  virtual ~FunctionPattern() {}
219 
220  protected:
222  struct Function
223  {
224  Function(const char* name_, LFEID id_, bool everywhere_,
225  const SubsetGroup& subsetIndices_)
226  : name(name_), id(id_),
227  everywhere(everywhere_), subsetIndices(subsetIndices_){};
228 
229  std::string name;
233 
234  bool is_def_in_subset(int si) const
235  {
236  if(everywhere) return true;
237  if(subsetIndices.contains(si)) return true;
238  return false;
239  }
240 
241  bool is_def_everywhere() const {return everywhere;}
242  };
243 
244  protected:
245  // flag if pattern is fixed
246  bool m_bLocked;
247 
248  // underlying subset handler
250 
251  // informations about Functions
252  std::vector<Function> m_vFunction;
253 };
254 
255 } // end namespace ug
256 
257 #endif /* __H__UG__LIB_DISC__DOF_MANAGER__FUNCTION_PATTERN__ */
Definition: smart_pointer.h:296
Describes the setup of discrete functions on a SubsetHandler.
Definition: function_pattern.h:60
void set_subset_handler(ConstSmartPtr< ISubsetHandler > spSH)
sets new subsets handler
Definition: function_pattern.cpp:44
const LFEID & lfeid(size_t fct) const
Definition: function_pattern.h:163
const LFEID & local_finite_element_id(size_t fct) const
Definition: function_pattern.h:158
size_t fct_id(size_t loc_fct, int si) const
returns function id of the loc_fct's function on subset si
Definition: function_pattern.h:183
std::vector< std::string > names() const
returns the names of a discrete function
Definition: function_pattern.h:174
ConstSmartPtr< ISubsetHandler > m_spSH
Definition: function_pattern.h:249
void add(const std::vector< std::string > &vName, LFEID id)
add single solutions of LocalShapeFunctionSetID to the entire domain
Definition: function_pattern.cpp:53
bool is_def_everywhere(size_t fct) const
returns true if the discrete function nr_fct is defined on all subsets
Definition: function_pattern.h:211
size_t num_fct(int si) const
number of discrete functions on a subset
Definition: function_pattern.h:146
const char * name(size_t fct) const
returns the name of a discrete function
Definition: function_pattern.h:167
int dim_subset(int si) const
dimension of subset
Definition: function_pattern.h:137
size_t num_fct() const
number of discrete functions this dof distributor handles
Definition: function_pattern.h:143
std::vector< Function > m_vFunction
Definition: function_pattern.h:252
int dim(size_t fct) const
returns the dimension in which solution lives
Definition: function_pattern.h:197
ConstSmartPtr< ISubsetHandler > subset_handler() const
get underlying subset handler
Definition: function_pattern.h:71
size_t fct_id_by_name(const char *name) const
returns the function id if function with given name found in pattern, exception else
Definition: function_pattern.cpp:128
void lock()
lock pattern (i.e. can not be changed then)
Definition: function_pattern.h:103
bool m_bLocked
Definition: function_pattern.h:246
SubsetGroup subset_grp_by_name(const char *names) const
returns a subset group consisting of the subsets specified by their names
Definition: function_pattern.h:119
FunctionPattern(ConstSmartPtr< ISubsetHandler > spSH)
Default Constructor.
Definition: function_pattern.h:63
void clear()
clear all functions
Definition: function_pattern.h:109
int subset_id_by_name(const char *name) const
returns the subset id
Definition: function_pattern.cpp:139
const char * subset_name(int si) const
returns the name of a subset
Definition: function_pattern.h:140
SubsetGroup all_subsets_grp_except_for(const char *names) const
returns a subset group consisting of all the subsets in the domain except for the specified ones
Definition: function_pattern.h:125
bool is_def_in_subset(size_t fct, int si) const
returns true if the discrete function nr_fct is defined on subset si
Definition: function_pattern.h:204
int num_subsets() const
number of subsets
Definition: function_pattern.h:116
bool is_locked() const
returns if pattern is locked
Definition: function_pattern.h:106
virtual ~FunctionPattern()
virtual destructor
Definition: function_pattern.h:218
Identifier for Local Finite Elements.
Definition: local_finite_element_id.h:98
Group of subsets.
Definition: subset_group.h:51
void add_all()
select all subsets of underlying subset handler
Definition: subset_group.cpp:133
void remove(int si)
removes a subset from this group
Definition: subset_group.cpp:142
bool contains(int si) const
returns true if subset is contained in this group
Definition: subset_group.cpp:272
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
the ug namespace
void TokenizeString(const string &str, vector< string > &vToken, const char delimiter)
Definition: string_util.cpp:56
int DimensionOfSubset(const ISubsetHandler &sh, int si)
returns the current dimension of the subset
Definition: subset_dim_util.cpp:89
internal structure to hold all functions
Definition: function_pattern.h:223
LFEID id
Definition: function_pattern.h:230
Function(const char *name_, LFEID id_, bool everywhere_, const SubsetGroup &subsetIndices_)
Definition: function_pattern.h:224
bool is_def_everywhere() const
Definition: function_pattern.h:241
SubsetGroup subsetIndices
Definition: function_pattern.h:232
bool is_def_in_subset(int si) const
Definition: function_pattern.h:234
bool everywhere
Definition: function_pattern.h:231
std::string name
Definition: function_pattern.h:227