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__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"
40 : #include "common/util/string_util.h"
41 : #include "lib_grid/tools/subset_handler_interface.h"
42 : #include "lib_grid/tools/subset_group.h"
43 : #include "lib_grid/algorithms/subset_dim_util.h"
44 : #include "lib_disc/local_finite_element/local_finite_element_id.h"
45 :
46 : namespace ug{
47 :
48 : // predeclaration
49 : class FunctionGroup;
50 :
51 : /// Describes the setup of discrete functions on a SubsetHandler
52 : /**
53 : * A Function Pattern is used to describe the setup for discrete functions on
54 : * a domain. Therefore, it has the underlying SubsetHandler of the Domain.
55 : * The functions (sometimes also called grid functions) are defined with respect
56 : * to the subsets: A function can 'live' on parts of the subsets as well as on
57 : * the whole domain.
58 : */
59 : class FunctionPattern
60 : {
61 : public:
62 : /// Default Constructor
63 0 : FunctionPattern(ConstSmartPtr<ISubsetHandler> spSH) :
64 0 : m_bLocked(false), m_spSH(spSH)
65 0 : {clear();}
66 :
67 : /// sets new subsets handler
68 : void set_subset_handler(ConstSmartPtr<ISubsetHandler> spSH);
69 :
70 : /// get underlying subset handler
71 : ConstSmartPtr<ISubsetHandler> subset_handler() const {return m_spSH;}
72 :
73 : /// add single solutions of LocalShapeFunctionSetID to the entire domain
74 : /**
75 : * \param[in] name name(s) of single solution (comma separated)
76 : * \param[in] id Shape Function set id
77 : * \param[in] dim Dimension (optional)
78 : */
79 : void add(const std::vector<std::string>& vName, LFEID id);
80 :
81 : /// add single solutions of LocalShapeFunctionSetID to selected subsets
82 : /**
83 : * \param[in] name name(s) of single solution (comma separated)
84 : * \param[in] id Shape Function set id
85 : * \param[in] subsets Subsets separated by ','
86 : * \param[in] dim Dimension
87 : */
88 : void add(const std::vector<std::string>& vName, LFEID id,
89 : const std::vector<std::string>& vSubset);
90 :
91 : private:
92 : /// add single solutions of LocalShapeFunctionSetID to selected subsets
93 : /**
94 : * \param[in] name name(s) of single solution (comma separated)
95 : * \param[in] id Shape Function set id
96 : * \param[in] SubsetIndices SubsetGroup, where solution lives
97 : * \param[in] dim Dimension
98 : */
99 : void add(const std::vector<std::string>& vName, LFEID id, const SubsetGroup& ssGrp);
100 :
101 : public:
102 : /// lock pattern (i.e. can not be changed then)
103 0 : void lock() {m_bLocked = true;}
104 :
105 : /// returns if pattern is locked
106 0 : bool is_locked() const {return m_bLocked;}
107 :
108 : /// clear all functions
109 0 : void clear()
110 : {
111 0 : if(is_locked()) UG_THROW("Pattern locked.");
112 : m_vFunction.clear();
113 0 : }
114 :
115 : /// number of subsets
116 : int num_subsets() const {return m_spSH->num_subsets();}
117 :
118 : /// returns a subset group consisting of the subsets specified by their names
119 0 : SubsetGroup subset_grp_by_name(const char* names) const
120 : {
121 0 : return SubsetGroup(subset_handler(), TokenizeString(names));
122 : }
123 :
124 : /// returns a subset group consisting of all the subsets in the domain except for the specified ones
125 0 : SubsetGroup all_subsets_grp_except_for(const char* names) const
126 : {
127 0 : SubsetGroup subset_grp(subset_handler());
128 0 : subset_grp.add_all();
129 0 : subset_grp.remove(TokenizeString(names));
130 0 : return subset_grp;
131 : }
132 :
133 : /// returns the subset id
134 : int subset_id_by_name(const char* name) const;
135 :
136 : /// dimension of subset
137 0 : int dim_subset(int si) const {return DimensionOfSubset(*m_spSH, si);}
138 :
139 : /// returns the name of a subset
140 0 : const char* subset_name(int si) const {return m_spSH->subset_info(si).name.c_str();}
141 :
142 : /// number of discrete functions this dof distributor handles
143 : size_t num_fct() const {return m_vFunction.size();}
144 :
145 : /// number of discrete functions on a subset
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 :
156 : /// returns the trial space of a discrete function
157 : /// \{
158 : const LFEID& local_finite_element_id(size_t fct) const
159 : {
160 : UG_ASSERT(fct < num_fct(), "Invalid index.");
161 0 : return m_vFunction[fct].id;
162 : }
163 : const LFEID& lfeid(size_t fct) const {return local_finite_element_id(fct);}
164 : /// \}
165 :
166 : /// returns the name of a discrete function
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 :
173 : /// returns the names of a discrete function
174 0 : std::vector<std::string> names() const
175 : {
176 0 : std::vector<std::string> vName(num_fct());
177 0 : for(size_t fct = 0; fct < vName.size(); ++fct)
178 : vName[fct] = name(fct);
179 0 : return vName;
180 0 : }
181 :
182 : /// returns function id of the loc_fct's function on subset si
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 :
193 : /// returns the function id if function with given name found in pattern, exception else
194 : size_t fct_id_by_name(const char* name) const;
195 :
196 : /// returns the dimension in which solution lives
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 :
203 : /// returns true if the discrete function nr_fct is defined on subset si
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 :
210 : /// returns true if the discrete function nr_fct is defined on all subsets
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 :
217 : /// virtual destructor
218 0 : virtual ~FunctionPattern() {}
219 :
220 : protected:
221 : /// internal structure to hold all functions
222 : struct Function
223 : {
224 0 : Function(const char* name_, LFEID id_, bool everywhere_,
225 : const SubsetGroup& subsetIndices_)
226 0 : : name(name_), id(id_),
227 0 : everywhere(everywhere_), subsetIndices(subsetIndices_){};
228 :
229 : std::string name;
230 : LFEID id;
231 : bool everywhere;
232 : SubsetGroup subsetIndices;
233 :
234 : bool is_def_in_subset(int si) const
235 : {
236 0 : if(everywhere) return true;
237 0 : if(subsetIndices.contains(si)) return true;
238 : return false;
239 : }
240 :
241 0 : 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
249 : ConstSmartPtr<ISubsetHandler> m_spSH;
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__ */
|